Hook Class Name Uniqueness

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murray99
    Member
    • Jan 2017
    • 57

    Hook Class Name Uniqueness

    I have written a few Hooks and came across something which may be by design or a bug, I'm not sure.

    I have 2 hooks in 2 separate Modules

    Modules\Module1\Hooks\Account\AccountHooks.php with a beforeSave
    Modules\Module2\Hooks\Account\AccountHooks.php with a beforeSave

    When the hooks.php cache is built only one of the 2 hooks appears. If I rename the file and content of Module 2 to AccountHooks2.php then the hook is correctly generated in the cache.

    So... it appears that the class name of the hook for a given hook type must be unique in order to get cached properly.

    My general naming convention was to call hook files {entityType}\ {entityName}Hooks.php, but I have now found that a couple of hooks are clashing.

    Is this by design or am I doing something wrong?
    Thanks
  • yuri
    Member
    • Mar 2014
    • 8453

    #2
    It's by design, how it was implemented 10 years ago and can't be easily changed as it would be a breaking change.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • rabii
      rabii commented
      Editing a comment
      is it fine to have many hooks for one entity ? is that a good way to do it or should some of the logic be written somewhere else like in entity? i just would love to keep my code as clean as possible and also want to keep it consist with espocrm coding style.

    • item
      item commented
      Editing a comment
      Hi Rabii,
      of course Yuri have the best response ..

      i have just looked :
      EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.


      so there are 2 afterSave in 2 different file... so i think, it's too for maintain/debug easyly.
      If no WebSocketSubmit, then look/debug the file WebSocketSubmit
      I have learned one think more today

    • rabii
      rabii commented
      Editing a comment
      thanks item i have a heavy usage of hooks in my app so i refactored most of the hooks logic into the entity class and just wanted to confirm if that was the right decision.
  • murray99
    Member
    • Jan 2017
    • 57

    #3
    Thanks Yuri.

    Comment

    Working...