/** * Transforms all fields in the FieldList to use Bootstrap templates * @return FieldList */ public function bootstrapify() { foreach ($this->owner as $f) { if (isset($this->ignores[$f->getName()])) { continue; } // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { $f->Tabs()->bootstrapify(); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { $f->Fields()->bootstrapify(); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } return $this->owner; }
/** * Called from templates to get rendered blocks for the given area * @param string $area * @param integer $limit Limit the items to this number, or null for no limit */ public function BlockArea($area, $limit = null) { if ($this->owner->ID <= 0) { return; } // blocks break on fake pages ie Security/login $list = $this->getBlockList($area); foreach ($list as $block) { if (!$block->canView()) { $list->remove($block); } } if ($limit !== null) { $list = $list->limit($limit); } $data = array(); $data['HasBlockArea'] = $this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview'] || $list->Count() > 0; $data['BlockArea'] = $list; $data['AreaID'] = $area; $data = $this->owner->customise($data); $template = array('BlockArea_' . $area); if (SSViewer::hasTemplate($template)) { return $data->renderWith($template); } else { return $data->renderWith('BlockArea'); } }
/** * Called from templates to get rendered blocks for the given area * @param string $area * @param integer $limit Limit the items to this number, or null for no limit */ public function BlockArea($area, $limit = null) { if ($this->owner->ID <= 0) { return; } // blocks break on fake pages ie Security/login $list = $this->getBlockList($area); foreach ($list as $block) { if (!$block->canView()) { $list->remove($block); } } if ($limit !== null) { $list = $list->limit($limit); } $data['BlockArea'] = $list; $data['AreaID'] = $area; $data = $this->owner->customise($data); $template[] = 'BlockArea_' . $area; if (SSViewer::hasTemplate($template)) { return $data->renderWith($template); } else { return $data->renderWith('BlockArea'); } }
/** * Changes the templates of all the {@link FormField} * objects in a given {@link FieldList} object to those * that work the Bootstrap framework * * @param FieldList $fields */ public static function apply_bootstrap_to_fieldlist($fields) { foreach ($fields as $f) { // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { self::apply_bootstrap_to_fieldlist($f->Tabs()); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { self::apply_bootstrap_to_fieldlist($f->Fields()); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } }
public function bootstrapify() { $inline_fields = Config::inst()->get('BootstrapForm', 'inline_fields'); foreach ($this->owner as $f) { if (isset($this->ignores[$f->getName()])) { continue; } if ($f instanceof CompositeField) { $f->getChildren()->bootstrapify(); continue; } if (!in_array($f->class, $inline_fields)) { $f->addExtraClass('form-control'); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } return $this->owner; }
public function getPreviewLayout() { $templateName = "Preview_" . $this->URLSegment; if (!SSViewer::hasTemplate($templateName)) { $templateName = "Preview_" . $this->ClassName; } $template = array($templateName, 'Preview'); return $this->renderWith($template); }
/** * Transforms all fields in the FieldList to use Foundation templates * @return FieldList */ public function bootstrapify() { foreach ($this->owner as $f) { $sng = Injector::inst()->get($f->class, true, ['dummy', '']); if (isset($this->ignores[$f->getName()])) { continue; } // if we have a CompositeField, bootstrapify its children if ($f instanceof CompositeField) { $f->getChildren()->bootstrapify(); continue; } // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { $f->Tabs()->bootstrapify(); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { $f->Fields()->bootstrapify(); } // If the user has customised the holder template already, don't apply the default one. if ($sng->getFieldHolderTemplate() == $f->getFieldHolderTemplate()) { $template = "Foundation{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("FoundationFieldHolder"); } } // If the user has customised the field template already, don't apply the default one. if ($sng->getTemplate() == $f->getTemplate()) { foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Foundation{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } } return $this->owner; }
public function transform(FormField $field) { Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css'); // tab if ($field instanceof Tab) { $field->Fields()->transform(new FoundationFormTransformation()); } // tabset if ($field instanceof TabSet) { $field->Tabs()->transform(new FoundationFormTransformation()); } // fieldgroup if ($field instanceof FieldGroup) { $field->FieldList()->transform(new FoundationFormTransformation()); } // compositefield if ($field instanceof CompositeField) { $field->FieldList()->transform(new FoundationFormTransformation()); } $holder = "Foundation{$field->class}_holder"; if (SSViewer::hasTemplate($holder)) { $field->setFieldHolderTemplate($holder); } else { $field->setFieldHolderTemplate("FoundationFieldHolder"); } $holder_small = "Foundation{$field->class}_holder_small"; if (SSViewer::hasTemplate($holder_small)) { $field->setSmallFieldHolderTemplate($holder_small); } else { $field->setSmallFieldHolderTemplate("FoundationFieldHolderMinimal"); } foreach (array_reverse(ClassInfo::ancestry($field)) as $className) { $foundationCandidate = "Foundation{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($foundationCandidate)) { $field->setTemplate($foundationCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $field->setTemplate($nativeCandidate); break; } } return $field; }
/** * Render the FeatureBanners * @return String */ public function FeatureBannersHTML() { // Check if there are any FeatureBanners, before doing further checks if (!$this->FeatureBanners()->Count()) { return false; } if (static::$includeCSS) { Requirements::css(FEATURE_BANNERS_FOLDER . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'feature-banners.min.css'); } $templates = array('FeatureBanners'); $classes = array_reverse(ClassInfo::ancestry($this->owner->ClassName)); foreach ($classes as $class) { $template = sprintf('FeatureBanners_%s', $class); if (SSViewer::hasTemplate($template)) { $templates[] = $template; } if ($class == 'SiteTree') { break; } } return $this->owner->renderWith($templates); }
/** * Traverses the given the given class context looking for templates with the relevant name. * * @param $className string - valid class name * @param $suffix string * @param $baseClass string * * @return array */ public static function get_templates_by_class($className, $suffix = '', $baseClass = null) { // Figure out the class name from the supplied context. if (!is_string($className) || !class_exists($className)) { throw new InvalidArgumentException('SSViewer::get_templates_by_class() expects a valid class name as ' . 'its first parameter.'); return array(); } $templates = array(); $classes = array_reverse(ClassInfo::ancestry($className)); foreach ($classes as $class) { $template = $class . $suffix; if (SSViewer::hasTemplate($template)) { $templates[] = $template; } // If the class is "Page_Controller", look for Page.ss if (stripos($class, '_controller') !== false) { $template = str_ireplace('_controller', '', $class) . $suffix; if (SSViewer::hasTemplate($template)) { $templates[] = $template; } } if ($baseClass && $class == $baseClass) { break; } } return $templates; }
/** * Show the "login" page * * @return string Returns the "login" page as HTML code. */ public function login() { $customCSS = project() . '/css/tabs.css'; if (Director::fileExists($customCSS)) { Requirements::css($customCSS); } $tmpPage = new Page(); $tmpPage->Title = _t('Security.LOGIN', 'Log in'); $tmpPage->URLSegment = "Security"; $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children $controller = new Page_Controller($tmpPage); $controller->init(); //Controller::$currentController = $controller; $content = ''; $forms = $this->GetLoginForms(); if (!count($forms)) { user_error('No login-forms found, please use Authenticator::register_authenticator() to add one', E_USER_ERROR); } // only display tabs when more than one authenticator is provided // to save bandwidth and reduce the amount of custom styling needed if (count($forms) > 1) { Requirements::javascript("jsparty/loader.js"); Requirements::javascript("jsparty/prototype.js"); Requirements::javascript("jsparty/behaviour.js"); Requirements::javascript("jsparty/prototype_improvements.js"); Requirements::javascript("jsparty/tabstrip/tabstrip.js"); Requirements::javascript("jsparty/scriptaculous/effects.js"); Requirements::css("jsparty/tabstrip/tabstrip.css"); Requirements::css("sapphire/css/Form.css"); // Needed because the <base href=".."> in the template makes problems // with the tabstrip library otherwise $link_base = Director::absoluteURL($this->Link("login")); $content = '<div id="Form_EditForm">'; $content .= '<ul class="tabstrip">'; $content_forms = ''; foreach ($forms as $form) { $content .= "<li><a href=\"{$link_base}#{$form->FormName()}_tab\">{$form->getAuthenticator()->get_name()}</a></li>\n"; $content_forms .= '<div class="tab" id="' . $form->FormName() . '_tab">' . $form->forTemplate() . "</div>\n"; } $content .= "</ul>\n" . $content_forms . "\n</div>\n"; } else { $content .= $forms[0]->forTemplate(); } if (strlen($message = Session::get('Security.Message.message')) > 0) { $message_type = Session::get('Security.Message.type'); if ($message_type == 'bad') { $message = "<p class=\"message {$message_type}\">{$message}</p>"; } else { $message = "<p>{$message}</p>"; } $customisedController = $controller->customise(array("Content" => $message, "Form" => $content)); } else { $customisedController = $controller->customise(array("Content" => $content)); } // custom processing if (SSViewer::hasTemplate("Security_login")) { return $customisedController->renderWith(array("Security_login", "Page")); } else { return $customisedController->renderWith("Page"); } }
/** * Return a list of appropriate templates for this class, with the given suffix */ public function getTemplatesWithSuffix($suffix) { $templates = array(); $classes = array_reverse(ClassInfo::ancestry($this->class)); foreach ($classes as $class) { $template = $class . $suffix; if (SSViewer::hasTemplate($template)) { $templates[] = $template; } if ($class == 'LeftAndMain') { break; } } return $templates; }
/** * Renders this block with appropriate templates * looks for templates that match BlockClassName_AreaName * falls back to BlockClassName * @return string **/ public function forTemplate() { $controller = $this->getController(); if ($this->BlockArea) { $template = array($this->class . '_' . $this->BlockArea); if (SSViewer::hasTemplate($template)) { return $controller->renderWith($template); } } return $controller->renderWith($this->ClassName); }
/** * Returns TRUE if this controller has a template that is specifically designed to handle a specific action. * * @param string $action * @return bool */ public function hasActionTemplate($action) { if (isset($this->templates[$action])) { return true; } $parentClass = $this->class; $templates = array(); while ($parentClass != 'Controller') { $templates[] = strtok($parentClass, '_') . '_' . $action; $parentClass = get_parent_class($parentClass); } return SSViewer::hasTemplate($templates); }
/** * Renders this block with appropriate templates * looks for templates that match BlockClassName_AreaName * falls back to BlockClassName * @return string **/ public function forTemplate() { if ($this->BlockArea) { $template[] = $this->class . '_' . $this->BlockArea; if (SSViewer::hasTemplate($template)) { return $this->renderWith($template); } } return $this->renderWith($this->ClassName); }
protected function sendEmail($what, Member $member, array $data = []) { $profiledConfig = ProfiledConfig::current_profiled_config(); $templateData = array_merge(['Member' => $member], $data); $memberEmailTemplate = self::MemberEmailPrefix . strtolower($what); if (SSViewer::hasTemplate($memberEmailTemplate)) { // send email to member from ProfiledConfig.SendEmailFrom to Member.Email $emailMember = new Email($profiledConfig->getProfiledSender('Member'), $member->Email, $profiledConfig->getProfiledEmailSubject('Member', $what)); $emailMember->setTemplate($memberEmailTemplate); $emailMember->populateTemplate($templateData); $emailMember->send(); } $adminEmailTemplate = self::AdminEmailPrefix . strtolower($what); if (SSViewer::hasTemplate([$adminEmailTemplate])) { // send admin email from either Member.Email or ProfiledConfig.SendEmailFrom to Profiled.AdminEmail $emailAdmin = new Email($profiledConfig->getProfiledSender('Admin', $member->Email), $profiledConfig->getAdminEmail(), $profiledConfig->getProfiledEmailSubject('Admin', $what)); $emailAdmin->setTemplate($adminEmailTemplate); $emailAdmin->populateTemplate($templateData); // save body to attach to admin email if (isset($emailMember)) { $emailAdmin->attachFileFromString($emailMember->Body(), $member->Email . "_registration.txt"); } $emailAdmin->send(); } }
public function RightBottom() { if (SSViewer::hasTemplate($this->getTemplatesWithSuffix('_rightbottom'))) { return $this->renderWith($this->getTemplatesWithSuffix('_rightbottom')); } }