From c39cd6d73d79ab77526e8dbcd372beb81b69bbd0 Mon Sep 17 00:00:00 2001 From: Stephen Cox Date: Tue, 26 Nov 2024 12:35:37 +0000 Subject: [PATCH] Add field_domain_access value to domain_path forms (#528) undefined --- localgov_microsites_group.module | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/localgov_microsites_group.module b/localgov_microsites_group.module index b7cda53..2825dc3 100644 --- a/localgov_microsites_group.module +++ b/localgov_microsites_group.module @@ -237,21 +237,37 @@ function localgov_microsites_group_form_alter(&$form, FormStateInterface $form_s if (isset($form['domain_path'])) { $domain_ids = Element::children($form['domain_path']); $active_domain = \Drupal::service('domain.negotiator')->getActiveDomain(); + $domain_access = []; foreach ($domain_ids as $id) { // Hide path auto settings for all but the active domain. if ($id !== $active_domain->id()) { $form['domain_path'][$id]['#access'] = FALSE; } + else { + $domain_access[] = ['target_id' => $id]; + } // Set domain path pathauto as on by default for new nodes. - elseif ( + if ( $form_state->getFormObject() instanceof EntityFormInterface && $form_state->getFormObject()->getEntity()->isNew() ) { $form['domain_path'][$id]['pathauto']['#default_value'] = TRUE; } } + + // The Domain Path module does a lot of checks for domain access + // configuration, but we use the Group module for access checks. Adding the + // domain access field to the form ensures the Domain Path checks pass, but + // is a bit of a hack as it would be better to fix whatever is going wrong + // in the Domain Path module. + if (!isset($form['field_domain_access'])) { + $form['field_domain_access'] = [ + '#type' => 'value', + '#value' => $domain_access, + ]; + } } }