Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
imageapi_optimize
Commits
30a602e9
Commit
30a602e9
authored
Dec 08, 2016
by
Steven Jones
Committed by
Steven Jones
Dec 08, 2016
Browse files
Issue
#2829536
by Steven Jones: Move hook implementations into a service
parent
137e2760
Changes
3
Hide whitespace changes
Inline
Side-by-side
imageapi_optimize.module
View file @
30a602e9
...
...
@@ -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
);
}
imageapi_optimize.services.yml
View file @
30a602e9
...
...
@@ -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
src/ImageAPIOptimizeHookImplementations.php
0 → 100644
View file @
30a602e9
<?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'
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment