Example #1
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)
 {
     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');
 }
 /**
  * @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 #4
0
 /**
  * {@inheritdoc}
  */
 public function getData(ContextInterface $context)
 {
     return $this->themeManager->getTheme($context->get('theme'));
 }