Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes it is needed that the referenced entities depend on the referencing entity.
for this a (optional) views argument is needed. (besides tha "already referenced entities" argument)
Comment | File | Size | Author |
---|---|---|---|
#8 | 1626668-8-extra_views_arguments.patch | 1.14 KB | daulet2030 |
#6 | 1626668-6-extra_views_arguments.patch.patch | 1.16 KB | daulet2030 |
#3 | 1626668-3-extra_views_arguments.patch | 1.06 KB | tedbow |
#2 | 1626668-2-extra_views_arguments.patch | 1.35 KB | stella |
Comments
Comment #1
geek-merlinif my current project demands it i might implement it and roll a patch.
for this we need to decide the order of arguments and hom optional.
what makes sense to me:
* rename option "pass argument" to "pass selected entities as views argument"
* add option "pass referencing entity as views argument"
* i'm not totally decided on the order of the arguments, but my gut feeling is that the new argument "referencing entity" should be first.
as both arguments can be switched on separately legacy views will not break.
Comment #2
stella CreditAttribution: stella commentedI've a similar but different issue - I wanted to pass in additional arguments from another form field value on the form (only on edit). To do this I just added in a call to drupal_alter() on 'entityreference_view_widget_views_arguments' and in my custom module then called hook_entityreference_view_widget_views_arguments_alter() to modify the arguments to the View. You might be able to use it or extend it for what you're looking for.
See attached patch.
Comment #3
tedbowI have found this issue because I have similar need as @axel.rutz
@stella I like your idea for the patch. I uploaded a version with 1 small change. I called the drupal_alter after the logic for added the referenced entities as the first argument.
The problem I see with calling the drupal_alter before is that
$arguments[] = implode(',', $selected_entity_ids);
Will add the argument after other arguments that are added in the alter hook. This conflicts with the description on the front end.
With the alter hook being after the hook code can react to whether they the first argument is supplied or not.
Here is the implementation that I needed to pass the Current nid as the second argument.
This way if the nid is available it is always the second argument and by passing 'all' as the first argument the View can will work even if there are no currently selected entities.
Comment #4
tedbowI started another issue to add this hook #1978084: Provide alter hook for view arguments
Comment #5
bojanz CreditAttribution: bojanz commentedThis is a reasonable request.
1.x branch is frozen and won't be getting further non-critical commits.
Hence, moving the issue to 2.x and marking "needs work" for a reroll.
Comment #6
daulet2030 CreditAttribution: daulet2030 commentedRe-rolled previous patch for 7.x-2.x
After you apply this patch you need to create your own module which will call hook_entityreference_view_widget_views_arguments_alter(&$arguments, $form_state), and add your arguments to $arguments array based on information in $form_state variable. And also update your view to accept this arguments.
For example:
Note: Previous patch used $context variable instead of $form_state
Comment #7
jsacksick CreditAttribution: jsacksick commentedHi, thanks for the patch, however, could you fix the space issues (2 spaces instead of 4) and could you also create a .api.php file to document the alter hook?
Comment #8
daulet2030 CreditAttribution: daulet2030 commentedNumber #4 might be a better candidate for re-roll, it also supports field collections from my understanding.
As requested here's re-rolled patch and api.php. Please note that I am new to patching and documentation :)
Comment #9
jsacksick CreditAttribution: jsacksick commentedThanks for your patch, I committed a slightly different patch.
Comment #12
arzuga CreditAttribution: arzuga commentedWhy this feature is not available in last version?