/** * Gets the form fields as defined through the metadata * on {@link $obj} and the custom parameters passed to FormScaffolder. * Depending on those parameters, the fields can be used in ajax-context, * contain {@link TabSet}s etc. * * @return FieldList */ public function getFieldList() { $fields = new FieldList(); // tabbed or untabbed if ($this->tabbed) { $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); } //var_dump($this->obj->db());exit(); // add database fields foreach ($this->obj->db() as $fieldName => $fieldType) { if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) { continue; } // @todo Pass localized title if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $fieldObject = new $fieldClass($fieldName); } else { $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } $fieldObject->setTitle($this->obj->fieldLabel($fieldName)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $fieldObject); } else { $fields->push($fieldObject); } } return $fields; }
/** * Gets the form fields as defined through the metadata * on {@link $obj} and the custom parameters passed to FormScaffolder. * Depending on those parameters, the fields can be used in ajax-context, * contain {@link TabSet}s etc. * * @return FieldSet */ public function getFieldSet() { $fields = new FieldSet(); // tabbed or untabbed if($this->tabbed) { $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); } // add database fields foreach($this->obj->db() as $fieldName => $fieldType) { if($this->restrictFields && !in_array($fieldName, $this->restrictFields)) continue; // @todo Pass localized title if($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $fieldObject = new $fieldClass($fieldName); } else { $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } $fieldObject->setTitle($this->obj->fieldLabel($fieldName)); if($this->tabbed) { $fields->addFieldToTab("Root.Main", $fieldObject); } else { $fields->push($fieldObject); } } // add has_one relation fields if($this->obj->has_one()) { foreach($this->obj->has_one() as $relationship => $component) { if($this->restrictFields && !in_array($relationship, $this->restrictFields)) continue; $hasOneField = $this->obj->dbObject("{$relationship}ID")->scaffoldFormField(null, $this->getParamsArray()); $hasOneField->setTitle($this->obj->fieldLabel($relationship)); if($this->tabbed) { $fields->addFieldToTab("Root.Main", $hasOneField); } else { $fields->push($hasOneField); } } } // only add relational fields if an ID is present if($this->obj->ID) { // add has_many relation fields if($this->obj->has_many() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) { foreach($this->obj->has_many() as $relationship => $component) { if($this->tabbed) { $relationTab = $fields->findOrMakeTab( "Root.$relationship", $this->obj->fieldLabel($relationship) ); } $relationshipFields = singleton($component)->summaryFields(); $foreignKey = $this->obj->getComponentJoinField($relationship); $ctf = new ComplexTableField( $this, $relationship, $component, $relationshipFields, "getCMSFields", "$foreignKey = " . $this->obj->ID ); $ctf->setPermissions(TableListField::permissions_for_object($component)); if($this->tabbed) { $fields->addFieldToTab("Root.$relationship", $ctf); } else { $fields->push($ctf); } } } if($this->obj->many_many() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) { foreach($this->obj->many_many() as $relationship => $component) { if($this->tabbed) { $relationTab = $fields->findOrMakeTab( "Root.$relationship", $this->obj->fieldLabel($relationship) ); } $relationshipFields = singleton($component)->summaryFields(); $filterWhere = $this->obj->getManyManyFilter($relationship, $component); $filterJoin = $this->obj->getManyManyJoin($relationship, $component); $ctf = new ComplexTableField( $this, $relationship, $component, $relationshipFields, "getCMSFields", $filterWhere, '', $filterJoin ); $ctf->setPermissions(TableListField::permissions_for_object($component)); $ctf->popupClass = "ScaffoldingComplexTableField_Popup"; if($this->tabbed) { $fields->addFieldToTab("Root.$relationship", $ctf); } else { $fields->push($ctf); } } } } return $fields; }
/** * Gets the form fields as defined through the metadata * on {@link $obj} and the custom parameters passed to FormScaffolder. * Depending on those parameters, the fields can be used in ajax-context, * contain {@link TabSet}s etc. * * @return FieldList */ public function getFieldList() { $fields = new FieldList(); // tabbed or untabbed if ($this->tabbed) { $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); } // add database fields foreach ($this->obj->db() as $fieldName => $fieldType) { if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) { continue; } // @todo Pass localized title if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $fieldObject = new $fieldClass($fieldName); } else { $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } $fieldObject->setTitle($this->obj->fieldLabel($fieldName)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $fieldObject); } else { $fields->push($fieldObject); } } // add has_one relation fields if ($this->obj->hasOne()) { foreach ($this->obj->hasOne() as $relationship => $component) { if ($this->restrictFields && !in_array($relationship, $this->restrictFields)) { continue; } $fieldName = $component === 'DataObject' ? $relationship : "{$relationship}ID"; if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $hasOneField = new $fieldClass($fieldName); } else { $hasOneField = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } if (empty($hasOneField)) { continue; } // Allow fields to opt out of scaffolding $hasOneField->setTitle($this->obj->fieldLabel($relationship)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $hasOneField); } else { $fields->push($hasOneField); } } } // only add relational fields if an ID is present if ($this->obj->ID) { // add has_many relation fields if ($this->obj->hasMany() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) { foreach ($this->obj->hasMany() as $relationship => $component) { if ($this->tabbed) { $relationTab = $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship)); } $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'GridField'; $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create()); if ($this->tabbed) { $fields->addFieldToTab("Root.{$relationship}", $grid); } else { $fields->push($grid); } } } if ($this->obj->manyMany() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) { foreach ($this->obj->manyMany() as $relationship => $component) { if ($this->tabbed) { $relationTab = $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship)); } $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'GridField'; $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create()); if ($this->tabbed) { $fields->addFieldToTab("Root.{$relationship}", $grid); } else { $fields->push($grid); } } } } return $fields; }
/** * Scaffolds the relation WidgetArea into the context CMSFields and configurates * the GridField. * * @param DataObject $context Context to get Widget admin for * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 05.03.2014 */ public static function scaffold_widget_area_fields_for($context) { $fields = $context->WidgetArea()->scaffoldFormFields(array('includeRelations' => $context->isInDB(), 'tabbed' => false, 'ajaxSafe' => true)); if ($context->isInDB()) { $widgetsField = $fields->dataFieldByName('Widgets'); $widgetsFieldConfig = $widgetsField->getConfig(); $widgetsFieldConfig->removeComponentsByType('GridFieldAddExistingAutocompleter'); if (class_exists('GridFieldSortableRows')) { $widgetsFieldConfig->addComponent(new GridFieldSortableRows('Sort')); } $widgetsFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array('Title' => $context->fieldLabel('Title'), 'ClassName' => _t('WidgetSetWidget.TYPE'))); // this is configured with a remove relation button by default which results in unaccessible widgets $widgetsFieldConfig->removeComponentsByType('GridFieldDeleteAction'); // so we add a new one without a relation button $widgetsFieldConfig->addComponent(new GridFieldDeleteAction()); } return $fields; }