Moderator element doesn't exist on Add forms, causes error

Created on 11 September 2023, over 1 year ago
Updated 28 September 2023, about 1 year ago

Problem/Motivation

Running into the issue of a WSOD (with error) on add forms for forums.
The error is as follows

The website encountered an unexpected error. Please try again later.
Error: Call to undefined function acl_edit_form_get_user_list() in forum_access_form_taxonomy_term_forums_x_form_alter_after_build() (line 660 of modules/contrib/forum_access/forum_access.mNodule).

If I add this line in that function `module_load_include('inc', 'acl', 'acl.admin');`, then I get this error:

The website encountered an unexpected error. Please try again later.
TypeError: acl_edit_form_get_user_list(): Argument #1 ($form) must be of type array, null given, called in /app/web/modules/contrib/forum_access/forum_access.module on line 660 in acl_edit_form_get_user_list() (line 193 of modules/contrib/acl/acl.admin.inc).

That's because the moderator element of the form does not yet exist, if you check the function `_forum_access_forum_moderators_form` in forum_access.admin.inc, it requires a term id which is not yet generated on add forms.

Steps to reproduce

Using these modules:
- forum_access
- acl
- content_access (probably doesn't matter, but listing it anyway)

On a Drupal 9.5.10

Proposed resolution

It seems fixed by simply adding this piece of code to the `forum_access_form_taxonomy_term_forums_x_form_alter_after_build` function:

  if (!isset($form['moderators'])) {
    return $form;
  }
  module_load_include('inc', 'acl', 'acl.admin');

Remaining tasks

Review MR.

Apologies if this issue has been reported before, but I couldn't find any.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium RandalV

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

Comments & Activities

  • Issue created by @RandalV
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Waiting for branch to pass
  • @randalv opened merge request.
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Waiting for branch to pass
  • πŸ‡§πŸ‡ͺBelgium RandalV

    Added a second module_load_include() to the MR, it was needed elsewhere too.

    Now I haven't run in any other issues.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Build Successful
  • πŸ‡¨πŸ‡­Switzerland salvis

    Thank you for your report and patches, @RandalV!

    I agree, something is completely broken here! With just ACL and FA, your patch allows opening Forum|Add, but it still crashes when trying to save the new forum. Also, the Moderator element is (obviously) not present on the Forum|Add page. This is the real issue!

    Ignoring the absence of the Moderator element is not the right approach β€” it must be there for us to use.

    Here's a new patch, please test it.

  • The last submitted patch, 4: fa-moderator-form-3386451-4.patch, failed testing. View results β†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Build Successful
  • πŸ‡¨πŸ‡­Switzerland salvis
  • πŸ‡¨πŸ‡­Switzerland salvis

    Failed because of not having any tests.

  • Status changed to Needs work about 1 year ago
  • πŸ‡§πŸ‡ͺBelgium RandalV

    Hi @Salvis,

    Thanks for your reply and patch! You're right, ignoring the lack of the moderator element is not the way.

    With your patch however, I'm still getting the following error when navigating to the 'Forum add'-form.
    I haven't got the time to debug this right now though, I'm afraid.

    The website encountered an unexpected error. Please try again later.
    TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in _acl_edit_form_after_build() (line 126 of modules/contrib/acl/acl.admin.inc).
    _acl_edit_form_after_build(Array, Object)
    call_user_func_array('_acl_edit_form_after_build', Array) (Line: 1083)
    Drupal\Core\Form\FormBuilder->doBuildForm('taxonomy_term_forums_forum_form', Array, Object) (Line: 1075)
    Drupal\Core\Form\FormBuilder->doBuildForm('taxonomy_term_forums_forum_form', Array, Object) (Line: 1075)
    Drupal\Core\Form\FormBuilder->doBuildForm('taxonomy_term_forums_forum_form', Array, Object) (Line: 579)
    Drupal\Core\Form\FormBuilder->processForm('taxonomy_term_forums_forum_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'forum') (Line: 259)
    Drupal\forum\Controller\ForumController->addForum()
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->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: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • πŸ‡ΊπŸ‡ΈUnited States leisurman

    I see the same, TypeError: count as mentioned by @RandalV
    Using Drupal core 9.5.11
    Forum Access Version: 8.x-1.0
    ACL Version: 8.x-1.0
    I have tried both patch #4 and patch #6
    Our production site is on PHP 7, my local environment is on PHP 8. The error occurs on both PHP versions.

  • πŸ‡ΊπŸ‡ΈUnited States leisurman

    Update. upgrading ACLfrom 8.x-1.0 to 8.x-1.1, and using patch #6 fixes the error.

  • Status changed to RTBC about 1 year ago
  • πŸ‡¨πŸ‡­Switzerland salvis

    Thank you, @leisurman and @RandalV for testing!

    I've pushed πŸ“Œ Update ACL dependency and fix some other issues in composer.json and *.info.yml Fixed to require ACL 8.x-1.1, which should make #6 work according to @leisurman's and my own testing.

    • salvis β†’ committed 20156522 on 8.x-1.x
      Issue #3386451 by salvis: Fix moderator element doesn't exist on Add...
  • Status changed to Fixed about 1 year ago
  • πŸ‡¨πŸ‡­Switzerland salvis
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024