You are here

function linkit_form_editor_link_dialog_submit in Linkit 8.5

Handles the data-* attributes and href replacement when appropriate.

1 string reference to 'linkit_form_editor_link_dialog_submit'
linkit_form_editor_link_dialog_alter in ./linkit.module
Implements hook_form_FORM_ID_alter().

File

./linkit.module, line 123
Linkit hook implementations.

Code

function linkit_form_editor_link_dialog_submit(array &$form, FormStateInterface $form_state) {
  $link_element = $form_state
    ->get('link_element');
  $href = parse_url($form_state
    ->getValue([
    'attributes',
    'href',
  ]), PHP_URL_PATH);
  $href_dirty_check = parse_url($form_state
    ->getValue([
    'href_dirty_check',
  ]), PHP_URL_PATH);
  if ($href !== $href_dirty_check) {
    $form_state
      ->unsetValue([
      'attributes',
      'data-entity-type',
    ]);
    $form_state
      ->unsetValue([
      'attributes',
      'data-entity-uuid',
    ]);
    $form_state
      ->unsetValue([
      'attributes',
      'data-entity-substitution',
    ]);
  }
  $fields = [
    'href',
    'data-entity-type',
    'data-entity-uuid',
    'data-entity-substitution',
  ];
  foreach ($fields as $field_name) {
    $value = $form_state
      ->getValue([
      'attributes',
      $field_name,
    ]);
    if (empty($value)) {
      if (!empty($link_element)) {
        $form_state
          ->setValue([
          'attributes',
          $field_name,
        ], '');
      }
      else {
        $form_state
          ->unsetValue([
          'attributes',
          $field_name,
        ]);
      }
    }
  }
}