Skip to content
Snippets Groups Projects
Commit 30a602e9 authored by Steven Jones's avatar Steven Jones Committed by Steven Jones
Browse files

Issue #2829536 by Steven Jones: Move hook implementations into a service

parent 137e2760
No related branches found
No related tags found
No related merge requests found
......@@ -37,37 +37,19 @@ function imageapi_optimize_pipeline_options($include_empty = TRUE, $include_site
* Implements hook_entity_type_alter().
*/
function imageapi_optimize_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);
}
return \Drupal::service('imageapi_optimize.hooks')->entity_type_alter($entity_types);
}
/**
* Implements hook_config_schema_info_alter().
*/
function imageapi_optimize_config_schema_info_alter(&$definitions) {
if (isset($definitions['image.style.*'])) {
$definitions['image.style.*']['mapping']['pipeline']['type'] = 'string';
}
return \Drupal::service('imageapi_optimize.hooks')->config_schema_info_alter($definitions);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function imageapi_optimize_form_image_style_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$entity = $form_state->getFormObject()->getEntity();
$form['pipeline'] = [
'#type' => 'select',
'#title' => t('Image Optimize Pipeline'),
'#options' => imageapi_optimize_pipeline_options(),
'#default_value' => $entity->getPipeline(),
'#description' => t('Optionally select an Image Optimization pipeline which will be applied after all effects in this image style.'),
'#weight' => 10,
];
return \Drupal::service('imageapi_optimize.hooks')->form_image_style_edit_form_alter($form, $form_state, $form_id);
}
......@@ -2,3 +2,5 @@ services:
plugin.manager.imageapi_optimize.processor:
class: Drupal\imageapi_optimize\ImageAPIOptimizeProcessorManager
parent: default_plugin_manager
imageapi_optimize.hooks:
class: Drupal\imageapi_optimize\ImageAPIOptimizeHookImplementations
<?php
namespace Drupal\imageapi_optimize;
/**
* Hook implementations for the Image Optimize module.
*/
class ImageAPIOptimizeHookImplementations {
/**
* 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, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$entity = $form_state->getFormObject()->getEntity();
$form['pipeline'] = [
'#type' => 'select',
'#title' => t('Image Optimize Pipeline'),
'#options' => imageapi_optimize_pipeline_options(),
'#default_value' => $entity->getPipeline(),
'#description' => 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';
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment