How to extend actions/forms without overriding core files?

With 3.x out now, I'm brushing up on my Elgg on a lot of things. I'm looking at the blog's save.php in actions folder and it looks like it's still hard coded for specific variables. In order to add a custom field, you'd also have to override the blog's save.php in the form folder. Can't add a new metadata by extending the existing forms because you need the entity's GUID, which you won't get unless the entity is made first. This makes it hard for plugin devs.

TL;DR basically what the title says on this topic.

  • Just write your own 'blog/save' action/form. 

    In elgg-plugin.php add:

    return [
         'actions' => [
            'blog/save' => [],
        ],
    ];

    I can't see any problem with it

  • I'm trying to avoid overriding it but after further studying the docs and core codes, I've managed to add a custom metadata on new blog post creation. The key is to use event handlers, I skimmed through this in the docs but I had tunnel vision and focused on physical files, rather than using hooks.

    elgg_register_event_handler('publish', 'object', 'myplugin_hook');
    
    function myplugin_hook($event, $object_type, $object) {
        if ($object_type = 'blog') {
            $guid = $object->getGUID();
            $blog = get_entity($guid);
            $blog->new_meta_upon_creation = 'success';
        }
    }

    Case closed!