Announcement

Collapse
No announcement yet.

2 Extensions override the same controller only one is loaded

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

  • 2 Extensions override the same controller only one is loaded

    I have 2 different extensions that override the same controller file \Espo\Controllers\EntityManager.php

    They do not over ride the same methods.

    The extension with the highest module number is loaded and executed and the other is not executed

    How does the overriding work? can only one extension override a controller at a time?

    There are no logs to indicate an error.








  • #2
    My understanding is that only metadata is "aggregated" from all modules or extensions but in the case of Controllers only the highest module order is executed.

    My suggestion would be to create different controllers in each module extending from EntityManager

    Comment


    • #3
      Thanks for the information if this is the case then its a significant limit on being able to have multiple extensions installed.

      Comment


      • #4
        May I ask why do you need to override the EntityManager Controller as opposed to just create a custom Controller extended from the code EntityManager Controller class ?

        Comment


        • #5
          Hi,

          I am not sure I understand the difference between these options, let me show what I have:

          Extension 1
          extension file: \application\Espo\Modules\MyExtensionOne\Controlle rs\EntityManager.php


          PHP Code:
          <?php
          namespace Espo\Modules\MyExtensionOne\Controllers;


          class 
          EntityManager extends \Espo\Controllers\EntityManager
          {
              protected function 
          checkControllerAccess()
              {
                  
          //some custom logic here
                  
          parent::checkControllerAccess();
              }
          }

          Extension 2
          extension file: \application\Espo\Modules\MyExtensionTwo\Controlle rs\EntityManager.php


          PHP Code:
          <?php
          namespace Espo\Modules\MyExtensionTwo\Controllers;


          class 
          EntityManager extends \Espo\Controllers\EntityManager
          {

              public function 
          postActionCreateEntity(Request $request)
              {
                     
          ///custom logic here
              
          }

          }


          Comment


          • #6
            Hi Kyle

            This is known issue, only one controller will be loaded, based on the module order number.

            So if you have 2 modules with numbers 30 and 50, then the module with order = 50 will dump its controller to loaded.

            The only one workaround I know, is to update the controller of module 50 to extend the controller of module 30,

            NOTE: this make module-30 as heavy dependency for module-50, may yuri have suggestions here ...
            CEO of Eblasoft
            EspoCRM Expert since 2014
            Full Stack Web Developer since 2008
            Creator of Numerous Successful Extensions & Projects​

            Comment


            • eymen-elkum
              eymen-elkum commented
              Editing a comment
              Actually there is another solution, to override the UI on module-50 to call another controller that extend the base Espo entity manager controller, but this is just an idea, implementing it depending on the need and case

          • #7
            Hi Kyle

            Not tested, but maybe this could work ?

            PHP Code:
            <?php
            namespace Espo\Modules\MyExtensionOne\Controllers;


            class 
            EntityManagerOne extends \Espo\Controllers\EntityManager
            {
                protected function 
            checkControllerAccess()
                {
                    
            //some custom logic here
                    
            parent::checkControllerAccess();
                }
            }
            PHP Code:
            <?php
            namespace Espo\Modules\MyExtensionTwo\Controllers;


            class 
            EntityManagerTwo extends \Espo\Controllers\EntityManager
            {

                public function 
            postActionCreateEntity(Request $request)
                {
                       
            ///custom logic here
                
            }

            }

            In the MyExtensionTwo class where you want to invoke a public EntityManager method (from a Service class for example):
            PHP Code:
            namespace Espo\Modules\MyExtensionTwo\Services;

            use 
            Espo\Modules\MyExtensionTwo\Controllers\EntityManagerTwo;

            class 
            MyServiceTwo {

                protected 
            $entityManagerTwo;

                public function 
            __construct(EntityManagerTwo $entityManagerTwo)
                {

                    
            $this->entityManagerTwo $entityManagerTwo;
                }

                public function 
            myMethod (myparams) {
                    
            $this->entityManagerTwo->postActionCreateEntity($request);
                }


            Last edited by telecastg; 10-25-2021, 03:48 PM.

            Comment


            • #8
              Thanks everybody, I will do some digging around based on the answers and see what I can come up with. Ideally I did not want the extensions to be reliant on each other but this may not be possible.

              Comment


              • #9
                You can define a custom route to handle the request in a different controller.

                Comment

                Working...
                X