Problem/Motivation

Original problem statement

When I perform a search from the admin content view anyway the search field limits the input to 128 characters. This makes no sense to me, but at least who compiles the search form is aware of what's going on.

I had to struggle with a rest service that was duplicating for no apparent reasons my contents because it couldn't find entities with titles >128 characters.

What actually happens is that if part of the title (<128 characters) is provided (e.g., ?title=...) results are found, otherwise if the complete title is passed through the query, an empty view is returned, while the content is obviously there.

A fix has been proposed in the past, see here. Is there any reason about this design? What's your opinion?

Steps to reproduce

  1. Create a new standard Drupal instance with DrupalPod
  2. Once the site is ready, visit the home page
  3. Log into the website
  4. Go to the main content admin page
  5. In the title search field, input a long search string ("this is a really long search request that is supposed to go more than 128 characters as a test of an issue where text inputs are being limited by Drupal Views.")
  6. You will see the string cut off in the input field after 128 characters
  7. If you submit the search, inspect the url query parameter in the browser location field; you will see the search string truncated after 128 characters

Proposed resolution

Update the maxlength setting for string inputs to allow 256 characters instead of the default 128.

Remaining tasks

  1. Investigate whether new/updated tests are needed

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Update view exposed filter string input field to accept up to 256 characters (up from the default 128 as set by the Textfield render element)

Issue fork drupal-3119290

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

artsakenos created an issue. See original summary.

lendude’s picture

Category: Bug report » Feature request
Status: Active » Needs review
StatusFileSize
new701 bytes

Don't think it's design really, Drupal just defaults all text fields to 128 characters. But I wouldn't call this a bug either. (maybe the rest thing? didn't try to reproduce that, we would need clearer steps to reproduce for that)

This does what #1033982: Exposed filter for a string has a maximum of 128 characters did, except not for D6 :)

Do we require test coverage for this? Seems unneeded, but again, maybe for the rest thing if we can reproduce that?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jhedstrom’s picture

+++ b/core/modules/views/src/Plugin/views/filter/StringFilter.php
@@ -271,6 +271,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
+        '#maxlength' => NULL,

Perhaps a comment here noting the purpose of this. Unsure if a test is needed, but I suppose an existing test for this filter plugin could easily be updated to add a search that is more than 128 characters in length?

abhijith s’s picture

StatusFileSize
new79.41 KB
new98.67 KB

Applied patch #2 and it removes the maxlength attribute from title search.

Before patch:
before

After patch:
after

RTBC +1

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new197.14 KB
new207.52 KB

Test patch #2 after verifying the issue and confirmed the patch works.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update, +Novice

A reminder that just because a patch works, an issue may not be eligible for RTBC.

The issue summary is not complete. Will someone add the standard template and complete the sections, see Write an issue summary for an existing issue for guidance. Adding tag, this is also suitable for a novice task.

Comment #7 has asked for a comment to be added to the patch, that has not happened.

This issue does not have tests. Both #2 and #7 question the need for tests and how to do it but #7 suggests that an existing test for this filter plugin could be used. The issue summary has steps using the UI, perhaps with steps to reproduce this could be manually tested, if an automated test is not possible. Testing needs to be investigated.

The screenshots in #8 and #9 show that the maxlength element is removed. I am not convinced that this is proving that the problem stated in the Issue Summary has indeed been fixed. I am removing credit for the screenshots in #9 because they are duplicates and the RTBC is a simple 'this patch works'.

This is a feature request, lets get a patch for 9.5 and 10.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

reenaraghavan made their first commit to this issue’s fork.

reenaraghavan’s picture

StatusFileSize
new700 bytes
new621 bytes
amanshukla6158’s picture

Status: Needs work » Needs review
StatusFileSize
new700 bytes

patch for 10.0.x

Sonam goswami52’s picture

Patch #14 applied successfully on drupal 9.5 and drupal 10.0.x work fine and it looks good to me.
Thank you

rinku jacob 13’s picture

StatusFileSize
new421.9 KB

I have tested the patch #14 on drupal version 10.1.0-dev. After applying the patch#14 maxlength attribute value changed to 255.
But patch #2 maxlength attribute value is null. Why this changes happened in new patch. Which value is acceptable ?
maxlength

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Questions and comments in #10 have not been addressed
Issue summary update is still needed

Patch #2 still applied to D10.1 so rerolls in #13 and #14 were not needed so removing credit.

rinku jacob 13’s picture

@smustgrave, patch 13 has changed the max length attribute value, in patch #2 max length value is null. but for patch #13 it is 255. that is the difference. That's why I have asked in comment #16 which value is correct.

anybody’s picture

