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);
 }
Exemplo n.º 2
0
 function it_knows_if_filter_with_given_name_already_exists(Filter $filter)
 {
     $filter->getName()->willReturn('enabled');
     $this->addFilter($filter);
     $this->hasFilter('enabled')->shouldReturn(true);
     $this->hasFilter('created_at')->shouldReturn(false);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function renderFilter(GridView $gridView, Filter $filter)
 {
     if (!isset($this->filterTemplates[$type = $filter->getType()])) {
         throw new \InvalidArgumentException(sprintf('Missing template for filter type "%s".', $type));
     }
     $form = $this->formFactory->createNamed('criteria', 'form', [], ['csrf_protection' => false, 'required' => false]);
     $form->add($filter->getName(), sprintf('sylius_grid_filter_%s', $filter->getType()), $filter->getOptions());
     $criteria = $gridView->getParameters()->get('criteria', []);
     $form->submit($criteria);
     return $this->twig->render($this->filterTemplates[$type], ['grid' => $gridView, 'filter' => $filter, 'form' => $form->get($filter->getName())->createView()]);
 }
Exemplo n.º 4
0
 /**
  * @param Filter $filter
  */
 public function addFilter(Filter $filter)
 {
     if ($this->hasFilter($name = $filter->getName())) {
         throw new \InvalidArgumentException(sprintf('Filter "%s" already exists.', $name));
     }
     $this->filters[$name] = $filter;
 }
Exemplo n.º 5
0
 /**
  * @param Filter $filter
  *
  * @return string
  *
  * @throws \InvalidArgumentException
  */
 private function getFilterTemplate(Filter $filter)
 {
     $template = $filter->getTemplate();
     if (null !== $template) {
         return $template;
     }
     $type = $filter->getType();
     if (!isset($this->filterTemplates[$type])) {
         throw new \InvalidArgumentException(sprintf('Missing template for filter type "%s".', $type));
     }
     return $this->filterTemplates[$type];
 }