Jump to content

Featured Replies

Posted

I'm trying to upgrade my old application that had some gallery hooks. I'm trying to turning the old hooks into Listeners, but not all events are firing as expected.

I created a content listener for the class \IPS\gallery\Album\Item, but only "onDelete" and "onView" are firing, why onBeforeCreateOrEdit isn't'?

What I'm expecting is to see this log to appear the moment I create a new album.

class albumItemHook extends ContentListenerType
{

    public static string $class = \IPS\gallery\Album\Item::class;

     public function onBeforeCreateOrEdit( ContentClass $object, array $values, bool $new = FALSE ): void
     {
         Log::log( 'before' );
     }
}

Solved by Esther E.

Go to solution

When the album is created (or modified), it uses the Album object (which is a node), rather than the Album Item object. You'll need to work with a NodeListener instead.

  • Author

But the NodeListener class only has the "onDelete" method as available event, or am I missing something?

/**
 * @method onDelete( Model $node ) : void
 */
class NodeListenerType extends ListenerType
{
    /**
     * @brief  Determine whether this listener requires an explicitly set class
     *           Example: MemberListeners are always for \IPS\Member, but ContentListeners
     *           will require a specific class.
     * @var bool
     */
    public static bool $requiresClassDeclaration = TRUE;

    /**
     * Defines the classes that are supported by each Listener Type
     * When a new Listener Type is created, we must specify which
     * classes are valid (e.g. \IPS\Content, \IPS\Member).
     *
     * @var array
     */
    protected static array $supportedBaseClasses = array(
       Model::class
    );
}
  • Solution

You're correct, sorry. Try UINode extension, that should have what you're looking for.

  • Author

Yes! That works now! Just one last question if I may: how do I add a new field in the modal to create a new album? all the elements returned by my "formElements" function appear only in the "edit" modal.

3 hours ago, Worgage said:

Yes! That works now! Just one last question if I may: how do I add a new field in the modal to create a new album? all the elements returned by my "formElements" function appear only in the "edit" modal.

Yes.... I don't know if I would call that a bug, more like an oversight. The album creation form doesn't really follow the same logic, and it's not a straightforward fix. I'll log it, but it definitely won't be in the next release (possibly 5.0.4).

  • Author

Alright, thank you. I guess I'll just manually edit the template for now

8 minutes ago, Worgage said:

Alright, thank you. I guess I'll just manually edit the template for now

I wouldn't advise this. You technically can't manually edit the template - any changes you make wouldn't carry over to a live system, and they would be overwritten with the next update.

Recently Browsing 0

  • No registered users viewing this page.