I think this core issue should be solved, we're running into this again and again in different situations and modules: #3331028: Increase default textfield #maxlength=128 to 256

volkswagenchick’s picture

Issue tags: +Pittsburgh 2023

Needs issue summary update
See comment #10

Tagging this for DrupalCon Pittsburgh 2023.

Please save for a mentee at the mentored workshop at DrupalCon Pittsburgh 2023.

chrisdarke’s picture

Issue tags: -Pittsburgh 2023 +Pittsburgh2023

Migrating Pittsburgh 2023 to Pittsburgh2023 tag for cleanup

aaronpinero’s picture

Assigned: Unassigned » aaronpinero
aaronpinero’s picture

Assigned: aaronpinero » Unassigned
aaronpinero’s picture

Looking at this issue, it seems like the following specific tasks will help get it to RTBC:

1. rewrite of the issue summary using the standard template. Also, generalizing the summary since this is about a search input but the character limit affects views generally.

2. agreeing on the patch that sets maxlength to 255. This seems to be a responsible setting (as opposed to null) and matches the aforementioned title character limit.

3. Check to see what tests are available for this module and if tests are adequate or need to be updated.

These notes are mostly for #novice #contribution #DrupalConPittsburgh2023

aaronpinero’s picture

The parent issue has proposed a fix that would address this issue "further up the chain" from Views. However, that fix is against Drupal 11.x, so we do need a fix applied for Drupal 9.5 (as this will be around for a while yet). The parent issue also suggests (option b) to set the maxlength to to 256 instead of 128 and we should probably go with that, providing a fix against Drupal 9.5.x

aaronpinero’s picture

Issue summary: View changes
aaronpinero’s picture

Issue summary: View changes
aaronpinero’s picture

StatusFileSize
new832 bytes

As suggested in #7 and #10, I have created an updated version of the patch that has comments.

aaronpinero’s picture

Existing tests for the StringFilter in the Views module all have to do with whether or not use of the exposed filter produces the expected result set. I don't know what sort of assertion one might use to to test this change other than adding a very simple test that checks to see if the input string longer than 128 characters is truncated. This is easy enough to test manually, so I don't know that it's necessary to add an automated test.

If no one has a differing viewpoint, this could be RTBC.

aaronpinero’s picture

Status: Needs work » Needs review

Setting to needs review to get some other eyes on this.

smustgrave’s picture

Status: Needs review » Needs work

Thank you for working on this!

Changing the issue to 11.x as that's the current development branch. Fixes and changes will be merged there first and backported.

#28 had a CC failure You can check for build errors by running ./core/scripts/dev/commit-code-check.sh locally.

If this issue is resolved in another issue we should close this one out and move over credit.

nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

Status: Needs work » Needs review
StatusFileSize
new1.1 KB
new211 bytes
new46.45 KB

I think CC failure is because of cspell plugin in core. Somehow the term 'backported' is not present in the cspell dictionary.txt. Regenerating the cspell dictionary.txt will resolve the issue. Also before starting, ensure that JavaScript dev dependencies are up-to-date.

cd core
yarn install

To regenerate cspell dictionary.txt you can use the following command in terminal:

cd core
yarn spellcheck:make-drupal-dict

Not sure how to fix this in drupal issue queue via patch therefore providing patch with the regenerated dictionary.txt.

validation

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Assigned: nitin_lama » Unassigned
Status: Needs review » Needs work

Not yet ready for review.

There are still open tags that need to be addressed.

And unless you’re a maintainer shouldn’t assign tickets to yourself. Leaving a comment is just fine

nitin_lama’s picture

StatusFileSize
new1.1 KB

Alright, providing patch for 11.x. Thanks.

lendude’s picture

Nice to see this move!

+++ b/core/modules/views/src/Plugin/views/filter/StringFilter.php
@@ -277,6 +277,9 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
+        // This could be removed if #3331028 is resolved and backported.

// @todo remove when https://www.drupal.org/project/drupal/issues/3331028 lands.

That is what we tend to do as wording, not just mention the issue number. This also means we wouldn't need to expand the dictionary and that change can be removed.

nitin_lama’s picture

StatusFileSize
new848 bytes
new675 bytes

Got it. Updated patch as per #36.

lendude’s picture

Status: Needs work » Needs review
+++ b/core/modules/views/src/Plugin/views/filter/StringFilter.php
@@ -277,6 +277,9 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
+        // @todo remove when https://www.drupal.org/project/drupal/issues/3331028 lands.

this is over 80 characters but doesn't bother the linting? ¯\_(ツ)_/¯

Test failure seems unrelated

smustgrave’s picture

Status: Needs review » Needs work

Seems issue summary update and test coverage still missing

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.