You are here

class ImageAPIOptimizeHookImplementations in Image Optimize (or ImageAPI Optimize) 8.2

Same name and namespace in other branches
  1. 8.3 src/ImageAPIOptimizeHookImplementations.php \Drupal\imageapi_optimize\ImageAPIOptimizeHookImplementations
  2. 4.x src/ImageAPIOptimizeHookImplementations.php \Drupal\imageapi_optimize\ImageAPIOptimizeHookImplementations

Hook implementations for the Image Optimize module.

Hierarchy

Expanded class hierarchy of ImageAPIOptimizeHookImplementations

1 string reference to 'ImageAPIOptimizeHookImplementations'
imageapi_optimize.services.yml in ./imageapi_optimize.services.yml
imageapi_optimize.services.yml
1 service uses ImageAPIOptimizeHookImplementations
imageapi_optimize.hooks in ./imageapi_optimize.services.yml
Drupal\imageapi_optimize\ImageAPIOptimizeHookImplementations

File

src/ImageAPIOptimizeHookImplementations.php, line 12

Namespace

Drupal\imageapi_optimize
View source
class ImageAPIOptimizeHookImplementations {
  use StringTranslationTrait;

  /**
   * Constructs a new ImageAPIOptimizeHookImplementations object.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The stream translation service.
   */
  public function __construct(TranslationInterface $string_translation) {
    $this->stringTranslation = $string_translation;
  }

  /**
   * Implements hook_entity_type_alter().
   */
  public function entity_type_alter(array &$entity_types) {

    /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
    if (isset($entity_types['image_style'])) {
      $image_style = $entity_types['image_style'];
      $image_style
        ->setClass('Drupal\\imageapi_optimize\\Entity\\ImageStyleWithPipeline');
      $image_style
        ->setHandlerClass('list_builder', 'Drupal\\imageapi_optimize\\ImageStyleWithPipelineListBuilder');
      $config_export = $image_style
        ->get('config_export');
      $config_export[] = 'pipeline';
      $image_style
        ->set('config_export', $config_export);
    }
  }

  /**
   * Implements hook_form_image_style_edit_form_alter().
   */
  public function form_image_style_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    $entity = $form_state
      ->getFormObject()
      ->getEntity();
    $form['pipeline'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Image Optimize Pipeline'),
      '#options' => imageapi_optimize_pipeline_options(),
      '#default_value' => $entity
        ->getPipeline(),
      '#description' => $this
        ->t('Optionally select an Image Optimization pipeline which will be applied after all effects in this image style.'),
      '#weight' => 10,
    ];
  }

  /**
   * Implements hook_config_schema_info_alter().
   */
  public function config_schema_info_alter(&$definitions) {
    if (isset($definitions['image.style.*'])) {
      $definitions['image.style.*']['mapping']['pipeline']['type'] = 'string';
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageAPIOptimizeHookImplementations::config_schema_info_alter public function Implements hook_config_schema_info_alter().
ImageAPIOptimizeHookImplementations::entity_type_alter public function Implements hook_entity_type_alter().
ImageAPIOptimizeHookImplementations::form_image_style_edit_form_alter public function Implements hook_form_image_style_edit_form_alter().
ImageAPIOptimizeHookImplementations::__construct public function Constructs a new ImageAPIOptimizeHookImplementations object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.