system/modules/pct_customelements/PCT/CustomElements/Frontend/ContentCustomElement.php line 125

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Open Source CMS
  4.  * 
  5.  * Copyright (C) 2005-2013 Leo Feyer
  6.  * 
  7.  * @copyright    Tim Gatzky 2013, Premium Contao Webworks, Premium Contao Themes
  8.  * @author        Tim Gatzky <info@tim-gatzky.de>
  9.  * @package        pct_customelements
  10.  * @link        http://contao.org
  11.  */
  12. /**
  13.  * Namespace
  14.  */
  15. namespace PCT\CustomElements\Frontend;
  16. /**
  17.  * Import
  18.  */
  19. use PCT\CustomElements\Core\CustomElementFactory as CustomElementFactory;
  20. use PCT\CustomElements\Backend\BackendIntegration as BackendHelper;
  21. use PCT\CustomElements\Core\FrontendTemplate as FrontendTemplate;
  22. use Contao\System;
  23. /**
  24.  * Class file
  25.  * ContentCustomElement
  26.  * Render a custom element from a content element
  27.  */
  28. class ContentCustomElement extends \Contao\ContentElement
  29. {
  30.     /**
  31.      * Template
  32.      * @var
  33.      */
  34.     protected $strTemplate 'customelement_simple';
  35.     
  36.     /**
  37.      * CustomElement object
  38.      * @var object
  39.      */
  40.     protected $objCE null;
  41.     
  42.     /**
  43.      * Display wildcard
  44.      */
  45.     public function generate()
  46.     {
  47.         $request System::getContainer()->get('request_stack')->getCurrentRequest();
  48.         if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
  49.         {
  50.             $this->objCE CustomElementFactory::findByAlias($this->type);
  51.             
  52.             $objModel $this->objModel;
  53.             $intId $this->id;
  54.             if($objModel->origId && $objModel->origId != $intId)
  55.             {
  56.                 $intId $objModel->origId;
  57.             }
  58.             
  59.             $strWildcard '';
  60.             if(!empty($this->objCE))
  61.             {
  62.                 $objBackendHelper = new BackendHelper();
  63.                 $strWildcard $objBackendHelper->generateBackendWildcard($this->objCE->get('id'),$intId,'tl_content');
  64.             }
  65.             
  66.             $this->Template = new \Contao\BackendTemplate('be_ce_wildcard');
  67.             $this->Template->wildcard $strWildcard;
  68.             
  69.             return $this->Template->parse();
  70.         }
  71.         
  72.         $this->objCE CustomElementFactory::findByAlias($this->type);
  73.         
  74.         if(empty($this->objCE))
  75.         {
  76.             return parent::generate();
  77.         }
  78.         
  79.         // set template
  80.         if(strlen($this->objCE->get('template')) > && $this->objCE->get('template') != $this->strTemplate)
  81.         {
  82.             $this->strTemplate $this->objCE->get('template');
  83.         }
  84.         
  85.         // customTpl
  86.         if(strlen($this->customTpl) > && $this->customTpl != $this->strTemplate)
  87.         {
  88.             $this->strTemplate $this->customTpl;
  89.         }
  90.         
  91.         // cssID
  92.         $arrCssID \Contao\StringUtil::deserialize($this->cssID);
  93.         
  94.         if(!is_array($arrCssID))
  95.         {
  96.             $arrCssID explode(',',$this->cssID);
  97.         }
  98.         
  99.         $arrCssID array_filter($arrCssID,'strlen');
  100.         
  101.         if(count($arrCssID) < 1)
  102.         {
  103.             $this->cssID $this->objModel->cssID \Contao\StringUtil::deserialize($this->objCE->get('cssID'));
  104.         }
  105.         else
  106.         {
  107.             $arr \Contao\StringUtil::deserialize($this->objCE->get('cssID'));
  108.             if( isset($arrCssID[0]) && strlen($arrCssID[0]) > 0)
  109.             {
  110.                 $arr[0] = $arrCssID[0];
  111.             }
  112.             if( isset($arrCssID[1]) && strlen($arrCssID[1]) > 0)
  113.             {
  114.                 $arr[1] = $arrCssID[1];
  115.             }
  116.             $this->cssID $this->objModel->cssID $arr;
  117.         }
  118.         
  119.         return parent::generate();
  120.     }
  121.     /**
  122.      * Generate the content element
  123.      */
  124.     protected function compile()
  125.     {
  126.         $objOrigTemplate $this->Template;
  127.         
  128.         $this->Template = new FrontendTemplate($this->strTemplate);
  129.         $this->Template->setData($objOrigTemplate->getData());
  130.         
  131.         $objModel $this->objModel;
  132.         $intId $this->id;
  133.         if($objModel->origId && $objModel->origId != $intId)
  134.         {
  135.             $intId $objModel->origId;
  136.         }
  137.         
  138.         $objOrigin = new \PCT\CustomElements\Core\Origin();
  139.         $objOrigin->set('intPid',$intId);
  140.         $objOrigin->set('strTable',$objModel::getTable());
  141.         $objOrigin->set('objActiveRecord',$objModel);
  142.         
  143.         $this->objCE->setOrigin$objOrigin );
  144.         
  145.         $this->Template $this->objCE->addToTemplate($this->Template);
  146.     }
  147. }