예제 #1
0
 public function render($label, $customTemplate, $description)
 {
     $obj = $this->getPageTypeComposerControlDraftValue();
     if (!is_object($obj)) {
         if ($this->page) {
             // we HAVE a page, but we don't have a block object, which means something has gone wrong.
             // we've lost the association. So we abort.
             View::element('page_types/composer/controls/invalid_block');
             return;
         }
         $obj = $this->getBlockTypeObject();
     }
     $this->getController($obj);
     $app = Application::getFacadeApplication();
     $env = Environment::get();
     $form = $app->make('helper/form');
     $set = $this->getPageTypeComposerFormLayoutSetControlObject()->getPageTypeComposerFormLayoutSetObject();
     if ($customTemplate) {
         $rec = $env->getRecord(DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle() . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $customTemplate);
         if ($rec->exists()) {
             $template = DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $customTemplate;
         } else {
             foreach (PackageList::get()->getPackages() as $pkg) {
                 $file = (is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE) . '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $obj->getBlockTypeHandle() . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $customTemplate;
                 if (file_exists($file)) {
                     $template = DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $customTemplate;
                     break;
                 }
             }
         }
     }
     if (!isset($template)) {
         $template = FILENAME_BLOCK_COMPOSER;
     }
     $this->inc($template, ['control' => $this, 'obj' => $obj, 'description' => $description]);
 }