Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Current user is being called from the static service container but could be injected instead as ActionBase implements ContainerFactoryPluginInterface
/**
* {@inheritdoc}
*/
public function executeMultiple(array $entities) {
$this->tempStoreFactory->get('user_user_operations_cancel')->set(\Drupal::currentUser()->id(), $entities);
}
Proposed resolution
Inject the container instead.
Beta phase evaluation
Issue category | Task |
---|---|
Issue priority | Not critical |
Unfrozen changes | Unfrozen because it only injects the current user into the plugin |
Non prioritized changes | The goal of this change is adding the current user service to the ActionBase plugin that is currently using the tempstore of the user, so currentUser would be a fairly common use case |
Disruption | Contributed/custom modules that implement an ActionBase. The change to implement is trivial, non disruptive |
Comment | File | Size | Author |
---|---|---|---|
#1 | 2400159-container_action_base.patch | 4.78 KB | pcambra |
Comments
Comment #1
pcambraComment #3
pcambraComment #4
jibranThanks for the patch and issue.
Comment #5
alexpottThis issue is a minor task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
We need to decide whether injection of dependencies is beta permissible or not - this one is especially interesting since it is a base class so any contrib modules that implement it will break.
Comment #6
dawehnerDon't we want to use the account switcher here as well?
Comment #7
dawehnerhttps://www.drupal.org/node/2377441
Comment #8
pcambraComment #9
pcambraAs discussed with @dawehner on IRC, there's no user switching on this change so no need to use that bit.
Added the beta evaluation table and setting back to RTBC
Comment #10
dawehnerYeah +1
Comment #11
alexpottPlugins should be properly injected with their services where possible. Committed b8b30d3 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.