class ImageDerivativeUtilities

Same name and namespace in other branches
  1. main core/modules/image/src/ImageDerivativeUtilities.php \Drupal\image\ImageDerivativeUtilities

Image style flush and options utilities.

Hierarchy

Expanded class hierarchy of ImageDerivativeUtilities

11 files declare their use of ImageDerivativeUtilities
ConfigTestForm.php in core/modules/config/tests/config_test/src/ConfigTestForm.php
image.module in core/modules/image/image.module
ImageAdminStylesTest.php in core/modules/image/tests/src/Functional/ImageAdminStylesTest.php
ImageFormatter.php in core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php
ImageHooks.php in core/modules/image/src/Hook/ImageHooks.php

... See full list

File

core/modules/image/src/ImageDerivativeUtilities.php, line 13

Namespace

Drupal\image
View source
class ImageDerivativeUtilities {
  use StringTranslationTrait;
  
  /**
   * Clears cached versions of a specific file in all styles.
   *
   * @param string $path
   *   The Drupal file path to the original image.
   */
  public function pathFlush(string $path) : void {
    $styles = ImageStyle::loadMultiple();
    foreach ($styles as $style) {
      $style->flush($path);
    }
  }
  
  /**
   * Gets an array of image styles suitable for using as select list options.
   *
   * @param bool $include_empty
   *   If TRUE a '- None -' option will be inserted in the options array.
   *
   * @return string[]
   *   Array of image styles where the key is the machine name and the value is
   *   the label.
   */
  public function styleOptions(bool $include_empty = TRUE) : array {
    $styles = ImageStyle::loadMultiple();
    $options = [];
    if ($include_empty && !empty($styles)) {
      $options[''] = $this->t('- None -');
    }
    foreach ($styles as $name => $style) {
      $options[$name] = $style->label();
    }
    if (empty($options)) {
      $options[''] = $this->t('No defined styles');
    }
    return $options;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ImageDerivativeUtilities::pathFlush public function Clears cached versions of a specific file in all styles.
ImageDerivativeUtilities::styleOptions public function Gets an array of image styles suitable for using as select list options.
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.