Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mb_strlen() error when saving an upload_or_link url #4278

Closed
swirtSJW opened this issue Sep 9, 2024 · 0 comments · Fixed by #4279
Closed

mb_strlen() error when saving an upload_or_link url #4278

swirtSJW opened this issue Sep 9, 2024 · 0 comments · Fixed by #4279
Assignees
Labels

Comments

@swirtSJW
Copy link
Contributor

swirtSJW commented Sep 9, 2024

Current Behavior

Trying to save a dataset with an upload_or_link url fails with the error
image

This is the result of this line in Drupal Core's FormValidator.php

    if (isset($elements['#maxlength']) && mb_strlen($elements['#value']) > $elements['#maxlength']) {
      $form_state->setError($elements, $this->t('@name cannot be longer than %max characters but is currently %length characters long.', ['@name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => mb_strlen($elements['#value'])]));
    }

If the maxlength is set, it will automatically try to validate the string.
It came from this commit
which introduced a default maxlength for many things. I believe the It was missed that upload_or_link should not have a maxlength applied (because it has multiple elements in an array).

image

Ultimately it is tied to a Drupal core bug
but that solution may be a ways off.

For now we should follow the existing pattern of

    // If a maxlength was set earlier, remove it as it is not allowed here.
    unset($element['#maxlength']);

Expected Behavior

Datasets save without error if they have a upload_or_link value supplied

Steps To Reproduce

  1. create a new dataset with a url for the upload
  2. save the dataset
  3. see error about mb_strlen being unhappy with being fed an array.

Relevant log output (optional)

-

Anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant