Question about class instantiation

Sorry if this is in the wrong group.  The drop down select is showing only numbers on my ipad. 


I recently encountered a couple of  things and wondered if anyone has any insight that can help understand if this is normal in elgg.

1st question :  I created the class for my main object in my announcement plugin. My preference in classes is to have the class coded to set up some of the properties when it instantiates .  In this case i had it  setting the access to public and the subtype.  It all seemed to work, the entities saved and  looked correct in the database, 
in testing i created several objects Using my form  and it saved them to the database.  Then i moved on to creating the view. Idiscovered that the  call to get the entity created an empty object. An SQL query in phpmyadmin did  pull up a record from the database using the relevant guid.

When i tried to pull up  any of my Announcement  entities in entity explorer i received a fatal error. The error referred to relationships, which i did  not have at the time. 

After several curse words i moved the code to set the access to public and the subtype to the action file and all is well.  

I have  scratched my head near bald trying to see why this would cause a problem.  Anyone have any insight?

My second question involves my attempt to extend the  ElggFile class.  I could not find an example of this being done but i can tell you it didn’t  work as i tried it. Wondering if anyone has done this or seen it done anywhere?



  • Offtopic:

    I strongly recommend that members stop creating discussions without specifying which Elgg version they are using

    Maybe it's a time to rewrite Community (scheduled for me now).

    About your Qs:

    Anyone have any insight?

    You're use Announcement plugin, so your issues could be related with it.

    Why you can't ask about it on the plugin's page?

    Also, all your words/text here are nothing.

    As i said in my previous replies - "No code No Answers."

    Use Gist, Pastepin, Nulled, similar services, or just <code> button in the Visual editor here to post your code.

    My second question

    What you want to do? Extend it? So do it!

    I don't know what you want but you can try this:

    1. Discussed already.
    2. Look at this QA also.

  • As I said right at the beginning - the drop-down on the iPad shows only numbers instead of the names of the groups. Apparently I choose the wrong number.  My bad. I  was killing some time at the car dealer where I only had my ipad.   

    That said This does seem like the right forum or rather the right forum name.  I  assumed that a beginner's forum would be suitable for beginners' questions.   

    As to your particulars, I use version 3.3.5 on Php 7.3  served by Nginx. 


    the code I used was this   

    protected function initializeAttributes() {
    $this->attributes["subtype"] = "Announcement";
    $this ->access_id = ACCESS_PUBLIC;

    Which as I said seemed to work okay. looked correct in the database but cause a fatal error in entity explorer I changed that to the following in my action file. 

    $announcement->subtype = "Announcement";
    $announcement ->access_id = ACCESS_PUBLIC;

    and all is well.  As I said I prefer to have the class instantiation handle this but that did not work and I wondered why

    At this point, after your reply, I don't even care to know why. I had hoped to learn something that I might carry forward, What I have learned instead is that we have vastly different ideas of what beginner means. I will simply continue to do it in a way that I consider "Wrong" and assume that is just the way Elgg works. 


    As for question 2. I thought I was clear that  I HAD extended ElggFile (or thought so anyway)  class but that it didn't work.   I got a series of errors   Again I thought this was a beginner's forum,  my bad.  But again it doesn't matter because I have moved on and did what I needed in another way.  As before I had hoped to learn something from someone else experience in this area. What I learned here is that the replies are often a glib as in an Apple forum.

    In the future, I will refrain from making queries. In the end, I may have to move on to a different solution. Which is too bad. Elgg seems like a powerful framework  and I like a good deal about it,  but good examples are hard to come by and clearly asking questions of those more sage in the subject is frowned upon 




  • I will simply continue to do it in a way that I consider "Wrong" and assume that is just the way Elgg works.

    Right, because elgg isn't CMS but framework aka CMF. You must be a developer to extend it.

    but good examples are hard to come by and clearly asking questions of those more sage in the subject is frowned upon

    Wrong, use Search on Community, Learn docs or References and you will not ask obvious questions.

    As said @ihayredinov - there's no longer a magic fairy that will fulfill all your wishes.

  • For the record the code I used to extend the ElggFile class is form the links that were posted  



    use ElggFile;
    class MotionData extends ElggFile {
        const SUBTYPE = 'Announcement';
        public function initializeAttributes() {
          $this->attributes['subtype'] = self::SUBTYPE;
       public function getDisplayName() {
          $name = parent::getDisplayName();
          if (!$name) {
            $name = elgg_echo('untitled');
         return $name;
  • You can't do it in Elgg 3.

    Just add this in elgg-plugin.php of your custom plugin:

    'entities' => [
       'file' => [
             'type' => 'object',
             'subtype' => 'announcement', //use lowercase only
             'class' => \YourPluginPlace\MotionData::class,
             'searchable' => true,
    Or don't use custom class, just replace subtype.
    Now add in your MotionData class just _set function or do stuff
  •  At no point in my post did I ask you to write code for me, or even correct it. I simply asked for insight as to why something did not work as I would expect it to. I did not find the answer in the community or I would not have wasted time asking. Yes, I know full well that this is not a CMS. Although I clearly do not have your near-divine level skillset I have been developing for more than a decade. I am however new to ELGG.  

    No one is expecting magic fairies, as for me I would settle for forum moderation by someone who is not an arrogant prick.  We all bow down to your vastly superior knowledge, you have nothing to prove.  But if you feel the need to prove anything try proving that you can actually teach. 

    The idea of a beginner's forum would seem to be to help people understand better. Pointing someone toward the docs as part of a complete answer is acceptable but chastising them for asking helps no one.  In fact, I prefer that a person say  "Oh, and by the way, for future reference this is where you might find this answer".  Contrast that with your approach.  Why have a forum if people are made to feel as though asking a question is the worst possible thing they could do. 

    Perhaps your attention is better spent focusing on the forums where people have your superior programming skills and experience.  Speaking only for myself I get the sense that us doofus low brow idiots would do better in struggling to answer each others questions than coming here to learn how stupid we obviously are. I say this a teacher, computer technician, a developer, and as a person who actually answers questions on several technical and non-technical topics all the time without feeling the need to berate. Perhaps focus on programming, you are clearly good at it and leave the question answering to those who don't find beginners offensive   




  • Please don't be offended by what I'm saying.

    It's just that many people ask questions without any details: there's no code. not snippets etc.

    And these people are demanding an immediate solution to the problems they've just invented.

    But I try to remind you to explain what you want every time.

    It's odd.

    There's a lot of people.

    I'm not contributed with Elgg organization/foundation.

    I'm a big Elgg fan, developer.

    And I answer questions on my own initiative.

    This is my contribution to the great Elgg.

    So don't judge strictly :)

  • If you'll insult me (and you're doing it now), you'll be banned here.

  • I simply asked for insight as to why something did not work as I would expect it to. 

    Where's that? Before I ask you for the code?

    Anyway, try to find a solution elsewhere.

    I'll never give you any help here.

  • @Shannon Hanson

    Your initializeAttributes() function seams correct to me. Also your ElggFile extension looks OK.

    Have you registered your custom class for the subtype otherwise it won't be picked up when you load the entity from the database.

    Also your classes are located in the 'classes' directory of you plugin? Either directly or in a PSR-4 namespace.

    I don't see what could explain the fatal error in the entity explorer. Could you maybe tell a bit more about the exception?

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking