ImageAPIOptimizeHookImplementations.php in Image Optimize (or ImageAPI Optimize) 4.x
File
src/ImageAPIOptimizeHookImplementations.php
View source
<?php
namespace Drupal\imageapi_optimize;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class ImageAPIOptimizeHookImplementations {
use StringTranslationTrait;
public function __construct(TranslationInterface $string_translation) {
$this->stringTranslation = $string_translation;
}
public function entity_type_alter(array &$entity_types) {
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);
}
}
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,
];
}
public function config_schema_info_alter(&$definitions) {
if (isset($definitions['image.style.*'])) {
$definitions['image.style.*']['mapping']['pipeline']['type'] = 'string';
}
}
}