Closed (fixed)
Project:
Drupal core
Version:
8.5.x-dev
Component:
views.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Oct 2017 at 08:37 UTC
Updated:
2 Jan 2019 at 18:05 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
robin.ingelbrecht commentedThis patch adds the extra placeholder option.
Comment #4
jwkovell commentedThanks for the patch! I've applied it to a fresh install of Drupal 8.4 for testing.
What worked
What seemed weird
The placeholder option is included even if the filter element don't support it. For example, Content: Published (exposed) is a select element. In such cases, I would expect the option to be hidden.
Alternate solution for select menus
This could get very complex very quickly, but I could see the placeholder being used to add the placeholder text as a null-value default option to the select menu. That might cause unexpected behavior if someone tries to submit the form with that option selected, though.EDIT: The solution described below (only show the option for relevant field types) is cleaner.
Comment #5
robin.ingelbrecht commentedI added the placeholder option in FilterPluginBase, that's why it is displayed on all types of fields. Maybe I should change this and add this option in the classes (StringFilter, NumericFilter, ...) that can use a HTML5 placeholder? Any thoughts?
Comment #6
jwkovell commented@robin.ingelbrecht, good idea!
It's probably best not to make other fields more complex than they have to be.
Comment #7
lendudePretty nice idea. Moving to 8.5.x because this is a feature.
As the failing tests show, this needs a place in the filter config schema, which in turn would need an upgrade path and test.
Comment #8
robin.ingelbrecht commentedI looked in to the proposed approach in #5, but I don't think this is a good solution.
Lets assume we add the placeholder attribute in the plugins "StringFilter" and "NumericFilter". This fixes the problem for Drupal core filters. But for example if we have a "SearchApiFulltext" provided by SearchApi then we won't be able to configure the placeholder because this plugin does not provide it.
There are a lot of other modules that expose custom filter plugins and the placeholder attribute should be configurable on all of them without the developers of the module having to alter their plugin.
What do you guys think?
Comment #9
kevin.dutra commentedI would lean toward the approach in #5. As we've already established, placeholder text only applies to particular form elements. As far as I can see, there's no way for us to generically apply it at the
FilterPluginBaselevel. It depends on the widget provided by each individual filter plugin, and only that plugin is going to know for sure where and how a placeholder should be applied.To take an example out of core, if you're using a
NumericFilterwith the BETWEEN operator, the value form contains both a "Min" and a "Max" field, not just a singular "Value" field. You may well want a placeholder for both of those fields, butFilterPluginBaseis going to have no idea how to accommodate that — onlyNumericFilterdoes.And yes, that means that any contributed module's filter derived from
FilterPluginBasedirectly (likeSearchApiFullText) will not magically inherit placeholders. Not ideal, but I'm not sure its avoidable.Comment #10
kevin.dutra commentedI'll work on a revised patch that follows the approach of #5.
Comment #11
jwkovell commented@kevin.dutra sounds good! I'll be happy to test a new patch that follows that method.
Comment #12
kevin.dutra commented@jkovell, awesome! Here's the first stab at it.
Comment #14
kevin.dutra commentedOops, missed a spot when refactoring.
Comment #15
jwkovell commentedThanks, testing now.
While I do, are the descriptions in these fields reversed?
Comment #16
kevin.dutra commentedOh geez, yep. Good eye!
Comment #17
kevin.dutra commentedFixed descriptions.
Comment #18
jwkovell commentedSo far everything is working great.
I've tried the following fields:
I've also tested setting default values in exposed views fields - also works!
I had a pedantic UI complaint, but it's part of an existing problem:
There are no fields to enter placeholder text for min/max values unless you save the filter and reopen it - at which point all 3 placeholder fields are available as expected.
You could temporarily set the operator to "between" to set the values there, then switch it back to "Is Equal to"... but that feels like a work around.
As I mentioned above, I realized this is related to an existing issue... the default value fields are wonky in the same way. I'm not sure we need to solve it here? I'll hold off on an answer to that before marking as RTBC, but looks very good!
Comment #19
lendudeLooking good.
Couple of things we need to address I feel:
We need an upgrade path for this (plus a test for that upgrade path)
Why 'Ghost text', why not just call it 'placeholder text'?
Also, this needs test for the placeholder functionality and the setting in the UI.
Comment #20
kevin.dutra commented@jkovell: I see what you mean. I'll rework that a bit so that all placeholders are immediately available to edit when you expose the operator. That's relatively easy to fix.
@Lendude:
And yes, test coverage is needed and was next on my list -- just didn't want to dive into immediately in case there were some design changes that cropped up immediately. Hopefully I'll have some time tomorrow to add in some coverage.
Comment #21
lendude@kevin.dutra the upgrade path needs something more elaborate, more like #2810097: Allow views to provide the canonical entity URL of all entities, not just nodes.
As a term, maybe 'HTML placeholder text'? If you google that anybody should be able to figure out what that does.
Comment #22
jwkovell commentedSince the Field's title already uses the technical term "Placeholder", can the description just define it? Something like "Hint text that appears inside the field when empty."
That said, I think "HTML placeholder text" is better than "Ghost text" since it's more Google-able. My only concern was that the "HTML" might make it sound like we can use HTML in that field.
Comment #23
kevin.dutra commentedWorking on the remaining items.
Comment #24
kevin.dutra commentedAlrighty, here are the updates:
Comment #25
jwkovell commentedTested item #4 and #5 - working as expected. Thanks!
Comment #26
lendudeThis looks great, some minor nits:
default once to '' and once to NULL, shouldn't they both be ''?
can just be {@inheritdoc}
can just be {@inheritdoc}
Needs an update.
Comment #27
kevin.dutra commentedThanks for another review pass @Lendude!
descriptionoption fromFilterPluginBaseas a basis. ThereNULLis used fordefaultExposeOptions()whereas an empty string is used fordefineOptions().My guess is that there would be no functional difference if it was empty string instead of
NULL, but since there was precedent,I figured it was safer to just follow along in the off-chance there was actually a reason it was done that way.
$modulesfarther up the chain, but I didn't spot a definition for$testViewsthat it could inherit from.Comment #28
lendude1. Fair enough, I can't tell why you'd need to set them in both at all, but you are right it happens for some other settings too, lets leave it
2. Hah! you are right, I could have sworn it was on ViewTestBase, but you are right, it's not (though it probably should be).
I think this is ready.
Comment #29
robin.ingelbrecht commentedThanks for working on this patch guys!
Comment #31
lendudeUnrelated fail, back to RTBC
Comment #33
kevin.dutra commentedTestbot is smoking something...everything is still green.
Comment #35
kevin.dutra commentedAnother unrelated fail. I'll open a DrupalCI issue.
Comment #36
lendude@kevin.dutra a critical already exist for this fail #2926309: Random fail due to APCu not being able to allocate memory
Comment #37
larowlanUpdating review credits, adding @jwkovell and @Lendude
Comment #39
larowlanCommitted b022734 and pushed to 8.5.x
A bit late, but can we get a change notice here to herald the new feature.
Comment #40
larowlanFor the posthumous change record.
Comment #41
lendudeAdded a CR: https://www.drupal.org/node/2935063
Comment #42
larowlanThanks @Lendude, published the CR
Comment #43
berdirFound a problem with the upgrade path, see #2936457: views_post_update_filter_placeholder_text() can result in errors in filter plugins due to incomplete definition
Comment #45
cilefen commented