Revert/Delete user revision actions trigger errors

Created on 18 June 2024, 10 months ago

Problem/Motivation

After installing the user_revision module on a Drupal site, several type errors are encountered when managing user revisions. The issue occurs when trying to revert or delete user revisions via the provided user interface.

Steps to reproduce:

  1. Ensure your server is running PHP version 8.2.14.
  2. Install Drupal 10.2.2 using the standard installation profile.
  3. Install the user_revision module version 2.0.0-alpha1.
  4. Clear the site's cache using drush cr.
  5. Log in to the site as an administrator.
  6. Navigate to any user account (or create a new one) and edit the user by creating a new revision at /user//edit, then save the changes.
  7. Go to the user's revision page at /user//revisions.
  8. Attempt to use any of the options (Revert or Delete) for a revision.
  9. Expected result: The revert or delete operations should be completed without any errors.

Actual result:

There are errors.
TypeError: Drupal\user_revision\Form\UserRevisionRevertForm::__construct(): Argument #1 ($user_storage) must be of type Drupal\user_revision\Form\EntityStorageInterface, Drupal\user\UserStorage given, called in /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionRevertForm.php on line 57 in Drupal\user_revision\Form\UserRevisionRevertForm->__construct() (line 48 of /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionRevertForm.php).

TypeError: Drupal\user_revision\Form\UserRevisionDeleteForm::__construct(): Argument #1 ($user_storage) must be of type Drupal\user_revision\Form\EntityStorageInterface, Drupal\user\UserStorage given, called in /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionDeleteForm.php on line 58 in Drupal\user_revision\Form\UserRevisionDeleteForm->__construct() (line 48 of /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionDeleteForm.php).

Expected result:

The revert or delete operations should be completed without any errors.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇺🇦Ukraine mr_fenix

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mr_fenix
  • 🇺🇦Ukraine mr_fenix

    This patch will fix the dependency and argument constructor bug.

  • 🇺🇦Ukraine mr_fenix

    This will be difficult to test because another error will appear there.

    Error: Call to a member function id() on null in Drupal\user_revision\Form\UserRevisionRevertForm->buildForm() (line 102 of /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionRevertForm.php).

    Error: Call to a member function id() on null in Drupal\user_revision\Form\UserRevisionDeleteForm->buildForm() (line 96 of /var/www/html/web/modules/contrib/user_revision/src/Form/UserRevisionDeleteForm.php).

    Please use the same steps to reproduce it.
    The attached to this comment patch will fix it.

  • Status changed to Needs review 10 months ago
  • 🇺🇦Ukraine mr_fenix

    Unfortunately, there is a third error that will appear and prevent to test

    InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 201 of /var/www/html/web/core/lib/Drupal/Component/Datetime/DateTimePlus.php).

    The patch attached to the comment will fix this issue too.
    And as a result it will be possible to see the result of all previous fixes on UI too.

    Please use the same reproduction for the error.

  • Issue was unassigned.
  • First commit to issue fork.
  • 🇮🇳India dipakmdhrm

    All 3 patches from #3, #4 & #5 need to be applied after one another to fix this. The MR combines the patches.

  • 🇮🇳India patelmayank7552 Mumbai

    Hi,

    After appylying the above patches, I still receive the below error.

    The website encountered an unexpected error. Try again later.

    Error: Call to a member function id() on null in Drupal\user_revision\Form\UserRevisionRevertForm->buildForm() (line 103 of modules/contrib/user_revision/src/Form/UserRevisionRevertForm.php).
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('user_revision_revert_confirm', Object) (Line: 284)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 43)
    Drupal\webform_product\RedirectMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

  • 🇮🇳India patelmayank7552 Mumbai

    Hi

    Please review the below patch for the above fix for comment no.13.

  • 🇮🇳India patelmayank7552 Mumbai

    Hi,

    Please find the updated patch.

Production build 0.71.5 2024