Skip to content
Snippets Groups Projects
Commit 9291146b authored by Andrew Wasson's avatar Andrew Wasson Committed by Andrew Wasson
Browse files

Issue #3379417 by awasson: Code Cleanup

parent 5424b734
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,12 @@
* Contains image_link_attributes.module.
*/
use Drupal\Core\Render\Element;
use Drupal\Component\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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment