/** * {@inheritdoc} */ public function renderAction(GridView $gridView, Action $action, $data = null) { if (!isset($this->actionTemplates[$type = $action->getType()])) { throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type)); } return $this->twig->render($this->actionTemplates[$type], ['grid' => $gridView, 'action' => $action, 'data' => $data]); }
function it_knows_if_action_with_given_name_already_exists(Action $action) { $action->getName()->willReturn('read_book'); $this->addAction($action); $this->hasAction('read_book')->shouldReturn(true); $this->hasAction('delete_book')->shouldReturn(false); }
/** * {@inheritdoc} */ public function renderAction(GridViewInterface $gridView, Action $action, $data = null) { $type = $action->getType(); if (!isset($this->actionTemplates[$type])) { throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type)); } $options = $this->optionsParser->parseOptions($action->getOptions(), $gridView->getRequestConfiguration()->getRequest(), $data); return $this->twig->render($this->actionTemplates[$type], ['grid' => $gridView, 'action' => $action, 'data' => $data, 'options' => $options]); }
function it_converts_an_array_to_grid_definition() { $grid = Grid::fromCodeAndDriverConfiguration('sylius_admin_tax_category', 'doctrine/orm', ['resource' => 'sylius.tax_category']); $grid->setSorting(['name' => 'desc']); $codeField = Field::fromNameAndType('code', 'string'); $codeField->setLabel('System Code'); $codeField->setPath('method.code'); $codeField->setOptions(['template' => 'bar.html.twig']); $grid->addField($codeField); $viewAction = Action::fromNameAndType('view', 'link'); $viewAction->setLabel('Display Tax Category'); $viewAction->setOptions(['foo' => 'bar']); $defaultActionGroup = ActionGroup::named('default'); $defaultActionGroup->addAction($viewAction); $grid->addActionGroup($defaultActionGroup); $filter = Filter::fromNameAndType('enabled', 'boolean'); $grid->addFilter($filter); $definitionArray = ['driver' => ['name' => 'doctrine/orm', 'options' => ['resource' => 'sylius.tax_category']], 'sorting' => ['name' => 'desc'], 'fields' => ['code' => ['type' => 'string', 'label' => 'System Code', 'path' => 'method.code', 'options' => ['template' => 'bar.html.twig']]], 'filters' => ['enabled' => ['type' => 'boolean']], 'actions' => ['default' => ['view' => ['type' => 'link', 'label' => 'Display Tax Category', 'options' => ['foo' => 'bar']]]]]; $this->convert('sylius_admin_tax_category', $definitionArray)->shouldBeSameGridAs($grid); }
function it_throws_an_exception_if_template_is_not_configured_for_given_action_type(GridView $gridView, Action $action) { $action->getType()->willReturn('foo'); $this->shouldThrow(new \InvalidArgumentException('Missing template for action type "foo".'))->during('renderAction', [$gridView, $action]); }