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 testIncludeTruthyness()
 {
     $data = new ArrayData(array('Title' => 'TruthyTest', 'Items' => new ArrayList(array(new ArrayData(array('Title' => 'Item 1')), new ArrayData(array('Title' => '')), new ArrayData(array('Title' => true)), new ArrayData(array('Title' => false)), new ArrayData(array('Title' => null)), new ArrayData(array('Title' => 0)), new ArrayData(array('Title' => 7))))));
     $result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
     // We should not end up with empty values appearing as empty
     $expected = array('Item 1 _ Item 1 - First-ODD top:Item 1', 'Untitled - EVEN top:', '1 _ 1 - ODD top:1', 'Untitled - EVEN top:', 'Untitled - ODD top:', 'Untitled - EVEN top:0', '7 _ 7 - Last-ODD top:7');
     $this->assertExpectedStrings($result, $expected);
 }
 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);
 }
 /**
  * @inheritdoc
  */
 public function onAfterInit()
 {
     $config = SiteConfig::current_site_config();
     // include the JS snippet into the frontend page markup
     if ($trackingID = $config->GoogleAnalyticsTrackingID) {
         $analyticsData = new ArrayData(['GoogleAnalyticsTrackingID' => $trackingID, 'GoogleAnalyticsParameters' => $config->GoogleAnalyticsParameters, 'GoogleAnalyticsConstructorParameters' => $config->GoogleAnalyticsConstructorParameters]);
         Requirements::insertHeadTags($analyticsData->renderWith('GoogleAnalyticsJSSnippet'), 'GoogleAnalytics');
     }
 }
 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));
 }
 /**
  * Combine the given forms into a formset with a tabbed interface
  *
  * @param array $forms List of LoginForm instances
  * @return string
  */
 protected function generateLoginFormSet($forms)
 {
     $viewData = new ArrayData(array('Forms' => new ArrayList($forms)));
     return $viewData->renderWith($this->getTemplatesFor('MultiAuthenticatorLogin'));
 }
 /**
  * @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);
 }
 /**
  * @param HTTPRequest $request
  * @return mixed
  */
 public function view($request)
 {
     if (!$this->record->canView()) {
         $this->httpError(403);
     }
     $controller = $this->getToplevelController();
     $form = $this->ItemEditForm();
     $form->makeReadonly();
     $data = new ArrayData(array('Backlink' => $controller->Link(), 'ItemEditForm' => $form));
     $return = $data->renderWith($this->getTemplates());
     if ($request->isAjax()) {
         return $return;
     } else {
         return $controller->customise(array('Content' => $return));
     }
 }
 public function testConditionalTemplateRequire()
 {
     $testPath = ltrim(preg_replace('#^' . BASE_PATH . '#', '', dirname(__DIR__)), '/');
     /** @var Requirements_Backend $backend */
     $backend = Injector::inst()->create('SilverStripe\\View\\Requirements_Backend');
     $this->setupRequirements($backend);
     $holder = Requirements::backend();
     Requirements::set_backend($backend);
     $data = new ArrayData(array('FailTest' => true));
     $data->renderWith('RequirementsTest_Conditionals');
     $this->assertFileIncluded($backend, 'css', $testPath . '/css/forms/RequirementsTest_a.css');
     $this->assertFileIncluded($backend, 'js', array($testPath . '/javascript/forms/RequirementsTest_b.js', $testPath . '/javascript/forms/RequirementsTest_c.js'));
     $this->assertFileNotIncluded($backend, 'js', $testPath . '/javascript/forms/RequirementsTest_a.js');
     $this->assertFileNotIncluded($backend, 'css', array($testPath . '/css/forms/RequirementsTest_b.css', $testPath . '/css/forms/RequirementsTest_c.css'));
     $backend->clear();
     $data = new ArrayData(array('FailTest' => false));
     $data->renderWith('RequirementsTest_Conditionals');
     $this->assertFileNotIncluded($backend, 'css', $testPath . '/css/forms/RequirementsTest_a.css');
     $this->assertFileNotIncluded($backend, 'js', array($testPath . '/javascript/forms/RequirementsTest_b.js', $testPath . '/javascript/forms/RequirementsTest_c.js'));
     $this->assertFileIncluded($backend, 'js', $testPath . '/javascript/forms/RequirementsTest_a.js');
     $this->assertFileIncluded($backend, 'css', array($testPath . '/css/forms/RequirementsTest_b.css', $testPath . '/css/forms/RequirementsTest_c.css'));
     Requirements::set_backend($holder);
 }
 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));
 }