According to [urlhttps://xenforo.com/community/help/resource-standards/]resource standards rule #20[/url] code event listeners should be used instead of full class extensions wheever possible.
However, this rule does not stete exactly how they should be used.
For example, if an Add-on requires modifying Post and Attachment structures, several approaches could be used:
However, this rule does not stete exactly how they should be used.
For example, if an Add-on requires modifying Post and Attachment structures, several approaches could be used:
- One code event listener on entity_structure without a hint
PHP:public static function entityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure) { switch ($structure->shortName) { case 'XF:Post': // do smth. break; case 'XF:Attachment': // do smth. break; } }
- Two code event listeners, each with an appropriate hint but still just one callback like in 1)
- Two code event listeners, each with an appropriate hint and a distinct callback
PHP:public static function entityStructureXFPost(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure) { // do smth. } public static function entityStructureXFAttachment(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure) { // do smth. }