Skip to content
Snippets Groups Projects
Select Git revision
  • 11.x
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
40 results

ImageRequirements.php

Open merge requests 1
Loading
Blame
  • Lee Rowlands's avatar
    Issue #3410938 by kim.pepper, dww, nicxvan, smustgrave, andypost, dpi,...
    Lee Rowlands authored
    Issue #3410938 by kim.pepper, dww, nicxvan, smustgrave, andypost, dpi, quietone: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants
    63740f3d
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ImageRequirements.php 1.66 KiB
    <?php
    
    declare(strict_types=1);
    
    namespace Drupal\image\Hook;
    
    use Drupal\Core\Extension\Requirement\RequirementSeverity;
    use Drupal\Core\Hook\Attribute\Hook;
    use Drupal\Core\ImageToolkit\ImageToolkitManager;
    use Drupal\Core\StringTranslation\StringTranslationTrait;
    
    /**
     * Requirements for the Image module.
     */
    class ImageRequirements {
    
      use StringTranslationTrait;
    
      public function __construct(
        protected readonly ImageToolkitManager $imageToolkitManager,
      ) {}
    
      /**
       * Implements hook_runtime_requirements().
       */
      #[Hook('runtime_requirements')]
      public function runtime(): array {
        $toolkit = $this->imageToolkitManager->getDefaultToolkit();
        if ($toolkit) {
          $plugin_definition = $toolkit->getPluginDefinition();
          $requirements = [
            'image.toolkit' => [
              'title' => $this->t('Image toolkit'),
              'value' => $toolkit->getPluginId(),
              'description' => $plugin_definition['title'],
            ],
          ];
    
          foreach ($toolkit->getRequirements() as $key => $requirement) {
            $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
            $requirements[$namespaced_key] = $requirement;
          }
        }
        else {
          $requirements = [
            'image.toolkit' => [
              'title' => $this->t('Image toolkit'),
              'value' => $this->t('None'),
              'description' => $this->t("No image toolkit is configured on the site. Check PHP installed extensions or add a contributed toolkit that doesn't require a PHP extension. Make sure that at least one valid image toolkit is installed."),
              'severity' => RequirementSeverity::Error,
            ],
          ];
        }
    
        return $requirements;
      }
    
    }