Commit 9abbb94b authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3272348 by RenatoG: Form validation with special chars isn't working for the attributes

parent 0113befc
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -701,11 +701,6 @@ class BlockClassHelperService {

    }

    // If it's only one line, skip.
    if (!str_contains($attributes, PHP_EOL)) {
      return FALSE;
    }

    $attributes = explode(PHP_EOL, $attributes);

    foreach ($attributes as $attribute) {
@@ -718,6 +713,30 @@ class BlockClassHelperService {

      }

      // Get the attributes values as array.
      $attribute_array = explode('|', $attribute);

      // Get the attribute key.
      $attribute_key = $attribute_array[0];

      // Get the attribute value.
      $attribute_value = $attribute_array[1];

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

        // Get the URL of Global settings page.
        $url_settings_page = Url::fromRoute('block_class.settings')->toString();

        // If there is a special char show the information.
        $form_state->setErrorByName('attributes][third_party_settings][block_class][attributes', $this->t('Special chars is not enabled. To enable this, go to the <a href="@url_settings_page@">settings page</a>', [
          '@url_settings_page@' => $url_settings_page,
        ]));

        return FALSE;

      }

    }

  }