From 1f06ada05a8d64f91af7cf4f22c2c32bb1c9941a Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Mon, 17 Mar 2025 10:49:06 -0400 Subject: [PATCH 01/12] Convert layout_discovery_requirements --- .../layout_discovery/layout_discovery.install | 22 ---------------- .../LayoutDiscoveryRequirements.php | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-) delete mode 100644 core/modules/layout_discovery/layout_discovery.install create mode 100644 core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php diff --git a/core/modules/layout_discovery/layout_discovery.install b/core/modules/layout_discovery/layout_discovery.install deleted file mode 100644 index 28222bc093ba..000000000000 --- a/core/modules/layout_discovery/layout_discovery.install +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * @file - * Install, update, and uninstall functions for the Layout Discovery module. - */ - -/** - * Implements hook_requirements(). - */ -function layout_discovery_requirements($phase): array { - $requirements = []; - if ($phase === 'install') { - if (\Drupal::moduleHandler()->moduleExists('layout_plugin')) { - $requirements['layout_discovery'] = [ - 'description' => t('Layout Discovery cannot be installed because the Layout Plugin module is installed and incompatible.'), - 'severity' => REQUIREMENT_ERROR, - ]; - } - } - return $requirements; -} diff --git a/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php b/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php new file mode 100644 index 000000000000..a972e882a12b --- /dev/null +++ b/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\layout_discovery\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; + +class LayoutDiscoveryRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + if (\Drupal::moduleHandler()->moduleExists('layout_plugin')) { + $requirements['layout_discovery'] = [ + 'description' => t('Layout Discovery cannot be installed because the Layout Plugin module is installed and incompatible.'), + 'severity' => REQUIREMENT_ERROR, + ]; + } + return $requirements; + } + +} -- GitLab From 6db472600d2c7e92b99b64ea78a2bd6e7d97ee04 Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Mon, 17 Mar 2025 11:08:06 -0400 Subject: [PATCH 02/12] convert media_requirements --- .../LayoutDiscoveryRequirements.php | 3 + core/modules/media/media.install | 98 ------------------- .../media/src/Hook/MediaRequirements.php | 98 +++++++++++++++++++ .../Requirements/MediaRequirements.php | 40 ++++++++ 4 files changed, 141 insertions(+), 98 deletions(-) create mode 100644 core/modules/media/src/Hook/MediaRequirements.php create mode 100644 core/modules/media/src/Install/Requirements/MediaRequirements.php diff --git a/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php b/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php index a972e882a12b..d6b8ef7fc24d 100644 --- a/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php +++ b/core/modules/layout_discovery/src/Install/Requirements/LayoutDiscoveryRequirements.php @@ -6,6 +6,9 @@ use Drupal\Core\Extension\InstallRequirementsInterface; +/** + * Install time requirements for the layout_discovery module. + */ class LayoutDiscoveryRequirements implements InstallRequirementsInterface { /** diff --git a/core/modules/media/media.install b/core/modules/media/media.install index f0acbf482da4..417d7f7cb54c 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -9,106 +9,8 @@ use Drupal\Core\File\FileExists; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Hook\Attribute\StopProceduralHookScan; -use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\Url; -use Drupal\image\Plugin\Field\FieldType\ImageItem; -use Drupal\media\Entity\MediaType; use Drupal\user\RoleInterface; -/** - * Implements hook_requirements(). - */ -function media_requirements($phase): array { - $requirements = []; - if ($phase == 'install') { - $destination = 'public://media-icons/generic'; - \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); - $is_writable = is_writable($destination); - $is_directory = is_dir($destination); - if (!$is_writable || !$is_directory) { - if (!$is_directory) { - $error = t('The directory %directory does not exist.', ['%directory' => $destination]); - } - else { - $error = t('The directory %directory is not writable.', ['%directory' => $destination]); - } - $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', [':handbook_url' => 'https://www.drupal.org/server-permissions']); - if (!empty($error)) { - $description = $error . ' ' . $description; - $requirements['media']['description'] = $description; - $requirements['media']['severity'] = REQUIREMENT_ERROR; - } - } - } - elseif ($phase === 'runtime') { - $module_handler = \Drupal::service('module_handler'); - foreach (MediaType::loadMultiple() as $type) { - // Load the default display. - $display = \Drupal::service('entity_display.repository') - ->getViewDisplay('media', $type->id()); - - // Check for missing source field definition. - $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); - if (empty($source_field_definition)) { - $requirements['media_missing_source_field_' . $type->id()] = [ - 'title' => t('Media'), - 'description' => t('The source field definition for the %type media type is missing.', - [ - '%type' => $type->label(), - ] - ), - 'severity' => REQUIREMENT_ERROR, - ]; - continue; - } - - // When a new media type with an image source is created we're - // configuring the default entity view display using the 'large' image - // style. Unfortunately, if a site builder has deleted the 'large' image - // style, we need some other image style to use, but at this point, we - // can't really know the site builder's intentions. So rather than do - // something surprising, we're leaving the embedded media without an - // image style and adding a warning that the site builder might want to - // add an image style. - // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay - if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { - continue; - } - - $component = $display->getComponent($source_field_definition->getName()); - if (empty($component) || $component['type'] !== 'image' || !empty($component['settings']['image_style'])) { - continue; - } - - $action_item = ''; - if ($module_handler->moduleExists('field_ui') && \Drupal::currentUser()->hasPermission('administer media display')) { - $url = Url::fromRoute('entity.entity_view_display.media.default', [ - 'media_type' => $type->id(), - ])->toString(); - $action_item = new TranslatableMarkup('If you would like to change this, <a href=":display">add an image style to the %field_name field</a>.', - [ - '%field_name' => $source_field_definition->label(), - ':display' => $url, - ]); - } - $requirements['media_default_image_style_' . $type->id()] = [ - 'title' => t('Media'), - 'description' => new TranslatableMarkup('The default display for the %type media type is not currently using an image style on the %field_name field. Not using an image style can lead to much larger file downloads. @action_item', - [ - '%field_name' => $source_field_definition->label(), - '@action_item' => $action_item, - '%type' => $type->label(), - ] - ), - 'severity' => REQUIREMENT_WARNING, - ]; - } - - } - - return $requirements; -} - /** * Implements hook_install(). */ diff --git a/core/modules/media/src/Hook/MediaRequirements.php b/core/modules/media/src/Hook/MediaRequirements.php new file mode 100644 index 000000000000..536e46074f85 --- /dev/null +++ b/core/modules/media/src/Hook/MediaRequirements.php @@ -0,0 +1,98 @@ +<?php + +namespace Drupal\media\Hook; + +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\Core\Url; +use Drupal\image\Plugin\Field\FieldType\ImageItem; +use Drupal\media\Entity\MediaType; + +/** + * Hook implementations for media. + */ +class MediaRequirements { + + use StringTranslationTrait; + + public function __construct( + protected readonly AccountInterface $currentUser, + protected readonly ModuleHandlerInterface $moduleHandler, + protected readonly EntityDisplayRepositoryInterface $entityDisplayRepository, + ) {} + + /** + * Implements hook_runtime_requirements(). + */ + #[Hook('runtime_requirements')] + public function runtime(): array { + $requirements = []; + foreach (MediaType::loadMultiple() as $type) { + // Load the default display. + $display = $this->entityDisplayRepository->getViewDisplay('media', $type->id()); + + // Check for missing source field definition. + $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); + if (empty($source_field_definition)) { + $requirements['media_missing_source_field_' . $type->id()] = [ + 'title' => $this->t('Media'), + 'description' => $this->t('The source field definition for the %type media type is missing.', + [ + '%type' => $type->label(), + ] + ), + 'severity' => REQUIREMENT_ERROR, + ]; + continue; + } + + // When a new media type with an image source is created we're + // configuring the default entity view display using the 'large' image + // style. Unfortunately, if a site builder has deleted the 'large' image + // style, we need some other image style to use, but at this point, we + // can't really know the site builder's intentions. So rather than do + // something surprising, we're leaving the embedded media without an + // image style and adding a warning that the site builder might want to + // add an image style. + // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay + if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { + continue; + } + + $component = $display->getComponent($source_field_definition->getName()); + if (empty($component) || $component['type'] !== 'image' || !empty($component['settings']['image_style'])) { + continue; + } + + $action_item = ''; + if ($this->moduleHandler->moduleExists('field_ui') && $this->currentUser->hasPermission('administer media display')) { + $url = Url::fromRoute('entity.entity_view_display.media.default', [ + 'media_type' => $type->id(), + ])->toString(); + $action_item = new TranslatableMarkup('If you would like to change this, <a href=":display">add an image style to the %field_name field</a>.', + [ + '%field_name' => $source_field_definition->label(), + ':display' => $url, + ]); + } + $requirements['media_default_image_style_' . $type->id()] = [ + 'title' => $this->t('Media'), + 'description' => new TranslatableMarkup('The default display for the %type media type is not currently using an image style on the %field_name field. Not using an image style can lead to much larger file downloads. @action_item', + [ + '%field_name' => $source_field_definition->label(), + '@action_item' => $action_item, + '%type' => $type->label(), + ] + ), + 'severity' => REQUIREMENT_WARNING, + ]; + } + + return $requirements; + } + +} diff --git a/core/modules/media/src/Install/Requirements/MediaRequirements.php b/core/modules/media/src/Install/Requirements/MediaRequirements.php new file mode 100644 index 000000000000..2274c5096ac7 --- /dev/null +++ b/core/modules/media/src/Install/Requirements/MediaRequirements.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\media\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; + +/** + * Install time requirements for the media module. + */ +class MediaRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + $destination = 'public://media-icons/generic'; + \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); + $is_writable = is_writable($destination); + $is_directory = is_dir($destination); + if (!$is_writable || !$is_directory) { + if (!$is_directory) { + $error = t('The directory %directory does not exist.', ['%directory' => $destination]); + } + else { + $error = t('The directory %directory is not writable.', ['%directory' => $destination]); + } + $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', [':handbook_url' => 'https://www.drupal.org/server-permissions']); + if (!empty($error)) { + $description = $error . ' ' . $description; + $requirements['media']['description'] = $description; + $requirements['media']['severity'] = REQUIREMENT_ERROR; + } + } + return $requirements; + } + +} -- GitLab From c88019e752226810c3253cbfa01a053fbadb26b8 Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Mon, 17 Mar 2025 11:16:25 -0400 Subject: [PATCH 03/12] Remove unnecessary empty and missing use statement --- core/.phpstan-baseline.php | 6 +++--- .../media/src/Install/Requirements/MediaRequirements.php | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 13fa6dc2a554..b4c85cdcf463 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -23746,10 +23746,10 @@ 'path' => __DIR__ . '/modules/locale/tests/src/Unit/Menu/LocaleLocalTasksTest.php', ]; $ignoreErrors[] = [ - 'message' => '#^Variable \\$error in empty\\(\\) always exists and is not falsy\\.$#', - 'identifier' => 'empty.variable', + 'message' => '#^Function media_filter_format_edit_form_validate\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', 'count' => 1, - 'path' => __DIR__ . '/modules/media/media.install', + 'path' => __DIR__ . '/modules/media/media.module', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\media\\\\Controller\\\\MediaFilterController\\:\\:checkCsrf\\(\\) has no return type specified\\.$#', diff --git a/core/modules/media/src/Install/Requirements/MediaRequirements.php b/core/modules/media/src/Install/Requirements/MediaRequirements.php index 2274c5096ac7..a69a79aaf811 100644 --- a/core/modules/media/src/Install/Requirements/MediaRequirements.php +++ b/core/modules/media/src/Install/Requirements/MediaRequirements.php @@ -5,6 +5,7 @@ namespace Drupal\media\Install\Requirements; use Drupal\Core\Extension\InstallRequirementsInterface; +use Drupal\Core\File\FileSystemInterface; /** * Install time requirements for the media module. @@ -28,11 +29,9 @@ public static function getRequirements(): array { $error = t('The directory %directory is not writable.', ['%directory' => $destination]); } $description = t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', [':handbook_url' => 'https://www.drupal.org/server-permissions']); - if (!empty($error)) { - $description = $error . ' ' . $description; - $requirements['media']['description'] = $description; - $requirements['media']['severity'] = REQUIREMENT_ERROR; - } + $description = $error . ' ' . $description; + $requirements['media']['description'] = $description; + $requirements['media']['severity'] = REQUIREMENT_ERROR; } return $requirements; } -- GitLab From 8be9c7fe775dced1b17ec757387c4549c9217bf1 Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Tue, 18 Mar 2025 16:18:08 -0400 Subject: [PATCH 04/12] Package Manager requirements --- .../package_manager/package_manager.install | 82 ----------------- .../src/Hook/PackageManagerRequirements.php | 92 +++++++++++++++++++ .../PackageManagerRequirements.php | 33 +++++++ 3 files changed, 125 insertions(+), 82 deletions(-) delete mode 100644 core/modules/package_manager/package_manager.install create mode 100644 core/modules/package_manager/src/Hook/PackageManagerRequirements.php create mode 100644 core/modules/package_manager/src/Install/Requirements/PackageManagerRequirements.php diff --git a/core/modules/package_manager/package_manager.install b/core/modules/package_manager/package_manager.install deleted file mode 100644 index 22d42a346ead..000000000000 --- a/core/modules/package_manager/package_manager.install +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -/** - * @file - * Contains install and update functions for Package Manager. - */ - -declare(strict_types=1); - -use Drupal\Core\Site\Settings; -use Drupal\package_manager\ComposerInspector; -use Drupal\package_manager\Exception\StageFailureMarkerException; -use Drupal\package_manager\FailureMarker; -use PhpTuf\ComposerStager\API\Exception\ExceptionInterface; -use PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface; - -/** - * Implements hook_requirements(). - */ -function package_manager_requirements(string $phase): array { - $requirements = []; - - if (Settings::get('testing_package_manager', FALSE) === FALSE) { - $requirements['testing_package_manager'] = [ - 'title' => 'Package Manager', - 'description' => t("Package Manager is available for early testing. To install the module set the value of 'testing_package_manager' to TRUE in your settings.php file."), - 'severity' => REQUIREMENT_ERROR, - ]; - return $requirements; - } - - // If we're able to check for the presence of the failure marker at all, do it - // irrespective of the current run phase. If the failure marker is there, the - // site is in an indeterminate state and should be restored from backup ASAP. - $service_id = FailureMarker::class; - if (\Drupal::hasService($service_id)) { - try { - \Drupal::service($service_id)->assertNotExists(NULL); - } - catch (StageFailureMarkerException $exception) { - $requirements['package_manager_failure_marker'] = [ - 'title' => t('Failed Package Manager update detected'), - 'description' => $exception->getMessage(), - 'severity' => REQUIREMENT_ERROR, - ]; - } - } - - if ($phase !== 'runtime') { - return $requirements; - } - /** @var \PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface $executable_finder */ - $executable_finder = \Drupal::service(ExecutableFinderInterface::class); - - // Report the Composer version in use, as well as its path. - $title = t('Composer version'); - try { - $requirements['package_manager_composer'] = [ - 'title' => $title, - 'description' => t('@version (<code>@path</code>)', [ - '@version' => \Drupal::service(ComposerInspector::class)->getVersion(), - '@path' => $executable_finder->find('composer'), - ]), - 'severity' => REQUIREMENT_INFO, - ]; - } - catch (\Throwable $e) { - // All Composer Stager exceptions are translatable. - $message = $e instanceof ExceptionInterface - ? $e->getTranslatableMessage() - : $e->getMessage(); - - $requirements['package_manager_composer'] = [ - 'title' => $title, - 'description' => t('Composer was not found. The error message was: @message', [ - '@message' => $message, - ]), - 'severity' => REQUIREMENT_ERROR, - ]; - } - return $requirements; -} diff --git a/core/modules/package_manager/src/Hook/PackageManagerRequirements.php b/core/modules/package_manager/src/Hook/PackageManagerRequirements.php new file mode 100644 index 000000000000..02e7335ca37c --- /dev/null +++ b/core/modules/package_manager/src/Hook/PackageManagerRequirements.php @@ -0,0 +1,92 @@ +<?php + +namespace Drupal\media\Hook; + +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Hook\Attribute\Hook; +use Drupal\package_manager\ComposerInspector; +use Drupal\package_manager\Exception\StageFailureMarkerException; +use Drupal\package_manager\FailureMarker; +use PhpTuf\ComposerStager\API\Exception\ExceptionInterface; +use PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface; + +/** + * Hook implementations for media. + */ +class PackageManagerRequirements { + + use StringTranslationTrait; + + public function __construct( + protected readonly ComposerInspector $composerInspector, + protected ExecutableFinderInterface $executableFinder, + ) {} + + /** + * Implements hook_runtime_requirements(). + */ + #[Hook('runtime_requirements')] + public function runtime(): array { + $requirements = $this->checkFailure(); + + // Report the Composer version in use, as well as its path. + $title = $this->t('Composer version'); + try { + $requirements['package_manager_composer'] = [ + 'title' => $title, + 'description' => $this->t('@version (<code>@path</code>)', [ + '@version' => $this->composerInspector->getVersion(), + '@path' => $this->executableFinder->find('composer'), + ]), + 'severity' => REQUIREMENT_INFO, + ]; + } + catch (\Throwable $e) { + // All Composer Stager exceptions are translatable. + $message = $e instanceof ExceptionInterface + ? $e->getTranslatableMessage() + : $e->getMessage(); + + $requirements['package_manager_composer'] = [ + 'title' => $title, + 'description' => $this->t('Composer was not found. The error message was: @message', [ + '@message' => $message, + ]), + 'severity' => REQUIREMENT_ERROR, + ]; + } + + return $requirements; + } + + /** + * Implements hook_update_requirements(). + */ + #[Hook('update_requirements')] + public function update(): array { + return $this->checkFailure(); + } + + public function checkFailure(): array { + $requirements = []; + // If we're able to check for the presence of the failure marker at all, do it + // irrespective of the current run phase. If the failure marker is there, the + // site is in an indeterminate state and should be restored from backup ASAP. + $service_id = FailureMarker::class; + if (\Drupal::hasService($service_id)) { + try { + \Drupal::service($service_id)->assertNotExists(NULL); + } + catch (StageFailureMarkerException $exception) { + $requirements['package_manager_failure_marker'] = [ + 'title' => $this->t('Failed Package Manager update detected'), + 'description' => $exception->getMessage(), + 'severity' => REQUIREMENT_ERROR, + ]; + } + } + + return $requirements; + } + +} diff --git a/core/modules/package_manager/src/Install/Requirements/PackageManagerRequirements.php b/core/modules/package_manager/src/Install/Requirements/PackageManagerRequirements.php new file mode 100644 index 000000000000..30b9cb6395be --- /dev/null +++ b/core/modules/package_manager/src/Install/Requirements/PackageManagerRequirements.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\package_manager\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; +use Drupal\Core\Site\Settings; + +/** + * Install time requirements for the package_manager module. + */ +class PackageManagerRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + + if (Settings::get('testing_package_manager', FALSE) === FALSE) { + $requirements['testing_package_manager'] = [ + 'title' => 'Package Manager', + 'description' => t("Package Manager is available for early testing. To install the module set the value of 'testing_package_manager' to TRUE in your settings.php file."), + 'severity' => REQUIREMENT_ERROR, + ]; + return $requirements; + } + + return $requirements; + } + +} -- GitLab From 113d20c1a47ce7a33b9c614977544ec862ab9ce2 Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Tue, 18 Mar 2025 17:22:49 -0400 Subject: [PATCH 05/12] Fix namespace --- .../package_manager/src/Hook/PackageManagerRequirements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/package_manager/src/Hook/PackageManagerRequirements.php b/core/modules/package_manager/src/Hook/PackageManagerRequirements.php index 02e7335ca37c..5226606e01e7 100644 --- a/core/modules/package_manager/src/Hook/PackageManagerRequirements.php +++ b/core/modules/package_manager/src/Hook/PackageManagerRequirements.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\media\Hook; +namespace Drupal\package_manager\Hook; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Hook\Attribute\Hook; -- GitLab From 9eed5d061e94c9371a8d0c3145fc19e0118ba796 Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 21:45:18 -0400 Subject: [PATCH 06/12] Add hook to classnamesand convert pgsql --- ...rements.php => MediaRequirementsHooks.php} | 2 +- ...hp => PackageManagerRequirementsHooks.php} | 2 +- core/modules/pgsql/pgsql.install | 36 ----------- .../pgsql/src/Hook/PgsqlRequirementsHooks.php | 63 +++++++++++++++++++ .../src/Requirements/PgsqlRequirements.php | 49 +++++++++++++++ 5 files changed, 114 insertions(+), 38 deletions(-) rename core/modules/media/src/Hook/{MediaRequirements.php => MediaRequirementsHooks.php} (99%) rename core/modules/package_manager/src/Hook/{PackageManagerRequirements.php => PackageManagerRequirementsHooks.php} (98%) create mode 100644 core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php create mode 100644 core/modules/pgsql/src/Requirements/PgsqlRequirements.php diff --git a/core/modules/media/src/Hook/MediaRequirements.php b/core/modules/media/src/Hook/MediaRequirementsHooks.php similarity index 99% rename from core/modules/media/src/Hook/MediaRequirements.php rename to core/modules/media/src/Hook/MediaRequirementsHooks.php index 536e46074f85..61d39c604ebe 100644 --- a/core/modules/media/src/Hook/MediaRequirements.php +++ b/core/modules/media/src/Hook/MediaRequirementsHooks.php @@ -15,7 +15,7 @@ /** * Hook implementations for media. */ -class MediaRequirements { +class MediaRequirementsHooks { use StringTranslationTrait; diff --git a/core/modules/package_manager/src/Hook/PackageManagerRequirements.php b/core/modules/package_manager/src/Hook/PackageManagerRequirementsHooks.php similarity index 98% rename from core/modules/package_manager/src/Hook/PackageManagerRequirements.php rename to core/modules/package_manager/src/Hook/PackageManagerRequirementsHooks.php index 5226606e01e7..0ec0cb9293cf 100644 --- a/core/modules/package_manager/src/Hook/PackageManagerRequirements.php +++ b/core/modules/package_manager/src/Hook/PackageManagerRequirementsHooks.php @@ -13,7 +13,7 @@ /** * Hook implementations for media. */ -class PackageManagerRequirements { +class PackageManagerRequirementsHooks { use StringTranslationTrait; diff --git a/core/modules/pgsql/pgsql.install b/core/modules/pgsql/pgsql.install index 3adeb4f5dff3..682ef7d605b5 100644 --- a/core/modules/pgsql/pgsql.install +++ b/core/modules/pgsql/pgsql.install @@ -5,42 +5,6 @@ * Install, update and uninstall functions for the pgsql module. */ -use Drupal\Core\Database\Database; - -/** - * Implements hook_requirements(). - */ -function pgsql_requirements(): array { - $requirements = []; - // Test with PostgreSQL databases for the status of the pg_trgm extension. - if (Database::isActiveConnection()) { - $connection = Database::getConnection(); - - // Set the requirement just for postgres. - if ($connection->driver() == 'pgsql') { - $requirements['pgsql_extension_pg_trgm'] = [ - 'severity' => REQUIREMENT_OK, - 'title' => t('PostgreSQL pg_trgm extension'), - 'value' => t('Available'), - 'description' => 'The pg_trgm PostgreSQL extension is present.', - ]; - - // If the extension is not available, set the requirement error. - if (!$connection->schema()->extensionExists('pg_trgm')) { - $requirements['pgsql_extension_pg_trgm']['severity'] = REQUIREMENT_ERROR; - $requirements['pgsql_extension_pg_trgm']['value'] = t('Not created'); - $requirements['pgsql_extension_pg_trgm']['description'] = t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 10 to improve performance when using PostgreSQL. See <a href=":requirements">Drupal database server requirements</a> for more information.', [ - ':pg_trgm' => 'https://www.postgresql.org/docs/current/pgtrgm.html', - ':requirements' => 'https://www.drupal.org/docs/system-requirements/database-server-requirements', - ]); - } - - } - } - - return $requirements; -} - /** * Implements hook_update_last_removed(). */ diff --git a/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php b/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php new file mode 100644 index 000000000000..324102af7c99 --- /dev/null +++ b/core/modules/pgsql/src/Hook/PgsqlRequirementsHooks.php @@ -0,0 +1,63 @@ +<?php + +namespace Drupal\pgsql\Hook; + +use Drupal\Core\Database\Database; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Hook\Attribute\Hook; + +/** + * Hook implementations for pgsql module. + */ +class PgsqlRequirementsHooks { + + use StringTranslationTrait; + + /** + * Implements hook_runtime_requirements(). + */ + #[Hook('runtime_requirements')] + public function runtime(): array { + return $this->checkRequirements(); + } + + /** + * Implements hook_update_requirements(). + */ + #[Hook('update_requirements')] + public function update(): array { + return $this->checkRequirements(); + } + + public function checkRequirements(): array { + $requirements = []; + // Test with PostgreSQL databases for the status of the pg_trgm extension. + if (Database::isActiveConnection()) { + $connection = Database::getConnection(); + + // Set the requirement just for postgres. + if ($connection->driver() == 'pgsql') { + $requirements['pgsql_extension_pg_trgm'] = [ + 'severity' => REQUIREMENT_OK, + 'title' => $this->t('PostgreSQL pg_trgm extension'), + 'value' => $this->t('Available'), + 'description' => 'The pg_trgm PostgreSQL extension is present.', + ]; + + // If the extension is not available, set the requirement error. + if (!$connection->schema()->extensionExists('pg_trgm')) { + $requirements['pgsql_extension_pg_trgm']['severity'] = REQUIREMENT_ERROR; + $requirements['pgsql_extension_pg_trgm']['value'] = $this->t('Not created'); + $requirements['pgsql_extension_pg_trgm']['description'] = $this->t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 10 to improve performance when using PostgreSQL. See <a href=":requirements">Drupal database server requirements</a> for more information.', [ + ':pg_trgm' => 'https://www.postgresql.org/docs/current/pgtrgm.html', + ':requirements' => 'https://www.drupal.org/docs/system-requirements/database-server-requirements', + ]); + } + + } + } + + return $requirements; + } + +} diff --git a/core/modules/pgsql/src/Requirements/PgsqlRequirements.php b/core/modules/pgsql/src/Requirements/PgsqlRequirements.php new file mode 100644 index 000000000000..bebd02702424 --- /dev/null +++ b/core/modules/pgsql/src/Requirements/PgsqlRequirements.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\pgsql\Install\Requirements; + +use Drupal\Core\Database\Database; +use Drupal\Core\Extension\InstallRequirementsInterface; + +/** + * Install time requirements for the pgsql module. + */ +class PgsqlRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + // Test with PostgreSQL databases for the status of the pg_trgm extension. + if (Database::isActiveConnection()) { + $connection = Database::getConnection(); + + // Set the requirement just for postgres. + if ($connection->driver() == 'pgsql') { + $requirements['pgsql_extension_pg_trgm'] = [ + 'severity' => REQUIREMENT_OK, + 'title' => t('PostgreSQL pg_trgm extension'), + 'value' => t('Available'), + 'description' => 'The pg_trgm PostgreSQL extension is present.', + ]; + + // If the extension is not available, set the requirement error. + if (!$connection->schema()->extensionExists('pg_trgm')) { + $requirements['pgsql_extension_pg_trgm']['severity'] = REQUIREMENT_ERROR; + $requirements['pgsql_extension_pg_trgm']['value'] = t('Not created'); + $requirements['pgsql_extension_pg_trgm']['description'] = t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 10 to improve performance when using PostgreSQL. See <a href=":requirements">Drupal database server requirements</a> for more information.', [ + ':pg_trgm' => 'https://www.postgresql.org/docs/current/pgtrgm.html', + ':requirements' => 'https://www.drupal.org/docs/system-requirements/database-server-requirements', + ]); + } + + } + } + + return $requirements; + } + +} -- GitLab From ef3f357d31af5deb8a35b2b13345cf09b18569ef Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 21:53:51 -0400 Subject: [PATCH 07/12] Experimental module requirements --- ...ntalModuleRequirementsTestRequirements.php | 28 +++++++++++++++++++ ...erimental_module_requirements_test.install | 22 --------------- 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php delete mode 100644 core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install diff --git a/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php b/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php new file mode 100644 index 000000000000..e4fa32c77517 --- /dev/null +++ b/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php @@ -0,0 +1,28 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\experimental_module_requirements_test\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; + +/** + * Install time requirements for the experimental_module_requirements_test module. + */ +class ExperimentalModuleRequirementsTestRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + if (\Drupal::state()->get('experimental_module_requirements_test_requirements', FALSE)) { + $requirements['experimental_module_requirements_test_requirements'] = [ + 'severity' => REQUIREMENT_ERROR, + 'description' => t('The Experimental Test Requirements module can not be installed.'), + ]; + } + return $requirements; + } + +} diff --git a/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install b/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install deleted file mode 100644 index beaa3cd15b70..000000000000 --- a/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * @file - * Experimental Test Requirements module to test hook_requirements(). - */ - -declare(strict_types=1); - -/** - * Implements hook_requirements(). - */ -function experimental_module_requirements_test_requirements(): array { - $requirements = []; - if (\Drupal::state()->get('experimental_module_requirements_test_requirements', FALSE)) { - $requirements['experimental_module_requirements_test_requirements'] = [ - 'severity' => REQUIREMENT_ERROR, - 'description' => t('The Experimental Test Requirements module can not be installed.'), - ]; - } - return $requirements; -} -- GitLab From 7193ce456501858c88819c536a81f25e1571adc4 Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 21:58:44 -0400 Subject: [PATCH 08/12] Convert workspaces --- .../Requirements/WorkspacesRequirements.php | 31 +++++++++++++++++++ core/modules/workspaces/workspaces.install | 19 ------------ 2 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 core/modules/workspaces/src/Install/Requirements/WorkspacesRequirements.php diff --git a/core/modules/workspaces/src/Install/Requirements/WorkspacesRequirements.php b/core/modules/workspaces/src/Install/Requirements/WorkspacesRequirements.php new file mode 100644 index 000000000000..a54148215af1 --- /dev/null +++ b/core/modules/workspaces/src/Install/Requirements/WorkspacesRequirements.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\workspaces\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; + +/** + * Install time requirements for the workspaces module. + */ +class WorkspacesRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + if (\Drupal::moduleHandler()->moduleExists('workspace')) { + $requirements['workspace_incompatibility'] = [ + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Workspaces can not be installed when the contributed Workspace module is also installed. See the <a href=":link">upgrade path</a> page for more information on how to upgrade.', [ + ':link' => 'https://www.drupal.org/node/2987783', + ]), + ]; + } + + return $requirements; + } + +} diff --git a/core/modules/workspaces/workspaces.install b/core/modules/workspaces/workspaces.install index a798b4a2c22b..6c9c99f29a3c 100644 --- a/core/modules/workspaces/workspaces.install +++ b/core/modules/workspaces/workspaces.install @@ -8,25 +8,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\workspaces\Entity\Workspace; -/** - * Implements hook_requirements(). - */ -function workspaces_requirements($phase): array { - $requirements = []; - if ($phase === 'install') { - if (\Drupal::moduleHandler()->moduleExists('workspace')) { - $requirements['workspace_incompatibility'] = [ - 'severity' => REQUIREMENT_ERROR, - 'description' => t('Workspaces can not be installed when the contributed Workspace module is also installed. See the <a href=":link">upgrade path</a> page for more information on how to upgrade.', [ - ':link' => 'https://www.drupal.org/node/2987783', - ]), - ]; - } - } - - return $requirements; -} - /** * Implements hook_install(). */ -- GitLab From cff24948fd5f2ecbda83c897c06343f32e684c04 Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 22:03:53 -0400 Subject: [PATCH 09/12] Convert profile testing requirements add comment for requirements1 --- .../requirements1_test.install | 2 ++ .../TestingRequirementsRequirements.php | 28 +++++++++++++++++++ .../testing_requirements.install | 25 ----------------- 3 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php delete mode 100644 core/profiles/tests/testing_requirements/testing_requirements.install diff --git a/core/modules/system/tests/modules/requirements1_test/requirements1_test.install b/core/modules/system/tests/modules/requirements1_test/requirements1_test.install index 70767c16544d..fb84be133cd7 100644 --- a/core/modules/system/tests/modules/requirements1_test/requirements1_test.install +++ b/core/modules/system/tests/modules/requirements1_test/requirements1_test.install @@ -9,6 +9,8 @@ /** * Implements hook_requirements(). + * + * This tests the procedural implementations for this hook. */ function requirements1_test_requirements($phase): array { $requirements = []; diff --git a/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php b/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php new file mode 100644 index 000000000000..3465dff89a65 --- /dev/null +++ b/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php @@ -0,0 +1,28 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\testing_requirements\Install\Requirements\Install\Requirements; + +use Drupal\Core\Extension\InstallRequirementsInterface; + +/** + * Install time requirements for the testing_requirements module. + */ +class TestingRequirementsRequirements implements InstallRequirementsInterface { + + /** + * {@inheritdoc} + */ + public static function getRequirements(): array { + $requirements = []; + $requirements['testing_requirements'] = [ + 'title' => t('Testing requirements'), + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Testing requirements failed requirements.'), + ]; + + return $requirements; + } + +} diff --git a/core/profiles/tests/testing_requirements/testing_requirements.install b/core/profiles/tests/testing_requirements/testing_requirements.install deleted file mode 100644 index 7cdb44d9d299..000000000000 --- a/core/profiles/tests/testing_requirements/testing_requirements.install +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -/** - * @file - * Install hooks for test profile. - */ - -declare(strict_types=1); - -/** - * Implements hook_requirements(). - */ -function testing_requirements_requirements($phase): array { - $requirements = []; - - if ($phase === 'install') { - $requirements['testing_requirements'] = [ - 'title' => t('Testing requirements'), - 'severity' => REQUIREMENT_ERROR, - 'description' => t('Testing requirements failed requirements.'), - ]; - } - - return $requirements; -} -- GitLab From 93f7ef4687344ec399de410a5b76678e9b0a2fd7 Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 22:47:42 -0400 Subject: [PATCH 10/12] Fix namespace --- .../Install/Requirements/TestingRequirementsRequirements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php b/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php index 3465dff89a65..71165b1c8dba 100644 --- a/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php +++ b/core/profiles/tests/testing_requirements/src/Install/Requirements/TestingRequirementsRequirements.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Drupal\testing_requirements\Install\Requirements\Install\Requirements; +namespace Drupal\testing_requirements\Install\Requirements; use Drupal\Core\Extension\InstallRequirementsInterface; -- GitLab From ee5eec463c6a280b225d32ff379eb1adb2c7e1a1 Mon Sep 17 00:00:00 2001 From: nicxvan <nic@nlightened.net> Date: Tue, 18 Mar 2025 23:35:41 -0400 Subject: [PATCH 11/12] Revert requirements --- ...ntalModuleRequirementsTestRequirements.php | 28 ------------------- ...erimental_module_requirements_test.install | 22 +++++++++++++++ 2 files changed, 22 insertions(+), 28 deletions(-) delete mode 100644 core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php create mode 100644 core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install diff --git a/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php b/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php deleted file mode 100644 index e4fa32c77517..000000000000 --- a/core/modules/system/tests/modules/experimental_module_requirements_test/Install/Requirements/ExperimentalModuleRequirementsTestRequirements.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\experimental_module_requirements_test\Install\Requirements; - -use Drupal\Core\Extension\InstallRequirementsInterface; - -/** - * Install time requirements for the experimental_module_requirements_test module. - */ -class ExperimentalModuleRequirementsTestRequirements implements InstallRequirementsInterface { - - /** - * {@inheritdoc} - */ - public static function getRequirements(): array { - $requirements = []; - if (\Drupal::state()->get('experimental_module_requirements_test_requirements', FALSE)) { - $requirements['experimental_module_requirements_test_requirements'] = [ - 'severity' => REQUIREMENT_ERROR, - 'description' => t('The Experimental Test Requirements module can not be installed.'), - ]; - } - return $requirements; - } - -} diff --git a/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install b/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install new file mode 100644 index 000000000000..beaa3cd15b70 --- /dev/null +++ b/core/modules/system/tests/modules/experimental_module_requirements_test/experimental_module_requirements_test.install @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Experimental Test Requirements module to test hook_requirements(). + */ + +declare(strict_types=1); + +/** + * Implements hook_requirements(). + */ +function experimental_module_requirements_test_requirements(): array { + $requirements = []; + if (\Drupal::state()->get('experimental_module_requirements_test_requirements', FALSE)) { + $requirements['experimental_module_requirements_test_requirements'] = [ + 'severity' => REQUIREMENT_ERROR, + 'description' => t('The Experimental Test Requirements module can not be installed.'), + ]; + } + return $requirements; +} -- GitLab From a57e9182908c929ca39ee90b68ae2bcf8513c52d Mon Sep 17 00:00:00 2001 From: nlighteneddesign <nic@nlighteneddevelopment.com> Date: Sun, 30 Mar 2025 12:46:52 -0400 Subject: [PATCH 12/12] Baseline --- core/.phpstan-baseline.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index b4c85cdcf463..97c1d762b81b 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -23745,12 +23745,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/locale/tests/src/Unit/Menu/LocaleLocalTasksTest.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Function media_filter_format_edit_form_validate\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/modules/media/media.module', -]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\media\\\\Controller\\\\MediaFilterController\\:\\:checkCsrf\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', -- GitLab