Cannot extend Controller from Core through Modules

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brianpunzalan
    Active Community Member
    • Aug 2017
    • 62

    Cannot extend Controller from Core through Modules

    Hi,

    I tried to extend the functionality of 'Users' by adding additional API functions through extending the existing Controllers in Core (\Espo\Controllers\User).

    But, it always throw error 404 Not found, since it cannot detect that the module has the extension controller.

    I dig deep and found out that it checks the 'scope.User.module' under the Metadata if this action is existing on the controller.

    Specifically on this line,
    EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.


    It returns false.

    It always check the \Espo\Controllers\User Controller but not my \Espo\Modules\ModuleName\User Controller.

    Since it checks the metadata, I added the User.json in scope under metadata of my module with below line.

    Code:
    {
      "module": "ModuleName"
    }

    Then it goes off with an error bad response, and it shows this error log.

    Espo.ERROR: Uncaught Exception TypeError: "Argument 1 passed to Espo\ORM\DB\Mapper::select() must implement interface Espo\ORM\IEntity, null given, called in ../application/Espo/ORM/Repositories/RDB.php on line 187" at ../application/Espo/ORM/DB/Mapper.php line 103 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Espo\\ORM\\DB\\Mapper::select() must implement interface Espo\\ORM\\IEntity, null given, called in .../application/Espo/ORM/Repositories/RDB.php on line 187 at .../application/Espo/ORM/DB/Mapper.php:103)"} []

    Not sure if it is a bug that I cannot extend the User Controller from Core to my own Extension User Controller.

    Note: It works fine if I apply the functions in Custom and Core but not when I try it modular.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hello
    Did you override other part of Entity in Entities, Repositories, Services, Select Manager, etc.? If you add module to scope, for entity wont be visible files from core, except that you inherit them

    Comment

    • brianpunzalan
      Active Community Member
      • Aug 2017
      • 62

      #3
      Hi Tanya,

      I only override the Controller and Service for entity User in my module since I only need to execute some functions in the through API. Should I extend also the Entities and Repositories for my module even User has already Entities and Repositories from Core?

      The code sample is below:


      PHP Code:
      <?php
      
      namespace Espo\Modules\ModuleName\Controllers;
      
      class User extends Espo\Controllers\User {
         // my api handlers inside
      }

      Comment

      • brianpunzalan
        Active Community Member
        • Aug 2017
        • 62

        #4
        It works! Thanks

        So if i set the scope to the specific module, it would now ignore the core but direct to the module entities, repositories, controllers and services itself. Inherit the parent core functions to enable everything.

        Comment

        Working...