public function Field($properties = array()) { $options = ''; foreach ($this->getSource() as $value => $title) { if (is_array($title)) { $options .= "<optgroup label=\"{$value}\">"; foreach ($title as $value2 => $title2) { $disabled = ''; if (array_key_exists($value, $this->disabledItems) && is_array($this->disabledItems[$value]) && in_array($value2, $this->disabledItems[$value])) { $disabled = 'disabled="disabled"'; } $selected = $value2 == $this->value ? " selected=\"selected\"" : ""; $options .= "<option{$selected} value=\"{$value2}\" {$disabled}>{$title2}</option>"; } $options .= "</optgroup>"; } else { // Fall back to the standard dropdown field $disabled = ''; if (in_array($value, $this->disabledItems)) { $disabled = 'disabled="disabled"'; } $selected = $value == $this->value ? " selected=\"selected\"" : ""; $options .= "<option{$selected} value=\"{$value}\" {$disabled}>{$title}</option>"; } } return FormField::create_tag('select', $this->getAttributes(), $options); }
function Field($properties = array()) { $properties = array_merge($properties, array('id' => $this->id(), 'name' => $this->action, 'class' => 'action cancel roundedButton ' . ($this->extraClass() ? $this->extraClass() : ''), 'name' => $this->action, 'href' => $this->getLink())); if ($this->isReadonly()) { $properties['disabled'] = 'disabled'; $properties['class'] = $properties['class'] . ' disabled'; } return FormField::create_tag('a', $properties, $this->buttonContent ? $this->buttonContent : $this->Title()); }
public function Field($properties = array()) { $url = Convert::raw2att($this->validateURL); if ($this->restrictedRegex) { $restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id() . "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />"; } $attributes = array('type' => 'text', 'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), 'name' => $this->getName(), 'value' => $this->Value(), 'tabindex' => $this->getAttribute('tabindex'), 'maxlength' => $this->maxLength ? $this->maxLength : null); return FormField::create_tag('input', $attributes); }
/** * {@inheritdoc} */ protected function newRow($total, $index, $record, $attributes, $content) { if (!isset($attributes['class'])) { $attributes['class'] = ''; } if ($record->IsSpam) { $attributes['class'] .= ' spam'; } return FormField::create_tag('tr', $attributes, $content); }
public function FieldList() { $items = parent::FieldList()->toArray(); $count = 0; $newItems = array(); foreach ($items as $item) { if ($this->value == $item->getValue()) { $firstSelected = " class=\"selected\""; $checked = true; } else { $firstSelected = ""; $checked = false; } $itemID = $this->ID() . '_' . ++$count; $extra = array("RadioButton" => FormField::create_tag('input', array('class' => 'selector', 'type' => 'radio', 'id' => $itemID, 'name' => $this->name, 'value' => $item->getValue(), 'checked' => $checked)), "RadioLabel" => FormField::create_tag('label', array('for' => $itemID), $item->getTitle()), "Selected" => $firstSelected); $newItems[] = $item->customise($extra); } return new ArrayList($newItems); }
public function FieldList() { $items = parent::FieldList()->toArray(); $count = 0; $newItems = array(); foreach ($items as $item) { if ($this->value == $item->getValue()) { $firstSelected = true; $checked = true; } else { $firstSelected = false; $checked = false; } $itemID = $this->ID() . '_' . ++$count; // @todo Move into SelectionGroup_Item.ss template at some point. $extra = array("RadioButton" => DBField::create_field('HTMLFragment', FormField::create_tag('input', array('class' => 'selector', 'type' => 'radio', 'id' => $itemID, 'name' => $this->name, 'value' => $item->getValue(), 'checked' => $checked, 'aria-labelledby' => "title-{$itemID}"))), "RadioLabel" => DBField::create_field('HTMLFragment', FormField::create_tag('label', array('id' => "title-{$itemID}", 'for' => $itemID), $item->getTitle())), "Selected" => $firstSelected); $newItems[] = $item->customise($extra); } return new ArrayList($newItems); }
public function Field($properties = array()) { if ($this->multiple) { $this->name .= '[]'; } $options = ''; foreach ($this->getSource() as $value => $title) { if (is_array($title)) { $options .= "<optgroup label=\"{$value}\">"; foreach ($title as $value2 => $title2) { $selected = !is_array($this->value) && $this->value == $value2 || (is_array($this->value) && in_array($value2, $this->value) || in_array($value2, $this->defaultItems)) ? ' selected="selected"' : ''; $disabled = $this->disabled || in_array($value2, $this->disabledItems) ? 'disabled="disabled"' : ''; $options .= "<option{$selected} value=\"{$value2}\" {$disabled}>{$title2}</option>"; } $options .= "</optgroup>"; } else { // Fall back to the standard dropdown field $selected = !is_array($this->value) && $this->value == $value || (is_array($this->value) && in_array($value, $this->value) || in_array($value, $this->defaultItems)) ? ' selected="selected"' : ''; $disabled = $this->disabled || in_array($value, $this->disabledItems) ? 'disabled="disabled"' : ''; $options .= "<option{$selected} value=\"{$value}\" {$disabled}>{$title}</option>"; } } return FormField::create_tag('select', $this->getAttributes(), $options); }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id, $fields); $folder = $id && is_numeric($id) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage(); $fields = $form->Fields(); $title = $folder && $folder->exists() ? $folder->Title : _t('AssetAdmin.FILES', 'Files'); $fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null)); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')); $gridField = GridField::create('File', $title, $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('StripThumbnail' => '', 'Title' => _t('File.Title', 'Title'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Size' => _t('AssetAdmin.SIZE', 'Size'))); $columns->setFieldCasting(array('Created' => 'SS_Datetime->Nice')); $gridField->setAttribute('data-url-folder-template', Controller::join_links($this->Link('show'), '%s')); if ($folder->canCreate()) { $uploadBtn = new LiteralField('UploadButton', sprintf('<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-pjax-target="Content" data-icon="drive-upload" href="%s">%s</a>', Controller::join_links(singleton('CMSFileAddController')->Link(), '?ID=' . $folder->ID), _t('Folder.UploadFilesButton', 'Upload'))); } else { $uploadBtn = null; } if (!$folder->hasMethod('canAddChildren') || $folder->hasMethod('canAddChildren') && $folder->canAddChildren()) { // TODO Will most likely be replaced by GridField logic $addFolderBtn = new LiteralField('AddFolderButton', sprintf('<a class="ss-ui-button ss-ui-action-constructive cms-add-folder-link" data-icon="add" data-url="%s" href="%s">%s</a>', Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array('action_doAdd' => 1, 'ParentID' => $folder->ID, 'SecurityID' => $form->getSecurityToken()->getValue()))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID), _t('Folder.AddFolderButton', 'Add folder'))); } else { $addFolderBtn = ''; } if ($folder->canEdit()) { $syncButton = new LiteralField('SyncButton', sprintf('<a class="ss-ui-button ss-ui-action ui-button-text-icon-primary ss-ui-button-ajax" data-icon="arrow-circle-double" title="%s" href="%s">%s</a>', _t('AssetAdmin.FILESYSTEMSYNCTITLE', 'Update the CMS database entries of files on the filesystem. Useful when new files have been uploaded outside of the CMS, e.g. through FTP.'), $this->Link('doSync'), _t('AssetAdmin.FILESYSTEMSYNC', 'Sync files'))); } else { $syncButton = null; } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, // without any dependencies into AssetAdmin (e.g. useful for "add folder" views). if (!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))); $tabList->addExtraClass("content-listview cms-tabset-icon list"); $tabTree->addExtraClass("content-treeview cms-tabset-icon tree"); if ($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); $tabDetails->addExtraClass("content-galleryview cms-tabset-icon edit"); foreach ($fields as $field) { $fields->removeByName($field->getName()); $tabDetails->push($field); } } $fields->push($tabs); } // we only add buttons if they're available. User might not have permission and therefore // the button shouldn't be available. Adding empty values into a ComposteField breaks template rendering. $actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row'); if ($uploadBtn) { $actionButtonsComposite->push($uploadBtn); } if ($addFolderBtn) { $actionButtonsComposite->push($addFolderBtn); } if ($syncButton) { $actionButtonsComposite->push($syncButton); } // List view $fields->addFieldsToTab('Root.ListView', array($actionsComposite = CompositeField::create($actionButtonsComposite)->addExtraClass('cms-content-toolbar field'), $gridField)); $treeField = new LiteralField('Tree', ''); // Tree view $fields->addFieldsToTab('Root.TreeView', array(clone $actionsComposite, new LiteralField('Tree', FormField::create_tag('div', array('class' => 'cms-tree', 'data-url-tree' => $this->Link('getsubtree'), 'data-url-savetreenode' => $this->Link('savetreenode')), $this->SiteTreeAsUL())))); // Move actions to "details" tab (they don't make sense on list/tree view) $actions = $form->Actions(); $saveBtn = $actions->fieldByName('action_save'); $deleteBtn = $actions->fieldByName('action_delete'); $actions->removeByName('action_save'); $actions->removeByName('action_delete'); if (($saveBtn || $deleteBtn) && $fields->fieldByName('Root.DetailsView')) { $fields->addFieldToTab('Root.DetailsView', CompositeField::create($saveBtn, $deleteBtn)->addExtraClass('Actions')); } $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); return $form; }
/** * @param $content * * @return string */ protected function getOptionalTableFooter($content) { if ($content['footer']) { return FormField::create_tag('tfoot', array(), $content['footer']); } return ''; }
/** * Returns the whole gridfield rendered with all the attached components * * @return string */ public function FieldHolder($properties = array()) { Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(FRAMEWORK_DIR . '/css/GridField.css'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/i18n.js'); Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/GridField.js'); // Get columns $columns = $this->getColumns(); // Get data $list = $this->getManipulatedList(); // Render headers, footers, etc $content = array("before" => "", "after" => "", "header" => "", "footer" => ""); foreach ($this->getComponents() as $item) { if ($item instanceof GridField_HTMLProvider) { $fragments = $item->getHTMLFragments($this); if ($fragments) { foreach ($fragments as $k => $v) { $k = strtolower($k); if (!isset($content[$k])) { $content[$k] = ""; } $content[$k] .= $v . "\n"; } } } } foreach ($content as $k => $v) { $content[$k] = trim($v); } // Replace custom fragments and check which fragments are defined // Nested dependencies are handled by deferring the rendering of any content item that // Circular dependencies are detected by disallowing any item to be deferred more than 5 times // It's a fairly crude algorithm but it works $fragmentDefined = array('header' => true, 'footer' => true, 'before' => true, 'after' => true); reset($content); while (list($k, $v) = each($content)) { if (preg_match_all('/\\$DefineFragment\\(([a-z0-9\\-_]+)\\)/i', $v, $matches)) { foreach ($matches[1] as $match) { $fragmentName = strtolower($match); $fragmentDefined[$fragmentName] = true; $fragment = isset($content[$fragmentName]) ? $content[$fragmentName] : ""; // If the fragment still has a fragment definition in it, when we should defer this item until // later. if (preg_match('/\\$DefineFragment\\(([a-z0-9\\-_]+)\\)/i', $fragment, $matches)) { // If we've already deferred this fragment, then we have a circular dependency if (isset($fragmentDeferred[$k]) && $fragmentDeferred[$k] > 5) { throw new LogicException("GridField HTML fragment '{$fragmentName}' and '{$matches['1']}' " . "appear to have a circular dependency."); } // Otherwise we can push to the end of the content array unset($content[$k]); $content[$k] = $v; if (!isset($fragmentDeferred[$k])) { $fragmentDeferred[$k] = 1; } else { $fragmentDeferred[$k]++; } break; } else { $content[$k] = preg_replace('/\\$DefineFragment\\(' . $fragmentName . '\\)/i', $fragment, $content[$k]); } } } } // Check for any undefined fragments, and if so throw an exception // While we're at it, trim whitespace off the elements foreach ($content as $k => $v) { if (empty($fragmentDefined[$k])) { throw new LogicException("GridField HTML fragment '{$k}' was given content," . " but not defined. Perhaps there is a supporting GridField component you need to add?"); } } $total = count($list); if ($total > 0) { $rows = array(); foreach ($list as $idx => $record) { if ($record->hasMethod('canView') && !$record->canView()) { continue; } $rowContent = ''; foreach ($this->getColumns() as $column) { $colContent = $this->getColumnContent($record, $column); // A return value of null means this columns should be skipped altogether. if ($colContent === null) { continue; } $colAttributes = $this->getColumnAttributes($record, $column); $rowContent .= FormField::create_tag('td', $colAttributes, $colContent); } $classes = array('ss-gridfield-item'); if ($idx == 0) { $classes[] = 'first'; } if ($idx == $total - 1) { $classes[] = 'last'; } $classes[] = $idx % 2 ? 'even' : 'odd'; $row = FormField::create_tag('tr', array("class" => implode(' ', $classes), 'data-id' => $record->ID, 'data-class' => $record->ClassName), $rowContent); $rows[] = $row; } $content['body'] = implode("\n", $rows); } // Display a message when the grid field is empty if (!(isset($content['body']) && $content['body'])) { $content['body'] = FormField::create_tag('tr', array("class" => 'ss-gridfield-item ss-gridfield-no-items'), FormField::create_tag('td', array('colspan' => count($columns)), _t('GridField.NoItemsFound', 'No items found'))); } // Turn into the relevant parts of a table $head = $content['header'] ? FormField::create_tag('thead', array(), $content['header']) : ''; $body = $content['body'] ? FormField::create_tag('tbody', array('class' => 'ss-gridfield-items'), $content['body']) : ''; $foot = $content['footer'] ? FormField::create_tag('tfoot', array(), $content['footer']) : ''; $this->addExtraClass('ss-gridfield field'); $attrs = array_diff_key($this->getAttributes(), array('value' => false, 'type' => false, 'name' => false)); $attrs['data-name'] = $this->getName(); $tableAttrs = array('id' => isset($this->id) ? $this->id : null, 'class' => 'ss-gridfield-table', 'cellpadding' => '0', 'cellspacing' => '0'); if ($this->getDescription()) { $content['after'] .= FormField::create_tag('span', array('class' => 'description'), $this->getDescription()); } return FormField::create_tag('fieldset', $attrs, $content['before'] . FormField::create_tag('table', $tableAttrs, $head . "\n" . $foot . "\n" . $body) . $content['after']); }
/** * @param array $properties * @return string */ public function Field($properties = array()) { return FormField::create_tag('input', array('type' => 'submit', 'name' => sprintf('action_%s', $this->name), 'value' => $this->title, 'id' => $this->ID(), 'disabled' => 'disabled', 'class' => 'action disabled ' . $this->extraClass)); }
public function getEditForm($id = null, $fields = null) { Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js'); Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css'); $form = parent::getEditForm($id, $fields); $folder = $id && is_numeric($id) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage(); $fields = $form->Fields(); $title = $folder && $folder->exists() ? $folder->Title : _t('AssetAdmin.FILES', 'Files'); $fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null)); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')); $gridField = GridField::create('File', $title, $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('StripThumbnail' => '', 'Title' => _t('File.Title', 'Title'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Size' => _t('AssetAdmin.SIZE', 'Size'))); $columns->setFieldCasting(array('Created' => 'SS_Datetime->Nice')); $gridField->setAttribute('data-url-folder-template', Controller::join_links($this->Link('show'), '%s')); if (!$folder->hasMethod('canAddChildren') || $folder->hasMethod('canAddChildren') && $folder->canAddChildren()) { // TODO Will most likely be replaced by GridField logic $addFolderBtn = new LiteralField('AddFolderButton', sprintf('<a class="ss-ui-button font-icon-folder-add no-text cms-add-folder-link" title="%s" data-icon="add" data-url="%s" href="%s"></a>', _t('Folder.AddFolderButton', 'Add folder'), Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array('action_doAdd' => 1, 'ParentID' => $folder->ID, 'SecurityID' => $form->getSecurityToken()->getValue()))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID))); } else { $addFolderBtn = ''; } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, // without any dependencies into AssetAdmin (e.g. useful for "add folder" views). if (!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))); $tabList->addExtraClass("content-listview cms-tabset-icon list"); $tabTree->addExtraClass("content-treeview cms-tabset-icon tree"); if ($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); $tabDetails->addExtraClass("content-galleryview cms-tabset-icon edit"); foreach ($fields as $field) { $fields->removeByName($field->getName()); $tabDetails->push($field); } } $fields->push($tabs); } // we only add buttons if they're available. User might not have permission and therefore // the button shouldn't be available. Adding empty values into a ComposteField breaks template rendering. $actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row'); if ($addFolderBtn) { $actionButtonsComposite->push($addFolderBtn); } // Add the upload field for new media if ($currentPageID = $this->currentPageID()) { Session::set("{$this->class}.currentPage", $currentPageID); } $folder = $this->currentPage(); $uploadField = UploadField::create('AssetUploadField', ''); $uploadField->setConfig('previewMaxWidth', 40); $uploadField->setConfig('previewMaxHeight', 30); $uploadField->setConfig('changeDetection', false); $uploadField->addExtraClass('ss-assetuploadfield'); $uploadField->removeExtraClass('ss-uploadfield'); $uploadField->setTemplate('AssetUploadField'); if ($folder->exists()) { $path = $folder->getFilename(); $uploadField->setFolderName($path); } else { $uploadField->setFolderName('/'); // root of the assets } $exts = $uploadField->getValidator()->getAllowedExtensions(); asort($exts); $uploadField->Extensions = implode(', ', $exts); // List view $fields->addFieldsToTab('Root.ListView', array($actionsComposite = CompositeField::create($actionButtonsComposite)->addExtraClass('cms-content-toolbar field'), $uploadField, new HiddenField('ID'), $gridField)); // Tree view $fields->addFieldsToTab('Root.TreeView', array(clone $actionsComposite, new LiteralField('Tree', FormField::create_tag('div', array('class' => 'cms-tree', 'data-url-tree' => $this->Link('getsubtree'), 'data-url-savetreenode' => $this->Link('savetreenode')), $this->SiteTreeAsUL())))); // Move actions to "details" tab (they don't make sense on list/tree view) $actions = $form->Actions(); $saveBtn = $actions->fieldByName('action_save'); $deleteBtn = $actions->fieldByName('action_delete'); $actions->removeByName('action_save'); $actions->removeByName('action_delete'); if (($saveBtn || $deleteBtn) && $fields->fieldByName('Root.DetailsView')) { $fields->addFieldToTab('Root.DetailsView', CompositeField::create($saveBtn, $deleteBtn)->addExtraClass('Actions')); } $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('cms-edit-form ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); return $form; }
/** * @param int $total * @param int $index * @param DataObject $record * @param array $attributes * @param string $content * * @return string */ protected function newRow($total, $index, $record, $attributes, $content) { return FormField::create_tag('tr', $attributes, $content); }
/** * We overwrite the field attribute to add our hidden fields, as this * formfield can contain multiple values. */ public function Field($properties = array()) { Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jstree/jquery.jstree.js'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/TreeDropdownField.js'); Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(FRAMEWORK_DIR . '/css/TreeDropdownField.css'); $value = ''; $itemList = ''; $items = $this->getItems(); if ($items && count($items)) { foreach ($items as $id => $item) { $titleArray[] = $item->Title; $idArray[] = $item->ID; } if (isset($titleArray)) { $title = implode(", ", $titleArray); $value = implode(",", $idArray); } } else { $title = _t('DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown'); } $dataUrlTree = ''; if ($this->form) { $dataUrlTree = $this->Link('tree'); if (isset($idArray) && count($idArray)) { $dataUrlTree = Controller::join_links($dataUrlTree, '?forceValue=' . implode(',', $idArray)); } } return FormField::create_tag('div', array('id' => "TreeDropdownField_{$this->id()}", 'class' => 'TreeDropdownField multiple' . ($this->extraClass() ? " {$this->extraClass()}" : '') . ($this->showSearch ? " searchable" : ''), 'data-url-tree' => $dataUrlTree, 'data-title' => $title, 'title' => $this->getDescription()), FormField::create_tag('input', array('id' => $this->id(), 'type' => 'hidden', 'name' => $this->name, 'value' => $value))); }
/** * @param array $properties * @return string */ public function FieldHolder($properties = array()) { $content = array('actions' => '', 'content' => '', 'gridfield' => ''); /** ----------------------------------------- * Actions * ----------------------------------------*/ $newContainer = FormField::create_tag('a', array('id' => $this->ID, 'class' => 'ss-ui-action-constructive ss-ui-button js-action site-builder__actions__item site-builder__action site-builder__actions__item--new-container', 'href' => $this->Link() . '/siteBuilderAddContainer?ParentID=' . $this->PageID), _t('SiteBuilder.ADDCONTAINER', 'Add Container') . ' <i class="icon ' . $this->config()->loading_icon . '"></i>'); $content['actions'] = FormField::create_tag('ul', array('class' => 'site-builder__actions'), $newContainer); /** ----------------------------------------- * Content * ----------------------------------------*/ $items = $this->getList(); $containers = array(); foreach ($items as $key => $item) { /** @var PageBuilderContainer $item */ $containers[] = $this->newContainer($item->ID, $item->Items()); } $content['content'] = FormField::create_tag('div', array('data-url' => $this->Link(), 'class' => 'site-builder'), implode("\n", $containers)); /** ----------------------------------------- * Attributes * ----------------------------------------*/ $attributes = array_merge(parent::getAttributes(), array('data-url' => $this->Link())); /** ----------------------------------------- * Return * ----------------------------------------*/ return FormField::create_tag('fieldset', array(), FormField::create_tag('div', $attributes, implode('', $content))); }