function it_knows_if_field_with_given_name_already_exists(Field $field) { $field->getName()->willReturn('enabled'); $this->addField($field); $this->hasField('enabled')->shouldReturn(true); $this->hasField('parent')->shouldReturn(false); }
/** * {@inheritdoc} */ public function render(Field $field, $data, array $options) { if ('.' !== $field->getPath()) { $data = $this->dataExtractor->get($field, $data); } return $this->twig->render($options['template'], ['data' => $data, 'options' => $options]); }
function it_renders_field_with_data_via_appriopriate_field_type(GridView $gridView, Field $field, ServiceRegistryInterface $fieldsRegistry, FieldTypeInterface $fieldType) { $field->getType()->willReturn('string'); $fieldsRegistry->get('string')->willReturn($fieldType); $fieldType->render($field, 'Value')->willReturn('<strong>Value</strong>'); $this->renderField($gridView, $field, 'Value')->shouldReturn('<strong>Value</strong>'); }
function it_uses_data_directly_if_dot_is_configured_as_path(\Twig_Environment $twig, Field $field) { $field->getOptions()->willReturn(['template' => 'foo.html.twig']); $field->getPath()->willReturn('.'); $twig->render('foo.html.twig', ['data' => 'bar'])->willReturn('<html>Bar</html>'); $this->render($field, 'bar')->shouldReturn('<html>Bar</html>'); }
/** * {@inheritdoc} */ public function render(Field $field, $data) { if ('.' !== $field->getPath()) { $data = $this->dataExtractor->get($field, $data); } return $this->twig->render($field->getOptions()['template'], ['data' => $data]); }
/** * @param Field $field * @param $data */ public function renderField(GridView $gridView, Field $field, $data) { $fieldType = $this->fieldsRegistry->get($field->getType()); $resolver = new OptionsResolver(); $fieldType->configureOptions($resolver); $options = $resolver->resolve($field->getOptions()); return $fieldType->render($field, $data, $options); }
function it_renders_field_with_data_via_appropriate_field_type(GridView $gridView, Field $field, ServiceRegistryInterface $fieldsRegistry, FieldTypeInterface $fieldType) { $field->getType()->willReturn('string'); $fieldsRegistry->get('string')->willReturn($fieldType); $fieldType->configureOptions(Argument::type(OptionsResolver::class))->will(function ($args) { $args[0]->setRequired('foo'); }); $field->getOptions()->willReturn(['foo' => 'bar']); $fieldType->render($field, 'Value', ['foo' => 'bar'])->willReturn('<strong>Value</strong>'); $this->renderField($gridView, $field, 'Value')->shouldReturn('<strong>Value</strong>'); }
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); }
/** * {@inheritdoc} */ public function get(Field $field, $data) { return $this->propertyAccessor->getValue($data, $field->getPath()); }
function it_uses_property_accessor_to_extract_the_data(PropertyAccessorInterface $propertyAccessor, Field $field) { $field->getPath()->willReturn('foo'); $propertyAccessor->getValue(['foo' => 'bar'], 'foo')->willReturn('Value'); $this->get($field, ['foo' => 'bar'])->shouldReturn('Value'); }
/** * @param Field $field */ public function addField(Field $field) { $name = $field->getName(); if ($this->hasField($name)) { throw new \InvalidArgumentException(sprintf('Field "%s" already exists.', $name)); } $this->fields[$name] = $field; }