Skip to content
Snippets Groups Projects
Commit deb75a36 authored by Ruby P's avatar Ruby P
Browse files

git commit -m 'Issue #3518735 by jborgesr, ruby232: Update the codebase to...

git commit -m 'Issue #3518735 by jborgesr, ruby232: Update the codebase to align with new features in Drupal 11 and PHP 8'
parent a5b297bd
No related branches found
No related tags found
No related merge requests found
name: 'DevUtils'
type: module
description: 'Develop utils'
core_version_requirement: '^8.9 || ^9 || ^10 || ^11'
core_version_requirement: '^11'
package: 'DP'
<?php
/**
* @file
* Contains devutils.module.
*/
/**
* Implements hook_help().
*/
function devutils_help($route_name) {
switch ($route_name) {
// Main module help for the devutils module.
case 'help.page.devutils':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Develop utils') . '</p>';
return $output;
default:
}
}
services:
devutils.update_import:
class: \Drupal\devutils\ConfigImport
arguments:
- '@config.manager'
- '@config.storage'
- '@cache.config'
- '@module_handler'
- '@event_dispatcher'
- '@lock'
- '@config.typed'
- '@module_installer'
- '@theme_handler'
- '@string_translation'
- '@extension.list.module'
- '@logger.factory'
class: Drupal\devutils\ConfigImport
autowire: true
......@@ -7,39 +7,27 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\file\FileUsage\DatabaseFileUsageBackend;
use Drush\Commands\AutowireTrait;
use Drush\Commands\DrushCommands;
/**
* Drush commandfile for devutils module.
*/
class DevutilsCommands extends DrushCommands {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* Service database file usage backend.
*
* @var \Drupal\file\FileUsage\DatabaseFileUsageBackend
*/
protected DatabaseFileUsageBackend $fileUsage;
use AutowireTrait;
/**
* DrushDevutilsCommands constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\file\FileUsage\DatabaseFileUsageBackend $file_usage
* @param \Drupal\file\FileUsage\DatabaseFileUsageBackend $fileUsage
* Service database file usage backend.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, DatabaseFileUsageBackend $file_usage) {
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager,
protected DatabaseFileUsageBackend $fileUsage) {
parent::__construct();
$this->entityTypeManager = $entity_type_manager;
$this->fileUsage = $file_usage;
}
/**
......@@ -72,7 +60,6 @@ class DevutilsCommands extends DrushCommands {
case 'menu_link':
$menu_content_storage = $this->entityTypeManager
->getStorage('menu_link_content');
/** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $menu_link_contents */
if ($filter == 'all') {
$entities = $menu_content_storage->loadByProperties();
break;
......@@ -119,7 +106,7 @@ class DevutilsCommands extends DrushCommands {
break;
case 'file':
/** @var \Drupal\file\FileInterface[] $files */
/** @var \Drupal\file\FileInterface[] $entities */
$entities = $this->entityTypeManager
->getStorage('file')
->loadMultiple();
......@@ -167,7 +154,6 @@ class DevutilsCommands extends DrushCommands {
* @aliases devutils clear-files
*/
public function clearFiles() {
/** @var \Drupal\file\FileInterface[] $files */
$files = [];
try {
$files = $this->entityTypeManager
......@@ -176,7 +162,7 @@ class DevutilsCommands extends DrushCommands {
}
catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
$this->output()
->writeln('Error uploading files: @message', ['@message' => $e->getMessage()]);
->writeln("Error uploading files: {$e->getMessage()}");
}
foreach ($files as $file) {
......@@ -188,10 +174,7 @@ class DevutilsCommands extends DrushCommands {
}
catch (EntityStorageException $e) {
$this->output()
->writeln('Error when deleting file: @name, @message', [
'@name' => $file->label(),
'@message' => $e->getMessage(),
]);
->writeln("Error when deleting file: {$file->label()}, {$e->getMessage()}.");
}
}
}
......
......@@ -7,43 +7,28 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\file\FileUsage\DatabaseFileUsageBackend;
use Drush\Commands\AutowireTrait;
use Drush\Commands\DrushCommands;
/**
* Drush commandfile for devutils module.
*/
class DrushDevutilsCommands extends DrushCommands {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* Service database file usage backend.
*
* @var \Drupal\file\FileUsage\DatabaseFileUsageBackend
*/
protected DatabaseFileUsageBackend $fileUsage;
use AutowireTrait;
/**
* DrushDevutilsCommands constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\file\FileUsage\DatabaseFileUsageBackend $file_usage
* @param \Drupal\file\FileUsage\DatabaseFileUsageBackend $fileUsage
* Service database file usage backend.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
DatabaseFileUsageBackend $file_usage
protected EntityTypeManagerInterface $entityTypeManager,
protected DatabaseFileUsageBackend $fileUsage
) {
parent::__construct();
$this->entityTypeManager = $entity_type_manager;
$this->fileUsage = $file_usage;
}
/**
......@@ -76,7 +61,6 @@ class DrushDevutilsCommands extends DrushCommands {
case 'menu_link':
$menu_content_storage = $this->entityTypeManager
->getStorage('menu_link_content');
/** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $menu_link_contents */
if ($filter == 'all') {
$entities = $menu_content_storage->loadByProperties();
break;
......@@ -123,7 +107,7 @@ class DrushDevutilsCommands extends DrushCommands {
break;
case 'file':
/** @var \Drupal\file\FileInterface[] $files */
/** @var \Drupal\file\FileInterface[] $entities */
$entities = $this->entityTypeManager
->getStorage('file')
->loadMultiple();
......@@ -180,7 +164,7 @@ class DrushDevutilsCommands extends DrushCommands {
}
catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
$this->output()
->writeln('Error uploading files: @message', ['@message' => $e->getMessage()]);
->writeln("Error uploading files: {$e->getMessage()}.");
}
foreach ($files as $file) {
......@@ -192,10 +176,7 @@ class DrushDevutilsCommands extends DrushCommands {
}
catch (EntityStorageException $e) {
$this->output()
->writeln('Error when deleting file: @name, @message', [
'@name' => $file->label(),
'@message' => $e->getMessage(),
]);
->writeln("Error when deleting file: {$file->label()}, {$e->getMessage()}.");
}
}
}
......
......@@ -12,155 +12,85 @@ use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\DependencyInjection\AutowireTrait;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Import configs from yml files.
*/
class ConfigImport {
use LoggerAwareTrait;
/**
* The config manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected ConfigManagerInterface $configManager;
/**
* The config storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected StorageInterface $configStorage;
/**
* The Config Cache.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected CacheBackendInterface $configCache;
/**
* The event dispatcher used to notify subscribers.
*
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
protected EventDispatcherInterface $eventDispatcher;
/**
* The used lock backend instance.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected LockBackendInterface $lock;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected TypedConfigManagerInterface $configTyped;
/**
* The module installer.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected ModuleInstallerInterface $moduleInstaller;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected ThemeHandlerInterface $themeHandler;
/**
* The string translation.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected TranslationInterface $stringTranslation;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected ModuleHandlerInterface $moduleHandler;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList
*/
protected ModuleExtensionList $moduleExtensionList;
use AutowireTrait;
/**
* Constructs an Import object.
*
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* @param \Drupal\Core\Config\ConfigManagerInterface $configManager
* The configuration manager.
* @param \Drupal\Core\Config\StorageInterface $config_storage
* @param \Drupal\Core\Config\StorageInterface $configStorage
* The config storage.
* @param \Drupal\Core\Cache\CacheBackendInterface $config_cache
* @param \Drupal\Core\Cache\CacheBackendInterface $configCache
* The config cache.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
* The event dispatcher used to notify subscribers of config import events.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend to ensure multiple imports do not occur at the same
* time.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $config_typed
* @param \Drupal\Core\Config\TypedConfigManagerInterface $configTyped
* The typed configuration manager.
* @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
* @param \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller
* The module installer.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* @param \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler
* The theme handler.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* @param \Drupal\Core\StringTranslation\TranslationInterface $stringTranslation
* The string translation service.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
* @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
* The module extension list.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
* The logger channel factory.
* @param \Drupal\Core\Extension\ThemeExtensionList $extensionListTheme
* The theme extension list.
*/
public function __construct(
ConfigManagerInterface $config_manager,
StorageInterface $config_storage,
CacheBackendInterface $config_cache,
ModuleHandlerInterface $module_handler,
EventDispatcherInterface $event_dispatcher,
LockBackendInterface $lock,
TypedConfigManagerInterface $config_typed,
ModuleInstallerInterface $module_installer,
ThemeHandlerInterface $theme_handler,
TranslationInterface $string_translation,
ModuleExtensionList $module_extension_list,
LoggerChannelFactoryInterface $logger_factory
#[Autowire(service: 'config.manager')]
protected ConfigManagerInterface $configManager,
#[Autowire(service: 'config.storage')]
protected StorageInterface $configStorage,
#[Autowire(service: 'cache.config')]
protected CacheBackendInterface $configCache,
#[Autowire(service: 'module_handler')]
protected ModuleHandlerInterface $moduleHandler,
#[Autowire(service: 'event_dispatcher')]
protected EventDispatcherInterface $eventDispatcher,
#[Autowire(service: 'lock')]
protected LockBackendInterface $lock,
#[Autowire(service: 'config.typed')]
protected TypedConfigManagerInterface $configTyped,
#[Autowire(service: 'module_installer')]
protected ModuleInstallerInterface $moduleInstaller,
#[Autowire(service: 'theme_handler')]
protected ThemeHandlerInterface $themeHandler,
#[Autowire(service: 'string_translation')]
protected TranslationInterface $stringTranslation,
#[Autowire(service: 'extension.list.module')]
protected ModuleExtensionList $moduleExtensionList,
#[Autowire(service: 'logger.factory')]
protected LoggerChannelFactoryInterface $logger_factory,
protected ThemeExtensionList $extensionListTheme
) {
$this->configManager = $config_manager;
$this->configStorage = $config_storage;
$this->configCache = $config_cache;
$this->moduleHandler = $module_handler;
$this->eventDispatcher = $event_dispatcher;
$this->lock = $lock;
$this->configTyped = $config_typed;
$this->moduleInstaller = $module_installer;
$this->themeHandler = $theme_handler;
$this->stringTranslation = $string_translation;
$this->moduleExtensionList = $module_extension_list;
$this->logger = $logger_factory->get('devutils');
}
......@@ -246,7 +176,8 @@ class ConfigImport {
$this->moduleInstaller,
$this->themeHandler,
$this->stringTranslation,
$this->moduleExtensionList
$this->moduleExtensionList,
$this->extensionListTheme
);
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment