Problem/Motivation

The media Authored by filter should use the user_name filter plugin OOTB in order to be consistent with Content, and provide a better UX with an autocomplete field.

Proposed resolution

Updated the Media Views Data to suggest the user_name Views Filter Plugin as the default for newly created fields.

How to test

  1. Enable the media module.
  2. Create a view for media content.
  3. Add a media author filter to a view and make it an exposed filter.
  4. Notice it's a simple text field and takes the uid as a value.
  5. Remove the filter and apply the patch, clearing caches just to be sure.
  6. Re-add the "Authored by" filter, notice it's now an autocomplete field taking usernames as the values.

Remaining tasks

None

User interface changes

Adding 'Authored by' to a Media View (like the default one at /admin/content/media) results in a username autocomplete instead of a plain text filter by ID.

Before:

Screenshot showing the original plain text UID filter

After:
Screenshot showing the username autocomplete filter

API changes

- N/A

Data model changes

- N/A

Release notes snippet

Newly created 'Authored by' filters added to Views that list Media will autocomplete on username instead of expecting the user to enter a user ID.

CommentFileSizeAuthor
#115 after.png13.16 KBscott_euser
#114 after.png13.83 KBscott_euser
#114 before.png10.71 KBscott_euser
#99 3113989-99.patch4.3 KBameymudras
#95 interdiff-3113989-93-95.txt1.68 KByogeshmpawar
#95 3113989-95.patch12.19 KByogeshmpawar
#93 interdiff-3113989-88-93.txt10.48 KByogeshmpawar
#93 3113989-93.patch12.19 KByogeshmpawar
#88 3113989-88.patch1.7 KBranjith_kumar_k_u
#81 Screenshot 2021-06-28 at 08.48.39.png84.11 KBlendude
#79 3113989-79.patch1.71 KBlendude
#76 interdiff-3113989-65-76.txt2.39 KBacbramley
#76 3113989-76.patch16.04 KBacbramley
#67 before patch.png21.16 KBrahul b
#67 After Patch .png49.78 KBrahul b
#65 interdiff-3113989-64-65.txt6.23 KBacbramley
#65 3113989-65.patch16.02 KBacbramley
#64 interdiff-3113989-59-64.txt6.65 KBacbramley
#64 3113989-64.patch16.04 KBacbramley
#59 interdiff-47-59.txt169.9 KBacbramley
#59 3113989-59.patch9.73 KBacbramley
#47 interdiff-3113989-44-47.txt444 bytesmohit_aghera
#47 3113989-47.patch178.55 KBmohit_aghera
#44 interdiff-3113989-40-44.txt614 bytesmohit_aghera
#44 3113989-44.patch178.55 KBmohit_aghera
#41 interdiff-3113989-38-40.txt7.86 KBmohit_aghera
#41 3113989-40.patch178.19 KBmohit_aghera
#38 interdiff-3113989-30-38.txt172.07 KBmohit_aghera
#38 3113989-38.patch175.21 KBmohit_aghera
#36 interdiff-3113989-30-35.txt172.07 KBmohit_aghera
#36 3113989-35.patch178.01 KBmohit_aghera
#30 interdiff-3113989-25-30.txt689 bytesacbramley
#30 3113989-30.patch3.14 KBacbramley
#25 interdiff-3113989-22-25.txt874 bytesacbramley
#25 3113989-25.patch3.21 KBacbramley
#22 interdiff-3113989-21-22.txt606 bytesacbramley
#22 3113989-22.patch3.25 KBacbramley
#21 3113989-21-test-only.patch2.61 KBacbramley
#21 interdiff-3113989-20-21.txt924 bytesacbramley
#21 3113989-21.patch3.18 KBacbramley
#20 3113989-20-test-only.patch2.86 KBacbramley
#20 3113989-20.patch3.42 KBacbramley
#12 Screen Shot 2020-05-14 at 5.30.39 PM.png57.65 KBkristen pol
#12 Screen Shot 2020-05-14 at 5.30.24 PM.png42.8 KBkristen pol
#12 Screen Shot 2020-05-14 at 5.29.08 PM.png96.84 KBkristen pol
#2 3113989-2.patch583 bytesacbramley

Issue fork drupal-3113989

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

