Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(['constraints' => function (Options $options) {
         return new GridSortingConstraint(['grid' => $options['grid']]);
     }, 'error_bubbling' => function (Options $options) {
         return !$this->parameterResolver->resolveApi();
     }])->setRequired('grid')->setAllowedTypes('grid', GridInterface::class);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getLocales()
 {
     if (($request = $this->requestStack->getMasterRequest()) === null) {
         return [$this->localeProvider->getDefaultLocale()->getCode()];
     }
     $locales = [];
     if ($this->parameterResolver->resolveApi()) {
         $locales = $this->parseAcceptLanguage($request);
     }
     if (empty($locales)) {
         $locales = [$request->getLocale()];
     }
     return $locales;
 }
Exemplo n.º 3
0
 /**
  * @param string|FormTypeInterface|ResourceInterface $type
  * @param mixed                                      $data
  * @param mixed[]                                    $options
  *
  * @return FormInterface
  */
 public function create($type = null, $data = null, array $options = [])
 {
     if ($type instanceof ResourceInterface) {
         $type = $this->parameterResolver->resolveForm($type);
     }
     $validationGroups = $this->parameterResolver->resolveValidationGroups();
     $translationDomain = $this->parameterResolver->resolveTranslationDomain();
     if (!empty($validationGroups)) {
         $options['validation_groups'] = $validationGroups;
     }
     if (!empty($translationDomain)) {
         $options['translation_domain'] = $translationDomain;
     }
     if ($this->parameterResolver->resolveApi()) {
         $options['csrf_protection'] = false;
     }
     return $this->factory->create($type, $data, $options);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function batch($data, array $options)
 {
     if (!is_array($data) && !$data instanceof \Traversable) {
         return;
     }
     $grid = $options['grid'];
     $domainManager = $this->domainManagerRegistry[$grid->getResource()->getName()];
     $api = $this->parameterResolver->resolveApi();
     foreach ($data as $object) {
         try {
             $domainManager->delete($object, !$api);
         } catch (DomainException $e) {
             if ($api) {
                 throw $e;
             }
         }
     }
     if ($api) {
         $domainManager->flush();
     }
 }
Exemplo n.º 5
0
 /**
  * @param DomainEvent $event
  */
 public function addMessage(DomainEvent $event)
 {
     if ($this->parameterResolver->resolveApi()) {
         return;
     }
     $messageType = $event->getMessageType();
     $message = $event->getMessage();
     if (empty($messageType)) {
         $messageType = $event->isStopped() ? 'error' : 'success';
     }
     if (empty($message)) {
         $data = $event->getData();
         $resource = $event->getResource();
         $name = $resource->getName();
         $labelPropertyPath = $resource->getLabelPropertyPath();
         $property = $labelPropertyPath !== null ? $this->propertyAccessor->getValue($data, $labelPropertyPath) : (string) $data;
         $message = $this->translator->trans('lug.' . $name . '.' . $event->getAction() . '.' . $messageType, ['%' . $name . '%' => $property], 'flashes');
     }
     $event->setMessageType($messageType);
     $event->setMessage($message);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $idPropertyPath = function (Options $options) {
         $propertyPath = $options['grid']->getDefinition()->getResource()->getIdPropertyPath();
         return function ($choice) use($propertyPath) {
             return $this->propertyAccessor->getValue($choice, $propertyPath);
         };
     };
     $labelPropertyPath = function (Options $options) {
         $propertyPath = $options['grid']->getDefinition()->getResource()->getLabelPropertyPath();
         return function ($choice) use($propertyPath) {
             return $this->propertyAccessor->getValue($choice, $propertyPath);
         };
     };
     $resolver->setDefaults(['multiple' => true, 'translation_domain' => false, 'choices' => [], 'choices_as_values' => true, 'choice_name' => $idPropertyPath, 'choice_value' => $idPropertyPath, 'choice_label' => $labelPropertyPath, 'class' => function (Options $options) {
         return $options['grid']->getDefinition()->getResource()->getModel();
     }, 'expanded' => function (Options $options) {
         return !$this->parameterResolver->resolveApi();
     }, 'constraints' => function (Options $options) {
         $resource = $options['grid']->getDefinition()->getResource();
         return [new Count(['min' => 1, 'minMessage' => 'lug.' . $resource->getName() . '.batch.empty'])];
     }])->setRequired('grid')->setAllowedTypes('grid', GridViewInterface::class);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefault('api', $this->parameterResolver->resolveApi())->setAllowedTypes('api', 'bool');
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getFallbackLocale()
 {
     if (!$this->parameterResolver->resolveApi()) {
         return $this->localeProvider->getDefaultLocale()->getCode();
     }
 }
 /**
  * @param FormEvent $event
  */
 public function onPreSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $grid = $form->getConfig()->getOption('grid');
     $this->buildForm($form, !$this->parameterResolver->resolveApi() ? iterator_to_array($grid->getDataSource()) : []);
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(['base64' => $this->parameterResolver->resolveApi()]);
 }
Exemplo n.º 11
0
 /**
  * @param DomainEvent $event
  */
 public function addFlash(DomainEvent $event)
 {
     if (!$this->parameterResolver->resolveApi()) {
         $this->session->getFlashBag()->add($event->getMessageType(), $event->getMessage());
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefault('type', $this->parameterResolver->resolveApi() ? self::TYPE_API : self::TYPE_CHECKBOX);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function resolveApi()
 {
     return !isset($this->cache[$key = 'api']) ? $this->cache[$key] = $this->parameterResolver->resolveApi() : $this->cache[$key];
 }