You are here

function domain_source_form_node_form_alter in Domain Access 8

Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.

File

domain_source/domain_source.module, line 209
Domain-based path rewrites for content.

Code

function domain_source_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Add the options hidden from the user silently to the form.
  $manager = \Drupal::service('domain_source.element_manager');
  $hide = TRUE;
  $form = $manager
    ->setFormOptions($form, $form_state, DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD, $hide);

  // If using a select field, load the JS to show/hide options.
  if (isset($form[DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD]) && \Drupal::moduleHandler()
    ->moduleExists('domain_access') && isset($form[DomainAccessManagerInterface::DOMAIN_ACCESS_FIELD])) {
    if ($form[DomainSourceElementManagerInterface::DOMAIN_SOURCE_FIELD]['widget']['#type'] == 'select') {
      $form['#attached']['library'][] = 'domain_source/drupal.domain_source';
    }
  }
}