If the grid field has not been sorted, this component will sort the data by the sort field.
Inheritance: extends RequestHandler, implements GridField_ColumnProvider, implements GridField_DataManipulator, implements GridField_HTMLProvider, implements GridField_URLHandler
 /**
  * @covers GridFieldOrderableRows::getSortTable
  */
 public function testGetSortTable()
 {
     $orderable = new GridFieldOrderableRows();
     $parent = new GridFieldOrderableRowsTest_Parent();
     $parent->write();
     $this->assertEquals('GridFieldOrderableRowsTest_Ordered', $orderable->getSortTable($parent->HasMany()));
     $this->assertEquals('GridFieldOrderableRowsTest_Ordered', $orderable->getSortTable($parent->HasManySubclass()));
     $this->assertEquals('GridFieldOrderableRowsTest_Ordered', $orderable->getSortTable($parent->ManyMany()));
     $this->assertEquals('GridFieldOrderableRowsTest_Parent_ManyMany', $orderable->setSortField('ManyManySort')->getSortTable($parent->ManyMany()));
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     /** =========================================
          * @var FieldList $fields
          * @var FieldGroup $settings
          * @var UploadField $image
          * @var GridFieldConfig_RelationEditor $config
          * @var GridField $gridField
         ===========================================*/
     $fields = FieldList::create(TabSet::create('Root'));
     $fields->addfieldToTab('Root.Main', $title = TextField::create('Title'));
     $title->setRightTitle('Title used in the cms as a visual cue for this piece of content.');
     $fields->addFieldToTab('Root.Main', $settings = FieldGroup::create(array(CheckboxField::create('IsFullWidth', 'Container full width'))));
     $settings->setTitle('Settings');
     $fields->addFieldToTab('Root.Main', HeaderField::create('', 'Style'));
     $fields->addFieldToTab('Root.Main', DesignField::create('Style', 'Container', '.container', array('padding-top' => 'TextField', 'padding-bottom' => 'TextField', 'margin-top' => 'TextField', 'margin-bottom' => 'TextField', 'color' => 'ColorField', 'background' => 'ColorField')));
     $fields->addFieldToTab('Root.Main', HeaderField::create('', 'Background (optional)', 4));
     $fields->addFieldToTab('Root.Main', $image = UploadField::create('Image', _t('PageBuilderContainer.IMAGE', 'Image')));
     $image->setAllowedExtensions(array('jpeg', 'jpg', 'gif', 'png'));
     $image->setFolderName('Uploads/site-builder/containers');
     $fields->addFieldToTab('Root.Main', DropdownField::create('BackgroundType', 'Type', $this->dbObject('BackgroundType')->enumValues()));
     $config = GridFieldConfig_RelationEditor::create(10);
     $config->addComponent(GridFieldOrderableRows::create('SortOrder'))->addComponent(new GridFieldDeleteAction());
     $gridField = GridField::create('Items', 'Items', $this->Items(), $config);
     $gridField->addExtraClass('hide');
     $fields->addFieldToTab('Root.Main', $gridField);
     return $fields;
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     if ($grid = $form->Fields()->fieldByName('AdminHelp')) {
         $grid->getConfig()->addComponent(GridFieldOrderableRows::create('Sort'));
     }
     return $form;
 }
