/** * Wrap module with inline admin controls. * * @param string $content * @param Curry_PageModuleWrapper $pageModuleWrapper * @return string */ protected function adminModule($content, Curry_PageModuleWrapper $pageModuleWrapper) { $user = User::getUser(); $pageId = $pageModuleWrapper->getPageRevision()->getPageId(); $page = $pageModuleWrapper->getPageRevision()->getPage(); $pageModuleId = $pageModuleWrapper->getPageModuleId(); $commands = array(); $templatePermission = $user->hasAccess('Curry_Backend_Template'); $contentPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT); $modulePermission = $user->hasPagePermission($page, PageAccessPeer::PERM_MODULES); $createPermission = $user->hasPagePermission($page, PageAccessPeer::PERM_CREATE_MODULE); if (!$user->hasModuleAccess($pageModuleWrapper)) { return $content; } if ($contentPermission || $modulePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'Module', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); if ($user->hasPagePermission($page, PageAccessPeer::PERM_CONTENT)) { $commands['edit'] = array('Name' => 'Edit', 'Url' => $url, 'Class' => 'iframe'); } } if ($pageModuleWrapper->getTemplate() && $templatePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Template', 'view' => 'Edit', 'file' => $pageModuleWrapper->getTemplate())); $commands['template'] = array('Name' => 'Edit template', 'Url' => $url, 'Class' => 'iframe'); } if ($modulePermission) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'ModuleProperties', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); $commands['properties'] = array('Name' => 'Properties', 'Url' => $url, 'Class' => 'iframe'); } if ($createPermission && ($contentPermission && !$pageModuleWrapper->isInherited() || $modulePermission)) { $url = url('admin.php', array('module' => 'Curry_Backend_Page', 'view' => 'DeleteModule', 'page_id' => $pageId, 'page_module_id' => $pageModuleId)); $commands['delete'] = array('Name' => 'Delete', 'Url' => $url, 'Class' => 'iframe'); } $module = $pageModuleWrapper->createObject(); $module->setPageGenerator($this); $commands = $module->getInlineCommands($commands); if (!count($commands)) { return $content; } $tpl = Curry_Twig_Template::loadTemplateString(Curry_InlineAdmin::getAdminModuleTpl()); return $tpl->render(array('Id' => $pageModuleId, 'Name' => $pageModuleWrapper->getName(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Content' => $content, 'commands' => $commands)); }
/** * Edit module form. * * @param Curry_PageModuleWrapper $wrapper * @return Curry_Form|null */ protected function getModuleForm(Curry_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; }