Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
image_link_attributes
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
image_link_attributes
Commits
9291146b
Commit
9291146b
authored
1 year ago
by
Andrew Wasson
Committed by
Andrew Wasson
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3379417
by awasson: Code Cleanup
parent
5424b734
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
image_link_attributes.module
+26
-10
26 additions, 10 deletions
image_link_attributes.module
with
26 additions
and
10 deletions
image_link_attributes.module
+
26
−
10
View file @
9291146b
...
...
@@ -5,12 +5,12 @@
* Contains image_link_attributes.module.
*/
use
Drupal\Co
re\Render\Element
;
use
Drupal\Co
mponent\Utility\Unicode
;
use
Drupal\Core\Entity\Entity\EntityViewDisplay
;
use
Drupal\Core\Render\Element
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\image\Entity\ImageStyle
;
use
Drupal\file\Entity\File
;
use
Drupal\image\Entity\ImageStyle
;
/**
* Implements hook_help().
...
...
@@ -176,12 +176,22 @@ function image_link_attributes_field_formatter_third_party_settings_form($plugin
'#default_value'
=>
$settings
[
'alternate_images'
],
'#states'
=>
[
'invisible'
=>
[
[
'select[name$="[settings][image_link]"]'
=>
[[
'value'
=>
''
],[
'value'
=>
'content'
],]],
[
'select[name$="[settings][image_link]"]'
=>
[
[
'value'
=>
''
],
[
'value'
=>
'content'
],
],
],
],
],
];
// Options for Alternate Image Styles
// Settings for Alternate Image Styles.
if
(
!
array_key_exists
(
'alternate_image_styles'
,
$settings
))
{
$settings
[
'alternate_image_styles'
]
=
0
;
}
// Options for Alternate Image Styles.
$element
[
'alternate_image_styles'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
t
(
'Alternate Image Styles'
),
...
...
@@ -189,7 +199,12 @@ function image_link_attributes_field_formatter_third_party_settings_form($plugin
'#options'
=>
image_style_options
(
FALSE
),
'#states'
=>
[
'invisible'
=>
[
[
'select[name$="[settings][image_link]"]'
=>
[[
'value'
=>
''
],[
'value'
=>
'content'
],]],
[
'select[name$="[settings][image_link]"]'
=>
[
[
'value'
=>
''
],
[
'value'
=>
'content'
],
],
],
[
'input[name$="[third_party_settings][image_link_attributes][alternate_images]"]'
=>
[
'unchecked'
=>
TRUE
]],
],
],
...
...
@@ -208,7 +223,7 @@ function image_link_attributes_preprocess_field(array &$variables) {
if
(
$element
[
'#formatter'
]
==
'image'
)
{
$items
=&
$variables
[
'items'
];
$entity
=
$element
[
'#object'
];
$entity
=
$element
[
'#object'
];
$view_mode
=
$element
[
'#view_mode'
];
$field_name
=
$element
[
'#field_name'
];
...
...
@@ -223,12 +238,13 @@ function image_link_attributes_preprocess_field(array &$variables) {
$is_enabled
=
$custom_settings
[
'extended'
]
??
FALSE
;
// If there is an alternate image style, get it, assign path.
$alternate_image
=
$custom_settings
[
'alternate_images'
];
$alternate_image
=
$custom_settings
[
'alternate_images'
]
??
FALSE
;
if
(
$alternate_image
)
{
$alternate_image_style
=
$custom_settings
[
'alternate_image_styles'
];
$style
=
ImageStyle
::
load
(
$alternate_image_style
);
foreach
(
Element
::
children
(
$items
)
as
$child_name
)
{
$delta
=&
$items
[
$child_name
];
$delta
=&
$items
[
$child_name
];
$content
=&
$delta
[
'content'
];
$alternate_path
=
$content
[
'#alternate_path'
]
??
""
;
$image_id
=
$items
[
$child_name
][
'content'
][
'#item'
]
->
getValue
()[
'target_id'
];
...
...
@@ -244,7 +260,7 @@ function image_link_attributes_preprocess_field(array &$variables) {
if
(
$is_enabled
)
{
$advanced_attributes
=
array_filter
(
$custom_settings
[
'advanced'
]);
foreach
(
Element
::
children
(
$items
)
as
$child_name
)
{
$delta
=&
$items
[
$child_name
];
$delta
=&
$items
[
$child_name
];
$content
=&
$delta
[
'content'
];
$link_attributes
=
$content
[
'#link_attributes'
]
??
[];
$link_attributes
=
array_merge
(
$link_attributes
,
$advanced_attributes
);
...
...
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