Ejemplo n.º 4
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Main', array(TextField::create('Title'), HtmlEditorField::create('Summary')->setDescription('Short summary to show on hover')->setRows(5), HtmlEditorField::create('Content')->setDescription('Content of help article'), TreeDropdownField::create('ParentID', 'Parent', 'AdminHelp', 'ID', 'Title')));
     if ($childrenGrid = $fields->fieldByName('Root.Children.Children')) {
         $childrenGrid->getConfig()->addComponent(GridFieldOrderableRows::create('Sort'));
     }
     return $fields;
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $params = $this->request->requestVar('q');
     if ($this->modelClass == 'FilterGroup') {
         $gridField = $form->Fields()->fieldByName('FilterGroup');
         $field_config = $gridField->getConfig();
         // Re add creation button and update grid field
         $add_button = new GridFieldAddNewButton('toolbar-header-left');
         $add_button->setButtonName(_t("Filterable.AddFilter", "Add Filter"));
         $field_config->removeComponentsByType('GridFieldExportButton')->removeComponentsByType('GridFieldPrintButton')->removeComponentsByType('GridFieldAddNewButton')->addComponents($add_button, GridFieldOrderableRows::create('Sort'));
     }
     return $form;
 }
 /**
  *
  * @param array $classname Name of class who's subclasses will be added to form
  * @param int $itemsPerPage - How many items per page should show up
  * @param boolean | string $sorting Allow sorting of rows, either false or the name of the sort column
  */
 public function __construct($classname, $itemsPerPage = null, $sort_col = false)
 {
     parent::__construct();
     // Setup Bulk manager
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("unLink");
     $manager->addBulkAction('disable', 'Disable', 'CatalogueProductBulkAction');
     $manager->addBulkAction('enable', 'Enable', 'CatalogueProductBulkAction');
     /// Setup add new button
     $add_button = new GridFieldAddNewMultiClass("buttons-before-left");
     $add_button->setClasses($this->get_subclasses($classname));
     $this->addComponent(new GridFieldButtonRow('before'));
     $this->addComponent(new GridFieldToolbarHeader());
     $this->addComponent($sort = new GridFieldSortableHeader());
     $this->addComponent($filter = new GridFieldFilterHeader());
     $this->addComponent(new GridFieldDataColumns());
     $this->addComponent(new GridFieldEditButton());
     $this->addComponent(new GridFieldDeleteAction());
     $this->addComponent(new GridFieldPageCount('toolbar-header-right'));
     $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
     $this->addComponent(new GridFieldExportButton("buttons-before-right"));
     // If we are manageing a category, use the relevent field, else use
     // product
     if ($classname == "Category") {
         $this->addComponent(new CatalogueCategoryDetailForm());
         $add_button->setItemRequestClass("CatalogueCategoryDetailForm_ItemRequest");
     } else {
         $this->addComponent(new CatalogueEnableDisableDetailForm());
         $add_button->setItemRequestClass("CatalogueEnableDisableDetailForm_ItemRequest");
     }
     $this->addComponent($add_button);
     if ($sort_col) {
         $this->addComponent(GridFieldOrderableRows::create($sort_col));
     }
     $sort->setThrowExceptionOnBadDataType(false);
     $filter->setThrowExceptionOnBadDataType(false);
     $pagination->setThrowExceptionOnBadDataType(false);
 }
 public function getEditForm($id = null, $fields = null)
 {
     $form = parent::getEditForm($id, $fields);
     $params = $this->request->requestVar('q');
     // Bulk manager
     $manager = new GridFieldBulkManager();
     $manager->removeBulkAction("unLink");
     $manager->addBulkAction('disable', 'Disable', 'CatalogueProductBulkAction');
     $manager->addBulkAction('enable', 'Enable', 'CatalogueProductBulkAction');
     if ($this->modelClass == 'Product') {
         $gridField = $form->Fields()->fieldByName('Product');
         $field_config = $gridField->getConfig();
         // Re add creation button and update grid field
         $add_button = new GridFieldAddNewButton('buttons-before-left');
         $add_button->setButtonName(_t("CatalogueAdmin.AddProduct", "Add Product"));
         $field_config->removeComponentsByType('GridFieldPrintButton')->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType('GridFieldDetailForm')->addComponents($add_button, $manager, new CatalogueEnableDisableDetailForm());
         // Set the page length
         $field_config->getComponentByType('GridFieldPaginator')->setItemsPerPage($this->config()->product_page_length);
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     // Alterations for Hiarachy on product cataloge
     if ($this->modelClass == 'Category') {
         $gridField = $form->Fields()->fieldByName('Category');
         // Set custom record editor
         $record_editor = new CatalogueEnableDisableDetailForm();
         $record_editor->setItemRequestClass('CatalogueCategory_ItemRequest');
         // Create add button and update grid field
         $add_button = new GridFieldAddNewButton('toolbar-header-left');
         $add_button->setButtonName(_t("CatalogueAdmin.AddCategory", "Add Category"));
         // Tidy up category config
         $field_config = $gridField->getConfig();
         $field_config->removeComponentsByType('GridFieldExportButton')->removeComponentsByType('GridFieldPrintButton')->removeComponentsByType('GridFieldDetailForm')->removeComponentsByType('GridFieldAddNewButton')->addComponents($record_editor, $add_button, $manager, GridFieldOrderableRows::create('Sort'));
         // Set the page length
         $field_config->getComponentByType('GridFieldPaginator')->setItemsPerPage($this->config()->category_page_length);
         // Setup hierarchy view
         $parentID = $this->request->requestVar('ParentID');
         if ($parentID) {
             $field_config->addComponent(GridFieldLevelup::create($parentID)->setLinkSpec('?ParentID=%d')->setAttributes(array('data-pjax' => 'ListViewForm,Breadcrumbs')));
         }
         // Find data colums, so we can add link to view children
         $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
         // Don't allow navigating into children nodes on filtered lists
         $fields = array('Title' => 'Title', 'URLSegment' => 'URLSegement');
         if (!$params) {
             $fields = array_merge(array('listChildrenLink' => ''), $fields);
         }
         $columns->setDisplayFields($fields);
         $columns->setFieldCasting(array('Title' => 'HTMLText', 'URLSegment' => 'Text'));
         $controller = $this;
         $columns->setFieldFormatting(array('listChildrenLink' => function ($value, &$item) use($controller) {
             return sprintf('<a class="list-children-link" data-pjax-target="ListViewForm" href="%s?ParentID=%d">&#9658;</a>', $controller->Link(), $item->ID);
         }));
         // Update list of items for subsite (if used)
         if (class_exists('Subsite')) {
             $list = $gridField->getList()->filter(array('SubsiteID' => Subsite::currentSubsiteID()));
             $gridField->setList($list);
         }
     }
     $this->extend("updateEditForm", $form);
     return $form;
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     /** =========================================
          * @var FieldList $fields
          * @var TextField $title
          * @var OptionsetField $type
          * @var HtmlEditorField $content
          * @var CheckboxField $externalLink
          * @var UploadField $image
          * @var FieldGroup $linkSettings
          * @var GridFieldConfig_RelationEditor $config
         ===========================================*/
     $fields = FieldList::create(TabSet::create('Root'));
     $fields->addfieldToTab('Root.Main', $title = TextField::create('Title'));
     $title->setRightTitle('Title used in the cms as a visual cue for this piece of content.');
     $fields->addfieldToTab('Root.Main', $type = OptionsetField::create('Type', 'Type', $this->dbObject('Type')->enumValues()));
     $type->setRightTitle('Determines what fields are displayed in the CMS, and what content is displayed in the front-end.');
     $contentField = $content = HtmlEditorField::create('Content');
     $content->setRows(15);
     if ($this->Type == 'Content') {
         $fields->addfieldToTab('Root.Main', $contentField);
     }
     if ($this->Type == 'Image') {
         $fields->addfieldToTab('Root.Main', $image = UploadField::create('Image'));
         $image->setAllowedExtensions(array('jpeg', 'jpg', 'gif', 'png'));
         $image->setFolderName('Uploads/site-builder/items');
         $fields->addfieldToTab('Root.Main', HeaderField::create('', 'Link (optional)', 4));
         $fields->addfieldToTab('Root.Main', TreeDropdownField::create('InternalLinkID', 'Internal Link', 'SiteTree'));
         $fields->addfieldToTab('Root.Main', $externalLink = TextField::create('ExternalLink'));
         $externalLink->setAttribute('placeholder', 'http://');
         $externalLink->setRightTitle('Setting an external link will override the internal link.');
         $fields->addfieldToTab('Root.Main', $linkSettings = FieldGroup::create(array(CheckboxField::create('OpenLinkInNewTab', 'Open link in a new tab?'))));
         $linkSettings->setTitle('Settings');
         $fields->addfieldToTab('Root.Main', HeaderField::create('', 'Content (optional)', 4));
         $fields->addfieldToTab('Root.Main', $contentField);
     }
     if ($this->Type == 'Video') {
         $fields->addFieldToTab('Root.Main', TextareaField::create('YoutubeLink'));
         $fields->addFieldToTab('Root.Main', TextareaField::create('VimeoLink'));
     }
     if ($this->Type == 'Slider') {
         $config = GridFieldConfig_RelationEditor::create(10);
         $config->addComponent(GridFieldOrderableRows::create('SortOrder'))->addComponent(new GridFieldDeleteAction());
         $gridField = GridField::create('SliderItems', 'Items', $this->SliderItems(), $config);
         $fields->addFieldToTab('Root.Main', $gridField);
     }
     return $fields;
 }
 /**
  * Create a grid builder with a default GridFieldConfig_RelationEditor
  * 
  * <p>
  * Allows drag and drop sorting of grid rows
  * </p>
  * 
  * <p>
  * Allows to search for existing records to add to the relationship, detach 
  * listed records from the relationship (rather than removing them from the 
  * database), and automatically add newly created records to it.
  * </p>
  * 
  * @return \self
  */
 public static function createRelationSortableGrid($sortField = "Sort")
 {
     $result = self::createRelation();
     $result->gridConfig->addComponent(GridFieldOrderableRows::create($sortField));
     return $result;
 }