public function getHTMLFragments($gridField)
 {
     $count = $gridField->getList()->count();
     $forTemplate = new ArrayData(array('ShowRecordCount' => $this->showrecordcount, 'Message' => $this->message, 'FirstShownRecord' => 1, 'LastShownRecord' => $count, 'NumRecords' => $count));
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array('footer' => $forTemplate->renderWith($template, array('Colspan' => count($gridField->getColumns()))));
 }
 public function getColumnContent($field, $record, $col)
 {
     if (!$record->canView()) {
         return null;
     }
     $data = new ArrayData(array('Link' => Controller::join_links($field->Link('item'), $record->ID, 'view')));
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return $data->renderWith($template);
 }
 /**
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     // Retrieve paging parameters from the directing paginator component
     $paginator = $this->getPaginator($gridField);
     if ($paginator && ($forTemplate = $paginator->getTemplateParameters($gridField))) {
         $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
         return array($this->targetFragment => $forTemplate->renderWith($template));
     }
     return null;
 }
 public function getHTMLFragments($gridField)
 {
     $singleton = singleton($gridField->getModelClass());
     if (!$singleton->canCreate()) {
         return array();
     }
     if (!$this->buttonName) {
         // provide a default button name, can be changed by calling {@link setButtonName()} on this component
         $objectName = $singleton->i18n_singular_name();
         $this->buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
     }
     $data = new ArrayData(array('NewLink' => Controller::join_links($gridField->Link('item'), 'new'), 'ButtonName' => $this->buttonName));
     $templates = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array($this->targetFragment => $data->renderWith($templates));
 }
 public function getHTMLFragments($gridField)
 {
     $modelClass = $gridField->getModelClass();
     $parentID = 0;
     if (!$this->currentID) {
         return null;
     }
     $modelObj = DataObject::get_by_id($modelClass, $this->currentID);
     $parent = null;
     if ($modelObj->hasMethod('getParent')) {
         $parent = $modelObj->getParent();
     } elseif ($modelObj->ParentID) {
         $parent = $modelObj->Parent();
     }
     if ($parent) {
         $parentID = $parent->ID;
     }
     // Attributes
     $attrs = array_merge($this->attributes, array('href' => sprintf($this->linkSpec, $parentID), 'class' => 'cms-panel-link ss-ui-button font-icon-level-up no-text grid-levelup'));
     $linkTag = FormField::create_tag('a', $attrs);
     $forTemplate = new ArrayData(array('UpLink' => DBField::create_field('HTMLFragment', $linkTag)));
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array('before' => $forTemplate->renderWith($template));
 }
 /**
  *
  * @param GridField $gridField
  * @return string[] - HTML
  */
 public function getHTMLFragments($gridField)
 {
     $dataClass = $gridField->getModelClass();
     $forTemplate = new ArrayData(array());
     $forTemplate->Fields = new FieldList();
     $searchField = new TextField('gridfield_relationsearch', _t('GridField.RelationSearch', "Relation search"));
     $searchField->setAttribute('data-search-url', Controller::join_links($gridField->Link('search')));
     $searchField->setAttribute('placeholder', $this->getPlaceholderText($dataClass));
     $searchField->addExtraClass('relation-search no-change-track action_gridfield_relationsearch');
     $findAction = new GridField_FormAction($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
     $findAction->setAttribute('data-icon', 'relationfind');
     $findAction->addExtraClass('action_gridfield_relationfind');
     $addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Existing"), 'addto', 'addto');
     $addAction->setAttribute('data-icon', 'chain--plus');
     $addAction->addExtraClass('action_gridfield_relationadd');
     // If an object is not found, disable the action
     if (!is_int($gridField->State->GridFieldAddRelation(null))) {
         $addAction->setReadonly(true);
     }
     $forTemplate->Fields->push($searchField);
     $forTemplate->Fields->push($findAction);
     $forTemplate->Fields->push($addAction);
     if ($form = $gridField->getForm()) {
         $forTemplate->Fields->setForm($form);
     }
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array($this->targetFragment => $forTemplate->renderWith($template));
 }
 /**
  * Returns the header row providing titles with sort buttons
  *
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $list = $gridField->getList();
     if (!$this->checkDataType($list)) {
         return null;
     }
     /** @var Sortable $list */
     $forTemplate = new ArrayData(array());
     $forTemplate->Fields = new ArrayList();
     $state = $gridField->State->GridFieldSortableHeader;
     $columns = $gridField->getColumns();
     $currentColumn = 0;
     $schema = DataObject::getSchema();
     foreach ($columns as $columnField) {
         $currentColumn++;
         $metadata = $gridField->getColumnMetadata($columnField);
         $fieldName = str_replace('.', '-', $columnField);
         $title = $metadata['title'];
         if (isset($this->fieldSorting[$columnField]) && $this->fieldSorting[$columnField]) {
             $columnField = $this->fieldSorting[$columnField];
         }
         $allowSort = $title && $list->canSortBy($columnField);
         if (!$allowSort && strpos($columnField, '.') !== false) {
             // we have a relation column with dot notation
             // @see DataObject::relField for approximation
             $parts = explode('.', $columnField);
             $tmpItem = singleton($list->dataClass());
             for ($idx = 0; $idx < sizeof($parts); $idx++) {
                 $methodName = $parts[$idx];
                 if ($tmpItem instanceof SS_List) {
                     // It's impossible to sort on a HasManyList/ManyManyList
                     break;
                 } elseif (method_exists($tmpItem, 'hasMethod') && $tmpItem->hasMethod($methodName)) {
                     // The part is a relation name, so get the object/list from it
                     $tmpItem = $tmpItem->{$methodName}();
                 } elseif ($tmpItem instanceof DataObject && $schema->fieldSpec($tmpItem, $methodName, DataObjectSchema::DB_ONLY)) {
                     // Else, if we've found a database field at the end of the chain, we can sort on it.
                     // If a method is applied further to this field (E.g. 'Cost.Currency') then don't try to sort.
                     $allowSort = $idx === sizeof($parts) - 1;
                     break;
                 } else {
                     // If neither method nor field, then unable to sort
                     break;
                 }
             }
         }
         if ($allowSort) {
             $dir = 'asc';
             if ($state->SortColumn(null) == $columnField && $state->SortDirection('asc') == 'asc') {
                 $dir = 'desc';
             }
             $field = GridField_FormAction::create($gridField, 'SetOrder' . $fieldName, $title, "sort{$dir}", array('SortColumn' => $columnField))->addExtraClass('grid-field__sort');
             if ($state->SortColumn(null) == $columnField) {
                 $field->addExtraClass('ss-gridfield-sorted');
                 if ($state->SortDirection('asc') == 'asc') {
                     $field->addExtraClass('ss-gridfield-sorted-asc');
                 } else {
                     $field->addExtraClass('ss-gridfield-sorted-desc');
                 }
             }
         } else {
             if ($currentColumn == count($columns) && $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldFilterHeader')) {
                 $field = new LiteralField($fieldName, '<button type="button" name="showFilter" class="btn font-icon-search btn--no-text btn--icon-large grid-field__filter-open"></button>');
             } else {
                 $field = new LiteralField($fieldName, '<span class="non-sortable">' . $title . '</span>');
             }
         }
         $forTemplate->Fields->push($field);
     }
     $template = SSViewer::get_templates_by_class($this, '_Row', __CLASS__);
     return array('header' => $forTemplate->renderWith($template));
 }
 public function getHTMLFragments($gridField)
 {
     $data = new ArrayData(array("TargetFragmentName" => $this->targetFragment, "LeftFragment" => "\$DefineFragment(buttons-{$this->targetFragment}-left)", "RightFragment" => "\$DefineFragment(buttons-{$this->targetFragment}-right)"));
     $templates = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array($this->targetFragment => $data->renderWith($templates));
 }
 /**
  * Determine the list of templates to use for rendering the given action.
  *
  * @skipUpgrade
  * @param string $action
  * @return array Template list
  */
 public function getTemplatesFor($action)
 {
     $templates = SSViewer::get_templates_by_class(get_class($this), "_{$action}", __CLASS__);
     return array_merge($templates, ["Security_{$action}", "Security", $this->stat("template_main"), "BlankPage"]);
 }
 /**
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $templates = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return array('header' => $gridField->renderWith($templates));
 }
 /**
  * @covers SilverStripe\View\SSViewer::get_templates_by_class()
  */
 public function testGetTemplatesByClass()
 {
     $self = $this;
     $this->useTestTheme(dirname(__FILE__), 'layouttest', function () use($self) {
         // Test passing a string
         $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel_Controller', '', 'SilverStripe\\Control\\Controller');
         $self->assertEquals(['TestNamespace\\SSViewerTestModel_Controller', ['type' => 'Includes', 'TestNamespace\\SSViewerTestModel_Controller'], 'TestNamespace\\SSViewerTestModel', 'SilverStripe\\Control\\Controller', ['type' => 'Includes', 'SilverStripe\\Control\\Controller']], $templates);
         // Test to ensure we're stopping at the base class.
         $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel_Controller', '', 'TestNamespace\\SSViewerTestModel_Controller');
         $self->assertEquals(['TestNamespace\\SSViewerTestModel_Controller', ['type' => 'Includes', 'TestNamespace\\SSViewerTestModel_Controller'], 'TestNamespace\\SSViewerTestModel'], $templates);
         // Make sure we can search templates by suffix.
         $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel', '_Controller', 'SilverStripe\\ORM\\DataObject');
         $self->assertEquals(['TestNamespace\\SSViewerTestModel_Controller', ['type' => 'Includes', 'TestNamespace\\SSViewerTestModel_Controller'], 'SilverStripe\\ORM\\DataObject_Controller', ['type' => 'Includes', 'SilverStripe\\ORM\\DataObject_Controller']], $templates);
         // Let's throw something random in there.
         $self->setExpectedException('InvalidArgumentException');
         SSViewer::get_templates_by_class(array());
     });
 }
 /**
  * Return a {@link FieldList} of fields that would appropriate for editing
  * this member.
  *
  * @return FieldList Return a FieldList of fields that would appropriate for
  *                   editing this member.
  */
 public function getCMSFields()
 {
     require_once 'Zend/Date.php';
     $self = $this;
     $this->beforeUpdateCMSFields(function (FieldList $fields) use($self) {
         /** @var FieldList $mainFields */
         $mainFields = $fields->fieldByName("Root")->fieldByName("Main")->getChildren();
         // Build change password field
         $mainFields->replaceField('Password', $self->getMemberPasswordField());
         $mainFields->replaceField('Locale', new DropdownField("Locale", _t('Member.INTERFACELANG', "Interface Language", 'Language of the CMS'), i18n::get_existing_translations()));
         $mainFields->removeByName($self->config()->hidden_fields);
         if (!$self->config()->lock_out_after_incorrect_logins) {
             $mainFields->removeByName('FailedLoginCount');
         }
         // Groups relation will get us into logical conflicts because
         // Members are displayed within  group edit form in SecurityAdmin
         $fields->removeByName('Groups');
         // Members shouldn't be able to directly view/edit logged passwords
         $fields->removeByName('LoggedPasswords');
         $fields->removeByName('RememberLoginHashes');
         if (Permission::check('EDIT_PERMISSIONS')) {
             $groupsMap = array();
             foreach (Group::get() as $group) {
                 // Listboxfield values are escaped, use ASCII char instead of &raquo;
                 $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
             }
             asort($groupsMap);
             $fields->addFieldToTab('Root.Main', ListboxField::create('DirectGroups', singleton('SilverStripe\\Security\\Group')->i18n_plural_name())->setSource($groupsMap)->setAttribute('data-placeholder', _t('Member.ADDGROUP', 'Add group', 'Placeholder text for a dropdown')));
             // Add permission field (readonly to avoid complicated group assignment logic).
             // This should only be available for existing records, as new records start
             // with no permissions until they have a group assignment anyway.
             if ($self->ID) {
                 $permissionsField = new PermissionCheckboxSetField_Readonly('Permissions', false, 'SilverStripe\\Security\\Permission', 'GroupID', $self->getManyManyComponents('Groups'));
                 $fields->findOrMakeTab('Root.Permissions', singleton('SilverStripe\\Security\\Permission')->i18n_plural_name());
                 $fields->addFieldToTab('Root.Permissions', $permissionsField);
             }
         }
         $permissionsTab = $fields->fieldByName("Root")->fieldByName('Permissions');
         if ($permissionsTab) {
             $permissionsTab->addExtraClass('readonly');
         }
         $defaultDateFormat = Zend_Locale_Format::getDateFormat(new Zend_Locale($self->Locale));
         $dateFormatMap = array('MMM d, yyyy' => Zend_Date::now()->toString('MMM d, yyyy'), 'yyyy/MM/dd' => Zend_Date::now()->toString('yyyy/MM/dd'), 'MM/dd/yyyy' => Zend_Date::now()->toString('MM/dd/yyyy'), 'dd/MM/yyyy' => Zend_Date::now()->toString('dd/MM/yyyy'));
         $dateFormatMap[$defaultDateFormat] = Zend_Date::now()->toString($defaultDateFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($dateFormatField = new MemberDatetimeOptionsetField('DateFormat', $self->fieldLabel('DateFormat'), $dateFormatMap));
         $formatClass = get_class($dateFormatField);
         $dateFormatField->setValue($self->DateFormat);
         $dateTemplate = SSViewer::get_templates_by_class($formatClass, '_description_date', $formatClass);
         $dateFormatField->setDescriptionTemplate($dateTemplate);
         $defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
         $timeFormatMap = array('h:mm a' => Zend_Date::now()->toString('h:mm a'), 'H:mm' => Zend_Date::now()->toString('H:mm'));
         $timeFormatMap[$defaultTimeFormat] = Zend_Date::now()->toString($defaultTimeFormat) . sprintf(' (%s)', _t('Member.DefaultDateTime', 'default'));
         $mainFields->push($timeFormatField = new MemberDatetimeOptionsetField('TimeFormat', $self->fieldLabel('TimeFormat'), $timeFormatMap));
         $timeFormatField->setValue($self->TimeFormat);
         $timeTemplate = SSViewer::get_templates_by_class($formatClass, '_description_time', $formatClass);
         $timeFormatField->setDescriptionTemplate($timeTemplate);
     });
     return parent::getCMSFields();
 }
 /**
  *
  * @param GridField $gridField
  * @return array
  */
 public function getHTMLFragments($gridField)
 {
     $forTemplate = $this->getTemplateParameters($gridField);
     if (!$forTemplate) {
         return null;
     }
     $template = SSViewer::get_templates_by_class($this, '_Row', __CLASS__);
     return array('footer' => $forTemplate->renderWith($template, array('Colspan' => count($gridField->getColumns()))));
 }
 /**
  * @param GridField $gridField
  * @param DataObject $record
  * @param string $columnName
  * @return string The HTML for the column
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     // No permission checks, handled through GridFieldDetailForm,
     // which can make the form readonly if no edit permissions are available.
     $data = new ArrayData(array('Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')));
     $template = SSViewer::get_templates_by_class($this, '', __CLASS__);
     return $data->renderWith($template);
 }
 /**
  * Return a list of appropriate templates for this class, with the given suffix using
  * {@link SSViewer::get_templates_by_class()}
  *
  * @param string $suffix
  * @return array
  */
 public function getTemplatesWithSuffix($suffix)
 {
     $templates = SSViewer::get_templates_by_class(get_class($this), $suffix, __CLASS__);
     return SSViewer::chooseTemplate($templates);
 }
 /**
  * Generate an array of class name strings to use for rendering this form field into HTML.
  *
  * @param string $customTemplate
  * @param string $customTemplateSuffix
  *
  * @return array
  */
 protected function _templates($customTemplate = null, $customTemplateSuffix = null)
 {
     $templates = SSViewer::get_templates_by_class(get_class($this), $customTemplateSuffix, __CLASS__);
     // Prefer any custom template
     if ($customTemplate) {
         // Prioritise direct template
         array_unshift($templates, $customTemplate);
     }
     return $templates;
 }
 /**
  * @return string
  */
 public function getTemplateViewFile()
 {
     return SSViewer::get_templates_by_class(get_class($this), '_viewfile', __CLASS__);
 }
 /**
  * Returs the ordered list of preferred templates for rendering this form
  * If the template isn't set, then default to the
  * form class name e.g "Form".
  *
  * @return array
  */
 public function getTemplates()
 {
     $templates = SSViewer::get_templates_by_class(get_class($this), '', __CLASS__);
     // Prefer any custom template
     if ($this->getTemplate()) {
         array_unshift($templates, $this->getTemplate());
     }
     return $templates;
 }
 public function getHTMLFragments($gridField)
 {
     $list = $gridField->getList();
     if (!$this->checkDataType($list)) {
         return null;
     }
     /** @var Filterable $list */
     $forTemplate = new ArrayData(array());
     $forTemplate->Fields = new ArrayList();
     $columns = $gridField->getColumns();
     $filterArguments = $gridField->State->GridFieldFilterHeader->Columns->toArray();
     $currentColumn = 0;
     foreach ($columns as $columnField) {
         $currentColumn++;
         $metadata = $gridField->getColumnMetadata($columnField);
         $title = $metadata['title'];
         $fields = new FieldGroup();
         if ($title && $list->canFilterBy($columnField)) {
             $value = '';
             if (isset($filterArguments[$columnField])) {
                 $value = $filterArguments[$columnField];
             }
             $field = new TextField('filter[' . $gridField->getName() . '][' . $columnField . ']', '', $value);
             $field->addExtraClass('grid-field__sort-field');
             $field->addExtraClass('no-change-track');
             $field->setAttribute('placeholder', _t('GridField.FilterBy', "Filter by ") . _t('GridField.' . $metadata['title'], $metadata['title']));
             $fields->push($field);
             $fields->push(GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('btn font-icon-cancel btn--no-text ss-gridfield-button-reset')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField));
         }
         if ($currentColumn == count($columns)) {
             $fields->push(GridField_FormAction::create($gridField, 'filter', false, 'filter', null)->addExtraClass('btn font-icon-search btn--no-text btn--icon-large grid-field__filter-submit ss-gridfield-button-filter')->setAttribute('title', _t('GridField.Filter', "Filter"))->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField));
             $fields->push(GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('btn font-icon-cancel btn--no-text grid-field__filter-clear ss-gridfield-button-close')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField));
             $fields->addExtraClass('filter-buttons');
             $fields->addExtraClass('no-change-track');
         }
         $forTemplate->Fields->push($fields);
     }
     $templates = SSViewer::get_templates_by_class($this, '_Row', __CLASS__);
     return array('header' => $forTemplate->renderWith($templates));
 }