silverstripe / silverstripe-admin

Silverstripe Admin Component
BSD 3-Clause "New" or "Revised" License
25 stars 92 forks source link

Intermittent CMS error on Archiving page #1051

Open purplespider opened 4 years ago

purplespider commented 4 years ago

I'm struggling to reliably reproduce this error, but it has been occasionally happening on several different Silverstripe 4.5 sites for a while now.

Sometimes when Archiving a page, the CMS locks up with a loading indicator and requires reloading. After reloading the page shows a successfully archived, but the error that occurs is:

Uncaught Error: Call to a member function forTemplate() on null POST /admin/pages/edit/EditForm/7/ Line 973 in /home/XXX/public_html/vendor/silverstripe/admin/code/LeftAndMain.php

View Full Trace

Hoping someone with more knowledge of this area may be able to identify the issue.

purplespider commented 3 years ago

This still occurs in Silverstripe 4.7.3 and I believe I have finally managed to find a way to reproduce it:

In a nutshell, if a user who does not have the View any page permission tries to Archive a child page then the CMS locks up with the error.

So to reproduce:

  1. From a fresh Silverstripe install.
  2. Log in as admin.
  3. Create a new user, and add them to the Content Authors group.
  4. Log out as admin and log in as the newly created user.
  5. Create a new child page - It must be the child of an existing page, and not on the top level.
  6. Attempt to Archive the page (... > Archive)

What happens: the page is archived, but the CMS locks up with the loading indicator, and the following error is generated:

[Emergency] Uncaught Error: Call to a member function forTemplate() on null

POST /admin/pages/edit/EditForm/10/

Line 982 in /home/site/vendor/silverstripe/admin/code/LeftAndMain.php

Source

973      *
974      * @return PjaxResponseNegotiator
975      */
976     public function getResponseNegotiator()
977     {
978         if (!$this->responseNegotiator) {
979             $this->responseNegotiator = new
PjaxResponseNegotiator(
980                 array(
981                     'CurrentForm' => function () {
982                         return
$this->getEditForm()->forTemplate();
983                     },
984                     'Content' => function () {
985                         return
$this->renderWith($this->getTemplatesWithSuffix('_Content'));
986                     },
987                     'Breadcrumbs' => function () {
988                         return $this->renderWith([

Note: There is no need to make any changes to the default group or page permissions to trigger this error, it occurs with the defaults.

A workaround is to enable the View any page permission on the Content Authors group, but this shouldn't be necessary.