You are here

function _editor_button_link_attributes_validate in Editor Button Link 8

Filter empty attributes to avoid empty HTML output.

1 string reference to '_editor_button_link_attributes_validate'
editor_button_link_form_editor_link_dialog_alter in ./editor_button_link.module
Implements hook_form_FORM_ID_alter().

File

./editor_button_link.module, line 125
Button link styles.

Code

function _editor_button_link_attributes_validate(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValue('attributes');
  $link_element = $form_state
    ->get('link_element');
  foreach ($values as $key => $value) {
    if (empty($value)) {
      $form_state
        ->setValue([
        'attributes',
        $key,
      ], '');

      // Special case on content creation.
      if (empty($link_element)) {
        $form_state
          ->unsetValue([
          'attributes',
          $key,
        ]);
      }
    }
  }
}