beforeRelate record hook options

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Firyo
    Senior Member
    • Jun 2022
    • 134

    beforeRelate record hook options

    Hi there,

    I'm currently refactoring my old Espo code in order to match the good standards and get rid of my deprecated code.
    I'm transforming my old "beforeRelate" functions (inside my Repositories) into record hooks (https://docs.espocrm.com/development...kclassnamelist).

    But, I did find there was no
    PHP Code:
    $options 
    
    parameter inside the
    PHP Code:
    public function process(Entity $entity, string $link, Entity $foreignEntity): void; 
    
    function inside the
    PHP Code:
    application/Espo/Core/Record/Hook/LinkHook.php 
    
    interface.

    How should I proceed in order to give optionnal parameters to my beforeRelate hooks ?

    Regards,
    Firyo.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Hello, It's a different hook. You need this: https://docs.espocrm.com/development/hooks/#interfaces

    But there's no beforeRelate, only after.
    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

    • Firyo
      Senior Member
      • Jun 2022
      • 134

      #3
      Hi Yuri,

      In my case I was using the
      PHP Code:
      $options 
      
      to do a check (and wheter or not) and throw an exception.
      So I guess the afterRelate hook won't be suited for this.

      Regards,
      Firyo.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        For throwing exceptions the Record BeforeRelate hook usually suits better. The fact that there's no BeforeRelate hook. Maybe worth reconsidering your approach.
        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

        • bandtank
          Active Community Member
          • Mar 2017
          • 379

          #5
          Originally posted by yuri
          Hello, It's a different hook. You need this: https://docs.espocrm.com/development/hooks/#interfaces

          But there's no beforeRelate, only after.
          Would it be possible to add beforeRelate? Or should I use beforeUpdateHookClassNameList?

          Comment

          • rabii
            Active Community Member
            • Jun 2016
            • 1250

            #6
            Hi bandtank,

            I think you could still use beforeLinkHookClassNameList to do the job if you want to check before a link is linked to an entity.

            I have used it in the paste and worked nicely.

            Thanks
            Rabii
            Web Dev

            Comment

            Working...