Commit fd12a755 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3271396 by RenatoG: Implement a validation to set errors when that is...

Issue #3271396 by RenatoG: Implement a validation to set errors when that is special chars on multiple classes when the settings to allow only letters, numbers, hyphen and underlines
parent f401a3b7
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -700,8 +700,37 @@ class BlockClassHelperService {
      return FALSE;
    }

    // Get the Third Party Settings from formState.
    $third_party_settings = $form_state->getValue('third_party_settings');

    if ($config->get('field_type') == 'multiple_textfields') {

      // Get the block class array from Third Party Settings.
      $multiple_items = $third_party_settings['block_class'];

      // Remove unnecessary values for this verification.
      unset($multiple_items['add_another_item']);
      unset($multiple_items['remove_item']);
      unset($multiple_items['attributes']);
      unset($multiple_items['classes']);

      // Run a foreach in all items.
      foreach ($multiple_items as $key => $item) {

        // Verify if there is a special char on this class.
        if (preg_match('/[\'^£$%&*()}{@#~?><>,|=+¬]/', $item)) {

          // If there is a special chat return the error for the user.
          $form_state->setErrorByName('class][third_party_settings][block_class][' . $key, $this->t("In class is allowed only letters, numbers, hyphen and underline"));

        }

      }

      return FALSE;

    }

    if (empty($third_party_settings['block_class']['classes'])) {
      return FALSE;
    }