예제 #1
0
 /**
  * Get all the Template Variables for this Resource
  * @return void
  */
 public function getTemplateVariables()
 {
     if (method_exists('modResource', 'getTemplateVarCollection')) {
         $tvObjs = modResource::getTemplateVarCollection($this->resource);
     } else {
         $tvObjs = $this->_getTemplateVars();
     }
     $tvs = array();
     $categories = array();
     /** @var modTemplateVar $tv */
     foreach ($tvObjs as $tv) {
         if ($tv instanceof modTemplateVar) {
             $tvArray = $tv->toArray();
             if (!empty($categories[$tvArray['category']])) {
                 $tvs[$categories[$tvArray['category']]][] = $tv;
             } else {
                 if ($tvArray['category'] == 0) {
                     $tvs[$this->modx->lexicon('uncategorized')][] = $tv;
                 } else {
                     $cat = $tv->getOne('Category');
                     if ($cat instanceof modCategory) {
                         $categories[$tvArray['category']] = $cat->get('category');
                         $tvs[$categories[$tvArray['category']]][] = $tv;
                     }
                 }
             }
         }
     }
     $list = array();
     if (count($tvs) > 0) {
         $this->modx->loadClass('hmTvInputRenderer', $this->hm->config['classesPath'], true, true);
         $renderer = new hmTvInputRenderer($this->hm);
         foreach ($tvs as $categoryName => $categoryTemplateVariables) {
             $tvList = array();
             /** @var modTemplateVar $tv */
             foreach ($categoryTemplateVariables as $tv) {
                 $tvList[] = $renderer->render($tv->get('display'), $tv);
             }
             $list[] = $this->hm->getTpl('fields/tvs/category', array('name' => $categoryName, 'collapsed' => !isset($notFirst) && count($tvs != 1) ? 'data-collapsed="false"' : 'data-collapsed="true"', 'tvs' => implode("\n", $tvList)));
             // This makes sure the first section is opened if there are > 1 sections
             $notFirst = true;
         }
         unset($notFirst);
     }
     $this->setPlaceholder('tvs', implode("\n", $list));
 }