Error on "/node/add" when the user only has access to one content type

Created on 26 November 2024, 23 days ago

Problem/Motivation

If you are logged into an account that only has access to edit/add one node type when you visit /node/add either via the admin menu content --> add content (not click on a content type) or the add content button on the content listing page you will get the following error.

Error: Cannot use object of type Symfony\Component\HttpFoundation\RedirectResponse as array in Drupal\det_node\Controller\NodeControllerOverride->addPage() (line 44 of /var/www/html/web/modules/contrib/domain_entity_type/modules/det_node/src/Controller/NodeControllerOverride.php).

I believe this is happening as core makes the add URL redirect to the add URL of the 1 content type that the user can access, so the code is expecting an array but receiving the redirect object.

Steps to reproduce

  • Make a new role that can only add 1 node type + the other permissions to access the admin pages.
  • Make a user that has the new role
  • log into the new user and visit /node/add and you should see the error

Proposed resolution

Update the code to check if $build is an array to avoid the error and allow the redirect to happen.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom belazoth

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

Merge Requests

Comments & Activities

  • Issue created by @belazoth
  • Merge request !4Update NodeControllerOverride.php → (Open) created by belazoth
  • Pipeline finished with Success
    23 days ago
    Total: 248s
    #350761
  • 🇬🇧United Kingdom belazoth

    I have made a merge request with the changes that stop the error from happening. I have also created patches for people to use before the changes are merged. The patches need to be slightly different between version 1.0.x and 1.0.0-rc2 so I have made 2 versions of the patch.

  • 🇲🇦Morocco akram zairig Rabat, Morocco

    Hello, i'm not able to reproduce this bug

    1. I have installed domain_entity_type in a fresh drupal
    2. added a new domain (default)
    3. created a user with access to content
    4. logged in with the user that has access to content
    5. Create a new content

    @belazoth , Can you describe the steps to reproduce this bug ?

  • 🇬🇧United Kingdom belazoth

    Hello @akram-zairig, thanks for taking a look. The steps I take to be able to reproduce this issue are the following,

    1. Make a fresh Drupal install, in my case 10.3.10
    2. Install Domain composer require 'drupal/domain:^2.0@beta'
    3. Install Domain Access Entity Type composer require 'drupal/domain_entity_type:^1.0@RC'
    4. Enable the following 3 modules, Domain, Domain Access Entity Type and Domain Content Type Access
    5. Make a new user role that can only add one type of content. I copied the content editor role but only allowed the new role to add/edit/delete articles instead of both articles and basic pages.
    6. Make a new user with the new single content type role
    7. Log into the new user and visit /node/add or click the add content button on the content overview page /admin/content
    8. You should then get the error that I am seeing. If there is no error you should get redirected to /node/add/article
  • Hello,
    I've followed the steps mentioned by @belazoth and I was able to reproduce the issue.

    After that, I applied the patch #3, and the issue was fixed.

Production build 0.71.5 2024