bundles/FoxHabbit/BasisBundle/Document/AreabrickTwig.php line 46

Open in your IDE?
  1. <?php
  2. namespace FoxHabbit\BasisBundle\Document;
  3. use Pimcore\Extension\Document\Areabrick\AbstractTemplateAreabrick;
  4. use Pimcore\Model\Document\Editable\Area\Info;
  5. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
  6. //use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  7. use FoxHabbit\BasisBundle\Manager\ConfigManager;
  8. abstract class AreabrickTwig extends AbstractTemplateAreabrick
  9. {
  10.     /**
  11.      * @var ConfigManager
  12.      */
  13.     protected $configManager;
  14.     /**
  15.      * @var TokenStorage
  16.      */
  17.     protected $tokenStorage ;
  18.     public function getTemplateLocation()
  19.     {
  20.         return static::TEMPLATE_LOCATION_BUNDLE;
  21.     }
  22.     public function getTemplateSuffix()
  23.     {
  24.         return static::TEMPLATE_SUFFIX_TWIG;
  25.     }
  26.     protected function getTemplateSubfolder() {
  27.         return '';
  28.     }
  29.     public function getName() {
  30.         $name $this->getId();
  31.         $name preg_replace'/^([^-]+)-(.+)$/''$2-($1)'$this->getId());
  32.         $name ucwordsstr_replace'-',' '$name));
  33.         return $name;
  34.     }
  35.     /**
  36.      * @param Info $info
  37.      *
  38.      * @throws \Exception
  39.      */
  40.     public function action(Info $info)
  41.     {
  42.         $this->configManager $this->container->get(ConfigManager::class);
  43.         //$info->getView()->configManager = $this->configManager;
  44.         $siteId null;
  45.         if($info->getDocument()) {
  46.             // Get site of current document for site specifig config
  47.             $site \Pimcore\Tool\Frontend::getSiteForDocument($info->getDocument());
  48.             if( $site) {
  49.                 $siteId $site->getId();
  50.             }
  51.         }
  52.         if( $info->getEditable()->getEditmode()) {
  53.             $config $this->configManager->getAreaConfigEditmode($this->getId(), $siteId);
  54.         } else {
  55.             $config $this->configManager->getAreaConfig($this->getId(), $siteId);
  56.         }
  57.         $info->setParam('config'$config);
  58.         $this->tokenStorage $this->container->get('security.token_storage');
  59.     }
  60.     // Hide the wrapper-div
  61.     public function getHtmlTagOpen(Info $info)
  62.     {
  63.         //return '<fieldset class="pimcore-area-outline"><legend>'.$info->getId().'</legend>';
  64.         return '<!-- START Brick '.$info->getId().' -->';
  65.     }
  66.     public function getHtmlTagClose(Info $info)
  67.     {
  68.         //return '</fieldset>';
  69.         return '<!-- END Brick '.$info->getId().' -->';
  70.     }
  71.     // Allow subfolder for the view scripts
  72.     public function getTemplate() { // For Pimcore 10
  73.         return $this->buildBrickTemplateReference'view');
  74.     }
  75.     public function getViewTemplate() { // For Pimcore 6
  76.         return $this->buildBrickTemplateReference'view');
  77.     }
  78.     public function getEditTemplate() { // For Pimcore 6
  79.         return $this->buildBrickTemplateReference'edit');
  80.     }
  81.     protected function buildBrickTemplateReference$type) {
  82.         $subfolder $this->getTemplateSubfolder();
  83.         if ($this->getTemplateLocation() === static::TEMPLATE_LOCATION_BUNDLE) {
  84.             return sprintf(
  85.                 '%s/Areas/%s%s/%s.%s',
  86.                 '@FoxHabbitBasis',
  87.                 $subfolder,
  88.                 $this->getId(),
  89.                 $type,
  90.                 $this->getTemplateSuffix()
  91.             );
  92.         } else {
  93.             return sprintf(
  94.                 'Areas/%s/%s%s.%s',
  95.                 $subfolder,
  96.                 $this->getId(),
  97.                 $type,
  98.                 $this->getTemplateSuffix()
  99.             );
  100.         }
  101.     }
  102.     protected function getUser() {
  103.         if( $this->tokenStorage) {
  104.             if( $this->tokenStorage->getToken()) {
  105.                 return $this->tokenStorage->getToken()->getUser();
  106.             }
  107.         }
  108.         return null;
  109.     }
  110. }