|
5 | 5 | * LocalGov Subsites module file.
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +use Drupal\Core\Entity\Display\EntityFormDisplayInterface; |
8 | 9 | use Drupal\localgov_roles\RolesHelper;
|
9 | 10 | use Drupal\localgov_subsites\Subsite;
|
10 | 11 | use Drupal\node\NodeInterface;
|
@@ -142,3 +143,42 @@ function localgov_subsites_preprocess_page(&$variables) {
|
142 | 143 | }
|
143 | 144 | }
|
144 | 145 | }
|
| 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