acbramley created an issue. See original summary.

acbramley’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new583 bytes

Still need to update tests, but I'm curious what this breaks.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

kristen pol’s picture

Thanks for the patch.

1) Patch applies cleanly to 8.9, 9.0, and 9.1.

[mac:kristen:drupal-8.9.x-dev]$ patch -p1 < 3113989-2.patch 
patching file core/modules/media/src/MediaViewsData.php
[mac:kristen:drupal-9.0.x-dev]$ patch -p1 < 3113989-2.patch 
patching file core/modules/media/src/MediaViewsData.php
[mac:kristen:drupal-9.1.x-dev]$ patch -p1 < 3113989-2.patch 
patching file core/modules/media/src/MediaViewsData.php

2) Searched the codebase for something similar to:

$data['media_field_data']['x']['filter']

but didn't see anything.

3) Looked at NodeViewsData based on issue summary note and see:

$data['node_field_data']['uid']['filter']['id'] = 'user_name';

which is the same pattern as the patch so this looks ok.

4) I'm not sure this would be considered a "Bug report" but I'll leave that as is.

5) What's the best way to manually test this?

kristen pol’s picture

Also, this might need tests.

acbramley’s picture

@Kristen Pol thanks for the review, it does need tests, I've added the label back in #2 :)

kristen pol’s picture

Doh! Sorry for the noise. :) Working on too little sleep and too many issues.

acbramley’s picture

No worries :) This also needs an upgrade path as pointed out by larowlan in #3135342: Use the user_name filter for the linky author for a better UX

kristen pol’s picture

@acbramley Do you have any thoughts on best way to manual test this?

acbramley’s picture

@Kristen Pol Sure:

1. add the media author filter to a view and make it an exposed filter
2. notice it's a simple text field and takes the uid as a value.
3. Remove the filter and apply the patch, clearing caches just to be sure.
4. Add the filter again, notice it's now an autocomplete field taking usernames as the vaules

kristen pol’s picture

Issue summary: View changes

Awesome, I added this to the issue summary. I'll try to test soon.

kristen pol’s picture

Tested manually and it works great!

Without patch:

With patch:

kristen pol’s picture

Status: Needs review » Needs work

Moving back to "Needs work" for the tests.

acbramley’s picture

Thanks so much!

kristen pol’s picture

Looked around for tests for a similar filter and had a hard time. I found testExposedFilter in:

core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php

but that's for the user entity and name property. Also found FilterUidRevisionTest in:

core/modules/node/tests/src/Kernel/Views/FilterUidRevisionTest.php

but that's for node author / node revision author check.

kristen pol’s picture

Issue tags: +Bug Smash Initiative

Trying to get some guidance from the Bug Smash Initiative on where the test(s) should go.

dww’s picture

How about adding another test method in core/modules/media/tests/src/Functional/MediaOverviewPageTest.php to add the media author as an exposed filter to the default media overview page? Then assert it's an autocomplete text field, not a simple integer UID field? I don't think we need to / want to actually use a JS test to verify the autocomplete works as autocomplete. That's already tested elsewhere. We just need to make sure that this filter is using the right plugin.

kristen pol’s picture

@dww Nice. That seems like a great approach, thanks!

shailja179’s picture

Assigned: Unassigned » shailja179
acbramley’s picture

Assigned: shailja179 » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.42 KB
new2.86 KB

This should work but for some reason is failing on the last assert for me locally. Checking what CI thinks.

Interdiff === test-only patch.

acbramley’s picture

StatusFileSize
new3.18 KB
new924 bytes
new2.61 KB

Of course I figure it out just after I post the patch 🤦‍♂️

acbramley’s picture

StatusFileSize
new3.25 KB
new606 bytes

And the missing doc block...obviously not enough coffee.

kristen pol’s picture

