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.
- CreatorTopic
- June 4, 2014 at 7:40 am #35761
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!
- CreatorTopic
- AuthorReplies
- June 4, 2014 at 10:04 pm #35762
Hi alps86,
Did you check if this route still exists?
In you console you can debug router names with the command1php app/console router:debug oro_workflow_definition_indexThe output for this route on my installation is:
123456789101112Hotlander:orocrm hotlander$ app/console router:debug oro_workflow_definition_index[router] Route "oro_workflow_definition_index"Name oro_workflow_definition_indexPath /workflowdefinitionHost ANYScheme ANYMethod ANYClass Symfony\Component\Routing\RouteDefaults _controller: Oro\Bundle\WorkflowBundle\Controller\WorkflowDefinitionController::indexActionRequirements NO CUSTOMOptions compiler_class: Symfony\Component\Routing\RouteCompilerPath-Regex #^/workflowdefinition$#sIf it’s a js error you could try and see if the route is in the routes.js by running the following command
1app/console fos:js-routing:debugand 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
1app/console fos:js-routing:debug | grep oro_workflow_definition_indexThe output of the command on my installation is
12Hotlander:orocrm hotlander$ app/console fos:js-routing:debug | grep oro_workflow_definition_indexoro_workflow_definition_index ANY ANY ANY /workflowdefinitionHope this helps!
Kind Regards,
Jaimy Casteleijn
June 5, 2014 at 12:16 am #35763Hi,
Without bundle inheritance the both commands can find the route.
With bundle inheritance the commands can not find the route.June 6, 2014 at 5:14 pm #35764Hi 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:1234567891011121314151617181920212223242526272829303132<?phpnamespace Tfone\Bundle\WorkflowBundle\Controller;use Oro\Bundle\WorkflowBundle\Controller\WorkflowDefinitionController as BaseController;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;use Oro\Bundle\SecurityBundle\Annotation\Acl;use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;use Oro\Bundle\WorkflowBundle\Entity\WorkflowDefinition;/*** @Route("/workflowdefinition")*/class WorkflowDefinitionController extends BaseController{/*** @Route(name="oro_workflow_definition_index")* @Template* @Acl(* id="oro_workflow_definition_view",* type="entity",* class="OroWorkflowBundle:WorkflowDefinition",* permission="VIEW"* )*/public function indexAction(){return parent::indexAction();}}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
June 10, 2014 at 4:42 am #35765Hello,
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-extendedThanks,
IgnatJuly 20, 2014 at 9:42 am #35766Ignat, 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:
123456789101112131415<?phpnamespace Test\Bundle\SalesBundle;use Symfony\Component\HttpKernel\Bundle\Bundle;class TestSalesBundle extends Bundle{public function getParent(){return 'OroCRMSalesBundle';}}src/Test/Bundle/SalesBundle/Controller/LeadController.php (same for OpportunityController and SalesFunnelController):
123456789101112<?phpnamespace Test\Bundle\SalesBundle\Controller;use Symfony\Bundle\FrameworkBundle\Controller\Controller;use OroCRM\Bundle\SalesBundle\Controller\LeadController as BaseLeadController;class LeadController extends BaseLeadController{}src/Test/Bundle/SalesBundle/Resources/config/oro/routing.yml:
12345test_sales_bundle:resource: "@TestSalesBundle/Controller"type: annotationAfter that I have:
123456789$ php app/console router:debug | grep orocrm_sales_leadorocrm_sales_lead_view ANY ANY ANY /view/{id}orocrm_sales_lead_info ANY ANY ANY /info/{id}orocrm_sales_lead_address_book ANY ANY ANY /address-book/{id}orocrm_sales_lead_create ANY ANY ANY /createorocrm_sales_lead_update ANY ANY ANY /update/{id}orocrm_sales_lead_index ANY ANY ANY /{_format}If I comment bundle inheritance I have what I had before and what I want:
123456789$ php app/console router:debug | grep orocrm_sales_leadorocrm_sales_lead_view ANY ANY ANY /lead/view/{id}orocrm_sales_lead_info ANY ANY ANY /lead/info/{id}orocrm_sales_lead_address_book ANY ANY ANY /lead/address-book/{id}orocrm_sales_lead_create ANY ANY ANY /lead/createorocrm_sales_lead_update ANY ANY ANY /lead/update/{id}orocrm_sales_lead_index ANY ANY ANY /lead/{_format}Can you please help me how I should inherit routes to save prefix “/lead” for LeadController, “/opportunity” for OpportunityController and others?
July 22, 2014 at 8:06 am #35767Anybody help me please. :)
July 23, 2014 at 12:29 am #35768Hi Nikita,
Try to add
prefix: /lead
in your src/Test/Bundle/SalesBundle/Resources/config/oro/routing.yml.So it will look something like this:
123456test_sales_bundle:resource: "@TestSalesBundle/Controller"type: annotationprefix: /leadHope this helps!
Kind Regards,
Jaimy Casteleijn
July 23, 2014 at 5:24 am #35769Jaimy, 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:
123456test_sales_bundle:resource: "@TestSalesBundle/Controller/LeadController.php"type: annotationprefix: /leadStill no result. :(
July 25, 2014 at 6:50 am #35770Hello, Nikita.
First solution: if you want to extend all controllers from SalesBundle, you’d better extend whole resource file, i.e.:
123my_sales_bundle:resource: "../../src/OroCRM/src/OroCRM/Bundle/SalesBundle/Controller" # full resource pathtype: annotationResult:
1234567maniac@laphere:/opt/www/crm_dev$ app/console router:debug | grep leadorocrm_sales_lead_view ANY ANY ANY /lead/view/{id}orocrm_sales_lead_info ANY ANY ANY /lead/info/{id}orocrm_sales_lead_address_book ANY ANY ANY /lead/address-book/{id}orocrm_sales_lead_create ANY ANY ANY /lead/createorocrm_sales_lead_update ANY ANY ANY /lead/update/{id}Second solution: if you want to extend each controller separately, you should put route annotation to your controller:
123my_sales_bundle:resource: "@OroCRMMySalesBundle/Controller/MyLeadController.php"type: annotationController:
123456789101112namespace OroCRM\Bundle\MySalesBundle\Controller;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use OroCRM\Bundle\SalesBundle\Controller\LeadController;/*** @Route("/lead")*/class MyLeadController extends LeadController{}Result:
1234567maniac@laphere:/opt/www/crm_dev$ app/console router:debug | grep leadorocrm_sales_lead_view ANY ANY ANY /lead/view/{id}orocrm_sales_lead_info ANY ANY ANY /lead/info/{id}orocrm_sales_lead_address_book ANY ANY ANY /lead/address-book/{id}orocrm_sales_lead_create ANY ANY ANY /lead/createorocrm_sales_lead_update ANY ANY ANY /lead/update/{id}July 31, 2014 at 1:50 am #35771Yevhen, 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.
July 31, 2014 at 2:15 am #35772You 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.
July 31, 2014 at 3:52 am #35773Yeah, 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.
July 31, 2014 at 4:28 am #35774It’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.
September 23, 2016 at 4:56 am #35775Please 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 Tracein 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 } - AuthorReplies
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.