Skip to content
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

BadMethodCallException (CMSEditLink not found) #1

Open
phptek opened this issue May 8, 2019 · 1 comment
Open

BadMethodCallException (CMSEditLink not found) #1

phptek opened this issue May 8, 2019 · 1 comment

Comments

@phptek
Copy link

phptek commented May 8, 2019

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.

@phptek
Copy link
Author

phptek commented May 8, 2019

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));
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant