Skip to content

Commit

Permalink
(#4414) NCIDS 2 Column Updates - Image & Video
Browse files Browse the repository at this point in the history
Closes #4414
  • Loading branch information
dev-rana-publicis committed Oct 14, 2024
1 parent 1771e89 commit 17b479c
Show file tree
Hide file tree
Showing 43 changed files with 1,607 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountInterface;
Expand Down Expand Up @@ -89,3 +90,31 @@ function cgov_home_landing_form_node_form_alter(&$form, \Drupal\Core\Form\FormSt

return $form;
}

/**
* Implements hook_ENTITY_TYPE_view().
*
* This changes the view mode of the image for
* ncids_image so it renders with the proper aspect ratio.
*/
function cgov_home_landing_paragraph_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
$bundle = $entity->bundle();
if ($bundle === 'ncids_image') {
// Note for tech review:
// PHPStan would produce an error with $entity->get('field_image_aspect_ratio')->value;
// and $entity->field_image_aspect_ratio->value; and therefore wouldn't pass `blt validate`.
$crop_display = $entity->toArray()['field_image_aspect_ratio'][0]['value'];
// Only rebuild the items if there are some.
if (
array_key_exists('#items', $build['field_override_image_promotional']) &&
(count($build['field_override_image_promotional']['#items']) > 0)
) {
$build['field_override_image_promotional'] = $build['field_override_image_promotional']['#items']->view([
'type' => 'entity_reference_entity_view',
'settings' => [
'view_mode' => $crop_display,
],
]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
langcode: en
status: true
dependencies:
config:
- entity_browser.browser.cgov_image_browser
- field.field.paragraph.ncids_image.field_image_aspect_ratio
- field.field.paragraph.ncids_image.field_override_image_promotional
- paragraphs.paragraphs_type.ncids_image
module:
- entity_browser
id: paragraph.ncids_image.default
targetEntityType: paragraph
bundle: ncids_image
mode: default
content:
field_image_aspect_ratio:
type: options_select
weight: 0
region: content
settings: { }
third_party_settings: { }
field_override_image_promotional:
type: entity_browser_entity_reference
weight: 1
region: content
settings:
entity_browser: cgov_image_browser
field_widget_display: rendered_entity
field_widget_edit: false
field_widget_remove: true
field_widget_replace: false
open: false
field_widget_display_settings:
view_mode: image_reference_field_form
selection_mode: selection_append
third_party_settings: { }
hidden:
created: true
status: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
langcode: en
status: true
dependencies:
config:
- entity_browser.browser.cgov_video_browser
- field.field.paragraph.ncids_video.field_featured_video
- paragraphs.paragraphs_type.ncids_video
module:
- entity_browser
id: paragraph.ncids_video.default
targetEntityType: paragraph
bundle: ncids_video
mode: default
content:
field_featured_video:
type: entity_browser_entity_reference
weight: 0
region: content
settings:
entity_browser: cgov_video_browser
field_widget_display: rendered_entity
field_widget_edit: false
field_widget_remove: true
field_widget_replace: false
open: false
field_widget_display_settings:
view_mode: entity_browser_selected_entity
selection_mode: selection_append
third_party_settings: { }
hidden:
created: true
status: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.ncids_image.field_image_aspect_ratio
- field.field.paragraph.ncids_image.field_override_image_promotional
- paragraphs.paragraphs_type.ncids_image
module:
- options
id: paragraph.ncids_image.default
targetEntityType: paragraph
bundle: ncids_image
mode: default
content:
field_image_aspect_ratio:
type: list_default
label: above
settings: { }
third_party_settings: { }
weight: 5
region: content
field_override_image_promotional:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: ncids_aspect_ratio_16_9
link: false
third_party_settings: { }
weight: 4
region: content
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
langcode: en
status: true
dependencies:
config:
- field.field.paragraph.ncids_video.field_featured_video
- paragraphs.paragraphs_type.ncids_video
id: paragraph.ncids_video.default
targetEntityType: paragraph
bundle: ncids_video
mode: default
content:
field_featured_video:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: video_display_ncids_video
link: false
third_party_settings: { }
weight: 0
region: content
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_image_aspect_ratio
- paragraphs.paragraphs_type.ncids_image
module:
- options
id: paragraph.ncids_image.field_image_aspect_ratio
field_name: field_image_aspect_ratio
entity_type: paragraph
bundle: ncids_image
label: 'Image Crop Display'
description: 'Sets the aspect ratio for the image at 1:1, 4:3, or 16:9.'
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_override_image_promotional
- media.type.cgov_image
- paragraphs.paragraphs_type.ncids_image
id: paragraph.ncids_image.field_override_image_promotional
field_name: field_override_image_promotional
entity_type: paragraph
bundle: ncids_image
label: 'Promotional Image'
description: 'Image with caption to be added to the 2 Column Layout'
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:media'
handler_settings:
target_bundles:
cgov_image: cgov_image
sort:
field: _none
direction: ASC
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ dependencies:
- paragraphs.paragraphs_type.ncids_feature_card_external
- paragraphs.paragraphs_type.ncids_feature_card_internal
- paragraphs.paragraphs_type.ncids_feature_card_multimedia
- paragraphs.paragraphs_type.ncids_image
- paragraphs.paragraphs_type.ncids_mlp_two_column_layout
- paragraphs.paragraphs_type.ncids_summary_box
- paragraphs.paragraphs_type.ncids_video
module:
- entity_reference_revisions
id: paragraph.ncids_mlp_two_column_layout.field_right_content
Expand All @@ -32,6 +34,8 @@ settings:
ncids_feature_card_multimedia: ncids_feature_card_multimedia
ncids_summary_box: ncids_summary_box
cgov_card_raw_html: cgov_card_raw_html
ncids_image: ncids_image
ncids_video: ncids_video
negate: 0
target_bundles_drag_drop:
body_section:
Expand Down Expand Up @@ -151,6 +155,9 @@ settings:
ncids_feature_card_multimedia:
weight: 63
enabled: true
ncids_flag_card_group:
weight: 95
enabled: false
ncids_guide_card:
weight: 94
enabled: false
Expand All @@ -160,6 +167,9 @@ settings:
ncids_hero:
weight: 96
enabled: false
ncids_image:
weight: 99
enabled: true
ncids_inline_video:
weight: 97
enabled: false
Expand Down Expand Up @@ -190,6 +200,9 @@ settings:
ncids_two_column_container:
weight: 105
enabled: false
ncids_video:
weight: 111
enabled: true
pdq_summary_section:
weight: 106
enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
langcode: en
status: true
dependencies:
config:
- field.storage.paragraph.field_featured_video
- media.type.cgov_video
- paragraphs.paragraphs_type.ncids_video
id: paragraph.ncids_video.field_featured_video
field_name: field_featured_video
entity_type: paragraph
bundle: ncids_video
label: 'Featured Video'
description: 'Video with caption to be added to the 2 Column Layout'
required: true
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: cgov_all_selection
handler_settings:
target_bundles:
cgov_video: cgov_video
sort:
field: _none
direction: ASC
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
langcode: en
status: true
dependencies:
module:
- options
- paragraphs
id: paragraph.field_image_aspect_ratio
field_name: field_image_aspect_ratio
entity_type: paragraph
type: list_string
settings:
allowed_values:
-
value: ncids_aspect_ratio_1_1
label: 1x1
-
value: ncids_aspect_ratio_4_3
label: 4x3
-
value: ncids_aspect_ratio_16_9
label: 16x9
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies: { }
id: ncids_image
label: 'NCIDS Image'
icon_uuid: null
icon_default: null
description: 'Image and caption to be displayed on Mini Landing Page'
behavior_plugins: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies: { }
id: ncids_video
label: 'NCIDS Video'
icon_uuid: null
icon_default: null
description: 'Video and caption to be displayed on Mini Landing Page'
behavior_plugins: { }
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,16 @@ function cgov_image_update_10003() {
$assigner->assignConfigPackages();
$result = $service->import(['cgov_image']);
}

/**
* Update for NCIDS Image.
*
* Force installation of core.entity_view_mode.media.ncids_aspect_ratio
* before node core.entity_view_display configs are loaded.
*/
function cgov_image_update_10004() {
$service = \Drupal::service('features.manager');
$assigner = \Drupal::service('features_assigner');
$assigner->assignConfigPackages();
$result = $service->import(['cgov_image']);
}
Loading

0 comments on commit 17b479c

Please sign in to comment.