/**
  * {@inheritdoc}
  */
 public function normalizeOptions(array &$options, ContextInterface $context, DataAccessorInterface $data)
 {
     if (false !== $context->getOr('expressions_evaluate_deferred')) {
         return;
     }
     $evaluate = $context->getOr('expressions_evaluate');
     $encoding = $context->getOr('expressions_encoding');
     $this->processor->processExpressions($options, $context, $data, $evaluate, $encoding);
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     $context->getResolver()->setDefaults(['debug' => function (Options $options, $value) {
         if (null === $value) {
             $value = $this->kernel->isDebug();
         }
         return $value;
     }])->setAllowedTypes(['debug' => 'bool']);
 }
Example #3
0
 /**
  * Returns the form accessor.
  *
  * @param ContextInterface $context
  * @param array            $options
  *
  * @return FormAccessorInterface
  *
  * @throws \OutOfBoundsException if the context does not contain the form accessor
  * @throws UnexpectedTypeException if the form accessor stored in the context has invalid type
  */
 protected function getFormAccessor(ContextInterface $context, array $options)
 {
     /** @var FormAccessorInterface $formAccessor */
     $formAccessor = $context->get($options['form_name']);
     if (!$formAccessor instanceof FormAccessorInterface) {
         throw new UnexpectedTypeException($formAccessor, 'Oro\\Bundle\\LayoutBundle\\Layout\\Form\\FormAccessorInterface', sprintf('context[%s]', $options['form_name']));
     }
     return $formAccessor;
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     $context->getResolver()->setDefaults(['theme' => function (Options $options, $value) {
         if (null === $value && $this->request) {
             if (null === $value) {
                 $value = $this->request->attributes->get('_theme');
             }
         }
         return $value;
     }])->setAllowedTypes(['theme' => ['string', 'null']]);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getPaths(array $existingPaths)
 {
     $widgetName = $this->context->getOr('widget_container');
     if (!$widgetName) {
         $widgetName = 'page';
     }
     $paths = [];
     foreach ($existingPaths as $path) {
         $paths[] = $path;
         $paths[] = implode(self::DELIMITER, [$path, $widgetName]);
     }
     return $paths;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 protected function loadLayoutUpdates(ContextInterface $context)
 {
     $updates = [];
     if ($context->getOr('theme')) {
         $iterator = new ResourceIterator($this->findApplicableResources($context));
         foreach ($iterator as $file) {
             $update = $this->loader->load($file);
             if ($update) {
                 $this->dependencyInitializer->initialize($update);
                 $el = $update instanceof ElementDependentLayoutUpdateInterface ? $update->getElement() : 'root';
                 $updates[$el][] = $update;
             }
         }
     }
     return $updates;
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     $request = $this->requestStack->getCurrentRequest();
     $context->getResolver()->setDefaults(['widget_container' => function (Options $options, $value) use($request) {
         if (null === $value && $request) {
             $value = $request->query->get('_widgetContainer') ?: $request->request->get('_widgetContainer');
         }
         return $value;
     }])->setAllowedTypes(['widget_container' => ['string', 'null']]);
     $context->data()->setDefault('widget_id', '$request._wid', function () use($request) {
         if (!$request) {
             throw new \BadMethodCallException('The request expected.');
         }
         return $request->query->get('_wid') ?: $request->request->get('_wid');
     });
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     if (!$context->has('data')) {
         return;
     }
     $data = $context->get('data');
     if (!is_array($data)) {
         return;
     }
     foreach ($data as $key => $val) {
         if (!is_string($key)) {
             throw new \InvalidArgumentException(sprintf('The data key "%s" must be a string, but "%s" given.', $key, gettype($key)));
         }
         if (!is_array($val)) {
             throw new \InvalidArgumentException(sprintf('The data item "%s" must be an array, but "%s" given.', $key, is_object($val) ? get_class($val) : gettype($val)));
         }
         $context->data()->set($key, $this->getDataIdentifier($key, $val), $this->getData($key, $val));
     }
     $context->remove('data');
 }
 /**
  * {@inheritdoc}
  */
 public function getPaths(array $existingPaths)
 {
     $themeName = $this->context->getOr('theme');
     if ($themeName) {
         $themePaths = [];
         foreach ($this->getThemesHierarchy($themeName) as $theme) {
             $existingPaths[] = $themePaths[] = $theme->getDirectory();
         }
         $actionName = $this->context->getOr('action');
         if ($actionName) {
             foreach ($themePaths as $path) {
                 $existingPaths[] = implode(self::DELIMITER, [$path, $actionName]);
             }
         }
         $routeName = $this->context->getOr('route_name');
         if ($routeName) {
             foreach ($themePaths as $path) {
                 $existingPaths[] = implode(self::DELIMITER, [$path, $routeName]);
             }
         }
     }
     return $existingPaths;
 }
 /**
  * @param ContextInterface $context
  *
  * @return string|null
  */
 protected function extractFormEnctype(ContextInterface $context)
 {
     $formEnctype = null;
     if ($context->has('form_enctype')) {
         $formEnctype = $context->get('form_enctype');
         if (!is_string($formEnctype)) {
             throw new \InvalidArgumentException(sprintf('The "form_enctype" must be a string, but "%s" given.', $this->getTypeName($formEnctype)));
         }
         $context->remove('form_enctype');
     }
     return $formEnctype;
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function getData(ContextInterface $context)
 {
     return $this->themeManager->getTheme($context->get('theme'));
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     $context->getResolver()->setDefaults(['expressions_evaluate' => true, 'expressions_evaluate_deferred' => false])->setOptional(['expressions_encoding'])->setAllowedTypes(['expressions_evaluate' => 'bool', 'expressions_evaluate_deferred' => 'bool', 'expressions_encoding' => ['string', 'null']]);
 }
Example #13
0
 /**
  * Configures the layout context.
  *
  * @param ContextInterface $context
  * @param LayoutAnnotation $layoutAnnotation
  */
 protected function configureContext(ContextInterface $context, LayoutAnnotation $layoutAnnotation)
 {
     $action = $layoutAnnotation->getAction();
     if (!empty($action)) {
         $currentAction = $context->getOr('action');
         if (empty($currentAction)) {
             $context->set('action', $action);
         }
     }
     $theme = $layoutAnnotation->getTheme();
     if (!empty($theme)) {
         $currentTheme = $context->getOr('theme');
         if (empty($currentTheme)) {
             $context->set('theme', $theme);
         }
     }
     $vars = $layoutAnnotation->getVars();
     if (!empty($vars)) {
         $context->getResolver()->setRequired($vars);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function configureContext(ContextInterface $context)
 {
     $context->getResolver()->setDefaults(['action' => ''])->setAllowedTypes(['action' => 'string']);
 }