Issue #2926070 by smustgrave, dimitriskr, andypost, gnuget, zahord, yogeshmpawar, MerryHamster, kim.pepper, alexpott, Mile23, daffie, larowlan: Deprecate ModuleHandlerInterface::getName()
parent
ea9cc7538b
commit
2ab774d6b8
|
@ -717,6 +717,7 @@ class ModuleHandler implements ModuleHandlerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName($module) {
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Extension\ModuleExtensionList::getName($module) instead. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
return \Drupal::service('extension.list.module')->getName($module);
|
||||
}
|
||||
|
||||
|
|
|
@ -406,6 +406,11 @@ interface ModuleHandlerInterface {
|
|||
* @return string
|
||||
* Returns the human readable name of the module or the machine name passed
|
||||
* in if no matching module is found.
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0.
|
||||
* Use \Drupal::service('extension.list.module')->getName($module) instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3310017
|
||||
*/
|
||||
public function getName($module);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Menu\Form;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Menu\MenuLinkInterface;
|
||||
use Drupal\Core\Menu\MenuLinkManagerInterface;
|
||||
|
@ -60,12 +61,18 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
|
|||
* The string translation.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler;
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(MenuLinkManagerInterface $menu_link_manager, MenuParentFormSelectorInterface $menu_parent_selector, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(MenuLinkManagerInterface $menu_link_manager, MenuParentFormSelectorInterface $menu_parent_selector, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
|
||||
$this->menuLinkManager = $menu_link_manager;
|
||||
$this->menuParentSelector = $menu_parent_selector;
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($this->moduleExtensionList === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$this->moduleExtensionList = \Drupal::service('extension.list.module');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +83,8 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
|
|||
$container->get('plugin.manager.menu.link'),
|
||||
$container->get('menu.parent_form_selector'),
|
||||
$container->get('string_translation'),
|
||||
$container->get('module_handler')
|
||||
$container->get('module_handler'),
|
||||
$container->get('extension.list.module')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -96,7 +104,7 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
|
|||
$provider = $this->menuLink->getProvider();
|
||||
$form['info'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', ['@name' => $this->moduleHandler->getName($provider)]),
|
||||
'#title' => $this->t('This link is provided by the @name module. The title and path cannot be edited.', ['@name' => $this->moduleExtensionList->getName($provider)]),
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'value',
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Core\Plugin;
|
||||
|
||||
use Drupal\Core\Extension\Exception\UnknownExtensionException;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
|
@ -46,13 +48,13 @@ trait CategorizingPluginManagerTrait {
|
|||
* machine-readable name passed.
|
||||
*/
|
||||
protected function getProviderName($provider) {
|
||||
$list = $this->getModuleHandler()->getModuleList();
|
||||
// If the module exists, return its human-readable name.
|
||||
if (isset($list[$provider])) {
|
||||
return $this->getModuleHandler()->getName($provider);
|
||||
try {
|
||||
return $this->getModuleExtensionList()->getName($provider);
|
||||
}
|
||||
catch (UnknownExtensionException $e) {
|
||||
// Otherwise, return the machine name.
|
||||
return $provider;
|
||||
}
|
||||
// Otherwise, return the machine name.
|
||||
return $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,8 +62,14 @@ trait CategorizingPluginManagerTrait {
|
|||
*
|
||||
* @return \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
* The module handler.
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no
|
||||
* replacement.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3310017
|
||||
*/
|
||||
public function getModuleHandler() {
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
// If the class has an injected module handler, use it. Otherwise fall back
|
||||
// to fetch it from the service container.
|
||||
if (isset($this->moduleHandler)) {
|
||||
|
@ -70,6 +78,21 @@ trait CategorizingPluginManagerTrait {
|
|||
return \Drupal::moduleHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the module extension list used.
|
||||
*
|
||||
* @return \Drupal\Core\Extension\ModuleExtensionList
|
||||
* The module extension list.
|
||||
*/
|
||||
protected function getModuleExtensionList(): ModuleExtensionList {
|
||||
// If the class has an injected module extension list, use it. Otherwise
|
||||
// fall back to fetch it from the service container.
|
||||
if (isset($this->moduleExtensionList)) {
|
||||
return $this->moduleExtensionList;
|
||||
}
|
||||
return \Drupal::service('extension.list.module');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Component\Assertion\Inspector;
|
|||
use Drupal\Component\Plugin\Attribute\AttributeInterface;
|
||||
use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Cache\UseCacheBackendTrait;
|
||||
|
@ -68,6 +69,13 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
|
|||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The module extension list.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleExtensionList
|
||||
*/
|
||||
protected ?ModuleExtensionList $moduleExtensionList;
|
||||
|
||||
/**
|
||||
* A set of defaults to be referenced by $this->processDefinition().
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
services:
|
||||
breakpoint.manager:
|
||||
class: Drupal\breakpoint\BreakpointManager
|
||||
arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@string_translation']
|
||||
arguments: ['@module_handler', '@theme_handler', '@cache.discovery', '@string_translation', '@extension.list.module']
|
||||
tags:
|
||||
- { name: plugin_manager_cache_clear }
|
||||
Drupal\breakpoint\BreakpointManagerInterface: '@breakpoint.manager'
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\breakpoint;
|
|||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
@ -98,11 +99,18 @@ class BreakpointManager extends DefaultPluginManager implements BreakpointManage
|
|||
* The cache backend.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation service.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $module_extension_list
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation) {
|
||||
public function __construct(ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, CacheBackendInterface $cache_backend, TranslationInterface $string_translation, ?ModuleExtensionList $module_extension_list = NULL) {
|
||||
$this->factory = new ContainerFactory($this);
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->themeHandler = $theme_handler;
|
||||
if ($module_extension_list === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $module_extension_list argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
}
|
||||
$this->moduleExtensionList = $module_extension_list;
|
||||
$this->setStringTranslation($string_translation);
|
||||
$this->alterInfo('breakpoints');
|
||||
$this->setCacheBackend($cache_backend, 'breakpoints', ['breakpoints']);
|
||||
|
@ -244,7 +252,7 @@ class BreakpointManager extends DefaultPluginManager implements BreakpointManage
|
|||
protected function getGroupLabel($group) {
|
||||
// Extension names are not translatable.
|
||||
if ($this->moduleHandler->moduleExists($group)) {
|
||||
$label = $this->moduleHandler->getName($group);
|
||||
$label = $this->moduleExtensionList->getName($group);
|
||||
}
|
||||
elseif ($this->themeHandler->themeExists($group)) {
|
||||
$label = $this->themeHandler->getName($group);
|
||||
|
|
|
@ -107,11 +107,12 @@ function field_help($route_name, RouteMatchInterface $route_match) {
|
|||
}
|
||||
$providers = array_unique($providers);
|
||||
sort($providers);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
foreach ($providers as $provider) {
|
||||
// Skip plugins provided by core components as they do not implement
|
||||
// hook_help().
|
||||
if (isset($modules[$provider])) {
|
||||
$display = \Drupal::moduleHandler()->getName($provider);
|
||||
$display = $module_extension_list->getName($provider);
|
||||
if (\Drupal::moduleHandler()->hasImplementations('help', $provider)) {
|
||||
$items[] = Link::fromTextAndUrl($display, Url::fromRoute('help.page', ['name' => $provider]))->toRenderable();
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ class HelpController extends ControllerBase {
|
|||
public function helpPage($name) {
|
||||
$build = [];
|
||||
if ($this->moduleHandler()->hasImplementations('help', $name)) {
|
||||
$module_name = $this->moduleHandler()->getName($name);
|
||||
$module_name = $this->moduleExtensionList->getName($name);
|
||||
$build['#title'] = $module_name;
|
||||
|
||||
$info = $this->moduleExtensionList->getExtensionInfo($name);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\help\Plugin\HelpSection;
|
||||
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\Link;
|
||||
|
@ -37,10 +38,16 @@ class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryP
|
|||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler service.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($this->moduleExtensionList === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$this->moduleExtensionList = \Drupal::service('extension.list.module');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +58,8 @@ class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryP
|
|||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('module_handler')
|
||||
$container->get('module_handler'),
|
||||
$container->get('extension.list.module'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,7 +71,7 @@ class HookHelpSection extends HelpSectionPluginBase implements ContainerFactoryP
|
|||
$this->moduleHandler->invokeAllWith(
|
||||
'help',
|
||||
function (callable $hook, string $module) use (&$topics) {
|
||||
$title = $this->moduleHandler->getName($module);
|
||||
$title = $this->moduleExtensionList->getName($module);
|
||||
$topics[$title] = Link::createFromRoute($title, 'help.page', ['name' => $module]);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -97,8 +97,9 @@ class HelpTest extends BrowserTestBase {
|
|||
|
||||
// Ensure a module which does not provide a module overview page is handled
|
||||
// correctly.
|
||||
$this->clickLink(\Drupal::moduleHandler()->getName('help_test'));
|
||||
$this->assertSession()->pageTextContains('No help is available for module ' . \Drupal::moduleHandler()->getName('help_test'));
|
||||
$module_name = \Drupal::service('extension.list.module')->getName('help_test');
|
||||
$this->clickLink($module_name);
|
||||
$this->assertSession()->pageTextContains('No help is available for module ' . $module_name);
|
||||
|
||||
// Verify that the order of topics is alphabetical by displayed module
|
||||
// name, by checking the order of some modules, including some that would
|
||||
|
|
|
@ -52,7 +52,7 @@ class NoHelpTest extends BrowserTestBase {
|
|||
$this->assertFalse(\Drupal::moduleHandler()->hasImplementations('help', 'menu_test'), 'The menu_test module does not implement hook_help');
|
||||
// Make sure the test module menu_test does not display a help link on
|
||||
// admin/help.
|
||||
$this->assertSession()->pageTextNotContains(\Drupal::moduleHandler()->getName('menu_test'));
|
||||
$this->assertSession()->pageTextNotContains(\Drupal::service('extension.list.module')->getName('menu_test'));
|
||||
|
||||
// Ensure that the module overview help page for a module that does not
|
||||
// implement hook_help() results in a 404.
|
||||
|
|
|
@ -418,6 +418,7 @@ function language_entity_field_access($operation, FieldDefinitionInterface $fiel
|
|||
* Implements hook_tour_tips_alter().
|
||||
*/
|
||||
function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
foreach ($tour_tips as $tour_tip) {
|
||||
if ($tour_tip->get('id') == 'language-overview') {
|
||||
$additional_overview = '';
|
||||
|
@ -433,10 +434,10 @@ function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
|
|||
$additional_continue = '';
|
||||
$additional_modules = [];
|
||||
if (!Drupal::service('module_handler')->moduleExists('locale')) {
|
||||
$additional_modules[] = Drupal::service('module_handler')->getName('locale');
|
||||
$additional_modules[] = $module_extension_list->getName('locale');
|
||||
}
|
||||
if (!Drupal::service('module_handler')->moduleExists('content_translation')) {
|
||||
$additional_modules[] = Drupal::service('module_handler')->getName('content_translation');
|
||||
$additional_modules[] = $module_extension_list->getName('content_translation');
|
||||
}
|
||||
if (!empty($additional_modules)) {
|
||||
$additional_continue = t('Depending on your site features, additional modules that you might want to install are:') . '<ul>';
|
||||
|
|
|
@ -5,7 +5,9 @@ namespace Drupal\migrate_drupal_ui\Form;
|
|||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Batch\BatchBuilder;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
|
||||
use Drupal\Core\Extension\Exception\UnknownExtensionException;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
|
@ -33,6 +35,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* @internal
|
||||
*/
|
||||
class ReviewForm extends MigrateUpgradeFormBase {
|
||||
use DeprecatedServicePropertyTrait;
|
||||
|
||||
/**
|
||||
* The service properties that should raise a deprecation error.
|
||||
*/
|
||||
private array $deprecatedProperties = ['moduleHandler' => 'module_handler'];
|
||||
|
||||
/**
|
||||
* The migrations.
|
||||
|
@ -49,11 +57,9 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
protected $migrationState;
|
||||
|
||||
/**
|
||||
* Module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
* Module extension list.
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
protected ModuleExtensionList $moduleExtensionList;
|
||||
|
||||
/**
|
||||
* Source system data set in buildForm().
|
||||
|
@ -75,8 +81,8 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
* Migration state service.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory service.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler service.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|\Drupal\Core\Extension\ModuleHandlerInterface $module_extension_list
|
||||
* The module extension list.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
|
@ -86,16 +92,20 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
PrivateTempStoreFactory $tempstore_private,
|
||||
MigrationState $migrationState,
|
||||
ConfigFactoryInterface $config_factory,
|
||||
ModuleHandlerInterface $module_handler,
|
||||
ModuleExtensionList|ModuleHandlerInterface $module_extension_list,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
parent::__construct($config_factory, $migration_plugin_manager, $state, $tempstore_private);
|
||||
$this->migrationState = $migrationState;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($this->time === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . ' without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3112298', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service('datetime.time');
|
||||
}
|
||||
if ($module_extension_list instanceof ModuleHandlerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with the $module_extension_list argument as ModuleHandlerInterface is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
}
|
||||
$this->moduleExtensionList = $module_extension_list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +118,7 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
$container->get('tempstore.private'),
|
||||
$container->get('migrate_drupal.migration_state'),
|
||||
$container->get('config.factory'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('extension.list.module'),
|
||||
$container->get('datetime.time'),
|
||||
);
|
||||
}
|
||||
|
@ -311,7 +321,7 @@ class ReviewForm extends MigrateUpgradeFormBase {
|
|||
}
|
||||
else {
|
||||
try {
|
||||
$destination_module_names[] = $this->moduleHandler->getName($destination_module);
|
||||
$destination_module_names[] = $this->moduleExtensionList->getName($destination_module);
|
||||
}
|
||||
catch (UnknownExtensionException $e) {
|
||||
$destination_module_names[] = $destination_module;
|
||||
|
|
|
@ -7,6 +7,7 @@ use Drupal\Core\Access\AccessResultInterface;
|
|||
use Drupal\Core\Config\ConfigManagerInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
@ -58,9 +59,15 @@ class EntityPermissionsForm extends UserPermissionsForm {
|
|||
* The configuration entity manager.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager service.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $module_extension_list
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(PermissionHandlerInterface $permission_handler, RoleStorageInterface $role_storage, ModuleHandlerInterface $module_handler, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($permission_handler, $role_storage, $module_handler);
|
||||
public function __construct(PermissionHandlerInterface $permission_handler, RoleStorageInterface $role_storage, ModuleHandlerInterface $module_handler, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager, ?ModuleExtensionList $module_extension_list = NULL) {
|
||||
if ($module_extension_list === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $module_extension_list argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
}
|
||||
parent::__construct($permission_handler, $role_storage, $module_handler, $module_extension_list);
|
||||
$this->configManager = $config_manager;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
@ -74,7 +81,8 @@ class EntityPermissionsForm extends UserPermissionsForm {
|
|||
$container->get('entity_type.manager')->getStorage('user_role'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('config.manager'),
|
||||
$container->get('entity_type.manager')
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('extension.list.module'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\user\Form;
|
||||
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
@ -46,11 +47,17 @@ class UserPermissionsForm extends FormBase {
|
|||
* The role storage.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(PermissionHandlerInterface $permission_handler, RoleStorageInterface $role_storage, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(PermissionHandlerInterface $permission_handler, RoleStorageInterface $role_storage, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
|
||||
$this->permissionHandler = $permission_handler;
|
||||
$this->roleStorage = $role_storage;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($this->moduleExtensionList === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$this->moduleExtensionList = \Drupal::service('extension.list.module');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +67,8 @@ class UserPermissionsForm extends FormBase {
|
|||
return new static(
|
||||
$container->get('user.permissions'),
|
||||
$container->get('entity_type.manager')->getStorage('user_role'),
|
||||
$container->get('module_handler')
|
||||
$container->get('module_handler'),
|
||||
$container->get('extension.list.module'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -186,7 +194,7 @@ class UserPermissionsForm extends FormBase {
|
|||
'class' => ['module'],
|
||||
'id' => 'module-' . $provider,
|
||||
],
|
||||
'#markup' => $this->moduleHandler->getName($provider),
|
||||
'#markup' => $this->moduleExtensionList->getName($provider),
|
||||
],
|
||||
];
|
||||
foreach ($permissions as $perm => $perm_item) {
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\user;
|
|||
|
||||
use Drupal\Core\Discovery\YamlDiscovery;
|
||||
use Drupal\Core\Controller\ControllerResolverInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
|
@ -84,8 +85,10 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
* The string translation.
|
||||
* @param \Drupal\Core\Utility\CallableResolver|\Drupal\Core\Controller\ControllerResolverInterface $callable_resolver
|
||||
* The callable resolver.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|null $moduleExtensionList
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, ControllerResolverInterface|CallableResolver $callable_resolver) {
|
||||
public function __construct(ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, ControllerResolverInterface|CallableResolver $callable_resolver, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
|
||||
if ($callable_resolver instanceof ControllerResolverInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with an argument of ControllerResolverInterface is deprecated in drupal:10.2.0 and is removed in drupal:11.0.0. Use \Drupal\Core\Utility\CallableResolver instead. See https://www.drupal.org/node/3397954', E_USER_DEPRECATED);
|
||||
$callable_resolver = \Drupal::service('callable_resolver');
|
||||
|
@ -96,6 +99,10 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
// container.
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->stringTranslation = $string_translation;
|
||||
if ($this->moduleExtensionList === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$this->moduleExtensionList = \Drupal::service('extension.list.module');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +240,7 @@ class PermissionHandler implements PermissionHandlerInterface {
|
|||
protected function getModuleNames() {
|
||||
$modules = [];
|
||||
foreach (array_keys($this->moduleHandler->getModuleList()) as $module) {
|
||||
$modules[$module] = $this->moduleHandler->getName($module);
|
||||
$modules[$module] = $this->moduleExtensionList->getName($module);
|
||||
}
|
||||
asort($modules);
|
||||
return $modules;
|
||||
|
|
|
@ -4,6 +4,8 @@ namespace Drupal\user\Plugin\views\access;
|
|||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
@ -24,6 +26,12 @@ use Symfony\Component\Routing\Route;
|
|||
* )
|
||||
*/
|
||||
class Permission extends AccessPluginBase implements CacheableDependencyInterface {
|
||||
use DeprecatedServicePropertyTrait;
|
||||
|
||||
/**
|
||||
* The service properties that should raise a deprecation error.
|
||||
*/
|
||||
private array $deprecatedProperties = ['moduleHandler' => 'module_handler'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -38,11 +46,9 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
protected $permissionHandler;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
* Module extension list.
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
protected ModuleExtensionList $moduleExtensionList;
|
||||
|
||||
/**
|
||||
* Constructs a Permission object.
|
||||
|
@ -55,13 +61,17 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
* The plugin implementation definition.
|
||||
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
|
||||
* The permission handler.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|\Drupal\Core\Extension\ModuleHandlerInterface $module_extension_list
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleExtensionList|ModuleHandlerInterface $module_extension_list) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->permissionHandler = $permission_handler;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($module_extension_list instanceof ModuleHandlerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with the $module_extension_list argument as ModuleHandlerInterface is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
}
|
||||
$this->moduleExtensionList = $module_extension_list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +83,7 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('user.permissions'),
|
||||
$container->get('module_handler')
|
||||
$container->get('extension.list.module'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -114,7 +124,7 @@ class Permission extends AccessPluginBase implements CacheableDependencyInterfac
|
|||
$permissions = $this->permissionHandler->getPermissions();
|
||||
foreach ($permissions as $perm => $perm_item) {
|
||||
$provider = $perm_item['provider'];
|
||||
$display_name = $this->moduleHandler->getName($provider);
|
||||
$display_name = $this->moduleExtensionList->getName($provider);
|
||||
$perms[$display_name][$perm] = strip_tags($perm_item['title']);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\user\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\views\field\FieldPluginBase;
|
||||
|
@ -38,17 +39,28 @@ class UserData extends FieldPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static($configuration, $plugin_id, $plugin_definition, $container->get('user.data'), $container->get('module_handler'));
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('user.data'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('extension.list.module')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a UserData object.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, UserDataInterface $user_data, ModuleHandlerInterface $module_handler, protected ?ModuleExtensionList $moduleExtensionList = NULL) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->userData = $user_data;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($this->moduleExtensionList === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $moduleExtensionList argument is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$this->moduleExtensionList = \Drupal::service('extension.list.module');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +84,7 @@ class UserData extends FieldPluginBase {
|
|||
$modules = $this->moduleHandler->getModuleList();
|
||||
$names = [];
|
||||
foreach (array_keys($modules) as $name) {
|
||||
$names[$name] = $this->moduleHandler->getName($name);
|
||||
$names[$name] = $this->moduleExtensionList->getName($name);
|
||||
}
|
||||
|
||||
$form['data_module'] = [
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Drupal\user\Plugin\views\filter;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\PermissionHandlerInterface;
|
||||
|
@ -18,6 +20,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
* @ViewsFilter("user_permissions")
|
||||
*/
|
||||
class Permissions extends ManyToOne {
|
||||
use DeprecatedServicePropertyTrait;
|
||||
|
||||
/**
|
||||
* The service properties that should raise a deprecation error.
|
||||
*/
|
||||
private array $deprecatedProperties = ['moduleHandler' => 'module_handler'];
|
||||
|
||||
/**
|
||||
* The permission handler.
|
||||
|
@ -27,11 +35,9 @@ class Permissions extends ManyToOne {
|
|||
protected $permissionHandler;
|
||||
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
* Module extension list.
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
protected ModuleExtensionList $moduleExtensionList;
|
||||
|
||||
/**
|
||||
* Constructs a Permissions object.
|
||||
|
@ -44,14 +50,18 @@ class Permissions extends ManyToOne {
|
|||
* The plugin implementation definition.
|
||||
* @param \Drupal\user\PermissionHandlerInterface $permission_handler
|
||||
* The permission handler.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList|\Drupal\Core\Extension\ModuleHandlerInterface $module_extension_list
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler, ModuleExtensionList|ModuleHandlerInterface $module_extension_list) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->permissionHandler = $permission_handler;
|
||||
$this->moduleHandler = $module_handler;
|
||||
if ($module_extension_list instanceof ModuleHandlerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with the $module_extension_list argument as ModuleHandlerInterface is deprecated in drupal:10.3.0 and will be required in drupal:12.0.0. See https://www.drupal.org/node/3310017', E_USER_DEPRECATED);
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
}
|
||||
$this->moduleExtensionList = $module_extension_list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +73,7 @@ class Permissions extends ManyToOne {
|
|||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('user.permissions'),
|
||||
$container->get('module_handler')
|
||||
$container->get('extension.list.module'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,7 +82,7 @@ class Permissions extends ManyToOne {
|
|||
$permissions = $this->permissionHandler->getPermissions();
|
||||
foreach ($permissions as $perm => $perm_item) {
|
||||
$provider = $perm_item['provider'];
|
||||
$display_name = $this->moduleHandler->getName($provider);
|
||||
$display_name = $this->moduleExtensionList->getName($provider);
|
||||
$this->valueOptions[$display_name][$perm] = Html::escape(strip_tags($perm_item['title']));
|
||||
}
|
||||
return $this->valueOptions;
|
||||
|
|
|
@ -10,6 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityDependency;
|
|||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
@ -57,6 +58,7 @@ class EntityPermissionsFormTest extends UnitTestCase {
|
|||
$permission_handler = $prophecy->reveal();
|
||||
$role_storage = $this->prophesize(RoleStorageInterface::class)->reveal();
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class)->reveal();
|
||||
$module_extension_list = $this->prophesize(ModuleExtensionList::class)->reveal();
|
||||
$prophecy = $this->prophesize(ConfigManagerInterface::class);
|
||||
$prophecy->getConfigEntitiesToChangeOnDependencyRemoval('config', ['node.type.article'])
|
||||
->willReturn([
|
||||
|
@ -75,7 +77,7 @@ class EntityPermissionsFormTest extends UnitTestCase {
|
|||
->willReturn($entity_type);
|
||||
$entity_type_manager = $prophecy->reveal();
|
||||
|
||||
$bundle_form = new EntityPermissionsForm($permission_handler, $role_storage, $module_handler, $config_manager, $entity_type_manager);
|
||||
$bundle_form = new EntityPermissionsForm($permission_handler, $role_storage, $module_handler, $config_manager, $entity_type_manager, $module_extension_list);
|
||||
|
||||
// Mock the method parameters.
|
||||
$route = new Route('some.path');
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Drupal\Tests\user\Unit;
|
||||
|
||||
use Drupal\Core\Extension\Extension;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
|
@ -20,6 +21,7 @@ use org\bovigo\vfs\vfsStreamWrapper;
|
|||
* @group user
|
||||
*
|
||||
* @coversDefaultClass \Drupal\user\PermissionHandler
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class PermissionHandlerTest extends UnitTestCase {
|
||||
|
||||
|
@ -130,7 +132,9 @@ EOF
|
|||
$this->callableResolver->expects($this->never())
|
||||
->method('getCallableFromDefinition');
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver);
|
||||
$module_extension_list = $this->createMock(ModuleExtensionList::class);
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);
|
||||
|
||||
$actual_permissions = $this->permissionHandler->getPermissions();
|
||||
$this->assertPermissions($actual_permissions);
|
||||
|
@ -162,7 +166,8 @@ EOF
|
|||
'module_b' => vfsStream::url('modules/module_b'),
|
||||
'module_c' => vfsStream::url('modules/module_c'),
|
||||
]);
|
||||
$this->moduleHandler->expects($this->exactly(3))
|
||||
$module_extension_list = $this->createMock(ModuleExtensionList::class);
|
||||
$module_extension_list->expects($this->exactly(3))
|
||||
->method('getName')
|
||||
->willReturnMap([
|
||||
['module_a', 'Module a'],
|
||||
|
@ -191,7 +196,7 @@ EOF
|
|||
->method('getModuleList')
|
||||
->willReturn(array_flip($modules));
|
||||
|
||||
$permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver);
|
||||
$permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);
|
||||
$actual_permissions = $permissionHandler->getPermissions();
|
||||
$this->assertEquals(['access_module_a4', 'access_module_a1', 'access_module_a2', 'access_module_a3'],
|
||||
array_keys($actual_permissions));
|
||||
|
@ -254,7 +259,9 @@ EOF
|
|||
['Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescriptionRestrictAccess', [new TestPermissionCallbacks(), 'titleDescriptionRestrictAccess']],
|
||||
]);
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver);
|
||||
$module_extension_list = $this->createMock(ModuleExtensionList::class);
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);
|
||||
|
||||
$actual_permissions = $this->permissionHandler->getPermissions();
|
||||
$this->assertPermissions($actual_permissions);
|
||||
|
@ -297,7 +304,9 @@ EOF
|
|||
->with('Drupal\\user\\Tests\\TestPermissionCallbacks::titleDescription')
|
||||
->willReturn([new TestPermissionCallbacks(), 'titleDescription']);
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver);
|
||||
$module_extension_list = $this->createMock(ModuleExtensionList::class);
|
||||
|
||||
$this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->callableResolver, $module_extension_list);
|
||||
|
||||
$actual_permissions = $this->permissionHandler->getPermissions();
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ services:
|
|||
Drupal\user\UserAuthInterface: '@user.auth'
|
||||
user.permissions:
|
||||
class: Drupal\user\PermissionHandler
|
||||
arguments: ['@module_handler', '@string_translation', '@callable_resolver']
|
||||
arguments: ['@module_handler', '@string_translation', '@callable_resolver', '@extension.list.module']
|
||||
Drupal\user\PermissionHandlerInterface: '@user.permissions'
|
||||
user.current_user_context:
|
||||
class: Drupal\user\ContextProvider\CurrentUserContext
|
||||
|
|
|
@ -134,6 +134,7 @@ class InstallerTest extends InstallerTestBase {
|
|||
$database = Database::getConnection();
|
||||
$module = $database->getProvider();
|
||||
$module_handler = \Drupal::service('module_handler');
|
||||
$module_extension_list = \Drupal::service('extension.list.module');
|
||||
|
||||
// Ensure the update module is not installed.
|
||||
$this->assertFalse($module_handler->moduleExists('update'), 'The Update module is not installed.');
|
||||
|
@ -148,7 +149,7 @@ class InstallerTest extends InstallerTestBase {
|
|||
$this->fail("Uninstalled $module module.");
|
||||
}
|
||||
catch (ModuleUninstallValidatorException $e) {
|
||||
$module_name = $module_handler->getName($module);
|
||||
$module_name = $module_extension_list->getName($module);
|
||||
$driver = $database->driver();
|
||||
$this->assertStringContainsString("The module '$module_name' is providing the database driver '$driver'.", $e->getMessage());
|
||||
}
|
||||
|
|
|
@ -21,7 +21,17 @@ class ModuleHandlerTest extends KernelTestBase {
|
|||
$this->expectException(UnknownExtensionException::class);
|
||||
$this->expectExceptionMessage('The module module_nonsense does not exist.');
|
||||
$module_handler = $this->container->get('module_handler');
|
||||
$module_handler->getName('module_nonsense');
|
||||
$module_handler->getModule('module_nonsense');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deprecation of getName() function.
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetNameDeprecation() {
|
||||
$this->expectDeprecation('Drupal\Core\Extension\ModuleHandler::getName() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Extension\ModuleExtensionList::getName($module) instead. See https://www.drupal.org/node/3310017');
|
||||
$this->assertNotNull(\Drupal::service('module_handler')->getName('module_test'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Drupal\Tests\Core\Menu;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Menu\Form\MenuLinkDefaultForm;
|
||||
use Drupal\Core\Menu\MenuLinkDefault;
|
||||
|
@ -16,6 +17,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Menu\Form\MenuLinkDefaultForm
|
||||
* @group Menu
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class MenuLinkDefaultFormTest extends UnitTestCase {
|
||||
|
||||
|
@ -26,7 +28,8 @@ class MenuLinkDefaultFormTest extends UnitTestCase {
|
|||
$menu_link_manager = $this->prophesize(MenuLinkManagerInterface::class);
|
||||
$menu_parent_form_selector = $this->prophesize(MenuParentFormSelectorInterface::class);
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$menu_link_form = new MenuLinkDefaultForm($menu_link_manager->reveal(), $menu_parent_form_selector->reveal(), $this->getStringTranslationStub(), $module_handler->reveal());
|
||||
$module_extension_list = $this->prophesize(ModuleExtensionList::class);
|
||||
$menu_link_form = new MenuLinkDefaultForm($menu_link_manager->reveal(), $menu_parent_form_selector->reveal(), $this->getStringTranslationStub(), $module_handler->reveal(), $module_extension_list->reveal());
|
||||
|
||||
$static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
|
||||
$menu_link = new MenuLinkDefault([], 'my_plugin_id', [], $static_override->reveal());
|
||||
|
|
|
@ -5,6 +5,8 @@ declare(strict_types=1);
|
|||
namespace Drupal\Tests\Core\Plugin;
|
||||
|
||||
use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
|
||||
use Drupal\Core\Extension\Exception\UnknownExtensionException;
|
||||
use Drupal\Core\Extension\ModuleExtensionList;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
@ -13,6 +15,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
/**
|
||||
* @coversDefaultClass \Drupal\Core\Plugin\CategorizingPluginManagerTrait
|
||||
* @group Plugin
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
||||
|
||||
|
@ -33,12 +36,16 @@ class CategorizingPluginManagerTraitTest extends UnitTestCase {
|
|||
$module_handler->expects($this->any())
|
||||
->method('getModuleList')
|
||||
->willReturn(['node' => []]);
|
||||
$module_handler->expects($this->any())
|
||||
$module_extension_list = $this->createMock(ModuleExtensionList::class);
|
||||
$module_extension_list->expects($this->any())
|
||||
->method('getName')
|
||||
->with('node')
|
||||
->willReturn('Node');
|
||||
|
||||
$this->pluginManager = new CategorizingPluginManager($module_handler);
|
||||
->willReturnCallback(function ($argument) {
|
||||
if ($argument == 'node') {
|
||||
return 'Node';
|
||||
}
|
||||
throw new UnknownExtensionException();
|
||||
});
|
||||
$this->pluginManager = new CategorizingPluginManager($module_handler, $module_extension_list);
|
||||
$this->pluginManager->setStringTranslation($this->getStringTranslationStub());
|
||||
}
|
||||
|
||||
|
@ -112,11 +119,14 @@ class CategorizingPluginManager extends DefaultPluginManager implements Categori
|
|||
/**
|
||||
* Replace the constructor so we can instantiate a stub.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject $module_handler
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
|
||||
* The module extension list.
|
||||
*/
|
||||
public function __construct(ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(ModuleHandlerInterface $module_handler, ModuleExtensionList $module_extension_list) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->moduleExtensionList = $module_extension_list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue