Merge pull request #8353 from open-sausages/pulls/4.2/2227-show-link-tracking

API: Add Link Tracking section to Relations developer guide
This commit is contained in:
Luke Edwards 2018-09-13 14:23:34 +12:00 committed by GitHub
commit a33866ff4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 24 deletions

View File

@ -594,6 +594,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
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
* [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)
@ -608,3 +615,4 @@ for displaying the objects contained in the relation.
* [HasManyList](api:SilverStripe\ORM\HasManyList)
* [ManyManyList](api:SilverStripe\ORM\ManyManyList)
* [DataObject](api:SilverStripe\ORM\DataObject)
* [LinkTracking](api:SilverStripe\CMS\Model\SiteTreeLinkTracking)

View File

@ -140,7 +140,8 @@ class FormScaffolder
if ($this->obj->ID) {
// add has_many relation fields
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) {
if ($this->tabbed) {
$fields->findOrMakeTab(
@ -168,32 +169,17 @@ class FormScaffolder
}
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) {
if ($this->tabbed) {
$fields->findOrMakeTab(
"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,
static::addManyManyRelationshipFields(
$fields,
$relationship,
$this->obj->fieldLabel($relationship),
$this->obj->$relationship(),
GridFieldConfig_RelationEditor::create()
(isset($this->fieldClasses[$relationship]))
? $this->fieldClasses[$relationship] : null,
$this->tabbed,
$this->obj
);
if ($this->tabbed) {
$fields->addFieldToTab("Root.$relationship", $grid);
} else {
$fields->push($grid);
}
}
}
}
@ -201,6 +187,47 @@ class FormScaffolder
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()}
* without tying this call to a FormScaffolder interface.