/** * {@inheritdoc} */ public function getNewInstance() { $instance = parent::getNewInstance(); if ($contextId = $this->getPersistentParameter('context')) { $context = $this->contextManager->find($contextId); if (!$context) { $context = $this->contextManager->create(); $context->setEnabled(true); $context->setId($context); $context->setName($context); $this->contextManager->save($context); } $instance->setContext($context); } return $instance; }
/** * @param $contextCode * * @return ContextInterface */ private function getContext($contextCode) { if (empty($contextCode)) { $contextCode = ContextInterface::DEFAULT_CONTEXT; } if ($contextCode instanceof ContextInterface) { return $contextCode; } $context = $this->contextManager->find($contextCode); if (!$context instanceof ContextInterface) { $context = $this->contextManager->create(); $context->setId($contextCode); $context->setName($contextCode); $context->setEnabled(true); $this->contextManager->save($context); } return $context; }