From 956461b26526e56134f6dc43a25953f057e2e17a Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 28 Nov 2024 14:51:44 +0000 Subject: [PATCH 1/4] adds field for guide navigation layout type --- ....node.localgov_guides_overview.default.yml | 7 +++++ ...s_overview.localgov_guides_list_layout.yml | 20 ++++++++++++++ ...orage.node.localgov_guides_list_layout.yml | 26 +++++++++++++++++++ src/Plugin/Block/GuidesContentsBlock.php | 12 +++++++++ 4 files changed, 65 insertions(+) create mode 100644 config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml create mode 100644 config/install/field.storage.node.localgov_guides_list_layout.yml diff --git a/config/install/core.entity_form_display.node.localgov_guides_overview.default.yml b/config/install/core.entity_form_display.node.localgov_guides_overview.default.yml index d096c88..6bc7d00 100644 --- a/config/install/core.entity_form_display.node.localgov_guides_overview.default.yml +++ b/config/install/core.entity_form_display.node.localgov_guides_overview.default.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - field.field.node.localgov_guides_overview.body + - field.field.node.localgov_guides_overview.localgov_guides_list_layout - field.field.node.localgov_guides_overview.localgov_guides_list_format - field.field.node.localgov_guides_overview.localgov_guides_pages - field.field.node.localgov_guides_overview.localgov_guides_section_title @@ -38,6 +39,12 @@ content: region: content settings: { } third_party_settings: { } + localgov_guides_list_layout: + type: options_select + weight: 4 + region: content + settings: { } + third_party_settings: { } localgov_guides_pages: type: localgov_entity_reference_labels weight: 14 diff --git a/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml b/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml new file mode 100644 index 0000000..3ee3302 --- /dev/null +++ b/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml @@ -0,0 +1,20 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.localgov_guides_list_layout + - node.type.localgov_guides_overview + module: + - options +id: node.localgov_guides_overview.localgov_guides_list_layout +field_name: localgov_guides_list_layout +entity_type: node +bundle: localgov_guides_overview +label: 'List Layout' +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: { } +field_type: list_string diff --git a/config/install/field.storage.node.localgov_guides_list_layout.yml b/config/install/field.storage.node.localgov_guides_list_layout.yml new file mode 100644 index 0000000..fa76db8 --- /dev/null +++ b/config/install/field.storage.node.localgov_guides_list_layout.yml @@ -0,0 +1,26 @@ +langcode: en +status: true +dependencies: + module: + - node + - options +id: node.localgov_guides_list_layout +field_name: localgov_guides_list_layout +entity_type: node +type: list_string +settings: + allowed_values: + - + value: horizontal + label: 'Horizontal (multiple columns)' + - + value: vertical + label: 'Vertical (single column)' + allowed_values_function: '' +module: options +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/src/Plugin/Block/GuidesContentsBlock.php b/src/Plugin/Block/GuidesContentsBlock.php index 9dee8b2..55a7cba 100644 --- a/src/Plugin/Block/GuidesContentsBlock.php +++ b/src/Plugin/Block/GuidesContentsBlock.php @@ -20,9 +20,17 @@ class GuidesContentsBlock extends GuidesAbstractBaseBlock { public function build() { $this->setPages(); $links = []; + $layout_type = FALSE; + $layout_type_field = $this->overview->get('localgov_guides_list_layout'); + + if (!empty($layout_type_field) && isset($layout_type_field->getValue()[0])) { + $layout_type = $layout_type_field->getValue()[0]['value']; + $layout_type = str_replace('_', '-', $layout_type); + } $options = $this->node->id() == $this->overview->id() ? ['attributes' => ['class' => 'active']] : []; $links[] = $this->overview->toLink($this->overview->localgov_guides_section_title->value, 'canonical', $options); + foreach ($this->guidePages as $guide_node) { $options = $this->node->id() == $guide_node->id() ? ['attributes' => ['class' => 'active']] : []; $links[] = $guide_node->toLink($guide_node->localgov_guides_section_title->value, 'canonical', $options); @@ -35,6 +43,10 @@ public function build() { '#format' => $this->format, ]; + if ($layout_type) { + $build['#attributes']['class'][] = 'block-localgov-guides-contents--' . $layout_type; + } + return $build; } From 1695cb959c100adc9751e7af5198b88f1e90a354 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 28 Nov 2024 14:57:06 +0000 Subject: [PATCH 2/4] adds default value --- ...e.localgov_guides_overview.localgov_guides_list_layout.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml b/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml index 3ee3302..95a2edb 100644 --- a/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml +++ b/config/install/field.field.node.localgov_guides_overview.localgov_guides_list_layout.yml @@ -14,7 +14,9 @@ label: 'List Layout' description: '' required: false translatable: false -default_value: { } +default_value: + - + value: vertical default_value_callback: '' settings: { } field_type: list_string From e8c306d2e9c5b717c21abed85f0d59bf6b3549e5 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Fri, 13 Dec 2024 15:46:17 +0000 Subject: [PATCH 3/4] adds check for field before acting on it --- src/Plugin/Block/GuidesContentsBlock.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Block/GuidesContentsBlock.php b/src/Plugin/Block/GuidesContentsBlock.php index 55a7cba..c9af694 100644 --- a/src/Plugin/Block/GuidesContentsBlock.php +++ b/src/Plugin/Block/GuidesContentsBlock.php @@ -21,11 +21,13 @@ public function build() { $this->setPages(); $links = []; $layout_type = FALSE; - $layout_type_field = $this->overview->get('localgov_guides_list_layout'); - if (!empty($layout_type_field) && isset($layout_type_field->getValue()[0])) { - $layout_type = $layout_type_field->getValue()[0]['value']; - $layout_type = str_replace('_', '-', $layout_type); + if ($this->overview->hasField('localgov_guides_list_layout')) { + $layout_type_field = $this->overview->get('localgov_guides_list_layout'); + if (!empty($layout_type_field) && isset($layout_type_field->getValue()[0])) { + $layout_type = $layout_type_field->getValue()[0]['value']; + $layout_type = str_replace('_', '-', $layout_type); + } } $options = $this->node->id() == $this->overview->id() ? ['attributes' => ['class' => 'active']] : []; From 246e88f210593ba573a1cbc5dd209dbfba1ee5b5 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Fri, 13 Dec 2024 16:16:48 +0000 Subject: [PATCH 4/4] fixes coding standards issue --- ...ocalgov_menu_link_group.localgov_menu_link_group_guide.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/optional/localgov_menu_link_group.localgov_menu_link_group.localgov_menu_link_group_guide.yml b/config/optional/localgov_menu_link_group.localgov_menu_link_group.localgov_menu_link_group_guide.yml index 972f2e6..d3fe254 100644 --- a/config/optional/localgov_menu_link_group.localgov_menu_link_group.localgov_menu_link_group_guide.yml +++ b/config/optional/localgov_menu_link_group.localgov_menu_link_group.localgov_menu_link_group_guide.yml @@ -3,8 +3,8 @@ status: true dependencies: enforced: module: - - localgov_guides - - localgov_menu_link_group + - localgov_guides + - localgov_menu_link_group id: localgov_menu_link_group_guide group_label: Guide weight: 0