Re-purposing the Blog plugin in

This is a seriously noob question... but I am a serious noob with next to no programming experience. However, I wanted to put up a site... so I dove in.

Here's my challenge:  I am trying to re purpose the blog plugin that comes with Elgg.  I've used it as a base for a new plugin, trimmed some features out I don't need and renamed some items.  However, I wanted to add some additional fields to the input form and use them later in different views.  I've successfully added the fields to the new form.

My question:  Where and how do I save the new variables and use them on other views within the plugins.  (e.g. I've added an author field that I want to display on other views)

What I've done to date:  I have scoured the documentation, the forums, tried to follow the various tutorials, and examined the code in a number of plugins trying to figure out what I just don't get.  I'm sure the answer is disgustingly simple and obvious... but not to me.  I've looked at how the blog plugin is saving variables such as "Title" but when I mimic the code with a new field like "Author" and later try to use it just like "Title" I get nowhere.

As I said, I'm sure this is a super simple answer, and I'm quite sure I'm missing the snake right in front of me, but with absolutely zero programming experience... I just don't know what I'm missing.

Thanks in advance for the help.



  • Brrrrr..

    What did you write in here?

    Please, just One question==One answer..


  • The general rule is that any database write operations should happen in actions, as they offer CSRF protection. So, look in the /actions folder for examples.

    Adding metadata to entities is straightforward:

    $blog = get_entity($blog_guid);
    $blog->author = 'Author Name';
    echo $blog->author;

    Certain entity attributes (e.g. title, description, owner_guid, container_guid, access_id) require you to call ElggEntity::save() to propagate the changes:

    $blog->title = 'New Title';
    $blog->access_id = ACCESS_PRIVATE;

    Creating new entities is straightforward as well:

    $blog = new ElggObject();
    $blog->subtype = 'blog';
    $blog->title = 'Wonderful Blog';
    $blog->description = 'A very long lorem ipsum to you';
    $blog->access_id = ACCESS_FRIENDS;
    $blog->author = 'Some Cool Dude';
    $blog->foo = 'bar';
    $guid = $blog->save();
    echo "New blog with $guid saved";
    $blog->foo = 'bar2'; // you can change the metadata as well


  • Thank you Ismayil!  This was enough to finally make things click in my head and make sense.  I was able to do what I set out to.  Thank again. Cheers.

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