/**
  * {@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;
 }
Exemple #2
0
 /**
  * Retrieves context with id $id or throws an exception if it doesn't exist.
  *
  * @param int $id A Context identifier
  *
  * @return ContextInterface
  *
  * @throws NotFoundHttpException
  */
 protected function getContext($id)
 {
     $context = $this->contextManager->find($id);
     if (null === $context) {
         throw new NotFoundHttpException(sprintf('Context (%d) not found', $id));
     }
     return $context;
 }
Exemple #3
0
 /**
  * @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;
 }