OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – How do I? Questions bundle inheritance routing

This topic contains 14 replies, has 6 voices, and was last updated by  pinak1161 7 years, 5 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #35761

    alps86
    Participant

    Hi,

    i use bundle inheritance for the OroWorkflowBundle.
    I would like override a controller, however i have a problem with the annotation routing definitions.

    “Unable to generate a URL for the named route “oro_workflow_definition_index” as such route does not exist.”

    The inheritance configuration overrides the complete definition of the OroWorkflowBundle.
    How i can solve this problem?

    Thanks!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Author
    Replies
  • #35762

    Jaimy
    Participant

    Hi alps86,

    Did you check if this route still exists?
    In you console you can debug router names with the command

    The output for this route on my installation is:

    If it’s a js error you could try and see if the route is in the routes.js by running the following command

    and find the oro_workflow_definition_index route. If you are working on unix based system like Mac or Linux distro, you could easily find the route (if there is one) by running

    The output of the command on my installation is

    Hope this helps!

    Kind Regards,

    Jaimy Casteleijn

    #35763

    alps86
    Participant

    Hi,

    Without bundle inheritance the both commands can find the route.
    With bundle inheritance the commands can not find the route.

    #35764

    Jaimy
    Participant

    Hi alps86,

    I can reproduce the error you’re getting. Apparently you have to define the route again if you’re going to override the Controller.
    I added this part to my annotations above the indexAction, but I don’t think this is the correct way to override a controller action. Full Controller class looks like this at this point:

    Just read the standard symfony 2 bundle inheritance article again, but they never mention anything about redefining the route itself. Maybe someone from the Oro Core team can shine a light on this one. This is not what I have foreseen as a potential problem.

    I also noticed If copy the code above, you’ll get in trouble with the Api/Rest/WorkflowDefinitionController. With the above code, all other methods in the controller seem to work, but you’ll get an error. This is the same as with overriding the “normal” controller for Workflow Definitions only for the Api/RestWorkflowDefinitionController. By which you are forced to override this controller as well.

    Sorry I couldn’t be more of help. Hopefully the Oro Core Team has an idea for overriding this controller or the controllers in general.

    Kind Regards,

    Jaimy Casteleijn

    #35765

    ignat
    Participant

    Hello,

    This issue is related to default Symfony behavior. When you extend bundle it’s child routing will be ignored in some cases. We are planning to make some improvements in this direction but for now you can use a workaround. One simple workaround is to extend all controllers in your bundle even if extended controller will be empty and mention them in your Resources/oro/routing.yml file using type “annotation”.

    You can also check this resources for additioanl info about other workarounds: http://stackoverflow.com/questions/9373433/symfony2-bundle-inheritance-losing-parent-bundles-routes
    http://stackoverflow.com/questions/9917939/how-should-symfony2-bundles-that-use-annotated-controllers-be-extended

    Thanks,
    Ignat

    #35766

    Nikita Petrov
    Participant

    Ignat, thank you for links, but can you please help me with routes inheritance for child of OroCRMSalesBundle? I need to modify some code for Lead entity but when I inherit Bundle as you linked above all routes of all OroCRMSalesBundle’s controllers append to “/”. How can I append them back to “/lead” prefix?

    I tried this solution.

    src/Test/Bundle/SalesBundle/TestSalesBundle.php:

    src/Test/Bundle/SalesBundle/Controller/LeadController.php (same for OpportunityController and SalesFunnelController):

    src/Test/Bundle/SalesBundle/Resources/config/oro/routing.yml:

    After that I have:

    If I comment bundle inheritance I have what I had before and what I want:

    Can you please help me how I should inherit routes to save prefix “/lead” for LeadController, “/opportunity” for OpportunityController and others?

    #35767

    Nikita Petrov
    Participant

    Anybody help me please. :)

    #35768

    Jaimy
    Participant

    Hi Nikita,

    Try to add prefix: /lead in your src/Test/Bundle/SalesBundle/Resources/config/oro/routing.yml.

    So it will look something like this:

    Hope this helps!

    Kind Regards,

    Jaimy Casteleijn

    #35769

    Nikita Petrov
    Participant

    Jaimy, thank you for your suggest. I tried this solution, but it proved to be ineffective – all routes still mapped to “/”.

    Also I tried map only LeadController in routing.yml:

    Still no result. :(

    #35770

    Yevhen Shyshkin
    Participant

    Hello, Nikita.

    First solution: if you want to extend all controllers from SalesBundle, you’d better extend whole resource file, i.e.:

    Result:

    Second solution: if you want to extend each controller separately, you should put route annotation to your controller:

    Controller:

    Result:

    #35771

    Nikita Petrov
    Participant

    Yevhen, thank you! First way for unknown for me reasons does not work for me (Symfony was unable to import directory by relation path). Second way pretty works for me.

    #35772

    Yevhen Shyshkin
    Participant

    You are welcome.

    As for first solution – probably, you didn’t set correct path to SalesBundle – if depends on your specific installation and starts from /app/config directory (so you have to put “../../” at the beginning). In future we are going to improve this behaviour and allow to set relative bundle paths.

    #35773

    Nikita Petrov
    Participant

    Yeah, thank you for relation path solution. First way works now for OroCRMSalesBundle. But for OroCRMAccountBundle I need to define prefix in routing.yml to get routes inheritance work.

    #35774

    Yevhen Shyshkin
    Participant

    It’s ok, you can customize routes whatever you want. There is just one thing you should remember about bundle and routes inheritance – if you inherit only one controller from parent bundle (second solution) then all other controllers will not be imported automatically, you have to put them in config manually.

    #35775

    pinak1161
    Participant

    Please help me i override Bundle and this error come when i try to insert record

    Expected argument of type “Oro\Bundle\OrganizationBundle\Entity\BusinessUnit”, “integer” given
    500 Internal Server Error – InvalidArgumentException
    Stack Trace

    in vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php at line 254 –
    $type = $trace[$i][‘args’][0];
    $type = is_object($type) ? get_class($type) : gettype($type);
    throw new InvalidArgumentException(sprintf(‘Expected argument of type “%s”, “%s” given’, substr($message, $pos, strpos($message, ‘,’, $pos) – $pos), $type));
    }
    }
    at PropertyAccessor ::throwInvalidArgumentException (‘Argument 1 passed to Oro\Bundle\OrganizationBundle\Entity\BusinessUnit::setParentBusinessUnit() must be an instance of Oro\Bundle\OrganizationBundle\Entity\BusinessUnit, integer given, called in /var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 605 and defined’, array(array(‘file’ => ‘/var/www/html/crm-application/vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Entity/BusinessUnit.php’, ‘line’ => ‘468’, ‘function’ => ‘handleError’, ‘class’ => ‘Symfony\Component\PropertyAccess\PropertyAccessor’, ‘type’ => ‘::’, ‘args’ => array(‘4096’, ‘Argument 1 passed to Oro\Bundle\OrganizationBundle\Entity\BusinessUnit::setParentBusinessUnit() must be an instance of Oro\Bundle\OrganizationBundle\Entity\BusinessUnit, integer given, called in /var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 605 and defined’, ‘/var/www/html/crm-application/vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Entity/BusinessUnit.php’, ‘468’, array(‘this’ => object(Business)))), array(‘file’ => ‘/var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php’, ‘line’ => ‘605’, ‘function’ => ‘setParentBusinessUnit’, ‘class’ => ‘Oro\Bundle\OrganizationBundle\Entity\BusinessUnit’, ‘type’ => ‘->’, ‘args’ => array(‘0’)), array(‘file’ => ‘/var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php’, ‘line’ => ‘201’, ‘function’ => ‘writeProperty’, ‘class’ => ‘Symfony\Component\PropertyAccess\PropertyAccessor’, ‘type’ => ‘->’, ‘args’ => array(array(object(Business), object(Business)), ‘parentBusinessUnit’, ‘0’)), array(‘file’ => ‘/var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php’, ‘line’ => ’93’, ‘function’ => ‘setValue’, ‘class’ => ‘Symfony\Component\PropertyAccess\PropertyAccessor’, ‘type’ => ‘->’, ‘args’ => array(object(Business), object(PropertyPath), ‘0’)), array(‘file’ => ‘/var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php’, ‘line’ => ‘623’, ‘function’ => ‘mapFormsToData’, ‘class’ => ‘Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper’, ‘type’ => ‘->’, ‘args’ => array(object(RecursiveIteratorIterator), object(Business))), array(‘file’ => ‘/var/www/html/crm-application/vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Form/Handler/BusinessUnitHandler.php’, ‘line’ => ’47’, ‘function’ => ‘submit’, ‘class’ => ‘Symfony\Component\Form\Form’, ‘type’ => ‘->’, ‘args’ => array(object(Request))), array(‘file’ => ‘/var/www/html/crm-application/src/Clra/BusinessBundle/Controller/DefaultController.php’, ‘line’ => ’30’, ‘function’ => ‘process’, ‘class’ => ‘Oro\Bundle\OrganizationBundle\Form\Handler\BusinessUnitHandler’, ‘type’ => ‘->’, ‘args’ => array(object(Business))), array(‘file’ => ‘/var/www/html/crm-application/src/Clra/BusinessBundle/Controller/DefaultController.php’, ‘line’ => ’18’, ‘function’ => ‘update’, ‘class’ => ‘Clra\BusinessBundle\Controller\DefaultController’, ‘type’ => ‘->’, ‘args’ => array(object(Business))), array(‘function’ => ‘createAction’, ‘class’ => ‘Clra\BusinessBundle\Controller\DefaultController’, ‘type’ => ‘->’, ‘args’ => array()), array(‘file’ => ‘/var/www/html/crm-application/app/bootstrap.php.cache’, ‘line’ => ‘3238’, ‘function’ => ‘call_user_func_array’, ‘args’ => array(array(object(DefaultController), ‘createAction’), array())), array(‘file’ => ‘/var/www/html/crm-application/app/bootstrap.php.cache’, ‘line’ => ‘3197’, ‘function’ => ‘handleRaw’, ‘class’ => ‘Symfony\Component\HttpKernel\HttpKernel’, ‘type’ => ‘->’, ‘args’ => array(object(Request), ‘1’)), array(‘file’ => ‘/var/www/html/crm-application/app/bootstrap.php.cache’, ‘line’ => ‘3351’, ‘function’ => ‘handle’, ‘class’ => ‘Symfony\Component\HttpKernel\HttpKernel’, ‘type’ => ‘->’, ‘args’ => array(object(Request), ‘1’, true)), array(‘file’ => ‘/var/www/html/crm-application/app/bootstrap.php.cache’, ‘line’ => ‘2536’, ‘function’ => ‘handle’, ‘class’ => ‘Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel’, ‘type’ => ‘->’, ‘args’ => array(object(Request), ‘1’, true)), array(‘file’ => ‘/var/www/html/crm-application/web/app_dev.php’, ‘line’ => ’30’, ‘function’ => ‘handle’, ‘class’ => ‘Symfony\Component\HttpKernel\Kernel’, ‘type’ => ‘->’, ‘args’ => array(object(Request)))), ‘1’)
    in vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php at line 240 +
    at PropertyAccessor ::handleError (‘4096’, ‘Argument 1 passed to Oro\Bundle\OrganizationBundle\Entity\BusinessUnit::setParentBusinessUnit() must be an instance of Oro\Bundle\OrganizationBundle\Entity\BusinessUnit, integer given, called in /var/www/html/crm-application/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 605 and defined’, ‘/var/www/html/crm-application/vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Entity/BusinessUnit.php’, ‘468’, array(‘this’ => object(Business)))
    in vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Entity/BusinessUnit.php at line 468 +
    at BusinessUnit ->setParentBusinessUnit (‘0’)
    in vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php at line 605 +
    at PropertyAccessor ->writeProperty (array(object(Business), object(Business)), ‘parentBusinessUnit’, ‘0’)
    in vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php at line 201 +
    at PropertyAccessor ->setValue (object(Business), object(PropertyPath), ‘0’)
    in vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php at line 93 +
    at PropertyPathMapper ->mapFormsToData (object(RecursiveIteratorIterator), object(Business))
    in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 623 +
    at Form ->submit (object(Request))
    in vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Form/Handler/BusinessUnitHandler.php at line 47 +
    at BusinessUnitHandler ->process (object(Business))
    in src/Clra/BusinessBundle/Controller/DefaultController.php at line 30 +
    at DefaultController ->update (object(Business))
    in src/Clra/BusinessBundle/Controller/DefaultController.php at line 18 +
    at DefaultController ->createAction ()
    at call_user_func_array (array(object(DefaultController), ‘createAction’), array())
    in app/bootstrap.php.cache at line 3238 +
    at HttpKernel ->handleRaw (object(Request), ‘1’)
    in app/bootstrap.php.cache at line 3197 +
    at HttpKernel ->handle (object(Request), ‘1’, true)
    in app/bootstrap.php.cache at line 3351 +
    at ContainerAwareHttpKernel ->handle (object(Request), ‘1’, true)
    in app/bootstrap.php.cache at line 2536 +
    at Kernel ->handle (object(Request))
    in web/app_dev.php at line 30 +

    Here, Is my code of Controller

    class DefaultController extends Controller {

    public function createAction() {
    return $this->update(new Business());
    }

    /**
    * @param Clra\BusinessBundle\Entity\BusinessUnit $entity
    * @return array
    */
    protected function update(Business $entity) {
    $em = $this->getDoctrine()->getManager();
    $form = $this->createForm(new BusinessType(), $entity);

    if ($this->get(‘oro_organization.form.handler.business_unit’)->process($entity)) {
    $this->get(‘session’)->getFlashBag()->add(
    ‘success’, $this->get(‘translator’)->trans(‘oro.business_unit.controller.message.saved’)
    );

    return $this->get(‘oro_ui.router’)->redirect($entity);
    }
    return $this->render(‘ClraBusinessBundle:BusinessUnit:update.html.twig’, array(‘form’ => $form->createView(), ‘entity’ => $entity));
    }

    public function viewProfileAction() {
    return $this->view($this->getUser(), true);
    }

    public function indexAction(Request $request) {
    return array(
    ‘entity_class’ => $this->container->getParameter(‘oro_organization.business_unit.entity.class’)
    );
    }

    public function usersAction(BusinessUnit $entity) {
    return array(
    ‘entity’ => $entity,
    );
    }

    }

    and here is my routing file

    #clra_business_homepage:
    # path: /hello/{name}
    # defaults: { _controller: ClraBusinessBundle:Default:index }

    oro_business_unit_create:
    path: /business-data/create
    defaults: { _controller: ClraBusinessBundle:Default:create }

    oro_business_unit_index:
    path: /
    defaults: { _controller: ClraBusinessBundle:Default:index }

    oro_user_profile_view:
    path: /profile/view
    defaults: { _controller: ClraBusinessBundle:Default:view }

    oro_business_unit_widget_users:
    path: /widget/users/{id}
    defaults: { _controller: ClraBusinessBundle:Default:users }

    oro_user_index:
    path: /format
    defaults: { _controller: ClraBusinessBundle:Default:index }

Viewing 14 replies - 1 through 14 (of 14 total)

The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.

Back to top