Inheritance: implements GridField_HTMLProvider, implements GridField_SaveHandler
Ejemplo n.º 1
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('LinkedFromCities');
     $grid = new GridField('LinkedToCities', $this->fieldLabel('LinkedToCities'), $this->LinkedToCities(), GridFieldConfig::create()->addComponent(new GridFieldDetailForm())->addComponent(new GridFieldButtonRow())->addComponent($GridFieldAddExistingSearchButton = new GridFieldAddExistingSearchButton('buttons-before-right'))->addComponent($GridFieldAddExistingAutocompleter = new GridFieldAddExistingAutocompleter('buttons-before-right'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent($comp = new GridFieldEditableColumns())->addComponent(new GridFieldEditButton())->addComponent(new GridFieldDeleteAction('unlinkrelation'))->addComponent(new GridFieldDeleteAction())->addComponent($GridFieldAddNewInlineButton = new GridFieldAddNewInlineButton()));
     $GridFieldAddNewInlineButton->setTitle(_t(__CLASS__ . '.AddNewCity', 'Add new city'));
     $GridFieldAddExistingSearchButton->setTitle(_t(__CLASS__ . '.SearchAndAddExistingCity', 'Search and add existing city'));
     $LinkTargetField = MapaelCountryPageExtension::getTargetField($this, 'LinkTarget');
     $LinkTargetField->setTitle(_t(__CLASS__ . '.LinkTarget', 'Link target'));
     $field_names = array_keys(array_merge($this->summaryFields(), self::$many_many_extraFields['LinkedToCities']));
     $arr = array();
     foreach ($field_names as $name) {
         preg_match('/(TooltipContent|Href|Target)$/', $name, $matches);
         $title = $this->fieldLabel($name);
         $arr[$name] = $title;
         if ($matches) {
             $arr[$name] = array('title' => $title, 'callback' => function ($record, $column, $grid) {
                 preg_match('/(TooltipContent|Href|Target)$/', $column, $matches);
                 return MapaelCountryPageExtension::getAttrField($record, $matches[1], $column);
             });
         }
     }
     $comp->setDisplayFields($arr);
     $fields->replaceField('LinkedToCities', $grid);
     $fields->replaceField('Target', MapaelCountryPageExtension::getTargetField($this));
     $fields->replaceField('Href', MapaelCountryPageExtension::getHrefField($this));
     $fields->replaceField('TooltipContent', MapaelCountryPageExtension::getTooltipContentField($this));
     return $fields;
 }
 public function updateCMSFields(FieldList $fields)
 {
     // Deal with product features
     $add_button = new GridFieldAddNewInlineButton('toolbar-header-left');
     $add_button->setTitle(_t("CommerceBulkPrice.AddDiscount", "Add Discount"));
     $bulk_field = new GridField('BulkPrices', '', $this->owner->BulkPrices(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button));
     $fields->addFieldToTab('Root.BulkPrices', $bulk_field);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     // Add creation button if member has create permissions
     $add_button = new GridFieldAddNewInlineButton('toolbar-header-left');
     $add_button->setTitle(_t("Discussions.AddCategory", "Add Category"));
     $gridField = new GridField('Categories', '', $this->Categories(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button));
     $fields->addFieldToTab("Root.Main", $gridField, "Content");
     $fields->removeByName("Content");
     return $fields;
 }
 public function getCMSFields()
 {
     //scaffold cms fields without calling 'updateCMSFields'
     $fields = $this->scaffoldFormFields(array('includeRelations' => $this->ID > 0, 'tabbed' => true, 'ajaxSafe' => true));
     if ($grid = $fields->fieldByName("Root.ProductSelections.ProductSelections")) {
         //move field to main tab
         $fields->removeByName("ProductSelections");
         $fields->addFieldToTab("Root.Main", $grid);
         $grid->setConfig($conf = new GridFieldConfig_RecordEditor());
         $conf->removeComponentsByType("GridFieldDataColumns")->removeComponentsByType("GridFieldDataColumns")->removeComponentsByType("GridFieldFilterHeader")->removeComponentsByType("GridFieldPaginator")->removeComponentsByType("GridFieldPageCount")->addComponent(new GridFieldOrderableRows())->addComponent(new GridFieldEditableColumns());
         $summaryfields = MenuProductSelection::config()->summary_fields;
         unset($summaryfields['Group']);
         //add editable group column to grid
         $groups = $this->Groups();
         if ($groups->exists()) {
             $dropdown = DropdownField::create("GroupID", 'Grouping', $groups->map('ID', 'Title')->toArray())->setHasEmptyDefault(true);
             $summaryfields['GroupID'] = array('title' => 'Group', 'callback' => function ($record, $column, $grid) use($dropdown) {
                 return $dropdown;
             });
             $conf->getComponentByType('GridFieldDetailForm')->setItemEditFormCallback(function ($form, $component) use($dropdown) {
                 $fields = $form->Fields();
                 if (!$fields->fieldByName("GroupID")) {
                     $fields->push($dropdown);
                 }
             });
         }
         $conf->getComponentByType('GridFieldEditableColumns')->setDisplayFields($summaryfields);
         //re-add edit/delete row actions so they are in the correct order
         $conf->removeComponentsByType("GridFieldEditButton")->removeComponentsByType("GridFieldDeleteAction")->addComponent(new GridFieldEditButton())->addComponent(new GridFieldDeleteAction())->addComponent($importer = new GridFieldImporter('before'));
         $loader = $importer->getLoader($grid);
         $self = $this;
         $loader->mappableFields = array('Product.InternalItemID' => 'SKU / Product Identifier', 'Group.Title' => 'Group');
         $loader->transforms = array("Product.InternalItemID" => array("create" => false, "link" => true, "required" => true), "Group.Title" => array('list' => $this->Groups()));
         $loader->duplicateChecks = array("Product.InternalItemID" => "Product.InternalItemID");
     }
     if ($grid = $fields->fieldByName("Root.Groups.Groups")) {
         $conf = $grid->getConfig()->removeComponentsByType("GridFieldAddExistingAutocompleter")->removeComponentsByType('GridFieldDataColumns')->removeComponentsByType('GridFieldAddNewButton')->removeComponentsByType("GridFieldFilterHeader")->removeComponentsByType("GridFieldPaginator")->removeComponentsByType("GridFieldPageCount")->addComponent($newbutton = new GridFieldAddNewInlineButton())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldOrderableRows());
         $newbutton->setTitle("Add Menu Grouping");
         $conf->getComponentByType('GridFieldEditableColumns')->setDisplayFields(array('Title' => function ($record, $column, $grid) {
             return new TextField($column, 'Title');
         }));
         //re-add edit/delete row actions so they are in the correct order
         $conf->removeComponentsByType("GridFieldEditButton")->removeComponentsByType("GridFieldDeleteAction")->addComponent(new GridFieldDeleteAction());
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Sort');
     $fields->removeByName('Options');
     // Deal with product features
     $add_button = new GridFieldAddNewInlineButton('toolbar-header-left');
     $add_button->setTitle(_t("Filterable.AddOption", "Add Option"));
     $options_field = new GridField('Options', '', $this->Options(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button)->addComponent(new GridFieldOrderableRows('Sort')));
     // Add fields to the CMS
     $fields->addFieldToTab('Root.Main', TextField::create('Title'));
     $fields->addFieldToTab('Root.Main', TextField::create('URLSegment'));
     $fields->addFieldToTab("Root.Main", HeaderField::create("OptionsHeader", "Options available to this filter"));
     $fields->addFieldToTab('Root.Main', $options_field);
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root')->removeByName("DistanceFares");
     if ($this->isInDB()) {
         $fields->addFieldToTab("Root.Main", $gridfield = GridField::create("DistanceFares", "Fares", $this->DistanceFares(), $config = new GridFieldConfig_RecordEditor()));
         $config->removeComponentsByType("GridFieldDataColumns");
         $config->removeComponentsByType("GridFieldEditButton");
         $config->removeComponentsByType("GridFieldDeleteAction");
         $config->removeComponentsByType("GridFieldAddNewButton");
         $config->addComponent($cols = new GridFieldEditableColumns());
         $config->addComponent(new GridFieldDeleteAction());
         $config->addComponent($addnew = new GridFieldAddNewInlineButton());
         $addnew->setTitle($addnew->getTitle() . " Fare");
         if ($greatest = $this->greatestCostDistance()) {
             $fields->insertAfter(LiteralField::create("costnote", "<p class=\"message\">Distances beyond the greatest specified distance will be cost " . $this->greatestCostDistance()->dbObject("Cost")->Nice() . " (the most expensive fare)</p>"), "DistanceFares");
         }
     }
     return $fields;
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Options');
     $fields->removeByName('ParentID');
     $fields->removeByName('Sort');
     $fields->removeByName('MaxLength');
     if ($this->ID && $this->DisplayAs != "TextEntry") {
         $field_types = singleton('ProductCustomisationOption')->getFieldTypes();
         // Deal with product features
         $add_button = new GridFieldAddNewInlineButton('toolbar-header-left');
         $add_button->setTitle('Add Customisation Option');
         $options_field = new GridField('Options', '', $this->Options(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button)->addComponent(new GridFieldOrderableRows('Sort')));
         $fields->addFieldToTab('Root.Main', $options_field);
     }
     if ($this->ID && $this->DisplayAs == "TextEntry") {
         $fields->addFieldToTab("Root.Main", TextField::create("MaxLength"));
     }
     if (!$this->ID) {
         $fields->addFieldToTab('Root.Main', LiteralField::create('CreateWarning', '<p>You need to create this before you can add options</p>'));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getHTMLFragments($grid)
 {
     $return = parent::getHTMLFragments($grid);
     if (isset($return['after'])) {
         $return['after'] = $this->getRowTemplate($grid, $return['after']);
     }
     return $return;
 }
 function updateCMSFields(\FieldList $fields)
 {
     $fields->addFieldToTab('Root.Configuration', new TextField('BaseFolder', _t('SubsiteExtra.BaseFolder', 'Base folder')));
     // Profiles
     $profiles = ClassInfo::subclassesFor('SubsiteProfile');
     array_shift($profiles);
     if (!empty($profiles)) {
         $profiles = array('' => '') + $profiles;
         $fields->insertAfter(new DropdownField('Profile', _t('SubsiteExtra.SubsiteProfile', 'Subsite profile'), $profiles), 'Title');
     }
     // Better gridfield
     if (class_exists('GridFieldEditableColumns')) {
         $DomainsGridField = GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldTitleHeader())->addComponent($editableCols = new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($addNew = new GridFieldAddNewInlineButton());
         $addNew->setTitle(_t('SubsitesExtra.ADD_NEW', "Add a new subdomain"));
         $editableColsFields = array();
         $editableColsFields['IsPrimary'] = array('title' => _t('SubsiteExtra.IS_PRIMARY', 'Is Primary'), 'callback' => function ($record, $column, $grid) {
             $field = new CheckboxField($column);
             return $field;
         });
         $editableColsFields['Domain'] = array('title' => _t('SubsitesExtra.TITLE', "Domain"), 'callback' => function ($record, $column, $grid) {
             $field = new TextField($column);
             $field->setAttribute('placeholder', 'mydomain.ext');
             return $field;
         });
         $editableCols->setDisplayFields($editableColsFields);
         $DomainsGridField = new GridField("Domains", _t('Subsite.DomainsListTitle', "Domains"), $this->owner->Domains(), $DomainsGridField);
         if ($fields->dataFieldByName('Domains')) {
             $fields->replaceField('Domains', $DomainsGridField);
         }
     }
 }
 public function getCMSFields()
 {
     $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), TextField::create("URLSegment", $this->fieldLabel('URLSegment')), NumericField::create("Price", $this->fieldLabel('Price')), HTMLEditorField::create('Description', $this->fieldLabel('Price'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('AdditionalData', 'Additional Data', array(NumericField::create("Quantity", $this->fieldLabel('Quantity')), TextField::create("SKU", $this->fieldLabel('SKU')), TextField::create("PackSize", $this->fieldLabel('PackSize')), TextField::create("Weight", $this->fieldLabel('Weight'))))->setHeadingLevel(4), ToggleCompositeField::create('Metadata', _t('CommerceAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4), CheckboxField::create("Disabled", $this->fieldLabel('Disabled'))), $tabImages = new Tab('Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images()))));
     // Help text for MetaData on page content editor
     $metaFieldDesc->setRightTitle(_t('CommerceAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
     $metaFieldExtra->setRightTitle(_t('CommerceAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example &lt;meta name=\"customName\" content=\"your custom content here\" /&gt;"))->addExtraClass('help');
     // Once product is saved, deal with more complex associations
     if ($this->ID) {
         // Deal with product features
         $add_button = new GridFieldAddNewInlineButton('toolbar-header-left');
         $add_button->setTitle('Add Attribute');
         $attributes_field = new GridField('Attributes', '', $this->Attributes(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button)->addComponent(new GridFieldOrderableRows('Sort')));
         $fields->addFieldToTab('Root.Attributes', $attributes_field);
         // Deal with customisations
         $add_button = new GridFieldAddNewButton('toolbar-header-left');
         $add_button->setButtonName('Add Customisation');
         $custom_config = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), $add_button, new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(20), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), new GridFieldOrderableRows('Sort'));
         $custom_field = GridField::create('Customisations', '', $this->Customisations(), $custom_config);
         $fields->addFieldToTab('Root.Customisations', $custom_field);
         $related_field = GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create());
         $fields->addFieldToTab('Root.Related', $related_field);
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }