Skip to content

Commit

Permalink
Limit the accessible domain path settings to the active domain #509 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-cox authored Oct 29, 2024
1 parent f750099 commit e7242cb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions localgov_microsites_group.module
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
Expand Down Expand Up @@ -233,16 +234,21 @@ function localgov_microsites_group_form_user_login_form_alter(&$form, FormStateI
*/
function localgov_microsites_group_form_alter(&$form, FormStateInterface $form_state, $form_id) {

// Set domain path pathauto as on by default for new nodes.
if (
$form_state->getFormObject() instanceof EntityFormInterface &&
$form_state->getFormObject()->getEntity()->isNew() &&
isset($form['domain_path'])
) {
if (isset($form['domain_path'])) {
$domain_ids = Element::children($form['domain_path']);
$active_domain = \Drupal::service('domain.negotiator')->getActiveDomain();
foreach ($domain_ids as $id) {
if (isset($form['domain_path'][$id]['pathauto']) && $id == $active_domain->id()) {

// Hide path auto settings for all but the active domain.
if ($id !== $active_domain->id()) {
$form['domain_path'][$id]['#access'] = FALSE;
}

// Set domain path pathauto as on by default for new nodes.
elseif (
$form_state->getFormObject() instanceof EntityFormInterface &&
$form_state->getFormObject()->getEntity()->isNew()
) {
$form['domain_path'][$id]['pathauto']['#default_value'] = TRUE;
}
}
Expand Down

0 comments on commit e7242cb

Please sign in to comment.