mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API: Add Link Tracking section to Relations developer guide and describe show_sitetree_link_tracking
, show_file_link_tracking
.
Refactor form scaffolder.
This commit is contained in:
parent
37a266f2f0
commit
01db5c9e98
@ -592,6 +592,13 @@ As these lists are not backed by the database, most of the filtering methods on
|
|||||||
this type. As such, an `UnsavedRelationList` should only be used for setting a relation before saving an object, not
|
this type. As such, an `UnsavedRelationList` should only be used for setting a relation before saving an object, not
|
||||||
for displaying the objects contained in the relation.
|
for displaying the objects contained in the relation.
|
||||||
|
|
||||||
|
## Link Tracking
|
||||||
|
|
||||||
|
You can control the visibility of the `Link Tracking` tab by setting the `show_sitetree_link_tracking` config.
|
||||||
|
This defaults to `false` for most `DataObject`'s.
|
||||||
|
|
||||||
|
It is also possible to control the visibility of the `File Tracking` tab by setting the `show_file_link_tracking` config.
|
||||||
|
|
||||||
## Related Lessons
|
## Related Lessons
|
||||||
* [Working with data relationships -- has_many](https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-has-many-1)
|
* [Working with data relationships -- has_many](https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-has-many-1)
|
||||||
* [Working with data relationships -- many_many](https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-many-many-1)
|
* [Working with data relationships -- many_many](https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-many-many-1)
|
||||||
@ -606,3 +613,4 @@ for displaying the objects contained in the relation.
|
|||||||
* [HasManyList](api:SilverStripe\ORM\HasManyList)
|
* [HasManyList](api:SilverStripe\ORM\HasManyList)
|
||||||
* [ManyManyList](api:SilverStripe\ORM\ManyManyList)
|
* [ManyManyList](api:SilverStripe\ORM\ManyManyList)
|
||||||
* [DataObject](api:SilverStripe\ORM\DataObject)
|
* [DataObject](api:SilverStripe\ORM\DataObject)
|
||||||
|
* [LinkTracking](api:SilverStripe\CMS\Model\SiteTreeLinkTracking)
|
||||||
|
@ -140,7 +140,8 @@ class FormScaffolder
|
|||||||
if ($this->obj->ID) {
|
if ($this->obj->ID) {
|
||||||
// add has_many relation fields
|
// add has_many relation fields
|
||||||
if ($this->obj->hasMany()
|
if ($this->obj->hasMany()
|
||||||
&& ($this->includeRelations === true || isset($this->includeRelations['has_many']))) {
|
&& ($this->includeRelations === true || isset($this->includeRelations['has_many']))
|
||||||
|
) {
|
||||||
foreach ($this->obj->hasMany() as $relationship => $component) {
|
foreach ($this->obj->hasMany() as $relationship => $component) {
|
||||||
if ($this->tabbed) {
|
if ($this->tabbed) {
|
||||||
$fields->findOrMakeTab(
|
$fields->findOrMakeTab(
|
||||||
@ -168,32 +169,17 @@ class FormScaffolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->obj->manyMany()
|
if ($this->obj->manyMany()
|
||||||
&& ($this->includeRelations === true || isset($this->includeRelations['many_many']))) {
|
&& ($this->includeRelations === true || isset($this->includeRelations['many_many']))
|
||||||
|
) {
|
||||||
foreach ($this->obj->manyMany() as $relationship => $component) {
|
foreach ($this->obj->manyMany() as $relationship => $component) {
|
||||||
if ($this->tabbed) {
|
static::addManyManyRelationshipFields(
|
||||||
$fields->findOrMakeTab(
|
$fields,
|
||||||
"Root.$relationship",
|
|
||||||
$this->obj->fieldLabel($relationship)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$fieldClass = (isset($this->fieldClasses[$relationship]))
|
|
||||||
? $this->fieldClasses[$relationship]
|
|
||||||
: 'SilverStripe\\Forms\\GridField\\GridField';
|
|
||||||
|
|
||||||
/** @var GridField $grid */
|
|
||||||
$grid = Injector::inst()->create(
|
|
||||||
$fieldClass,
|
|
||||||
$relationship,
|
$relationship,
|
||||||
$this->obj->fieldLabel($relationship),
|
(isset($this->fieldClasses[$relationship]))
|
||||||
$this->obj->$relationship(),
|
? $this->fieldClasses[$relationship] : null,
|
||||||
GridFieldConfig_RelationEditor::create()
|
$this->tabbed,
|
||||||
|
$this->obj
|
||||||
);
|
);
|
||||||
if ($this->tabbed) {
|
|
||||||
$fields->addFieldToTab("Root.$relationship", $grid);
|
|
||||||
} else {
|
|
||||||
$fields->push($grid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,6 +187,47 @@ class FormScaffolder
|
|||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the default many-many relation fields for the relationship provided.
|
||||||
|
*
|
||||||
|
* @param FieldList $fields Reference to the @FieldList to add fields to.
|
||||||
|
* @param string $relationship The relationship identifier.
|
||||||
|
* @param mixed $overrideFieldClass Specify the field class to use here or leave as null to use default.
|
||||||
|
* @param bool $tabbed Whether this relationship has it's own tab or not.
|
||||||
|
* @param DataObject $dataObject The @DataObject that has the relation.
|
||||||
|
*/
|
||||||
|
public static function addManyManyRelationshipFields(
|
||||||
|
FieldList &$fields,
|
||||||
|
$relationship,
|
||||||
|
$overrideFieldClass,
|
||||||
|
$tabbed,
|
||||||
|
DataObject $dataObject
|
||||||
|
) {
|
||||||
|
if ($tabbed) {
|
||||||
|
$fields->findOrMakeTab(
|
||||||
|
"Root.$relationship",
|
||||||
|
$dataObject->fieldLabel($relationship)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fieldClass = $overrideFieldClass ?: GridField::class;
|
||||||
|
|
||||||
|
/** @var GridField $grid */
|
||||||
|
$grid = Injector::inst()->create(
|
||||||
|
$fieldClass,
|
||||||
|
$relationship,
|
||||||
|
$dataObject->fieldLabel($relationship),
|
||||||
|
$dataObject->$relationship(),
|
||||||
|
GridFieldConfig_RelationEditor::create()
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($tabbed) {
|
||||||
|
$fields->addFieldToTab("Root.$relationship", $grid);
|
||||||
|
} else {
|
||||||
|
$fields->push($grid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array suitable for passing on to {@link DBField->scaffoldFormField()}
|
* Return an array suitable for passing on to {@link DBField->scaffoldFormField()}
|
||||||
* without tying this call to a FormScaffolder interface.
|
* without tying this call to a FormScaffolder interface.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user