BadMethodCallException (CMSEditLink not found)
phptek opened this issue · comments
Russ Michell commented
PHP 7.1 / Ubuntu 16.04 / silverstripe/framework 4.3.3
HistoryGridFieldItemRequest
on line 138 expects decorated objects to feature a CMSEditLink()
method, but doesn't enforce / indicate this requirement anywhere.
CMSEditLink()
comes from silverstripe/framework, in the CMSPreviewable
interface, and I would expect decorated objects to throw an exception far earlier in the control chain, if not on install (dev/build). If going with the latter idea, then declaring an add_to_class()
or a constructor on method the DataObjectHistory
extension and checking that the decorated object implements CMSPreviewable
, would be the way to go.
Russ Michell commented
This sorts it out, in DataObjectHistory.php
<?php
...
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\CMSPreviewable;
...
/**
*
* @throws \Exception
*/
public static function add_to_class($class, $extensionClass, $args = null)
{
parent::add_to_class($class, $extensionClass, $args);
if (!in_array($class, ClassInfo::implementorsOf(CMSPreviewable::class))) {
throw new \Exception(sprintf('Decorated class: %s, must implement %s.', $class, CMSPreviewable::class));
}
}