Skip to content

Commit 1259eb9

Browse files
committed
Add services parent to subsite views #148
1 parent 8a77a19 commit 1259eb9

3 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
langcode: en
2+
status: true
3+
dependencies:
4+
config:
5+
- field.storage.node.localgov_services_parent
6+
- node.type.localgov_subsites_overview
7+
- node.type.localgov_services_landing
8+
- node.type.localgov_services_sublanding
9+
id: node.localgov_subsites_overview.localgov_services_parent
10+
field_name: localgov_services_parent
11+
entity_type: node
12+
bundle: localgov_subsites_overview
13+
label: 'Parent page'
14+
description: ''
15+
required: false
16+
translatable: true
17+
default_value: { }
18+
default_value_callback: ''
19+
settings:
20+
handler: localgov_services
21+
handler_settings:
22+
target_bundles:
23+
localgov_services_landing: localgov_services_landing
24+
localgov_services_sublanding: localgov_services_sublanding
25+
field_type: entity_reference

localgov_subsites.install

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
* LocalGov Subsites install file.
66
*/
77

8+
/**
9+
* Implements hook_install()
10+
*/
11+
function localgov_subsites_install() {
12+
13+
if (\Drupal::moduleHandler()->moduleExists('localgov_services_navigation')) {
14+
localgov_subsites_optional_fields_settings();
15+
}
16+
}
17+
818
/**
919
* Clear caches after moving subsites paragraphs to localgov_paragraphs.
1020
*/

localgov_subsites.module

+40
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LocalGov Subsites module file.
66
*/
77

8+
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
89
use Drupal\localgov_roles\RolesHelper;
910
use Drupal\localgov_subsites\Subsite;
1011
use Drupal\node\NodeInterface;
@@ -142,3 +143,42 @@ function localgov_subsites_preprocess_page(&$variables) {
142143
}
143144
}
144145
}
146+
147+
/**
148+
* Set form settings for optional services fields on installation.
149+
*/
150+
function localgov_subsites_optional_fields_settings() {
151+
152+
$form_displays = \Drupal::entityTypeManager()
153+
->getStorage('entity_form_display')
154+
->loadByProperties([
155+
'targetEntityType' => 'node',
156+
'bundle' => 'localgov_subsites_overview',
157+
]);
158+
if ($form_displays) {
159+
foreach ($form_displays as $form_display) {
160+
assert($form_display instanceof EntityFormDisplayInterface);
161+
if (!$form_display->getComponent('localgov_services_parent')) {
162+
$form_display->setComponent('localgov_services_parent', [
163+
'type' => 'entity_reference_autocomplete',
164+
'region' => 'content',
165+
'settings' => [
166+
'match_operator' => 'CONTAINS',
167+
'size' => '60',
168+
'placeholder' => '',
169+
'match_limit' => 10,
170+
],
171+
'weight' => -1,
172+
])->save();
173+
if (
174+
($field_groups = $form_display->getThirdPartySettings('field_group')) &&
175+
($group = $field_groups['group_description'] ?? FALSE)
176+
) {
177+
$group['children'][] = 'localgov_services_parent';
178+
$form_display->setThirdPartySetting('field_group', 'group_description', $group)
179+
->save();
180+
}
181+
}
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)