class CMSEditLinkExtension extends Extension (View source)

An extension that automatically generates a CMS edit link for DataObjects even if they are canonically edited in some nested {@link GridField}.

Designed to be used in conjunction with the {@link CMSPreviewable} interface.

For nested relations (e.g. a DataObject managed in a GridField of another DataObject) you can apply this extension to both the parent and the child object and the links will chain down the nested GridFields to the root cms_edit_owner.

You must set a cms_edit_owner config variable which defines the cms edit owner for this class. e.g. set this to a {@link LeftAndMain} class: private static string cms_edit_owner = MyModelAdmin::class; or to a has_one relation: private static string cms_edit_owner = 'Parent';

Note that the cms_edit_owner must implement a getCMSEditLinkForManagedDataObject() method.

If the cms_edit_owner is a has_one relation, the class on the other end of the relation must have a CMSEditLink() method.

Methods

__construct()

No description

static 
add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

setOwner(object $owner)

Set the owner of this extension.

mixed
withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

object
getOwner()

Returns the owner of this extension.

static string
get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.

mixed
invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

getCMSEditOwner()

Get the ModelAdmin, LeftAndMain, or DataObject which owns this object for CMS editing purposes.

string
getCMSEditLinkForManagedDataObject(DataObject $obj, string $reciprocalRelation)

Get the link for editing an object from the CMS edit form of this object.

string
CMSEditLink()

Get a link to edit this DataObject in the CMS.

Details

__construct()

static add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

Parameters

string $class
string $extensionClass
mixed $args

setOwner(object $owner)

Set the owner of this extension.

Parameters

object $owner

The owner object

mixed withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

Parameters

mixed $owner

Owner to set

callable $callback

Callback to invoke

array $args

Args to pass to callback

Return Value

mixed

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

object getOwner()

Returns the owner of this extension.

Return Value

object

static string get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.

Parameters

string $extensionStr

E.g. "Versioned('Stage','Live')"

Return Value

string

Extension classname, e.g. "Versioned"

mixed invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

Parameters

object $owner
string $method
array ...$arguments

Return Value

mixed

LeftAndMain|DataObject|null getCMSEditOwner()

Get the ModelAdmin, LeftAndMain, or DataObject which owns this object for CMS editing purposes.

Return Value

LeftAndMain|DataObject|null

string getCMSEditLinkForManagedDataObject(DataObject $obj, string $reciprocalRelation)

Get the link for editing an object from the CMS edit form of this object.

Parameters

DataObject $obj
string $reciprocalRelation

Return Value

string

Exceptions

LogicException

if a link cannot be established e.g. if the object is not in a has_many relation or not edited inside a GridField.

Get a link to edit this DataObject in the CMS.

Return Value

string