Created on 19 August 2023, over 1 year ago
Updated 20 September 2023, over 1 year ago

Problem/Motivation

I found a white screen (WSOD) for my site. On trying to clear cache using drush (drush cr) I got the following error message:

$ drush cr
PHP Fatal error: Cannot redeclare permissions_by_term_theme() (previously declared in /var/www/...../web/modules/contrib/permissions_by_term/permissions_by_term.module:592) in /var/www/...../web/modules/contrib/permissions_by_term/permissions_by_term.module on line 612
[warning] Drush command terminated abnormally.

On looking into the code, at the end of the file, I found the function definition was duplicated: I merely commented out the duplicate definition, which fixed the problem.

Below I copied and pasted the code that was duplicated. I merely commented out the repeated function definition, which got the site up and running again.

/**
 * Implements hook_theme().
 */
function permissions_by_term_theme() {
  return [
    'permissions_by_term_render_node_details' => [
      'variables' => [
        'roles' => [],
        'users' => [],
      ],
      'template' => 'node-details',
      'path' => \Drupal::service('extension.list.module')->getPath('permissions_by_term') . '/src/View',
    ]
  ];
}

/**
 * Implements hook_theme().
 */
function permissions_by_term_theme() {
  return [
    'permissions_by_term_render_node_details' => [
      'variables' => [
        'roles' => [],
        'users' => [],
      ],
      'template' => 'node-details',
      'path' => \Drupal::service('extension.list.module')->getPath('permissions_by_term') . '/src/View',
    ]
  ];
}

Proposed resolution

Remove the duplicated code.

More info

Drupal version : 9.5.10
Database : Connected
Drupal bootstrap : Successful
PHP binary : /usr/bin/php8.1
PHP OS : Linux
Drush version : 10.6.2
Install profile : standard

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

πŸ› Bug report
Status

Fixed

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States snowmountain

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

Comments & Activities

  • Issue created by @snowmountain
  • πŸ‡ΊπŸ‡ΈUnited States snowmountain
  • Status changed to Closed: cannot reproduce over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States snowmountain

    I checked further into this by downloading the .tar.gz file for version 3.1.25 of this module. The affected file, permissions_by_term.module, did NOT contain the duplicated function. It is unclear how this duplicated function got into my site, but since the duplicated function definition was not in the downloaded module, I am closing this.

  • Status changed to Active over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States codeelegance

    I'm opening this again, because I, too, found the duplicated theme function at the end of the file. Module was updated via composer.

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

    After correcting this by removing the duplicated function code, the module was updated by composer and the problem reappeared - even though the downloaded tarred gzipped code for the new version did not contain the duplicated function code. Composer seems to be somehow duplicating the code.

  • πŸ‡©πŸ‡ͺGermany marcoliver Neuss, NRW, Germany

    I've spent some time just now trying to reproduce the problem, changing module versions in all directions, but the module file always comes through clean.

    Can anyone please note the steps to make this problem reproducible on a clean Drupal installation?

    Also, what Composer versions are you using?

    And are you maybe applying any additional patches from other issues?

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

    Here ids what I was using:

    Drupal version : 9.5.10
    Composer version 2.1.5 2021-07-23 10:35:47

    After restoring the site by commenting out the duplicate function,
    I ran composer again:

    $ composer update drupal/permissions_by_term

    and composer reported it could not apply a patch: the result was the WSOD again for the site, and this message from composer, after
    $ composer update drupal/permissions_by_term

    Gathering patches for root package.
    Removing package drupal/permissions_by_term so that it can be re-installed and re-patched.
    - Removing drupal/permissions_by_term (3.1.26)
    Deleting ./modules/contrib/permissions_by_term - deleted
    Loading composer repositories with package information
    Updating dependencies
    Nothing to modify in lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 0 updates, 0 removals
    Gathering patches for root package.
    Gathering patches for dependencies. This might take a minute.
    - Installing drupal/permissions_by_term (3.1.26): Extracting archive
    - Applying patches for drupal/permissions_by_term
    https://git.drupalcode.org/project/permissions_by_term/-/merge_requests/... (perm by term patch to allow editing nodes)
    Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/permissions_by_term/-/merge_requests/...

    Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
    Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
    Package webmozart/path-util is abandoned, you should avoid using it. Use symfony/filesystem instead.
    Generating autoload files
    54 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    Scaffolding files for drupal/core:
    - Copy [web-root]/.htaccess from assets/scaffold/files/htaccess

  • Status changed to Needs review over 1 year ago
  • πŸ‡©πŸ‡ͺGermany marcoliver Neuss, NRW, Germany

    Hi snowmountain, okay, but that makes sense though, because the issue the now failing patch addresses has been fixed. So your Composer installation is attempting to apply the patch to files that already include the changes from the patch.

    Kindly remove the patch from your composer.json and let me know if that solves your problem.

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

    I had the same problem after updating from composer.
    I was able to fix with composer "reinstall"

    -bash-4.2$ drush cr
    PHP Fatal error:  Cannot redeclare permissions_by_term_theme() (previously declared in ###/html/web/modules/contrib/permissions_by_term/permissions_by_term.module:592) in ###/html/web/modules/contrib/permissions_by_term/permissions_by_term.module on line 604
    
    -bash-4.2$ composer reinstall drupal/permissions_by_term
      - Removing drupal/permissions_by_term (3.1.26)
    Deleting web/modules/contrib/permissions_by_term - deleted
    Gathering patches for root package.
    Gathering patches for dependencies. This might take a minute.
      - Installing drupal/permissions_by_term (3.1.26): Extracting archive
    
    -bash-4.2$ drush cr
     [success] Cache rebuild complete.
    
  • πŸ‡ΊπŸ‡ΈUnited States snowmountain

    Thanks marcoliver,

    I removed the patch from composer.json, which got rid of the duplicate function error!

    However, a new error appeared. This new error is specific to version 3.1.27; after reverting back to 3.1.26, the error disappeared. I plan to open a new issue reporting this error, unless I find it has already been reported.

    I did not find it reported, so I reported it at https://www.drupal.org/project/permissions_by_term/issues/3387431 πŸ› too few args in AccessChecker Active

    The new error is below, FYI - but, reverting to 3.1.26 fixed it, and there is an issue for it (above).

    The website encountered an unexpected error. Please try again later.
    ArgumentCountError: Too few arguments to function Drupal\permissions_by_entity\Service\AccessChecker::__construct(), 4 passed in /var/www/clients/client3/web41/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 5 expected in Drupal\permissions_by_entity\Service\AccessChecker->__construct() (line 52 of modules/contrib/permissions_by_term/modules/permissions_by_entity/src/Service/AccessChecker.php).

  • Status changed to Fixed over 1 year ago
  • πŸ‡©πŸ‡ͺGermany marcoliver Neuss, NRW, Germany

    Hi snowmountain,

    as some people commented your new issue, clearing the cache should do the trick. I was just able to reproduce the problem. Clearing the cache, so the changed method signature becomes known, should be the solution.

    I'll mark this and the other issue as fixed. Feel free to reopen either one if the problems persist.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024