Skip to content

Add services parent to subsite overviews #148 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ content:
type: layout_paragraphs
region: content
localgov_subsites_parent:
weight: -3
weight: -6
settings:
match_operator: CONTAINS
match_limit: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ id: node.localgov_subsites_page.localgov_subsites_parent
field_name: localgov_subsites_parent
entity_type: node
bundle: localgov_subsites_page
label: Parent
label: 'Subsite parent page'
description: ''
required: true
translatable: false
Expand All @@ -25,6 +25,7 @@ settings:
localgov_subsites_page: localgov_subsites_page
sort:
field: _none
direction: ASC
auto_create: false
auto_create_bundle: localgov_subsites_overview
weight_min: -50
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.localgov_services_parent
- node.type.localgov_subsites_overview
- node.type.localgov_services_landing
- node.type.localgov_services_sublanding
id: node.localgov_subsites_overview.localgov_services_parent
field_name: localgov_services_parent
entity_type: node
bundle: localgov_subsites_overview
label: 'Service parent page'
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
handler: localgov_services
handler_settings:
target_bundles:
localgov_services_landing: localgov_services_landing
localgov_services_sublanding: localgov_services_sublanding
field_type: entity_reference
13 changes: 13 additions & 0 deletions localgov_subsites.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
* LocalGov Subsites install file.
*/

/**
* Implements hook_install().
*/
function localgov_subsites_install($is_syncing) {
if ($is_syncing) {
return;
}

if (\Drupal::moduleHandler()->moduleExists('localgov_services_navigation')) {
localgov_subsites_optional_fields_settings();
}
}

/**
* Clear caches after moving subsites paragraphs to localgov_paragraphs.
*/
Expand Down
40 changes: 40 additions & 0 deletions localgov_subsites.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LocalGov Subsites module file.
*/

use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\localgov_roles\RolesHelper;
use Drupal\localgov_subsites\Subsite;
use Drupal\node\NodeInterface;
Expand Down Expand Up @@ -142,3 +143,42 @@ function localgov_subsites_preprocess_page(&$variables) {
}
}
}

/**
* Set form settings for optional services fields on installation.
*/
function localgov_subsites_optional_fields_settings() {

$form_displays = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->loadByProperties([
'targetEntityType' => 'node',
'bundle' => 'localgov_subsites_overview',
]);
if ($form_displays) {
foreach ($form_displays as $form_display) {
assert($form_display instanceof EntityFormDisplayInterface);
if (!$form_display->getComponent('localgov_services_parent')) {
$form_display->setComponent('localgov_services_parent', [
'type' => 'entity_reference_autocomplete',
'region' => 'content',
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'placeholder' => '',
'match_limit' => 10,
],
'weight' => -1,
])->save();
if (
($field_groups = $form_display->getThirdPartySettings('field_group')) &&
($group = $field_groups['group_description'] ?? FALSE)
) {
$group['children'][] = 'localgov_services_parent';
$form_display->setThirdPartySetting('field_group', 'group_description', $group)
->save();
}
}
}
}
}