Announcement

Collapse
No announcement yet.

Help with Hook

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • yuri
    replied
    \Espo\Core\Hooks\Base has been deprecated for long. Not to be extended.

    Leave a comment:


  • telecastg
    commented on 's reply
    No worries, typos are the achilles heel of every coder :-)

    For future reference I spotted the error by reading this line from the error msg:
    "Call to undefined function Espo\Custom\Hooks\Location\arry_keys()"

  • jpennington
    replied
    telecastg Thank you! I am not much of a coder. Works great now

    Leave a comment:


  • telecastg
    replied
    Try array_keys instead of arry_keys

    Leave a comment:


  • jpennington
    started a topic Help with Hook

    Help with Hook

    I have been trying to get the following Hook to work:

    PHP Code:
    <?php




    namespace Espo\Custom\Hooks\Location;

    use 
    Espo\Core\Hooks\Base;

    use 
    Espo\ORM\Entity;

    class 
    LocationAddressCorrect extends \Espo\Core\Hooks\Base

    {

    public static 
    $order 20;

    public function 
    afterSave(Entity $entity)

    {

    // list of words to correct with replacement

    $abvAddress = Array(

    'Township' => 'Twp',

    'Twp.' => 'Twp',

    'Road' => 'Rd',

    'Rd.' => 'Rd',

    'Private' => 'Pvt',

    'Pvt.' => 'Pvt',

    'Co.' => 'Co',

    'County Road' => 'CR',

    'County Rd' => 'CR',

    'Co Rd' => 'CR',

    'Co Road' => 'CR',

    'State Route' => 'SR',

    'State Rte' => 'Sr',

    'St Rte' => 'Sr',

    'Avenue' => 'Ave',

    'Parkway' => 'Pkwy',

    'Apartment' => 'Apt',

    'Apt.' => 'Apt',

    'Boulevard' => 'Blvd',

    'Blvd.' => 'Blvd',

    'Place' => 'Pl',

    'Pl.' => 'Pl',

    'Room' => 'Rm',

    'Rm.' => 'Rm',

    'Center' => 'Ctr',

    'Ctr.' => 'Ctr',

    'Plaza' => 'Plz',

    'Plz.' => 'Plz',

    'Suite' => 'Ste',

    'Ste.' => 'Ste',

    'Circle' => 'Cir',

    'Cir.' => 'Cir',

    'Ridge' => 'Rdg',

    'Rdg.' => 'Rdg',

    'Court' => 'Ct',

    'Ct.' => 'Ct',

    'North' => 'N',

    'Drive' => 'Dr',

    'Dr.' => 'Dr',

    'Square' => 'Sq',

    'Sq.' => 'Sq',

    'East' => 'E',

    'E.' => 'E',

    'Expressway' => 'Expy',

    'Street' => "st",

    'St.' => 'St',

    'South' => 'S',

    'S.' => 'S',

    'Heights' => 'Hts',

    'Hts.' => 'Hts',

    'Station' => 'Sta',

    'Sta.' => 'Sta',

    'West' => 'W',

    'W.' => 'W',

    'Highway' => 'Hwy',

    'Terrace' => 'Ter',

    'Ter.' => 'Ter',

    'Northeast' => 'Ne',

    'Ne.' => 'Ne',

    'Island' => 'Is',

    'Is.' => 'Is',

    'Trail' => 'Trl',

    'Northwest' => 'Nw',

    'Nw.' => 'Nw',

    'Junction' => 'Jct',

    'Jct.' => 'Jct',

    'Turnpike' => 'Tpke',

    'Tpke.' => 'Tpke',

    'Southeast' => 'Se',

    'Se.' => 'Se',

    'Lake' => 'Lk',

    'Lk.' => 'Lk',

    'Valley' => 'Vly',

    'Vly.' => 'Vly',

    'Southwest' => 'Sw',

    'Sw.' => 'Sw',

    'Lane' => 'Ln',

    'Ln.' => 'Ln',

    '.' => '',

    ',' => '',

    );

    $streetAddress $entity->get('locationOfInterestStreet');

    $streetAddressCorrect str_replace(arry_keys($abvAddress), $abvAddress$streetAddress);

    $correctedStreetAddress $streetAddressCorrect;

    $entity->set('locationOfInterestStreet'$correctedStreetAddress);

    }

    }
    However, I am getting the following error, which I do not understand because the code works as a simple script to make corrects to a string.

    [2021-01-23 10:25:57] Espo.ERROR: Slim Application Error Type: Error Code: 0 Message: Call to undefined function Espo\Custom\Hooks\Location\arry_keys() File: /var/www/espocrm/custom/Espo/Custom/Hooks/Location/LocationAddressCorrect.php Line: 101 Trace: #0 /var/www/espocrm/application/Espo/Core/HookManager.php(111): Espo\Custom\Hooks\Location\LocationAddressCorrect->afterSave() #1 /var/www/espocrm/application/Espo/Core/Repositories/Database.php(287): Espo\Core\HookManager->process() #2 /var/www/espocrm/application/Espo/ORM/Repository/RDBRepository.php(140): Espo\Core\Repositories\Database->afterSave() #3 /var/www/espocrm/application/Espo/Core/Repositories/Database.php(347): Espo\ORM\Repository\RDBRepository->save() #4 /var/www/espocrm/application/Espo/Services/Record.php(687): Espo\Core\Repositories\Database->save() #5 /var/www/espocrm/application/Espo/Services/Record.php(1145): Espo\Services\Record->storeEntity() #6 /var/www/espocrm/application/Espo/Core/Controllers/Record.php(93): Espo\Services\Record->create() #7 /var/www/espocrm/application/Espo/Core/ControllerManager.php(109): Espo\Core\Controllers\Record->actionCreate() #8 /var/www/espocrm/application/Espo/Core/Api/RouteProcessor.php(84): Espo\Core\ControllerManager->process() #9 /var/www/espocrm/application/Espo/Core/ApplicationRunners/Api.php(184): Espo\Core\Api\RouteProcessor->process() #10 /var/www/espocrm/application/Espo/Core/ApplicationRunners/Api.php(112): Espo\Core\ApplicationRunners\Api->processRequest() #11 /var/www/espocrm/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(43): Espo\Core\ApplicationRunners\Api->Espo\Core\ApplicationRunners\{closure}() #12 /var/www/espocrm/vendor/slim/slim/Slim/Routing/Route.php(381): Slim\Handlers\Strategies\RequestResponse->__invoke() #13 /var/www/espocrm/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\Route->handle() #14 /var/www/espocrm/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle() #15 /var/www/espocrm/vendor/slim/slim/Slim/Routing/Route.php(341): Slim\MiddlewareDispatcher->handle() #16 /var/www/espocrm/vendor/slim/slim/Slim/Routing/RouteRunner.php(84): Slim\Routing\Route->run() #17 /var/www/espocrm/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(60): Slim\Routing\RouteRunner->handle() #18 /var/www/espocrm/vendor/slim/slim/Slim/MiddlewareDispatcher.php(140): Slim\Middleware\RoutingMiddleware->process() #19 /var/www/espocrm/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(107): class@anonymous->handle() #20 /var/www/espocrm/vendor/slim/slim/Slim/MiddlewareDispatcher.php(140): Slim\Middleware\ErrorMiddleware->process() #21 /var/www/espocrm/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): class@anonymous->handle() #22 /var/www/espocrm/vendor/slim/slim/Slim/App.php(215): Slim\MiddlewareDispatcher->handle() #23 /var/www/espocrm/vendor/slim/slim/Slim/App.php(199): Slim\App->handle() #24 /var/www/espocrm/application/Espo/Core/ApplicationRunners/Api.php(94): Slim\App->run() #25 /var/www/espocrm/application/Espo/Core/Application.php(107): Espo\Core\ApplicationRunners\Api->run() #26 /var/www/espocrm/api/v1/index.php(37): Espo\Core\Application->run() #27 {main} Tips: To display error details in HTTP response set "displayErrorDetails" to true in the ErrorHandler constructor. [] []
Working...
X