Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
imageapi_optimize
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
imageapi_optimize
Commits
30a602e9
Commit
30a602e9
authored
8 years ago
by
Steven Jones
Committed by
Steven Jones
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
imageapi_optimize.module
+3
-21
3 additions, 21 deletions
imageapi_optimize.module
imageapi_optimize.services.yml
+2
-0
2 additions, 0 deletions
imageapi_optimize.services.yml
src/ImageAPIOptimizeHookImplementations.php
+48
-0
48 additions, 0 deletions
src/ImageAPIOptimizeHookImplementations.php
with
53 additions
and
21 deletions
imageapi_optimize.module
+
3
−
21
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
);
}
This diff is collapsed.
Click to expand it.
imageapi_optimize.services.yml
+
2
−
0
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
This diff is collapsed.
Click to expand it.
src/ImageAPIOptimizeHookImplementations.php
0 → 100644
+
48
−
0
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'
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment