Announcement

Collapse
No announcement yet.

loadAdditionalFieldsForList not working as expected

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

  • loadAdditionalFieldsForList not working as expected

    I'm trying to load a linkMultiple field in a list view using the instructions I found on the forum, but it isn't working.

    Here are the threads I found that explain how to do this:
    1. How can I get an entity as available field in a list?
    2. Upddate a Listview including a LinkMulti Field
    3. Email: Customize Layout / Set Default Account

    Here's what I've tried:

    In custom/Espo/Custom/Services/Project.php:

    PHP Code:
      1 <?php
      2
      3 
    namespace Espo\Custom\Services;
      
    4
      5 
    class Project extends \Espo\Core\Templates\Services\BasePlus
      6 
    {
      
    7   public function loadAdditionalFieldsForList(Entity $entity)
      
    8   {
      
    9     parent::loadAdditionalFieldsForList($entity);
     
    10     $entity->loadLinkMultipleField('accounts');
     
    11   }
     
    12 }
    In custom/Espo/Custom/Resources/layouts/Project/list.json:

    Code:
      6     {
      7         "name": "accounts"
      8     },
    The column appears in the list view, but I get a Bad Server Response error and this appears in the log:

    Code:
    [2018-03-19 11:22:30] Espo.WARNING: E_WARNING: Declaration of Espo\Custom\Services\Project::loadAdditionalFieldsForList(Espo\Custom\Services\Entity $entity) should be compatible with Espo\Services\Record::loadAdditionalFieldsForList(Espo\ORM\Entity $entity) {"code":2,"message":"Declaration of Espo\\Custom\\Services\\Project::loadAdditionalFieldsForList(Espo\\Custom\\Services\\Entity $entity) should be compatible with Espo\\Services\\Record::loadAdditionalFieldsForList(Espo\\ORM\\Entity $entity)","file":"/var/www/crm/custom/Espo/Custom/Services/Project.php","line":5,"context":{"file":"/var/www/crm/custom/Espo/Custom/Services/Project.php"}} []
    [2018-03-19 11:22:30] Espo.ERROR: Uncaught Exception TypeError: "Argument 1 passed to Espo\Custom\Services\Project::loadAdditionalFieldsForList() must be an instance of Espo\Custom\Services\Entity, instance of Espo\Custom\Entities\Project given, called in /var/www/crm/application/Espo/Services/Record.php on line 837" at /var/www/crm/custom/Espo/Custom/Services/Project.php line 7 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Espo\\Custom\\Services\\Project::loadAdditionalFieldsForList() must be an instance of Espo\\Custom\\Services\\Entity, instance of Espo\\Custom\\Entities\\Project given, called in /var/www/crm/application/Espo/Services/Record.php on line 837 at /var/www/crm/custom/Espo/Custom/Services/Project.php:7)"} []
    What am I doing wrong?

  • #2
    Hello

    use \Espo\ORM\Entity;

    Comment


    • #3
      Originally posted by tanya View Post
      Hello

      use \Espo\ORM\Entity;
      I'm not sure if I did this right, but the errors look the same:

      PHP Code:
        1 <?php
        2
        3 
      use \Espo\ORM\Entity;
        
      4
        5 
      namespace Espo\Custom\Services;
        
      6
        7 
      class Project extends \Espo\Core\Templates\Services\BasePlus
        8 
      {
        
      9   public function loadAdditionalFieldsForList(Entity $entity)
       
      10   {
       
      11     parent::loadAdditionalFieldsForList($entity);
       
      12     $entity->loadLinkMultipleField('accounts');
       
      13   }
       
      14 }
      Code:
      [2018-03-19 11:33:08] Espo.WARNING: E_WARNING: Declaration of Espo\Custom\Services\Project::loadAdditionalFieldsForList(Espo\Custom\Services\Entity $entity) should be compatible with Espo\Services\Record::loadAdditionalFieldsForList(Espo\ORM\Entity $entity) {"code":2,"message":"Declaration of Espo\\Custom\\Services\\Project::loadAdditionalFieldsForList(Espo\\Custom\\Services\\Entity $entity) should be compatible with Espo\\Services\\Record::loadAdditionalFieldsForList(Espo\\ORM\\Entity $entity)","file":"/var/www/crm/custom/Espo/Custom/Services/Project.php","line":7,"context":{"file":"/var/www/crm/custom/Espo/Custom/Services/Project.php"}} []
      [2018-03-19 11:33:08] Espo.ERROR: Uncaught Exception TypeError: "Argument 1 passed to Espo\Custom\Services\Project::loadAdditionalFieldsForList() must be an instance of Espo\Custom\Services\Entity, instance of Espo\Custom\Entities\Project given, called in /var/www/crm/application/Espo/Services/Record.php on line 837" at /var/www/crm/custom/Espo/Custom/Services/Project.php line 9 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Espo\\Custom\\Services\\Project::loadAdditionalFieldsForList() must be an instance of Espo\\Custom\\Services\\Entity, instance of Espo\\Custom\\Entities\\Project given, called in /var/www/crm/application/Espo/Services/Record.php on line 837 at /var/www/crm/custom/Espo/Custom/Services/Project.php:9)"} []

      Comment


      • #4
        Oh, I had to change the type in the function definition:

        PHP Code:
          1 <?php
          2
          3 
        use \Espo\ORM\Entity;
          
        4
          5 
        namespace Espo\Custom\Services;
          
        6
          7 
        class Project extends \Espo\Core\Templates\Services\BasePlus
          8 
        {
          
        9   public function loadAdditionalFieldsForList(\Espo\ORM\Entity $entity)
         
        10   {
         
        11     parent::loadAdditionalFieldsForList($entity);
         
        12     $entity->loadLinkMultipleField('accounts');
         
        13   }
         
        14 }

        The errors went away, but the field isn't loading. I'm not sure what's wrong yet.

        Comment


        • #5
          try define namespace first

          namespace Espo\Custom\Services;

          use \Espo\ORM\Entity;

          class Project extends \Espo\Core\Templates\Services\BasePlus

          Comment


          • #6
            I think I had to clear the cache and force reload the page in the browser. It's working now. Thank you so much.

            Comment

            Working...
            X