Reputation: 51
I am making some customizations to OroCRM, in this case I need to do a massive action on several records, but when selecting the desired option a modal should appear to choose one of the possible owners of the system.
For that I included the following changes in the system:
change_owner:
type: lead_change_owner_mass_edit
handler: pb_lead.mass_action.change_owner.handler
acl_resource: oro_sales_lead_update
route: pb_lead_datagrid_mass_action_change_owner
label: pb.lead.mass_actions.change_owner.label
icon: user
data_identifier: lead.id
frontend_options:
title: "@translator->trans(pb.lead.mass_actions.change_owner.label)"
dialogOptions:
width: 500
modal: true
allowMaximize: false
allowMinimize: false
class ChangeOwnerAction extends WindowMassAction
{
/** @var array */
protected $requiredOptions = ['handler', 'route', 'data_identifier'];
/**
* {@inheritDoc}
*/
public function setOptions(ActionConfiguration $options)
{
if (empty($options['frontend_type'])) {
$options['frontend_type'] = 'edit-mass';
}
return parent::setOptions($options);
}
/**
* {@inheritdoc}
*/
protected function getAllowedRequestTypes()
{
return [Request::METHOD_POST];
}
}
This action is defined as a service:
services:
#Change owner windows action
pb_lead.mass_action.type.changeownermass:
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassAction\Actions\Widget\ChangeOwnerAction
shared: false
tags:
- { name: oro_datagrid.extension.mass_action.type, type: lead_change_owner_mass_edit }
Additionally, the controller that has a method with the route defined in the datagrid is included:
/**
* @Route("/change-owner-mass-edit-lead", name="pb_lead_datagrid_mass_action_change_owner")
* @AclAncestor("oro_sales_lead_update")
* @Template("@PBLead/Lead/widget/mass_change_owner_update.html.twig")
* @param Request $request
* @return array
*/
public function massChangeOwnerAction(Request $request)
{
dump($request);
$responseData = [
'inset' => $request->get('inset', null),
'values' => $request->get('values', null),
];
...
return $responseData;
}
This controller was defined as a service in controllers.yml:
PB\Bundle\LeadBundle\Controller\Frontend\LeadChangeOwnerController:
calls:
- [setContainer, ['@Psr\Container\ContainerInterface']]
tags:
- { name: container.service_subscriber }
On the other hand, 2 classes were defined: an abstract and a handler that extends from it to manage the mass actions. Both handlers are defined as services:
#Abstract Lead mass action handler
pb_lead.abstract_lead_mass_action_handler:
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassAction\AbstractLeadMassActionHandler
abstract: true
arguments:
- '@oro_entity.doctrine_helper'
- '@oro_security.acl_helper'
#Lead change owner mass action HANDLER
pb_lead.mass_action.change_owner.handler:
parent: pb_lead.abstract_lead_mass_action_handler
public: true
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassActionxzczxcz\LeadChangeOwnerMassActionHandler
calls:
- ['setTranslator', ['@translator']]
- ['setFormFactory', ['@form.factory']]
There is a custom form and a view that are called from the controller.
Form:
class LeadChangeOwnerMassType extends AbstractType
{
const NAME = 'pb_lead_change_owner_mass_type';
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'owner',
UserAclSelectType::class,
[
'required' => true,
'label' => 'pb.lead.mass_actions.change_owner.label',
'constraints' => [
new NotNull()
]
]
);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Lead::class,
]);
}
View:
{% extends '@OroAction/Operation/form.html.twig' %}
{% set formAction = path('pb_lead_datagrid_mass_action_change_owner', {gridName: 'sales-lead-grid', actionName: 'change_owner', inset: inset, values: values }) %}
{% block form %}
<form id="{{ form.vars.id }}"
name="{{ form.vars.name }}"
action="{{ formAction }}"
method="{{ form.vars.method }}"
class="form-dialog"
>
<fieldset class="form-horizontal">
{{ form_row(form) }}
</fieldset>
<div class="hidden">
{{ form_rest(form) }}
</div>
<div class="widget-actions">
<button class="btn" type="reset">{{ 'Cancel'|trans }}</button>
<button class="btn btn-success" type="submit">{{ 'Apply'|trans }}</button>
</div>
</form>
{{ oro_form_js_validation(form) }}
{% endblock %}
The question is: Why is the modal not showing?
Thank you very much for the help
Upvotes: 2
Views: 63
Reputation: 51
the error is that the route must start with "oro_", only that a small detail does not allow to show modal.
change_owner:
type: lead_change_owner_mass_edit
handler: pb_lead.mass_action.change_owner.handler
acl_resource: oro_sales_lead_update
route: oro_lead_mass_action_change_owner
label: pb.lead.mass_actions.change_owner.label
icon: user
data_identifier: lead.id
frontend_options:
title: "@translator->trans(pb.lead.mass_actions.change_owner.label)"
dialogOptions:
width: 500
modal: true
allowMaximize: false
allowMinimize: false
Upvotes: 1