Needs work
Project:
Drupal core
Version:
main
Component:
user.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Aug 2017 at 04:37 UTC
Updated:
28 Jul 2023 at 01:27 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
drugan commentedThere is an urgent need on drupalcommerce users for this feature.
Comment #3
zenimagine commentedThank you very much, it works
But I encounter another small problem.
1) I want to exclude the node or product from the current page. So I added to my view a pop-up filter to exclude the ID.
It would be interesting to replace:
"Identifier (ID) of the content from the url"
by :
"Identifier (ID) of the entity from the url"
2) I installed the "Commerce" and "Group" modules.
In contextual filters, I have:
- Identifier (ID) of the content from the URL.
- Group ID from URL.
- Store ID from the current store.
Why not group these 3 filters in:
- Identifier (ID) of the entity from the URL.
Comment #4
zenimagine commentedThe patch works for me, but it does not work with the profile module page.
Every user on my site has a personal profile. I want to display a block with the nodes of the same author as the current profile.
Thank you for your help.
Comment #5
zenimagine commentedSorry I've been searching for it, the patch is working properly ;-)
I hope it will be applied for the next update.
Comment #6
punamshelkeThis patch is working for me.......
Thanks
Comment #7
alexpott@drugan thanks for working on this issue. This patch needs a test that proves it works for entities other than nodes.
Also...
Will the entity always be the first route parameter? That seems a big assumption.
Here we're are assuming we know what the getOwnerId() method does and returns. But this is not at all enforced. We need to check whether or not the parameter implements \Drupal\user\EntityOwnerInterface - then getOwnerId() is safe to call.
Comment #8
drugan commentedDid not found a test for existing Drupal\user\Plugin\views\argument_default\User::getArgument() method. So I've decided that it will be useful to cover getting argument also for User entity (not only for changes on the patch).
Comment #9
drugan commentedComment #10
bojanz commentedIn general this looks good.
Are we fine with saying "entity" in the UI? I remember that it was discouraged before, but I guess that ship sailed a long time ago.
Do we still allow non-Prophecy mocking to be added in new tests?
Comment #11
drugan commentedYes, it may sound unclear for non-developer users but what else? Revert to "node" wording? No, it may mislead even developers because they can think that this work only for node entities. Needs help from English native speakers.
It was my first experience with unit test, so I can imagine that it may look weird. A bit later I'll try another version of the patch using prophecy mocking.
Comment #12
dawehnerI like the general feature. It is always nice to get rid of hardcoded stuff for node, especially because the label "User ID from route context" totally indicate that already.
I think I would have written a kernel test rather.
Comment #13
drugan commentedAs it were suggested by @dawehner the
'Also look for a node and use the node author'option removed altogether and a new kernel test created.Comment #14
boazpoolman commentedThis works great!
Only thing is that I can't use the Product ID contextual filter to exclude a product if it is the same as the current product.
Using 'Content ID from URL'. Just like #3.
Comment #15
drugan commented@boazpoolman
Note that current patch has nothing to do with Content ID or Product ID from url. Instead it fetches User ID from whatever entity which will be found in the route context of the current page and filters the view result based on this ID. It may be any entity: node, product, profile, store, etc.. That means all the content displayed by the view will be authored by the same user as the author of those entities. If you want to negate the result of the view and display the content which is authored by any user excerpt the author of the entity in the route context you need to scroll down in the contextual filter settings form and tick Exclude checkbox.
If you have created Products I'd recommend for testing purposes to import the 2-VIEW_author_products_and_nodes.txt view from the Drupal Commerce related issue:
#2885448: How do I display the products and nodes of the same author in the current page ?
How to:
Create three test users who are authors of a some number of product and node entities.
Go to admin/config/development/configuration/single/import Configuration type -> View
Paste the content of the file above and click Import.
Go to admin/structure/block and place the Author products and nodes block into any region (Sidebar first?).
Go to whatever content authored by the users and check that only content for the current entity author is displayed.
Go to admin/structure/views/view/author_products_and_nodes/edit/block_1 and Exclude (negate) the User ID form route context default value for the Product: Author contextual filter.
Go to whatever content authored by the users and check that content for all but not the current entity author is displayed.
Comment #17
Ralf Eisler commentedThis patch works great. Use it on nodes.
Thank you very much.
Comment #19
zenimagine commentedThe patch works with 8.6
Comment #21
zenimagine commentedHi guys, it's been 2 years since I applied the patch on my site and it works for me. Do you think that one day it will be applied to the kernel ?
Thank you
Comment #22
drugan commentedIn the next few days I'll try re-roll the patch to the 8.8 version.
Comment #23
drugan commentedDone.
Comment #24
zenimagine commentedthanks, the patch #23 works for me
Comment #26
zenimagine commentedHi, do you know if the patch will finally be applied to drupal 8.8 ?
Comment #27
zenimagine commented@drugan Hi, was the patch applied to the kernel? If I test a blank installation on simplytest, there is the parameter user ID from the context of the route.
Drupal 8.8.2
Comment #34
pooja saraah commentedFixed failed commands on #23
Attached patch against Drupal 10.1.x
Comment #35
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #38
bhanu951 commentedComment #39
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
This could use an issue summary update using the default template. Steps to reproduce? Was the suggestion what was used in the solution?
Taking this setting away seems like it could affect existing views. If so they'll need upgrade paths.
Comment #41
tyler-durden commentedHours of searching, and I keep on finding this post so I need to ask some questions.
I'm converting my site from Drupal 7 to 10, where on D7 I had multiple views with a contextual filter that properly got the userid from the node the block was on, so I could show other nodes from this author. I have spent hours trying to get it to work, is this post stating this is not working in Drupal 10+?
I have the option, "Also look for a node and use the node author" checked so I'd assume since that option is in there it should be working? This seems to be a feature I'd think many sites would need, so maybe I'm just not doing something right?
I'd try this patch, but it looks like it has issues now and I'm on 10.1. If this is the patch to try I can help test, as I'm not a programmer but I will help how I can.
Comment #42
tyler-durden commentedI found a work around, instead of basing my view on node/content, I based it on users and used the authour/user relationship to pull nodes and it works great.