function ActiveModulePosition($alias) { // get the module area as an object $position = ModulePosition::get()->filter('Alias', $alias)->First(); if (!isset($position->ID)) { user_error("Cannot find a Module Position by that name (" . $alias . "). Check your template is calling a ModulePosition by an alias that exists!", E_USER_ERROR); } // get this page's module list for specified position $modules = $this->PageModules()->Filter('PositionID', $position->ID); // if there are any modules in this area if ($modules->Count() > 0) { return true; } return false; }
public function onBeforeWrite() { parent::onBeforeWrite(); // convert name to lowercase, dashed $newAlias = $this->URLFriendly($this->Title); // get positions that already have this alias $positionsThatMatch = ModulePosition::get()->Filter('Alias', $newAlias)->First(); // if we find a match if (isset($positionsThatMatch->ID)) { // create a new unique alias (based on ID) $this->Alias = $newAlias . '-' . $this->ID; // no match, meaning we're safe to use this as a unique alias } else { $this->Alias = $newAlias; } }
public function getEditForm($id = null, $fields = null) { // get the cmsfields from ModuleManager DataObject $moduleManager = ModuleManager::CurrentModuleManager(); $fields = $moduleManager->getCMSFields(); // what pages is this module active on $modulesGridField = GridField::create("Modules_Gridfield", "Modules", Module::get(), $modulesGridFieldConfig = GridFieldConfig_RecordEditor::create()); $modulePositionsGridField = GridField::create("ModulePositions_Gridfield", "Module Positions", ModulePosition::get(), GridFieldConfig_RecordEditor::create()); // add multiclass dropdown for modules $modulesGridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); $modulesGridFieldConfig->addComponent(new GridFieldAddNewMultiClass()); // add the fields $fields->addFieldToTab('Root.Modules', $modulesGridField); $fields->addFieldToTab('Root.ModulePositions', $modulePositionsGridField); $fields->addFieldToTab('Root.ModulePositions', LiteralField::create('html', '<em>To load a position into your template, simply write <code>$ModulePosition(Alias)</code> where <code>Alias</code> is your position alias</em>')); // actions $actions = $moduleManager->getCMSActions(); $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-content center cms-edit-form'); // don't add data-pjax-fragment=CurrentForm, its added in the content template instead if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($moduleManager); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Use <button> to allow full jQuery UI styling $actions = $actions->dataFields(); if ($actions) { foreach ($actions as $action) { $action->setUseButtonTag(true); } } return $form; }
/** * Detect if this there are any modules on this page for this module area * @return boolean **/ public function HasModules($alias) { // get the module area as an object $position = ModulePosition::get()->filter('Alias', $alias)->First(); // no position by that ID, so we certainly cannot have any modules! if (!isset($position->ID)) { return false; } // get this page's module list for specified position $modules = $this->PageModules()->Filter('PositionID', $position->ID); return $modules->Count() > 0; }