Problem/Motivation

I'd like to upgrade my site but Entity Limit does not support D11.

Upgrade Status module scan reports 2 issues, both usages of user_roles().

Call to deprecated function user_roles(). Deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\user\Entity\Role::loadMultiple() and, if necessary, an inline implementation instead.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

karuonu created an issue. See original summary.

orkutmuratyilmaz’s picture

orkutmuratyilmaz’s picture

Status: Active » Needs review

Can someone test and review this?

pearls’s picture

Status: Needs review » Needs work

Tested. Unable to add role limits.

The website encountered an unexpected error. Try again later.

Error: Call to a member function getStorage() on null in Drupal\entity_limit\Plugin\EntityLimit\RoleLimit->buildConfigurationForm() (line 77 of modules/contrib/entity_limit/src/Plugin/EntityLimit/RoleLimit.php).

Details

Drupal\entity_limit\Form\EntityLimitAddLimitForm->form() (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm()
call_user_func_array() (Line: 528)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 279)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 57)
Drupal\advban\AdvbanMiddleware->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 263)
Drupal\shield\ShieldMiddleware->bypass() (Line: 219)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19
jdvc’s picture

Here is a new patch with updates and dependency injection updates. Resolved error for me.

jdvc’s picture

jdvc’s picture

StatusFileSize
new7.44 KB

Patch with actual diff..

orkutmuratyilmaz’s picture

Status: Needs work » Needs review

@pearls, can you review the @jdvc's MR too?

orkutmuratyilmaz’s picture

Sorry, I forgot saying that, I've applied the MR as a patch and scanned entity limit with upgrade status module:

No problems found

pearls’s picture

Status: Needs review » Needs work

#8 patch is ok. But now the other patches can not be applied with this patch(#8).

3432063-Drupal calls should be avoided in classes, use dependency injection instead

3347700-checkAccess() throws an exception Invalid specifier 'type' with non node entities

Maybe, there must be a holistic solution.

orkutmuratyilmaz’s picture

@pearls, I do agree with you. Should I contact one of the maintainers?

jdvc’s picture

Yeah I tried messaging one of them, haven't heard anything, can't we just close the other two issues to merge this one in?

pearls’s picture

The problems mentioned above(#12) are important and the patches created for them work without any problems. But unfortunately they were not merged. Maybe a new version should be created for d11.
I think entity_limit is an important module for Drupal environment, but unfortunately it did not get the value it deserved. If mainteinars has stopped supporting this module, maybe it would be good to replace it with those who do.

marvs5’s picture

What do we need to do to get changes for D11 across the finish line? This module is the only thing preventing me from being able to move 2 D10 sites to D11.

orkutmuratyilmaz’s picture

Version: 3.0.0-beta1 » 3.0.x-dev

thanks to @gaurav.goyal, I can create new releases and merge the requests too.

now, this issue is fixed in new 3.0.x-dev release.

if this one is refactored for the same release, we can go back to d11 compatibility issue as well.

@jdvc, @pearls, @marvs5 can you check the latest release?

ighosh’s picture

I can test the MR-4. And comment my findings/observations.

orkutmuratyilmaz’s picture

@ighosh thank you:)

can you also read all the comments and consider the other issues, mentioned on #17?

jmaties made their first commit to this issue’s fork.

jmaties changed the visibility of the branch entity_limit-3510678-3.0.x to hidden.

orkutmuratyilmaz’s picture

Status: Needs work » Patch (to be ported)

@jmaties, thanks for your patching and MR.

I've just tested it and it works so nice with D11. If nobody says something against it, I'll merge it in a week.

aquiniou’s picture

Thanks @jmaties for the patch!

@orkut murat yılmaz any news on the merge? Would love to get a D11 version release here :)

orkutmuratyilmaz’s picture

Status: Patch (to be ported) » Fixed

Merge is done and 3.0.0-beta2 is released too.

Thanks to everyone:)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

arx-e’s picture

Something has gone wrong with this merge and one can not create new limits in Drupal 11.4.
I see MR !5 has produced a merge error.

orkutmuratyilmaz’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

@arx-e, can you give more details about the "one can not create new limits in Drupal 11.4" part please?

arx-e’s picture

yes, of course: after installing the module in Drupal 11.4 I tried to create a new limit, I selected the values and when trying to save I got the following error:

Referrer
/en/admin/structure/entity_limit/add
Message
Error: Call to a member function getStorage() on null in Drupal\entity_limit\Plugin\EntityLimit\RoleLimit->buildConfigurationForm() (line 77 of .../drupalsite/web/modules/contrib/entity_limit/src/Plugin/EntityLimit/RoleLimit.php).

I used claude to solve this and I got the following reply that indeed solved the issue:

The crash is because `$this->entityTypeManager` is **null** in this plugin. This `RoleLimit` plugin overrides `__construct()` and `create()` but only injects `current_user` — it never injects/sets the `entity_type_manager` service that the parent base class expects. So at line 77 `$this->entityTypeManager->getStorage(...)` fails.
The fix is to inject `entity_type_manager` and assign it. Here's the corrected top portion of the class:

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountProxy;
use Drupal\entity_limit\Entity\EntityLimit;
use Drupal\entity_limit\EntityLimitInspector;
use Drupal\entity_limit\Plugin\EntityLimitPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
  /**
   * The user account.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $account;

  /**
   * RoleLimit constructor.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxy $account, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->account = $account;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('current_user'),
      $container->get('entity_type.manager')
    );
  }

I am not 100% sure but I think most of these changes are contained in !MR5 that shows an error.

orkutmuratyilmaz’s picture

Assigned: Unassigned » orkutmuratyilmaz
Status: Postponed (maintainer needs more info) » Needs work

Let me work on it.

orkutmuratyilmaz’s picture

Status: Needs work » Needs review

@arx-e, can you check it now?

arx-e’s picture

Yes, it works fine for me. I can add limits and the users are prevented from creating more nodes than the set limit.
Thank you!

arx-e’s picture

Status: Needs review » Reviewed & tested by the community
orkutmuratyilmaz’s picture

Status: Reviewed & tested by the community » Fixed

@arx-e, ευχαριστώ πολύ :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

arx-e’s picture

@orkutmuratyilmaz teşekkür eden benim!

Status: Fixed » Closed (fixed)

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