class ImageRequirements

Requirements for the Image module.

Hierarchy

Expanded class hierarchy of ImageRequirements

File

core/modules/image/src/Hook/ImageRequirements.php, line 15

Namespace

Drupal\image\Hook
View source
class ImageRequirements {
  use StringTranslationTrait;
  public function __construct(protected readonly ImageToolkitManager $imageToolkitManager) {
  }
  
  /**
   * Implements 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;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ImageRequirements::runtime public function Implements hook_runtime_requirements().
ImageRequirements::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.