Skip to content

Commit

Permalink
Add field_domain_access value to domain_path forms (#528)
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
stephen-cox authored Nov 26, 2024
1 parent f52b368 commit c39cd6d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion localgov_microsites_group.module
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
}

Expand Down

0 comments on commit c39cd6d

Please sign in to comment.