"on Page load" Hook

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    I am using latest version. Not sure if that is available for version 5.5.6

  • mohnewald
    replied
    Originally posted by mohnewald

    Thank you. I cannot find the sub directory Espo\Custom\Reources\metadata\recordDefs\ , do I just need to create this directory and the Connection.json?
    We tried what you said and cleared the cache, but the script is not triggered. We are on Espo version: 5.5.6

    Leave a comment:


  • rabii
    commented on 's reply
    All of the should go into custom main directory (if you can't find find recordDefs folder you just need to create one)

  • mohnewald
    replied
    Originally posted by rabii
    Given your example i assume your custom entity is called connection, try the steps below:

    1 - Create your php file under Espo\Custom\Hooks\Connection\BeforeReadConnectionC heck.php

    PHP Code:
    <?php

    namespace Espo\Custom\Hooks\Connection;

    use 
    Espo\Core\Record\Hook\ReadHook;
    use 
    Espo\Core\Record\ReadParams;

    use 
    Espo\ORM\Entity;


    /**
    * @implements ReadHook<\Espo\Custom\Entities\Connection>
    */
    class BeforeReadConnectionCheck implements ReadHook
    {
    public function 
    process(Entity $entityReadParams $params): void
    {

    $entity->set([
    'status' => 'Read',
    'description' => 'Status has been set as Read via ReadHook'
    ]);

    }
    }

    2 - map the file on the recordDefs under Espo\Custom\Reources\metadata\recordDefs\Connectio n.json

    PHP Code:
    {
    "beforeReadHookClassNameList": [
    "Espo\\Custom\\Hooks\\Connection\\BeforeReadConnectionCheck"
    ]


    This should work fine, tested.
    Thank you. I cannot find the sub directory Espo\Custom\Reources\metadata\recordDefs\ , do I just need to create this directory and the Connection.json?

    Leave a comment:


  • rabii
    replied
    Given your example i assume your custom entity is called connection, try the steps below:

    1 - Create your php file under Espo\Custom\Hooks\Connection\BeforeReadConnectionC heck.php

    PHP Code:
    <?php

    namespace Espo\Custom\Hooks\Connection;

    use 
    Espo\Core\Record\Hook\ReadHook;
    use 
    Espo\Core\Record\ReadParams;

    use 
    Espo\ORM\Entity;


    /**
     * @implements ReadHook<\Espo\Custom\Entities\Connection>
     */
    class BeforeReadConnectionCheck implements ReadHook
    {
        public function 
    process(Entity $entityReadParams $params): void
        
    {

            
    $entity->set([
                
    'status' => 'Read',
                
    'description' => 'Status has been set as Read via ReadHook'
            
    ]);

        }
    }

    2 - map the file on the recordDefs under Espo\Custom\Reources\metadata\recordDefs\Connectio n.json

    PHP Code:
    {
        
    "beforeReadHookClassNameList": [
            
    "Espo\\Custom\\Hooks\\Connection\\BeforeReadConnectionCheck"
        
    ]


    This should work fine, tested.

    Leave a comment:


  • mohnewald
    replied
    Originally posted by yuri
    Hi,

    You can use the before-read record hook: https://docs.espocrm.com/development...kclassnamelist. It executes on read API call.

    Thanks for the suggestion. I've tried some sample code:

    https://pastebin.com/1RBR9GrW

    But it does not seem to work. Is there any working implementation that you can share?

    Leave a comment:


  • yuri
    replied
    Hi,

    You can use the before-read record hook: https://docs.espocrm.com/development...kclassnamelist. It executes on read API call.

    Leave a comment:


  • mohnewald
    started a topic "on Page load" Hook

    "on Page load" Hook

    Hi,

    is there any possiblity to Hook into the page load from PHP?

    I'd like to set certain fields when the user loads a certain Object.

    JavaScript is not an option, it must be PHP.
Working...