Closed elliot-sawyer closed 5 years ago
Suggest changing the method on Versioned to this, to avoid conflicting with any existing field named "Author"
/**
* Get author of this record.
* Note: Only works on records selected via Versions()
*
* @return Member|null
*/
public function Author()
{
//return the contents of the Author field, if one exists
if($author = $this->owner->getField('Author')) {
return $author;
}
if (!$this->owner->AuthorID) {
return null;
}
/** @var Member $member */
$member = DataObject::get_by_id(Member::class, $this->owner->AuthorID);
return $member;
}
It's unlikely we'll be changing either Versioned's API or the DB field name to fix this issue, but we could add a method to the CWP page that returns the value with a different name, e.g.
public function getNewsPageAuthor()
{
return $this->dbObject('Author');
}
You could add something like that to an extension as a workaround until it is fixed in CWP itself.
Does that mean that "Author" is effectively a reserved name when working with Pages?
Yep, I think so
I'd vote for this being catered for at the Versioned
module's end to interfere with custom dataobject db field names as little as possible.
Thanks for the input. We can't easily change the Versioned method name due to semantic versioning restrictions, but even if we could, this would only fix this particular case.
You can track the general problem you're describing here: https://github.com/silverstripe/silverstripe-framework/issues/6329
We will fix this in CWP by adding a non-conflicting accessor for the Author property, since we also can't rename that due to semantic versioning restrictions.
Fixed in CWP 2.4
CWP News Page has one of these as a $db field:
But it's a Page type, which is Versioned.... which has a
public function Author()
methodThe result is that Author is not shown at all... how would you go about resolving this?