Programming Language PHP

Namespace Oro\Component\Layout

Class ContextInterface

Total Examples 4

4 code examples of PHP Oro\Component\Layout\ContextInterface extracted from open source projects

Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function configureContext(ContextInterface $context)
    {
        $context->getResolver()
            ->setRequired(['is_mobile'])
            ->setAllowedTypes('is_mobile', ['boolean']);

        $context->set('is_mobile', $this->userAgentProvider->getUserAgent()->isMobile());
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function configureContext(ContextInterface $context)
    {
        $context->getResolver()
            ->setRequired([self::OPTION_NAME])
            ->setAllowedTypes(self::OPTION_NAME, ['bool']);

        $context->set(self::OPTION_NAME, $this->tokenAccessor->hasUser());
    }
                                            
Was this example useful?
0
                                                    /**
     * @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)) {
                $context->data()->set($key, $this->getData($key, $val));
            } else {
                $context->data()->set($key, $val);
            }
        }

        $context->remove('data');
    }
                                            
Was this example useful?
0
                                                    /**
     * Sets grid config for given grid name(-s) into layout context
     *
     * {@inheritdoc}
     */
    public function configureContext(ContextInterface $context)
    {
        if (!$context->has('grid_config')) {
            return;
        }

        $context->getResolver()
            ->setDefined(['grid_config'])
            ->setAllowedTypes('grid_config', ['array']);

        $data = $context->getOr('grid_config');

        if (!is_array($data)) {
            return;
        }

        $gridConfig = [];
        foreach ($data as $gridName) {
            if (!is_string($gridName)) {
                throw new \InvalidArgumentException(
                    sprintf('The "grid_config" value must be a string, but "%s" given.', gettype($gridName))
                );
            }

            $config = $this->dataGridManager->getConfigurationForGrid($gridName);
            $gridConfig[$gridName] = $config->toArray();
        }

        $context->set('grid_config', $gridConfig);
    }