From 263212f4c33cdd40f0aa36e11eb11427cbf527d6 Mon Sep 17 00:00:00 2001 From: berliner Date: Wed, 15 Nov 2023 23:21:39 +0100 Subject: [PATCH] HPC-9191: Make changes to the cropping UI, wording, remove obsolete fields --- composer.patches.json | 3 +++ ...tity_form_display.node.article.default.yml | 9 ------- ...ity_form_display.node.document.default.yml | 9 ------- ....entity_view_display.node.article.card.yml | 2 -- ...view_display.node.article.card_summary.yml | 2 -- ...tity_view_display.node.article.default.yml | 11 -------- ....entity_view_display.node.article.grid.yml | 2 -- ...iew_display.node.article.search_result.yml | 2 -- ...ntity_view_display.node.article.teaser.yml | 2 -- ...ity_view_display.node.document.default.yml | 11 -------- ...ew_display.node.document.search_result.yml | 2 -- ...tity_view_display.node.document.teaser.yml | 2 -- config/crop.type.14x5.yml | 2 +- config/crop.type.16x9.yml | 2 +- ...eld.node.article.field_crop_hero_image.yml | 23 ----------------- ....node.article.field_display_hero_image.yml | 2 +- ...de.article.field_inherit_section_image.yml | 4 +-- ...ld.node.document.field_crop_hero_image.yml | 23 ----------------- ...eld.storage.node.field_crop_hero_image.yml | 18 ------------- .../custom/ghi_content/ghi_content.module | 23 ++++++++++++----- .../src/ContentManager/BaseContentManager.php | 8 ------ .../ghi_content/src/Entity/ContentBase.php | 14 ----------- .../ghi_hero_image/ghi_hero_image.module | 16 ++++++------ .../src/Element/HeroImageCrop.php | 2 +- .../src/HeroImageWidgetCropManager.php | 8 ++++++ .../Field/FieldWidget/HeroImageWidget.php | 25 +++++++++++++------ .../ApiObjects/Attachments/DataAttachment.php | 7 ++++-- .../ghi_plans/src/ApiObjects/Organization.php | 7 ++++++ 28 files changed, 73 insertions(+), 168 deletions(-) delete mode 100644 config/field.field.node.article.field_crop_hero_image.yml delete mode 100644 config/field.field.node.document.field_crop_hero_image.yml delete mode 100644 config/field.storage.node.field_crop_hero_image.yml diff --git a/composer.patches.json b/composer.patches.json index 3e3f5d1bf..6878c368b 100644 --- a/composer.patches.json +++ b/composer.patches.json @@ -23,6 +23,9 @@ "drupal/google_tag": { "Issue #3250315: Error during cache rebuild when assets are stored on NFS": "https://www.drupal.org/files/issues/2022-11-23/3250315-google-tag-nfs-locks-5.patch" }, + "drupal/image_widget_crop": { + "Issue #3401986: The containers summary text should not be overwritten": "https://www.drupal.org/files/issues/2023-11-15/3401986-2.patch" + }, "drupal/page_manager": { "Issue #3176661: Allow to edit page title when using Layout Builder variant": "https://www.drupal.org/files/issues/2022-11-15/page_manager-lb-title-3176661-15.patch" }, diff --git a/config/core.entity_form_display.node.article.default.yml b/config/core.entity_form_display.node.article.default.yml index 6c7464116..23650c4bc 100644 --- a/config/core.entity_form_display.node.article.default.yml +++ b/config/core.entity_form_display.node.article.default.yml @@ -5,7 +5,6 @@ dependencies: config: - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -78,7 +77,6 @@ third_party_settings: group_display: children: - field_display_hero_image - - field_crop_hero_image - image_crop - field_inherit_section_image label: Display @@ -125,13 +123,6 @@ content: size: 60 placeholder: '' third_party_settings: { } - field_crop_hero_image: - type: boolean_checkbox - weight: 28 - region: content - settings: - display_label: true - third_party_settings: { } field_display_hero_image: type: boolean_checkbox weight: 27 diff --git a/config/core.entity_form_display.node.document.default.yml b/config/core.entity_form_display.node.document.default.yml index 04a506f4b..f5c073e9e 100644 --- a/config/core.entity_form_display.node.document.default.yml +++ b/config/core.entity_form_display.node.document.default.yml @@ -4,7 +4,6 @@ status: true dependencies: config: - field.field.node.document.field_base_objects - - field.field.node.document.field_crop_hero_image - field.field.node.document.field_display_hero_image - field.field.node.document.field_image - field.field.node.document.field_inherit_section_image @@ -43,7 +42,6 @@ third_party_settings: group_display: children: - field_display_hero_image - - field_crop_hero_image - image_crop - field_inherit_section_image label: Display @@ -115,13 +113,6 @@ content: disable_drag_and_drop: 0 wrapper: 0 third_party_settings: { } - field_crop_hero_image: - type: boolean_checkbox - weight: 16 - region: content - settings: - display_label: true - third_party_settings: { } field_display_hero_image: type: boolean_checkbox weight: 15 diff --git a/config/core.entity_view_display.node.article.card.yml b/config/core.entity_view_display.node.article.card.yml index 10561b20a..cce585fc9 100644 --- a/config/core.entity_view_display.node.article.card.yml +++ b/config/core.entity_view_display.node.article.card.yml @@ -6,7 +6,6 @@ dependencies: - core.entity_view_mode.node.card - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -90,7 +89,6 @@ content: hidden: field_base_objects: true field_chapter: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_article: true diff --git a/config/core.entity_view_display.node.article.card_summary.yml b/config/core.entity_view_display.node.article.card_summary.yml index 65f0f2332..f15ef80e0 100644 --- a/config/core.entity_view_display.node.article.card_summary.yml +++ b/config/core.entity_view_display.node.article.card_summary.yml @@ -6,7 +6,6 @@ dependencies: - core.entity_view_mode.node.card_summary - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -104,7 +103,6 @@ content: hidden: field_base_objects: true field_chapter: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_article: true diff --git a/config/core.entity_view_display.node.article.default.yml b/config/core.entity_view_display.node.article.default.yml index c48fba3c6..ff213de03 100644 --- a/config/core.entity_view_display.node.article.default.yml +++ b/config/core.entity_view_display.node.article.default.yml @@ -5,7 +5,6 @@ dependencies: config: - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -111,16 +110,6 @@ content: third_party_settings: { } weight: 7 region: content - field_crop_hero_image: - type: boolean - label: above - settings: - format: default - format_custom_false: '' - format_custom_true: '' - third_party_settings: { } - weight: 9 - region: content field_display_hero_image: type: boolean label: above diff --git a/config/core.entity_view_display.node.article.grid.yml b/config/core.entity_view_display.node.article.grid.yml index 55a19afce..b459984b5 100644 --- a/config/core.entity_view_display.node.article.grid.yml +++ b/config/core.entity_view_display.node.article.grid.yml @@ -6,7 +6,6 @@ dependencies: - core.entity_view_mode.node.grid - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -105,7 +104,6 @@ content: region: content hidden: field_base_objects: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_article: true diff --git a/config/core.entity_view_display.node.article.search_result.yml b/config/core.entity_view_display.node.article.search_result.yml index 9353d0ff1..bfb37e250 100644 --- a/config/core.entity_view_display.node.article.search_result.yml +++ b/config/core.entity_view_display.node.article.search_result.yml @@ -6,7 +6,6 @@ dependencies: - core.entity_view_mode.node.search_result - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -117,7 +116,6 @@ content: hidden: field_base_objects: true field_chapter: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_article: true diff --git a/config/core.entity_view_display.node.article.teaser.yml b/config/core.entity_view_display.node.article.teaser.yml index 2ec545934..031d240b3 100644 --- a/config/core.entity_view_display.node.article.teaser.yml +++ b/config/core.entity_view_display.node.article.teaser.yml @@ -6,7 +6,6 @@ dependencies: - core.entity_view_mode.node.teaser - field.field.node.article.field_base_objects - field.field.node.article.field_chapter - - field.field.node.article.field_crop_hero_image - field.field.node.article.field_display_hero_image - field.field.node.article.field_image - field.field.node.article.field_inherit_section_image @@ -47,7 +46,6 @@ content: hidden: field_base_objects: true field_chapter: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_article: true diff --git a/config/core.entity_view_display.node.document.default.yml b/config/core.entity_view_display.node.document.default.yml index 18bb3b7df..b3596d3d0 100644 --- a/config/core.entity_view_display.node.document.default.yml +++ b/config/core.entity_view_display.node.document.default.yml @@ -4,7 +4,6 @@ status: true dependencies: config: - field.field.node.document.field_base_objects - - field.field.node.document.field_crop_hero_image - field.field.node.document.field_display_hero_image - field.field.node.document.field_image - field.field.node.document.field_inherit_section_image @@ -101,16 +100,6 @@ content: third_party_settings: { } weight: 110 region: content - field_crop_hero_image: - type: boolean - label: above - settings: - format: default - format_custom_false: '' - format_custom_true: '' - third_party_settings: { } - weight: 114 - region: content field_display_hero_image: type: boolean label: above diff --git a/config/core.entity_view_display.node.document.search_result.yml b/config/core.entity_view_display.node.document.search_result.yml index c76a324a0..9de9a690a 100644 --- a/config/core.entity_view_display.node.document.search_result.yml +++ b/config/core.entity_view_display.node.document.search_result.yml @@ -5,7 +5,6 @@ dependencies: config: - core.entity_view_mode.node.search_result - field.field.node.document.field_base_objects - - field.field.node.document.field_crop_hero_image - field.field.node.document.field_display_hero_image - field.field.node.document.field_image - field.field.node.document.field_inherit_section_image @@ -104,7 +103,6 @@ content: region: content hidden: field_base_objects: true - field_crop_hero_image: true field_display_hero_image: true field_inherit_section_image: true field_remote_document: true diff --git a/config/core.entity_view_display.node.document.teaser.yml b/config/core.entity_view_display.node.document.teaser.yml index 731935200..73dc36b38 100644 --- a/config/core.entity_view_display.node.document.teaser.yml +++ b/config/core.entity_view_display.node.document.teaser.yml @@ -5,7 +5,6 @@ dependencies: config: - core.entity_view_mode.node.teaser - field.field.node.document.field_base_objects - - field.field.node.document.field_crop_hero_image - field.field.node.document.field_display_hero_image - field.field.node.document.field_image - field.field.node.document.field_inherit_section_image @@ -29,7 +28,6 @@ content: region: content hidden: field_base_objects: true - field_crop_hero_image: true field_display_hero_image: true field_image: true field_inherit_section_image: true diff --git a/config/crop.type.14x5.yml b/config/crop.type.14x5.yml index afac7b4e3..850c7b13f 100644 --- a/config/crop.type.14x5.yml +++ b/config/crop.type.14x5.yml @@ -2,7 +2,7 @@ uuid: 14c68939-0df4-4319-b4c6-14c3d62e9763 langcode: en status: true dependencies: { } -label: 14x5 +label: 'On page (14x5)' id: 14x5 description: 'Letterbox size for hero images' aspect_ratio: '14:5' diff --git a/config/crop.type.16x9.yml b/config/crop.type.16x9.yml index 4e63861f1..b4307c085 100644 --- a/config/crop.type.16x9.yml +++ b/config/crop.type.16x9.yml @@ -2,7 +2,7 @@ uuid: 0990d642-014f-438c-8f6a-e13c90907019 langcode: en status: true dependencies: { } -label: 16x9 +label: 'In links (16x9)' id: 16x9 description: 'Card size for galleries' aspect_ratio: '16:9' diff --git a/config/field.field.node.article.field_crop_hero_image.yml b/config/field.field.node.article.field_crop_hero_image.yml deleted file mode 100644 index 87759f44c..000000000 --- a/config/field.field.node.article.field_crop_hero_image.yml +++ /dev/null @@ -1,23 +0,0 @@ -uuid: 8cd368b1-7055-4de1-8021-2d476c20b5c1 -langcode: en -status: true -dependencies: - config: - - field.storage.node.field_crop_hero_image - - node.type.article -id: node.article.field_crop_hero_image -field_name: field_crop_hero_image -entity_type: node -bundle: article -label: 'Crop hero image' -description: 'Check this to apply cropping to the hero image' -required: false -translatable: false -default_value: - - - value: 1 -default_value_callback: '' -settings: - on_label: 'On' - off_label: 'Off' -field_type: boolean diff --git a/config/field.field.node.article.field_display_hero_image.yml b/config/field.field.node.article.field_display_hero_image.yml index 7c2d8cc49..3b84b128d 100644 --- a/config/field.field.node.article.field_display_hero_image.yml +++ b/config/field.field.node.article.field_display_hero_image.yml @@ -10,7 +10,7 @@ field_name: field_display_hero_image entity_type: node bundle: article label: 'Display hero image' -description: 'Display a hero image on the top of the article page.' +description: 'Display a hero image on the top of the article page and when showing links to the article page.' required: false translatable: false default_value: diff --git a/config/field.field.node.article.field_inherit_section_image.yml b/config/field.field.node.article.field_inherit_section_image.yml index 37f4cf0e2..1ced0b9de 100644 --- a/config/field.field.node.article.field_inherit_section_image.yml +++ b/config/field.field.node.article.field_inherit_section_image.yml @@ -10,12 +10,12 @@ field_name: field_inherit_section_image entity_type: node bundle: article label: 'Inherit document image' -description: 'If checked and this article is displayed as a subpage of a document, the hero image will be taken from the document instead of the article.' +description: "If checked and this article is displayed as a subpage of a document, the hero image on the article page will be taken from the document instead of the article. Links to the article will continue to use the article's own image if available." required: false translatable: true default_value: - - value: 1 + value: 0 default_value_callback: '' settings: on_label: 'On' diff --git a/config/field.field.node.document.field_crop_hero_image.yml b/config/field.field.node.document.field_crop_hero_image.yml deleted file mode 100644 index 6a2db15ee..000000000 --- a/config/field.field.node.document.field_crop_hero_image.yml +++ /dev/null @@ -1,23 +0,0 @@ -uuid: 623f0fbd-4fd0-49eb-b6c3-0ce3b6aa68a4 -langcode: en -status: true -dependencies: - config: - - field.storage.node.field_crop_hero_image - - node.type.document -id: node.document.field_crop_hero_image -field_name: field_crop_hero_image -entity_type: node -bundle: document -label: 'Crop hero image' -description: 'Check this to apply cropping to the hero image' -required: false -translatable: false -default_value: - - - value: 1 -default_value_callback: '' -settings: - on_label: 'On' - off_label: 'Off' -field_type: boolean diff --git a/config/field.storage.node.field_crop_hero_image.yml b/config/field.storage.node.field_crop_hero_image.yml deleted file mode 100644 index 2c2821c89..000000000 --- a/config/field.storage.node.field_crop_hero_image.yml +++ /dev/null @@ -1,18 +0,0 @@ -uuid: 386a50eb-f798-4e38-adac-70870526bf1a -langcode: en -status: true -dependencies: - module: - - node -id: node.field_crop_hero_image -field_name: field_crop_hero_image -entity_type: node -type: boolean -settings: { } -module: core -locked: false -cardinality: 1 -translatable: true -indexes: { } -persist_with_no_fields: false -custom_storage: false diff --git a/html/modules/custom/ghi_content/ghi_content.module b/html/modules/custom/ghi_content/ghi_content.module index 67aae1141..a111446c7 100644 --- a/html/modules/custom/ghi_content/ghi_content.module +++ b/html/modules/custom/ghi_content/ghi_content.module @@ -7,11 +7,13 @@ use Drupal\Core\Batch\BatchBuilder; use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; +use Drupal\file\Plugin\Field\FieldType\FileFieldItemList; use Drupal\ghi_content\Controller\MigrationBatchController; use Drupal\ghi_content\Entity\Article; use Drupal\ghi_content\Entity\ContentBase; @@ -284,12 +286,7 @@ function ghi_content_preprocess_page(&$variables) { return; } - $crop_image = TRUE; - if ($image_node instanceof ContentBase) { - $crop_image = $image_node->shouldCropHeroImage(); - } - - $image_style_name = $crop_image ? 'hero' : 'hero_not_cropped'; + $image_style_name = 'hero'; // Go through some trouble to show a responsive image here. $repsonsive_image_style_id = $image_style_name; @@ -380,6 +377,20 @@ function ghi_content_preprocess_node(&$variables) { ]; } + if ($node instanceof ContentBase && !$node->shouldDisplayHeroImage()) { + // If the article is configured to hide the image, hide it everywhere. + /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $view_mode_entity */ + $view_mode_entity = EntityViewDisplay::load('node.article.' . $variables['view_mode']); + /** @var \Drupal\file\Plugin\Field\FieldType\FileFieldItemList $items */ + $items = $node->field_image; + if ($view_mode_entity && $items instanceof FileFieldItemList) { + $items->filter(function ($item) { + return FALSE; + }); + $variables['content']['field_image'] = $view_mode_entity->getRenderer('field_image')->view($items); + } + } + if ($node instanceof Document) { $variables['document_summary'] = $node->getSummary(); } diff --git a/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php b/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php index 03a0e82ae..0cd6b27ad 100644 --- a/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php +++ b/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php @@ -684,14 +684,6 @@ public function nodeEditFormAlter(array &$form, FormStateInterface $form_state) $form['field_display_hero_image']['widget']['value']['#default_value'] = TRUE; } - // If the hero image crop checkbox is NULL (never actively saved), we - // want to make sure that it shows as selected, which is the default state - // for new content pages. - $crop_hero_image = $node->get('field_crop_hero_image')->value; - if ($crop_hero_image === NULL) { - $form['field_crop_hero_image']['widget']['value']['#default_value'] = TRUE; - } - // If the inherit section image control checkbox is NULL (never actively // saved), we want to make sure that it shows as selected, which is the // default state for new content pages. diff --git a/html/modules/custom/ghi_content/src/Entity/ContentBase.php b/html/modules/custom/ghi_content/src/Entity/ContentBase.php index f8cc7f986..7ce732e6e 100644 --- a/html/modules/custom/ghi_content/src/Entity/ContentBase.php +++ b/html/modules/custom/ghi_content/src/Entity/ContentBase.php @@ -301,20 +301,6 @@ public function shouldDisplayHeroImage() { return $display_hero_image == 1 || $display_hero_image === NULL; } - /** - * Check if the current node can and should crop the hero image. - * - * @return bool - * TRUE if a hero image, if available, should be cropped, FALSE otherwise. - */ - public function shouldCropHeroImage() { - if (!$this->hasField('field_crop_hero_image')) { - return FALSE; - } - $crop_hero_image = $this->get('field_crop_hero_image')->value; - return $crop_hero_image == 1 || $crop_hero_image === NULL; - } - /** * {@inheritdoc} */ diff --git a/html/modules/custom/ghi_hero_image/ghi_hero_image.module b/html/modules/custom/ghi_hero_image/ghi_hero_image.module index 0c7d32913..aae8a2452 100644 --- a/html/modules/custom/ghi_hero_image/ghi_hero_image.module +++ b/html/modules/custom/ghi_hero_image/ghi_hero_image.module @@ -66,14 +66,11 @@ function ghi_hero_image_preprocess_page(&$variables) { // show a default image or the image from a parent node. $hero_image_field = $node->get($hero_image_field_definition->getName()); - // See if the image should be cropped. - $crop_image = $hero_image_field?->first()?->getValue()['settings']['crop_image'] ?? TRUE; - // Get the hero image for the current page. $hero_image = $hero_image_field->view([ 'label' => 'hidden', 'settings' => [ - 'responsive_image_style' => $crop_image ? 'hero' : 'hero_not_cropped', + 'responsive_image_style' => 'hero', 'image_link' => NULL, 'include_credits' => TRUE, ], @@ -139,14 +136,19 @@ function ghi_hero_image_form_alter(array &$form, FormStateInterface $form_state) if (!empty($form['image_crop']) && !empty($form['field_hero_image'])) { $form['image_crop']['#states'] = [ 'visible' => [ - ':input[name="field_hero_image[0][settings][crop_image]"]' => ['checked' => TRUE], + [ + ':input[name="field_hero_image[0][source]"]' => ['value' => 'hpc_webcontent_file_attachment'], + ], + [ + ':input[name="field_hero_image[0][source]"]' => ['value' => 'smugmug_api'], + ], ], ]; } - if (!empty($form['image_crop']) && !empty($form['field_crop_hero_image'])) { + if (!empty($form['image_crop']) && !empty($form['field_display_hero_image'])) { $form['image_crop']['#states'] = [ 'visible' => [ - ':input[name="field_crop_hero_image[value]"]' => ['checked' => TRUE], + ':input[name="field_display_hero_image[value]"]' => ['checked' => TRUE], ], ]; } diff --git a/html/modules/custom/ghi_hero_image/src/Element/HeroImageCrop.php b/html/modules/custom/ghi_hero_image/src/Element/HeroImageCrop.php index 4fbd3b74c..c26e73de4 100644 --- a/html/modules/custom/ghi_hero_image/src/Element/HeroImageCrop.php +++ b/html/modules/custom/ghi_hero_image/src/Element/HeroImageCrop.php @@ -72,7 +72,7 @@ public static function processCrop(array &$element, FormStateInterface $form_sta } $element['crop_wrapper'] = [ '#type' => 'details', - '#title' => t('Crop image'), + '#title' => t('Adjust image cropping'), '#attributes' => [ 'class' => ['image-data__crop-wrapper'], 'data-drupal-iwc' => 'wrapper', diff --git a/html/modules/custom/ghi_hero_image/src/HeroImageWidgetCropManager.php b/html/modules/custom/ghi_hero_image/src/HeroImageWidgetCropManager.php index 387eb1803..366228407 100644 --- a/html/modules/custom/ghi_hero_image/src/HeroImageWidgetCropManager.php +++ b/html/modules/custom/ghi_hero_image/src/HeroImageWidgetCropManager.php @@ -214,6 +214,11 @@ public function contentEntityFormAlter(array &$form, FormStateInterface $form_st continue; } + // If a newer value for the image is avialble, use that. + if ($form_state->hasValue($field_name)) { + $entity->get($field_name)->setValue($form_state->getValue($field_name)); + } + $file = NULL; $field = $entity->get($field_name); /** @var \Drupal\file\Plugin\Field\FieldType\FileFieldItemList $field_image */ @@ -257,6 +262,9 @@ public function contentEntityFormAlter(array &$form, FormStateInterface $form_st * Submit handler for content entity forms using the crop api. */ public function contentEntityFormCropSubmit(array &$form, FormStateInterface $form_state) { + if (empty($form['image_crop'])) { + return; + } $crop_type_names = self::CROP_TYPES; $form_state_values = $form_state->getValues(); $file = $form['image_crop']['image_crop']['#file']; diff --git a/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldWidget/HeroImageWidget.php b/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldWidget/HeroImageWidget.php index 8371793eb..fea5989b2 100644 --- a/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldWidget/HeroImageWidget.php +++ b/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldWidget/HeroImageWidget.php @@ -2,6 +2,7 @@ namespace Drupal\ghi_hero_image\Plugin\Field\FieldWidget; +use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; @@ -31,6 +32,13 @@ class HeroImageWidget extends WidgetBase { */ public $smugmugUser; + /** + * A wrapper id for ajax replace actions. + * + * @var string + */ + protected $ajaxWrapperId; + /** * {@inheritdoc} */ @@ -49,7 +57,6 @@ public static function defaultSettings() { 'settings' => [ 'hpc_webcontent_file_attachment' => NULL, 'smugmug_api' => NULL, - 'crop_image' => TRUE, ], ] + parent::defaultSettings(); } @@ -61,6 +68,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $form_object = $form_state->getFormObject(); $entity = $form_object instanceof EntityFormInterface ? $form_object->getEntity() : NULL; + $this->ajaxWrapperId = Html::getUniqueId($form_state->getFormObject()->getFormId() . '-ajax-wrapper'); + + // Add a wrapper for ajax actions. + $element['#prefix'] = '
'; + $element['#suffix'] = '
'; + $element['add_more']['#ajax']['wrapper'] = $this->ajaxWrapperId; // See if we have a plan context. $plan_object = NULL; @@ -90,6 +103,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#title' => $element['#title'], '#options' => $source_options, '#default_value' => $items[$delta]->source ?? array_key_first($source_options), + '#ajax' => [ + 'event' => 'change', + 'wrapper' => $this->ajaxWrapperId, + ], ]; $element['settings'] = [ @@ -124,12 +141,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#smugmug_user_scope' => $smugmug_ocha, ]; - $element['settings']['crop_image'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Crop image'), - '#default_value' => $items[$delta]->settings['crop_image'] ?? TRUE, - ]; - return $element; } diff --git a/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php b/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php index ead52b0b9..a2ef4a1fb 100644 --- a/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php +++ b/html/modules/custom/ghi_plans/src/ApiObjects/Attachments/DataAttachment.php @@ -682,11 +682,14 @@ protected function extractValues() { * This fetches either the metrics from the attachment version, or from a * measurement if a published one is already present. * - * @return object - * A metric object. + * @return object|null + * A metric object or NULL. */ protected function getMetrics() { $attachment = $this->getRawData(); + if (!$attachment || !is_object($attachment)) { + return NULL; + } // Get the metrics from the attachment version by default. $metrics = $attachment->attachmentVersion->value->metrics; // If there are measurements, look at the most recent one and get the diff --git a/html/modules/custom/ghi_plans/src/ApiObjects/Organization.php b/html/modules/custom/ghi_plans/src/ApiObjects/Organization.php index 6dbe6a81f..accf55210 100644 --- a/html/modules/custom/ghi_plans/src/ApiObjects/Organization.php +++ b/html/modules/custom/ghi_plans/src/ApiObjects/Organization.php @@ -10,6 +10,13 @@ */ class Organization extends BaseObject { + /** + * A list of clusters. + * + * @var array + */ + public $clusters; + /** * Map the raw data. *