/** * @param \Symfony\Component\HttpFoundation\Request $request * @param \Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration * @return bool */ public function apply(Request $request, ParamConverter $configuration) { $param = $configuration->getName(); $id = $request->attributes->get($param, ''); if (!$this->manager->hasElement($id)) { throw new NotFoundHttpException(sprintf('Admin element with id %s does not exist.', $id)); } $request->attributes->set($param, $this->manager->getElement($id)); return true; }
/** * @param \FSi\Component\DataGrid\Column\ColumnTypeInterface $column * @param string $action * @param array $actionOptions */ private function validateActionOptions(ColumnTypeInterface $column, $action, array $actionOptions) { if (!isset($actionOptions['element'])) { return false; } if (!$this->manager->hasElement($actionOptions['element'])) { throw new RuntimeException(sprintf('Unknown element "%s" specified in action "%s" of datagrid "%s"', $actionOptions['element'], $action, $column->getDataGrid()->getName())); } return true; }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager * @param \FSi\Bundle\AdminBundle\Admin\Element $element * @param \FSi\Bundle\DataGridBundle\DataGrid\Extension\Symfony\ColumnType\Action $column * @throws \FSi\Component\DataGrid\Exception\UnknownOptionException */ function it_initializes_action_route_and_parameters_based_on_element_id($manager, $element, $column) { $actionOptions = array('element' => 'some_element_id', 'additional_parameters' => array('additional_action_parameter' => 'action_parameter_value'), 'other_action_option' => 'other_option_value'); $otherAction = array('any_action_option' => 'any_option_value'); $column->getOption('actions')->willReturn(array('some_action' => $actionOptions, 'other_action' => $otherAction)); $manager->hasElement('some_element_id')->willReturn(true); $manager->getElement('some_element_id')->willReturn($element); $element->getId()->willReturn('some_element_id'); $element->getRoute()->willReturn('admin_element_route'); $element->getRouteParameters()->willReturn(array('additional_element_parameter' => 'element_parameter_value')); $column->setOption('actions', array('some_action' => array('route_name' => 'admin_element_route', 'additional_parameters' => array('element' => 'some_element_id', 'additional_element_parameter' => 'element_parameter_value', 'additional_action_parameter' => 'action_parameter_value'), 'parameters_field_mapping' => array('id' => 'id'), 'other_action_option' => 'other_option_value'), 'other_action' => array('any_action_option' => 'any_option_value')))->shouldBeCalled(); $this->filterValue($column, 'whatever')->shouldReturn('whatever'); }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager */ function let($manager) { $prophet = new Prophet(); $manager->getElement(Argument::type('string'))->will(function ($args) use($prophet) { if ($args[0] == 'non_existing') { throw new \Exception(sprintf('Element %s does not exist', $args[0])); } $element = $prophet->prophesize('FSi\\Bundle\\AdminBundle\\Admin\\Element'); $element->getId()->willReturn($args[0]); return $element; }); $manager->hasElement(Argument::type('string'))->will(function ($args) { return $args[0] != 'non_existing'; }); $this->beConstructedWith($manager, __DIR__ . '/admin_menu.yml'); }
/** * @param \Symfony\Component\OptionsResolver\Options $options */ private function validateElementFromOptions(Options $options) { if (!$this->manager->hasElement($options['element'])) { throw new RuntimeException(sprintf('Unknown element "%s" specified in batch action', $options['element'])); } }
/** * @param \FSi\Bundle\AdminBundle\Admin\Manager $manager * @param \FSi\Bundle\AdminBundle\Admin\CRUD\BatchElement $batchElement * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\ParameterBag $queryAttributes * @param \Symfony\Component\Routing\RouterInterface $router * @param \Symfony\Component\Form\Test\FormBuilderInterface $formBuilder * @param \Symfony\Component\Form\FormView $formView * @param \FSi\Component\DataGrid\Column\ColumnTypeInterface $column * @param \FSi\Component\DataGrid\Column\HeaderViewInterface $view */ function it_adds_redirect_uri_to_actions_when_no_redirect_uri_is_defined($manager, $batchElement, $request, $queryAttributes, $router, $formBuilder, $formView, $column, $view) { $column->getOption('actions')->willReturn(array(array('element' => 'some_batch_element_id', 'additional_parameters' => array('some_additional_parameter' => 'some_value'), 'label' => 'batch_action_label'))); $column->getOption('translation_domain')->willReturn('FSiAdminBundle'); $manager->hasElement('some_batch_element_id')->willReturn(true); $manager->getElement('some_batch_element_id')->willReturn($batchElement); $batchElement->getId()->willReturn('some_batch_element_id'); $batchElement->getRoute()->willReturn('fsi_admin_batch'); $batchElement->getRouteParameters()->willReturn(array('element' => 'some_batch_element_id')); $queryAttributes->has('redirect_uri')->willReturn(false); $request->getRequestUri()->willReturn('current_request_uri'); $router->generate('fsi_admin_batch', array('element' => 'some_batch_element_id', 'some_additional_parameter' => 'some_value', 'redirect_uri' => 'current_request_uri'))->willReturn('path_to_batch_action'); $formBuilder->add('action', 'choice', array('choices' => array(0 => 'crud.list.batch.empty_choice', 'path_to_batch_action' => 'batch_action_label'), 'translation_domain' => 'FSiAdminBundle'))->willReturn(); $formBuilder->add('submit', 'submit', array('label' => 'crud.list.batch.confirm', 'translation_domain' => 'FSiAdminBundle'))->willReturn(); $view->setAttribute('batch_form', $formView)->shouldBeCalled(); $this->buildHeaderView($column, $view); }