Type/Variable/ImageVariableType.php
public function getMediaContext($context_id = null)
    {

        if (is_null($context_id)) {
            $context_id = $this->getMediaContextId();
        }

        $context = $this->getClassificationContextManager()->find($context_id);

        if (is_null($context)) {
            $context = $this->getClassificationContextManager()->create();
            $context->setId($context_id);
            $context->setName($context_id);
            $context->setEnabled(true);
            $context->setCreatedAt(new \Datetime());
            $context->setUpdatedAt(new \Datetime());
            $this->getEntityManager()->persist($context);
            $this->getEntityManager()->flush($context);

            $defaultCategory = $this->getClassificationCategoryManager()->create();
            $defaultCategory->setContext($context);
            $defaultCategory->setName($context->getId() . '_default');
            $defaultCategory->setEnabled(true);
            $defaultCategory->setCreatedAt(new \Datetime());
            $defaultCategory->setUpdatedAt(new \Datetime());
            $defaultCategory->setSlug($context->getId() . '_default');
            $defaultCategory->setDescription($context->getId() . '_default');
            $this->getEntityManager()->persist($defaultCategory);
            $this->getEntityManager()->flush($defaultCategory);
        }

        return $context;
    }
public function getMediaContext($context_id = null)
    {

        if (is_null($context_id)) {
            $context_id = $this->getMediaContextId();
        }

        $context = $this->getClassificationContextManager()->find($context_id);

        if (is_null($context)) {
            $context = $this->getClassificationContextManager()->create();
            $context->setId($context_id);
            $context->setName($context_id);
            $context->setEnabled(true);
            $context->setCreatedAt(new \Datetime());
            $context->setUpdatedAt(new \Datetime());
            $this->getEntityManager()->persist($context);
            $this->getEntityManager()->flush($context);

            $defaultCategory = $this->getClassificationCategoryManager()->create();
            $defaultCategory->setContext($context);
            $defaultCategory->setName($context->getId() . '_default');
            $defaultCategory->setEnabled(true);
            $defaultCategory->setCreatedAt(new \Datetime());
            $defaultCategory->setUpdatedAt(new \Datetime());
            $defaultCategory->setSlug($context->getId() . '_default');
            $defaultCategory->setDescription($context->getId() . '_default');
            $this->getEntityManager()->persist($defaultCategory);
            $this->getEntityManager()->flush($defaultCategory);
        }

        return $context;
    }
public function getMediaContext ( $ context_id = null ) { if ( is_null ( $ context_id ) ) { $ context_id = $ this -> getMediaContextId ( ) ; } $ context = $ this -> getClassificationContextManager ( ) -> find ( $ context_id ) ; if ( is_null ( $ context ) ) { $ context = $ this -> getClassificationContextManager ( ) -> create ( ) ; $ context -> setId ( $ context_id ) ; $ context -> setName ( $ context_id ) ; $ context -> setEnabled ( true ) ; $ context -> setCreatedAt ( new \ Datetime ( ) ) ; $ context -> setUpdatedAt ( new \ Datetime ( ) ) ; $ this -> getEntityManager ( ) -> persist ( $ context ) ; $ this -> getEntityManager ( ) -> flush ( $ context ) ; $ defaultCategory = $ this -> getClassificationCategoryManager ( ) -> create ( ) ; $ defaultCategory -> setContext ( $ context ) ; $ defaultCategory -> setName ( $ context -> getId ( ) . '_default' ) ; $ defaultCategory -> setEnabled ( true ) ; $ defaultCategory -> setCreatedAt ( new \ Datetime ( ) ) ; $ defaultCategory -> setUpdatedAt ( new \ Datetime ( ) ) ; $ defaultCategory -> setSlug ( $ context -> getId ( ) . '_default' ) ; $ defaultCategory -> setDescription ( $ context -> getId ( ) . '_default' ) ; $ this -> getEntityManager ( ) -> persist ( $ defaultCategory ) ; $ this -> getEntityManager ( ) -> flush ( $ defaultCategory ) ; } return $ context ; }
Obtiene el contexto de medias

@return \Sonata\ClassificationBundle\Entity\BaseContext
Obtiene el contexto de medias