0

We're using the Domain Access module to assign content to different domains.

When creating new content the default domain record is checked, but not the others.

The desired behavior: Example.com should also be checked by default when creating new content. (regardless of the content type)

Where would this behavior be configured/coded?

enter image description here

Drupal Version: 9.5.11
Domain Access: 8.x-1.0-beta8

1
  • 1
    There isn't a setting to change the default value for that field, which actually is the domain where the node is created. A module could change the default value implementing hook_form_node_form_alter().
    – apaderno
    Jan 5 at 22:11

1 Answer 1

0

As @apaderno mentioned, one possible solution is to manipulate the form field (field_domain_access).

function module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  try {
    if (array_key_exists('field_domain_access', $form)) {
      $node = $form_state->getFormObject()->getEntity();

      if ($node->isNew()) {
        $form['field_domain_access']['widget']['#default_value'] = ['www_example_ch', 'www_example_com'];
      }
    }
  } catch(\Throwable $any) {
    \Drupal::logger('global')->info('Exception: %msg', ['%msg' => $any->getMessage() ]);;
  }
}

I'm not a big fan of this approach. Probably I don't understand the system good enough yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.