Пример #1
0
 /**
  * Edit module form.
  *
  * @param PageModuleWrapper $wrapper
  * @return Curry_Form|null
  */
 protected function getModuleForm(PageModuleWrapper $wrapper)
 {
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('pid_editmodule' => array('hidden'))));
     if ($wrapper->hasData()) {
         $subform = $wrapper->createObject()->showBack();
         if ($subform == null) {
             return null;
         }
         if (!$subform instanceof Curry_Form_SubForm) {
             throw new Exception($wrapper->getClassName() . '::showBack() did not return an instance of Curry_Form_SubForm.');
         }
         if (!$subform->getLegend()) {
             $subform->setLegend($wrapper->getName() . ' (' . $wrapper->getClassName() . ')');
         }
         if (!$subform instanceof Curry_Form_MultiForm) {
             $subform->setDecorators(array('FormElements'));
         }
         $form->addSubForm($subform, 'module' . $wrapper->getPageModuleId());
         $buttons = array('save');
         $form->addElement('submit', 'save', array('label' => 'Save'));
         if ($wrapper->isDeletable()) {
             $form->addElement('submit', 'delete', array('label' => 'Remove content'));
             $buttons[] = 'delete';
         }
         $form->addDisplayGroup($buttons, 'dg1', array('class' => 'horizontal-group'));
     } else {
         $form->addElement('submit', 'create', array('label' => $wrapper->isInherited() ? 'Override content' : 'Create content'));
     }
     return $form;
 }
Пример #2
0
 /**
  * Get "copy code" for module.
  *
  * @param PageModuleWrapper $module
  * @return array
  */
 public static function getModuleCode(PageModuleWrapper $module)
 {
     $datas = array();
     $moduleDatas = ModuleDataQuery::create()->filterByPageModule($module->getPageModule())->filterByPageRevision($module->getPageRevision())->orderByLangcode()->find();
     foreach ($moduleDatas as $moduleData) {
         $datas[] = self::getModuleDataCode($moduleData);
     }
     return array("is_inherited" => $module->isInherited(), "uid" => $module->getPageModule()->getUid(), "name" => $module->getName(), "module_class" => $module->getClassName(), "inherit" => true, "target" => $module->getTarget(), "content_visibility" => $module->getPageModule()->getContentVisibility(), "search_visibility" => $module->getPageModule()->getSearchVisibility(), "datas" => $datas);
 }
Пример #3
0
 /**
  * Insert module and return generated content.
  *
  * @param PageModuleWrapper $pageModuleWrapper
  * @return string
  */
 protected function insertModule(PageModuleWrapper $pageModuleWrapper)
 {
     $this->app->logger->debug(($pageModuleWrapper->getEnabled() ? 'Inserting' : 'Skipping') . ' module "' . $pageModuleWrapper->getName() . '" of type "' . $pageModuleWrapper->getClassName() . '" with target "' . $pageModuleWrapper->getTarget() . '"');
     /** @var PreModuleEvent $event */
     $event = $this->app->dispatcher->dispatch(GeneratorEvents::PRE_MODULE, new PreModuleEvent($pageModuleWrapper));
     if ($event->getContent() === null) {
         // TODO: how do we handle $event->isEnabled() ?
         /** @var \Curry\Module\AbstractModule $module */
         $module = $pageModuleWrapper->createObject();
         $template = null;
         if ($event->getTemplate() !== null) {
             $this->app->twig->loadTemplate($event->getTemplate());
         } else {
             if ($module->getDefaultTemplate()) {
                 $template = $this->app->loadTemplateString($module->getDefaultTemplate());
             }
         }
         if ($template && $template->getEnvironment()) {
             $twig = $template->getEnvironment();
             $twig->addGlobal('module', array('Id' => $pageModuleWrapper->getPageModuleId(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Name' => $pageModuleWrapper->getName(), 'ModuleDataId' => $pageModuleWrapper->getModuleDataId(), 'Target' => $pageModuleWrapper->getTarget()));
         }
         $content = (string) $module->showFront($template);
     } else {
         $content = $event->getContent();
     }
     /** @var PostModuleEvent $postEvent */
     $postEvent = $this->app->dispatcher->dispatch(GeneratorEvents::POST_MODULE, new PostModuleEvent($pageModuleWrapper, $content, $event->getExtras()));
     return $postEvent->getContent();
 }