public function initializeConfigurationForForm(ActionFactory $actionFactory, ConfigurationInterface $configuration, ActionInterface $indexAction)
 {
     $actionFactory->getAction('entity', 'index')->willReturn($indexAction);
     $configuration->hasAction('index')->willReturn(true);
     $indexAction->getRoute()->willReturn('index');
     $indexAction->getRouteParameters(null)->willReturn(['ir_param1' => 'value1']);
 }
 /**
  * {@inheritdoc}
  */
 public function getRawValue(ResultRecordInterface $record)
 {
     list($this->customEntityName, $actionType) = explode('/', $this->get(self::ROUTE_KEY));
     $action = $this->actionFactory->getAction($this->customEntityName, $actionType);
     $route = $this->router->generate($action->getRoute(), $this->getParameters($record) + $action->getRouteParameters(), $this->getOr(self::IS_ABSOLUTE_KEY, false));
     return $route . $this->getOr(self::ANCHOR_KEY);
 }
 /**
  * Default action
  *
  * @param string $customEntityName
  * @param string $actionType
  *
  * @return Response
  * @throws NotFoundHttpException
  */
 public function executeAction($customEntityName, $actionType)
 {
     $action = $this->actionFactory->getAction($customEntityName, $actionType);
     if (!$action) {
         throw new NotFoundHttpException();
     }
     return $action->execute($this->request);
 }
 public function it_supports_options(ActionFactory $actionFactory, ActionEventManager $eventManager, ConfigurationInterface $configuration, Request $request, EngineInterface $templating, ActionInterface $createAction, Response $response)
 {
     $configuration->getActionOptions('index')->willReturn(['quick_create' => true, 'template' => 'template', 'base_template' => 'base_template']);
     $configuration->hasAction('create')->willReturn(true);
     $actionFactory->getAction('entity', 'create')->willReturn($createAction);
     $createAction->getRoute()->willReturn('create_route');
     $createAction->getRouteParameters(null)->willReturn(['cr_param1' => 'value1']);
     $templating->renderResponse('template', ['createUrl' => 'create_route?&cr_param1=value1', 'quickCreate' => true, 'customEntityName' => 'entity', 'baseTemplate' => 'base_template', 'indexUrl' => 'pim_customentity_index?&customEntityName=entity', 'pre_render' => true])->willReturn($response);
     $this->initializeEventManager($eventManager);
     $this->setConfiguration($configuration);
     $this->execute($request)->shouldReturn($response);
 }
 public function it_accepts_a_limit(ActionFactory $actionFactory, AbstractAction $indexAction, Request $request, ConfigurationInterface $configuration, ActionEventManager $eventManager, FlashBag $flashBag)
 {
     $actionFactory->getAction('entity', 'index')->willReturn($indexAction);
     $indexAction->getRoute()->willReturn('index_route');
     $indexAction->getRouteParameters(null)->willReturn([]);
     $this->initializeEventManager($eventManager);
     $configuration->getActionOptions('quick_export')->willReturn(['limit' => 2]);
     $this->setConfiguration($configuration);
     $response = $this->execute($request);
     $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse');
     $response->getTargetUrl()->shouldReturn('index_route?');
     $flashBag->add('error', '<pim_custom_entity.export.limit_exceeded>%limit%=2;')->shouldBeCalled();
 }
 public function it_configures_mass_actions(BuildBefore $event, DatagridConfiguration $datagridConfig, ActionInterface $indexAction, ActionFactory $actionFactory, ActionInterface $action1, ActionInterface $action2)
 {
     $action1->implement('Pim\\Bundle\\CustomEntityBundle\\Action\\GridActionInterface');
     $action2->implement('Pim\\Bundle\\CustomEntityBundle\\Action\\GridActionInterface');
     $actionFactory->getAction('entity', 'action1')->willReturn($action1);
     $actionFactory->getAction('entity', 'action2')->willReturn($action2);
     $action1->getGridActionOptions()->willReturn(['action1_key1' => 'action1_value1']);
     $datagridConfig->getName()->willReturn('entity');
     $indexAction->getMassActions()->willReturn(['action1', 'action2']);
     $indexAction->getRowActions()->willReturn([]);
     $indexAction->getOptions()->willReturn([]);
     $datagridConfig->offsetGetByPath('[extends]')->willReturn('custom_entity');
     $datagridConfig->offsetGetByPath('[properties]')->willReturn([]);
     $datagridConfig->offsetGetByPath('[actions]')->willReturn([]);
     $datagridConfig->offsetGetByPath('[source]')->willReturn([]);
     $datagridConfig->offsetGetByPath('[mass_actions]')->willReturn(['action2' => []]);
     $datagridConfig->offsetSetByPath("[source]", ["entity" => "entity_class", "type" => "pim_custom_entity"])->shouldBeCalled();
     $datagridConfig->offsetSetByPath("[actions]", [])->shouldBeCalled();
     $datagridConfig->offsetSetByPath("[properties]", ['id' => []])->shouldBeCalled();
     $datagridConfig->offsetSetByPath("[mass_actions]", ["action2" => [], "action1" => ["action1_key1" => "action1_value1"]])->shouldBeCalled();
     $this->buildBefore($event);
 }
 /**
  * Sets the mass actions
  *
  * @param \Oro\Bundle\DataGridBundle\Datagrid\Common\DatagridConfiguration $datagridConfig
  * @param \Pim\Bundle\CustomEntityBundle\Action\ActionInterface            $indexAction
  */
 protected function setMassActions(DatagridConfiguration $datagridConfig, ActionInterface $indexAction)
 {
     $name = $indexAction->getConfiguration()->getName();
     $massActions = $datagridConfig->offsetGetByPath('[mass_actions]') ?: [];
     foreach ($indexAction->getMassActions() as $massActionType) {
         if (isset($massActions[$massActionType])) {
             continue;
         }
         $massAction = $this->actionFactory->getAction($name, $massActionType);
         $massActions[$massActionType] = $massAction->getGridActionOptions();
     }
     $datagridConfig->offsetSetByPath('[mass_actions]', $massActions);
 }
 /**
  * Removes the create link if no ACLS
  *
  * @param  PreRenderActionEvent $event
  * @return type
  */
 public function removeCreateLink(PreRenderActionEvent $event)
 {
     $action = $event->getAction();
     if ('index' != $action->getType()) {
         return;
     }
     $vars = $event->getTemplateVars();
     if (!isset($vars['createUrl'])) {
         return;
     }
     $customEntityName = $action->getConfiguration()->getName();
     $createAction = $this->actionFactory->getAction($customEntityName, 'create');
     $options = $createAction->getOptions();
     if (isset($options['acl']) && !$this->securityFacade->isGranted($options['acl'])) {
         unset($vars['createUrl']);
         unset($vars['quickCreate']);
         $event->setTemplateVars($vars);
     }
 }
 public function it_throws_404_when_there_is_no_configuration_for_action(ActionFactory $actionFactory)
 {
     $actionFactory->getAction('entity', 'other_action')->willReturn(false);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException')->duringExecuteAction('entity', 'other_action');
 }
 /**
  * Returns the url for a specified action
  *
  * @param string $actionType
  * @param object $object
  * @param array  $parameters
  * @param mixed  $referenceType
  */
 protected function getActionUrl($actionType, $object = null, $parameters = [], $referenceType = Router::ABSOLUTE_PATH)
 {
     $action = $actionType === $this->getType() ? $this : $this->actionFactory->getAction($this->configuration->getName(), $actionType);
     return $this->router->generate($action->getRoute(), $parameters + $action->getRouteParameters($object), $referenceType);
 }