Thanks for the patch. Not sure I follow it completely :) but I noticed a couple things.

  1. +++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
    @@ -171,4 +172,72 @@ public function testMediaOverviewPage() {
     
    +  public function testMediaOverviewAuthorFilter() {
    

    Missing doc block.

  2. +++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
    @@ -171,4 +172,72 @@ public function testMediaOverviewPage() {
    +    $view = View::load('media');
    +    $display =& $view->getDisplay('default');
    

    Nitpick: Although I see a small number of tests use the =& $view formatting like:

    $display =& $view->getDisplay('default');
    

    most of the core code uses = &$view like:

    $display = &$view->getDisplay('default');
    
  3. +++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
    @@ -171,4 +172,72 @@ public function testMediaOverviewPage() {
    +    $this->drupalGet('/admin/content/media');
    +    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
    +    $this->grantPermissions($role, ['access media overview']);
    +    $this->drupalGet('/admin/content/media');
    

    I'm unclear why $this->drupalGet('/admin/content/media'); is done twice here.

kristen pol’s picture

Ah, we crossposted. Ignore #23.1.

acbramley’s picture

StatusFileSize
new3.21 KB
new874 bytes

Fixed #23.2 and .3

kristen pol’s picture

Thanks for the updates. I reviewed again and feel like I understand the test now. Not sure why the timestamp is adjusted for $media2 and $media3 but it doesn't hurt anything. I see that the text being checked is the correct string so, if the tests pass, this is looking good to me.

+++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
@@ -171,4 +172,64 @@ public function testMediaOverviewPage() {
+    $this->assertSession()->pageTextContains('Enter a comma separated list of user names.');
...
 
[mac:kristen:drupal-9.1.x-dev]$ grep -r "Enter a comma separated list of user names" .
./core/modules/user/src/Plugin/views/filter/Name.php:      '#description' => $this->t('Enter a comma separated list of user names.'),
acbramley’s picture

Not sure why the timestamp is adjusted for $media2 and $media3 but it doesn't hurt anything

Yeah you're right this can be removed (maybe on commit?), it was a copy-paste from the other test function in the class.

The last submitted patch, 21: 3113989-21-test-only.patch, failed testing. View results

kristen pol’s picture

Woot! Looks like the test is passing fine and the test-only patch fails as expected. If you want to adjust it to remove those couple timestamps, that's fine. I'll wait a bit before moving this forward. Thanks.

acbramley’s picture

StatusFileSize
new3.14 KB
new689 bytes

Thanks @Kristen Pol! I've removed the changed dates now.

kristen pol’s picture

Nice! Ok, crossing fingers there is no glitch in the testbot matrix.

dww’s picture

Status: Needs review » Reviewed & tested by the community

#30 looks great.
Actual fix is tiny and correct.
Test coverage looks reasonable.
No nits found.
No CS violations.

Therefore... RTBC!

Thanks,
-Derek

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This needs an update path for existing view. If I apply this patch and have a view created as suggested in the issue summary I get an error - The operator is invalid on filter: Media: Authored by.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new178.01 KB
new172.07 KB

- Added a post_update hook to change the filter and related attributes.
- Add test case to evaluate the post_update hook logic.

mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned
mohit_aghera’s picture

StatusFileSize
new175.21 KB
new172.07 KB

- Added a post_update hook to change the filter and related attributes.
- Add test case to evaluate the post_update hook logic. Update testcase is passing on local

Ignore the patch from comment #36
Accidentally, I created diff from older 9.2.x head.
I've hidden patch and interdiff.

lendude’s picture

Nice, like @Kristen Pol not convinced it's a bug (can you not just workaround it by adding a relationship to the author?), but don't care too much.

Some things I see:

  1. +++ b/core/modules/media/src/MediaViewsData.php
    @@ -15,6 +15,7 @@ class MediaViewsData extends EntityViewsData {
    +    $data['media_field_data']['uid']['filter']['id'] = 'user_name';
    
    +++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
    @@ -171,4 +172,62 @@ public function testMediaOverviewPage() {
    +    $display['display_options']['filters']['uid'] = [
    +      'id' => 'uid',
    +      'table' => 'media_field_data',
    +      'field' => 'uid',
    +      'operator' => 'in',
    +      'exposed' => TRUE,
    +      'expose' => [
    +        'label' => 'Authored by',
    +        'identifier' => 'uid',
    +      ],
    +      'entity_type' => 'media',
    +      'entity_field' => 'uid',
    +      'plugin_id' => 'user_name',
    +    ];
    

    Since we are hardcoding the plugin ID in the test when we add the filter, this would pass even without the change in MediaViewsData, so that makes the test a little suspect I think. If we really want to test that setting, we would need to add the filter through the UI.

  2. +++ b/core/modules/views/views.post_update.php
    @@ -68,3 +68,41 @@ function views_post_update_rename_default_display_setting() {
    +function views_post_update_media_author_views_filter_update() {
    

    Ideally the update would use \Drupal\views\ViewsConfigUpdater so we also update any config provided by contrib and the like

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

StatusFileSize
new178.19 KB
new7.86 KB

Updating test cases and post_update hook as mentioned in #39

mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned
lendude’s picture

Thanks @mohit_aghera, looks great already.

One last thing I see:

+++ b/core/modules/views/src/ViewsConfigUpdater.php
@@ -477,4 +491,45 @@ protected function mapOperatorFromSingleToMultiple($single_operator) {
+  protected function processMediaAuthorFilterPlugins(array &$handler, string $handler_type): bool {

We should also add a call to this in \Drupal\views\ViewsConfigUpdater::updateAll so that Views getting saved are also updated, see the other calls in updateAll

mohit_aghera’s picture

StatusFileSize
new178.55 KB
new614 bytes

Thanks, @Lendude for correcting me.
I've updated test cases accordingly.

kristen pol’s picture

Status: Needs review » Needs work

Thanks for the update.

1) I confirmed the interdiff addresses #43.

2) Since @Lendude already approved other than that, I only scanned the code quickly. I found one minor nitpick:

+++ b/core/modules/views/src/ViewsConfigUpdater.php
@@ -71,6 +72,14 @@ class ViewsConfigUpdater implements ContainerInjectionInterface {
   protected $triggeredDeprecations = [];
 
+
+  /**

Extra empty line.

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new178.55 KB
new444 bytes

Removed the additional empty space issue mentioned in #46

mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned

Status: Needs review » Needs work

The last submitted patch, 47: 3113989-47.patch, failed testing. View results

benjifisher’s picture

Please do not ask the testbot to try again until #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 47: 3113989-47.patch, failed testing. View results

acbramley’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC, looks like another random fail.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kristen pol’s picture

While it should have been moved back to needs review in #51 rather than RTBC, I've confirmed that the interdiff in #45 does fix the nitpick in #45 so RTBC is good :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 47: 3113989-47.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status after HEAD was broken.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Looking great, couple of questions

  1. +++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
    @@ -171,4 +171,63 @@ public function testMediaOverviewPage() {
    +    $this->submitForm($edit, 'Add and configure filter criteria');
    +
    +    $edit = [
    +      'options[expose_button][checkbox][checkbox]' => 1,
    +    ];
    +    $this->submitForm($edit, 'Expose filter');
    +    $edit = [
    +      'options[expose_button][checkbox][checkbox]' => 1,
    +      'options[group_button][radios][radios]' => 0,
    +    ];
    +    $this->submitForm($edit, 'Apply');
    
    +++ b/core/modules/views/tests/src/Functional/Update/MediaExposedFilterPluginTest.php
    @@ -0,0 +1,39 @@
    +    $view = View::load('test_media_view_exposed_filter');
    

    if we already have a test view with the media author exposed, shouldn't we just use that in test instead of going to the trouble of editing the default media view?

  2. +++ b/core/modules/views/tests/fixtures/update/drupal-9.0.0.filled.standard.php.gz
    @@ -0,0 +1,651 @@
    +�Cne`drupal-9.0.0.filled.standard.php�k�㸙.8��W(*&��'�ٸ���=v�>�8m���=��
    

    We already have a d9 filled standard in core/modules/system/tests/fixtures/update/drupal-9.0.0.filled.standard.php.gz

    Any reason to add a new one? Can we just use the existing one?

  3. +++ b/core/modules/views/views.post_update.php
    @@ -68,3 +68,18 @@ function views_post_update_rename_default_display_setting() {
    +function views_post_update_media_author_views_filter_update18(&$sandbox = NULL) {
    

    is the 18 in the function name significant here, this is the first instance of it I can see for the views post update file.

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new9.73 KB
new169.9 KB

@larowlan re 1: This is explained in #39

Have fixed 2 and 3

Status: Needs review » Needs work

The last submitted patch, 59: 3113989-59.patch, failed testing. View results

acbramley’s picture

Ah, that fixture had the test_media_view_exposed_filter view in it...

larowlan’s picture

Can we do a fixture that adds to the existing dump, like e.g. core/modules/system/tests/fixtures/update/drupal-8.update-test-semver-update-n-enabled.php

acbramley’s picture

Sure, so far have downloaded the old fixture, loaded into a db manually, and extracted the config XD good lesson in how this stuff works!

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new16.04 KB
new6.65 KB

This should work but something's a bit screwy with my local environment. Maybe someone else can have more luck.

acbramley’s picture

StatusFileSize
new16.02 KB
new6.23 KB
daffie’s picture

All points of @larowlan have been addressed.
I have just one question:

+++ b/core/modules/views/src/ViewsConfigUpdater.php
@@ -477,4 +493,45 @@ protected function mapOperatorFromSingleToMultiple($single_operator) {
+      // Remove additional attributes set for numeric filter.
+      unset($handler['expose']['placeholder']);
+      unset($handler['expose']['min_placeholder']);
+      unset($handler['expose']['max_placeholder']);

What happens when somebody has a custom project that uses the view with the min/max placeholder values?

rahul b’s picture

Assigned: Unassigned » rahul b
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new49.78 KB
new21.16 KB

The patch works fine for me. after applying the same it is generating prediction auto-completion successfully.

Before Patch
Before Patch

After Patch

After patch

rahul b’s picture

Assigned: rahul b » Unassigned

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 65: 3113989-65.patch, failed testing. View results

acbramley’s picture

Status: Needs work » Reviewed & tested by the community

Random fail.

kim.pepper’s picture

Issue tags: +#pnx-sprint
larowlan’s picture

Issue tags: +Needs change record

Saving issue credit

Can we get an answer for #66 and a change notice here.

With both of those, I think this is good to go.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

For #72

acbramley’s picture

Issue tags: -Needs change record

Drafted a Changed record using the screenshots from #67

https://www.drupal.org/node/3220467

lendude’s picture

Status: Needs review » Needs work

Re: #66, since we are updating the plugin, those values wouldn't do much anymore anyway, so I don't see any harm in removing them with the current fix, but it does raise a very good point because the same goes for projects that have a filter and they are using it with a 'between' operator (or anything not '='), we are destroying that too ('between' will become 'in', so does something completely different after the update). I think it is fairly unlikely that anybody would have that, but we do have to ask the question if we are ok with that.

Found some other things that probably need addressing.

  1. +++ b/core/modules/views/src/ViewsConfigUpdater.php
    @@ -138,6 +151,9 @@ public function updateAll(ViewEntityInterface $view) {
    +      if ($this->processMediaAuthorFilterPlugins($handler, $handler_type)) {
    +        $changed = TRUE;
    +      }
    

    Calling this without the media_field_data check in that method will have the potential to update WAY more then the field we are trying to target (see point 4 below)

  2. +++ b/core/modules/views/src/ViewsConfigUpdater.php
    @@ -477,4 +493,45 @@ protected function mapOperatorFromSingleToMultiple($single_operator) {
    +    if ($handler_type === 'filter' && isset($handler['id']) && $handler['field'] === 'uid') {
    

    we are checking $handler['id'] in the isset() but checking $handler['field'] after that, should they both check $handler['field']?

  3. +++ b/core/modules/views/tests/fixtures/update/drupal-9.add-media-uid-exposed-filter-view.php
    @@ -0,0 +1,36 @@
    + * @file
    + * Database to mimic the installation of the update_test_schema module.
    

    This comment needs an update

  4. +++ b/core/modules/views/views.post_update.php
    @@ -68,3 +68,18 @@ function views_post_update_rename_default_display_setting() {
    +    if ($view->get('base_table') !== 'media_field_data') {
    +      return;
    +    }
    

    This should probably be checked in needsMediaAuthorFilterPluginId() or probably processMediaAuthorFilterPlugins()

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new16.04 KB
new2.39 KB

Nice catches @Lendude

Have rerolled + addressed #75

Status: Needs review » Needs work

The last submitted patch, 76: 3113989-76.patch, failed testing. View results

lendude’s picture

+++ b/core/modules/views/src/ViewsConfigUpdater.php
@@ -138,6 +151,9 @@ public function updateAll(ViewEntityInterface $view) {
+      if ($this->processMediaAuthorFilterPlugins($handler, $handler_type)) {
+        $changed = TRUE;
+      }

@@ -477,4 +493,48 @@ protected function mapOperatorFromSingleToMultiple($single_operator) {
+  public function needsMediaAuthorFilterPluginId(ViewEntityInterface $view): bool {
+    if ($view->get('base_table') !== 'media_field_data') {
+      return FALSE;
+    }
...
+  protected function processMediaAuthorFilterPlugins(array &$handler, string $handler_type): bool {
+    if ($handler_type === 'filter' && isset($handler['field']) && $handler['field'] === 'uid') {

Hmm the check on base table is still circumvented in the updateAll call like this. We probably need to pass the View along to the process method and check it there.

The update still feels potentially destructive though. An alternative would be to do this without an update and provide the user name filter as a separate filter so the original can stay as it is. Too extreme BC? ¯\_(ツ)_/¯

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB

Something like this would also work, without the BC implications. We should probably add the test coverage, but this is just an idea.

acbramley’s picture

@Lendude I've tested the upgrade path while using the filter as non-exposed. It's currently using the EntityReference plugin which only has the following operators: Is one of, Is all of, Is none of, Is empty, Is not empty.

Tested using "Is one of" and referencing a user and running the update hook. The operator and value were correctly migrated and the filter continued to work exactly as it had before.

Is all of does not make sense for this field, Is none of doesn't even work in the current state. The other 2 are 1 to 1 mappings.

I think given all of this, it's safe to update the existing filter.

lendude’s picture

StatusFileSize
new84.11 KB

When I add the 'Authored by' filter without the patch, I see all the options in the screenshot. In the update we are mapping all of these to the 'in' operator. Again, I doubt anybody is using those operators, but we can't be sure.

Or are your seeing something else?

acbramley’s picture

I was definitely seeing something else! I will spin up a vanilla instance and re-test.

EDIT: It's most likely because I was testing a site that had #2429699: Add Views EntityReference filter to be available for all entity reference fields applied :(

quietone’s picture

i manually tested the patch in #79 on 9.4.x, standard install. Both before and after the patch the uid was used for the filter not the name. I did not experience any difference before and after the patch.

acbramley’s picture

@quietone #79 does not contain an upgrade path so you would have to remove and re-add the filter to see the changes, or test #76 and run database updates :)

quietone’s picture

Oh, I see the problem. I don't think the steps in the IS are correct. The last step is to apply the filter again. To me that means the same filter used in the previous step when instead it is to use the new filter with the title 'Author name'. When I use that filter it works as expected.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kristen pol’s picture

Tagging for issue summary update for proposed resolution and possibly testing steps (per #85).

ranjith_kumar_k_u’s picture

StatusFileSize
new1.7 KB

Re-rolled #79 for 9.4

kristen pol’s picture

Issue tags: +Needs tests

@ranjith_kumar_k_u Thanks for the reroll. Tagging for tests.

Compared patch in #88 with previous one in #79 and the changes are the same.

Patch in #88 applies cleanly to versions 9.4 and 10 and with offsets for 9.3.

[drupal-9.3.x-dev/9.3.x] [drupal-9.3.x-dev]$ patch -p1 < 3113989-88.patch 
patching file core/modules/media/media.post_update.php
patching file core/modules/media/src/MediaViewsData.php
Hunk #1 succeeded at 25 with fuzz 2 (offset 7 lines).
acbramley’s picture

Tests are present in #76 - not sure why they weren't brought forward.

kristen pol’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

Moving back to needs work.

As @acbramley points out in #90, tests were in patch #76. These need to be added back.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new12.19 KB
new10.48 KB

Adding tests again from #76 as suggested in #91.

Status: Needs review » Needs work

The last submitted patch, 93: 3113989-93.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Needs review
StatusFileSize
new12.19 KB
new1.68 KB

Updated patch with interdiff.

Status: Needs review » Needs work

The last submitted patch, 95: 3113989-95.patch, failed testing. View results

acbramley’s picture

@yogeshmpawar sorry I should've been more clear - we don't need the upgrade path test or fixture because there is no longer an upgrade path, we are simply adding a new filter.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

Removing tests related to upgrade path and fixtures. Also updated the testMediaOverviewAuthorFilter inline comment.

Status: Needs review » Needs work

The last submitted patch, 99: 3113989-99.patch, failed testing. View results

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

maskedjellybean’s picture

Thank you for the patch in #99. It still works in Drupal core 10.2.3.

I opened a MR (in case that helps move this along) which contains the changes from #99, plus hopefully fixes the tests, although I can already see they've failed...

maskedjellybean’s picture

Made the requested changed to the MR. Unfortunately I can't do anything more to make the tests pass because the error appears to have nothing to do with the test being added here.

mrshowerman’s picture

Issue summary: View changes

Just came across this and fell into the same trap as #85.
Updating IS for clarity.

mohit_aghera’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

- All three points mentioned by @acbramley is fixed by @maskedjellybean
- Issue summary is updated and PR is rebased with latest 11.x.
- Merge conflict is resolved.
- Hiding older patches in favour of PR based approach.
- I think it is ready for moving to needs review.

mohit_aghera’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran test-only feature

1) Drupal\Tests\media\Functional\MediaOverviewPageTest::testMediaOverviewAuthorFilter
Behat\Mink\Exception\ElementNotFoundException: Form field with id|name|label|value "name[media_field_data.user_name]" not found.
/builds/issue/drupal-3113989/vendor/behat/mink/src/WebAssert.php:731
/builds/issue/drupal-3113989/core/tests/Drupal/Tests/UiHelperTrait.php:85
/builds/issue/drupal-3113989/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php:219
FAILURES!
Tests: 2, Assertions: 58, Failures: 1.

Manually testing editing the view I'm seeing the new filters.

Believe this is good

catch’s picture

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs screenshots, +Needs change record updates

There are no unanswered questions here.

After reading the IS I expected to see a new plugin of some type, but there isn't one. The IS says there are no UI changes but there are so there should be screenshots available from the Issue summary.

I then read the CR and saw that the screenshots are out of date. For that I applied the diff to make new ones. I then saw that the description for the new filter, 'Author name' is that it is the user ID. That is not correct, it is the user name. Should this be doing the same as the Content view and use a title of "Authored by" and a description of "The username of the content author."?

At the lest the description should change. Setting to NW.

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

scott_euser’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs screenshots, -Needs change record updates
StatusFileSize
new10.71 KB
new13.83 KB
  1. Updated label and description to match /admin/content (agree with #112)
  2. Updated issue summary
  3. Updated screenshots
  4. Updated change record
scott_euser’s picture

Issue summary: View changes
StatusFileSize
new13.16 KB

Updated 'After' screenshot to reflect change to default label

scott_euser’s picture

smustgrave’s picture

Status: Needs review » Needs work

Appears to have a relevant test failure

Have not reviewed yet.

scott_euser’s picture

Status: Needs work » Needs review

Test coverage passing now; applies a filter on username (rather than uid) and returns expected media entities as results.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Ran test-only feature

1) Drupal\Tests\media\Functional\MediaOverviewPageTest::testMediaOverviewAuthorFilter
Behat\Mink\Exception\ElementNotFoundException: Form field with id|name|label|value "name[media_field_data.user_name]" not found.
/builds/issue/drupal-3113989/vendor/behat/mink/src/WebAssert.php:731
/builds/issue/drupal-3113989/core/tests/Drupal/Tests/UiHelperTrait.php:90
/builds/issue/drupal-3113989/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php:270
FAILURES!
Tests: 3, Assertions: 65, Failures: 1.
Exiting with EXIT_CODE=1

Resolved the open threads as they appears to be addressed

Applied the MR before doing an install
Followed the steps in the summary and am seeing the new filter "The username of the content author."
Applied it to the Media Library view I can filter by usernames

LGTM

alexpott’s picture

Version: 11.x-dev » 11.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 68013115a83 to 11.x and c3a9311a660 to 11.1.x. Thanks!

  • alexpott committed c3a9311a on 11.1.x
    Issue #3113989 by acbramley, mohit_aghera, maskedjellybean, scott_euser...

  • alexpott committed 68013115 on 11.x
    Issue #3113989 by acbramley, mohit_aghera, maskedjellybean, scott_euser...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.