-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMSEditLinkExtension doesn't work with Hierarchy #1628
Comments
Can you please provide some more information about how the parent provides the edit link for this model? i.e. what is the modeladmin, gridfield, or other setup you're using in order to manage the |
@GuySartorelli ContentLayouts are managed by Pages, which has_many of them. We have other models like Articles that also have many ContentLayouts, and these can be managed by either a Some |
Ahhh, interesting. So you're using the That said, if the Also, you said in your report:
But just now you said:
So... it should be looking for the has_many of the page, shouldn't it? |
Yes, that's correct.
Yes, I think we need a dynamic |
There are PageID, ArticleID, and ParentID columns on ContentLayouts.
|
Ooohhhh.... so you're saying that |
What is expectedWhen I save a ContentLayout after changing the ParentID, I should not receive the error: "[Emergency] Uncaught LogicException: Could not produce an edit link for the passed object." Instead of using the public function getCMSEditOwner()
{
$owner = null;
if ($this->PageID) {
$owner = $this->Page();
} else if ($this->ParentID) {
$owner = $this->Parent();
}
$this->extend('updateCMSEditOwner', $owner);
return $owner;
} I think we need a public function getCMSEditOwnerRelation()
{
return $this->owner->config()->get('cms_edit_owner');
} But we could use it in our ContentLayout class like: public function getCMSEditOwnerRelation()
{
$owner = '';
if ($this->PageID) {
$owner = 'Page';
} else if ($this->ParentID) {
$owner = 'Parent';
}
$this->extend('updateCMSEditOwnerRelation', $owner);
return $owner;
} Then, the CMSEditLinkExtension's /**
* Get the link for editing an object from the CMS edit form of this object.
* @throws 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.
*/
public function getCMSEditLinkForManagedDataObject(DataObject $obj, string $reciprocalRelation): string
{
$fields = $this->owner->getCMSFields();
if ($reciprocalRelation == 'Parent' && $this->owner->hasExtension(Hierarchy::class)) {
$children = $this->owner->AllChildren()->toArray();
} else {
$children = $this->owner->hasMany(false);
}
$link = $this->getCMSEditLinkForRelation($children, $obj, $reciprocalRelation, $fields);
if (!$link) {
throw new LogicException('Could not produce an edit link for the passed object.');
}
return $link;
} |
Ahh thank you for that context. Sounds like this is working exactly as expected, then. It's not meant to handle scenarios where different contexts can be used to manage a model. Overriding the |
I've updated the context to what it seems like the problem actually is - not that the new description only mentioned the I have had a closer look at this and can see that |
Original context
We have a class that uses both the Hierarchy and CMSEditLinkExtension extensions. After the ParenID is changed, and the ContentLayout is saved, I get the error: `[Emergency] Uncaught LogicException: Could not produce an edit link for the passed object.`It doesn't look like there is any support for DataObjects in a Hierarchy in the CMSEditLinkExtension. Instead, it looks like it only checks for has_many/has_one relationships: https://github.com/silverstripe/silverstripe-admin/blob/2/code/CMSEditLinkExtension.php#L62
If a class has the
Hierarchy
extension it cannot rely on theParent
relation as the owner relation, because there is no corresponding has_many relation.Hierarchy
relies on its own methods to get the related children records.Developers could choose either of
Children()
orAllChildren()
to put in theGridField
so we'd need to check if either of these are editable, and if so return the link for it. They could also implement their own method to link back to the child records, though that would be out of scope.Note that we also need to validate that the parent record and the child record both share the same hierarchical base class before getting a hierarchical link - otherwise you could have a
has_one
fromMyRandomDataObject
toSiteTree
, and accidentally try to give a hierarchical link even though they don't share a hierarchical base class.There's also no way to define what the edit owner is for the root level item in the hierarchy.
e.g:
The grandchild checks its parent and finds the child. The child checks its parent and finds the root. But the root will try to check its parent and find nothing...
The text was updated successfully, but these errors were encountered: