Magento 2 add extra button in backend

The problem is that Magento\Cms\Block\Adminhtml\Page\Edit { is using the namespace you have declared Magento\Cms\Block\Adminhtml\Page\Edit so becomes Company\Modulename\Block\Adminhtml\Page\Magento\Cms\Block\Adminhtml\Page\Edit

Your missing a \ from the front of the extended class so that it doesn't use the current namespace - you should then have

class Edit extends \Magento\Cms\Block\Adminhtml\Page\Edit {

That fixes the error - but there may still be a better way to do this.


It is better to use plugins instead of declaring preference in your case. The main benefit is that there will be no conflicts if another extension will try to modify/extend the same functionality. Keep in mind that there can be only one active preference for each class/interface, priority is defined according to sequence in the final merged module.xml

Preferences should be used when there is a need to provide custom implementation of core interface.


Can be done with a plugin on \Magento\Cms\Block\Adminhtml\Page\Edit using beforeSetLayout since there is in \Magento\Backend\Block\Widget\Container this:

protected function _prepareLayout()
{
    $this->toolbar->pushButtons($this, $this->buttonList);
    return parent::_prepareLayout();
}

In method beforeSetLayout use $subject->addButton().