You are here

function webform_node_field_widget_webform_entity_reference_autocomplete_form_alter in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_node/webform_node.module \webform_node_field_widget_webform_entity_reference_autocomplete_form_alter()

Implements hook_field_widget_WIDGET_TYPE_form_alter().

1 call to webform_node_field_widget_webform_entity_reference_autocomplete_form_alter()
webform_node_field_widget_webform_entity_reference_select_form_alter in modules/webform_node/webform_node.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().

File

modules/webform_node/webform_node.module, line 163
Provides a webform content type which allows webforms to be integrated into a website as nodes.

Code

function webform_node_field_widget_webform_entity_reference_autocomplete_form_alter(&$element, FormStateInterface $form_state, $context) {
  static $once;
  if (!empty($once)) {
    return;
  }
  $once = TRUE;

  // Make sure the 'target_id' is included.
  if (!isset($element['target_id'])) {
    return;
  }

  // Display a warning message if webform query string parameter is missing.
  if (empty($element['target_id']['#default_value'])) {
    $element['target_id']['#attributes']['class'][] = 'js-target-id-webform-node-references';
    $element['webform_node_references'] = [
      '#type' => 'webform_message',
      '#message_type' => 'info',
      '#message_close' => TRUE,
      '#message_id' => 'webform_node.references',
      '#message_storage' => WebformMessage::STORAGE_USER,
      '#message_message' => t('Webforms must first be <a href=":href">created</a> before referencing them.', [
        ':href' => Url::fromRoute('entity.webform.collection')
          ->toString(),
      ]),
      '#cache' => [
        'max-age' => 0,
      ],
      '#weight' => -10,
      '#states' => [
        'visible' => [
          '.js-target-id-webform-node-references' => [
            'value' => '',
          ],
        ],
      ],
    ];
  }
}