Problem/Motivation

The argument handler ViewsReferenceArgument currently uses the node from the route as token replacement argument:

$node = $this->routeMatch->getParameter('node');
....
$arguments[$index] = $this->tokenService->replace($argument, ['node' => $node]);

This is problematic if the reference field is used on other entities / nested entities e.g. Paragraphs. In such cases the arguments field won't accept tokens from the entity the reference field belongs to because the context data is missing.

Steps to reproduce

Add multiple Paragraphs with the same Views Reference field. Attempt to have them differ based on the argument, yet the argument is the same, so they cannot differ.

Proposed resolution

The suggestion is to pass the context data of the entity where the reference field is actually attached to.

Remaining tasks

  1. Initial draft merge request
  2. Address feedback in #42
  3. Address feedback in #62
  4. Resolve all feedback on the MR itself
  5. Ensure no new phpstan/phpcs/etc issues are added (currently issues are added)
  6. Add test coverage
  7. Arguments plugin should implement alterFormField to explain which tokens are available in the arguments

User interface changes

Details about which tokens are replaced in arguments plugin are provided

API changes

More tokens are replaced in the arguments plugin

Data model changes

None

Original issue summary

Hello. I created a few fields in the paragraph and also attached viewsreference field.
Since the node can have a few similar paragraphs, I want to display only own content related to the current paragraph.
However when I am trying to use "[paragraph:id]", nothing happen.

I have checked alterView() and seams as the viewsreference module are looking for tokens from the node and maybe will work in some cases, but I don't know how to pass a current delta value in the token, example [node:field_content_bottom:0:target_id].

Anyway or idea how to fix it?
Thanks in advance.


The argument handler ViewsReferenceArgument currently uses the node from the route as token replacement argument:

$node = $this->routeMatch->getParameter('node');
....
$arguments[$index] = $this->tokenService->replace($argument, ['node' => $node]);

This is problematic if the reference field is used on other entities / nested entities e.g. Paragraphs. In such cases the arguments field won't accept tokens from the entity the reference field belongs to because the context data is missing.
The suggestion is to pass the context data of the entity where the reference field is actually attached to.

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

RuslanP created an issue. See original summary.

ruslan piskarov’s picture

Issue summary: View changes
venge’s picture

I also search a solution for the same problem.

bmunslow’s picture

Check the patch submitted in comment 11 in this issue:

https://www.drupal.org/project/viewsreference/issues/2836015#comment-125...

I haven't tested the patch yet, but it seems to do exactly what you are requesting.

I will try it out and report back about it.

meltajon’s picture

#4 works for me, I'm able to pass [paragraph:id] as an argument to my view.

bmunslow’s picture

Yes, I can confirm as well that I have tried and tested the patch linked in #4 and it works perfectly

ruslan piskarov’s picture

Status: Active » Needs review
Related issues: +#2836015: Use tokens in arguments input
StatusFileSize
new6.83 KB

Copied the path with the author info. Thank you.

amerie’s picture

StatusFileSize
new6.83 KB

I was asked to upload my patch from https://www.drupal.org/project/viewsreference/issues/2836015 to this issue, so here it is. :)

ruslan piskarov’s picture

jacobbell84’s picture

Thanks all for the work on this. In my testing I did find one issue, in that when you use this patch with an Ajax view you'll receive the following error on subsequent Ajax calls:

TypeError: Argument 3 passed to Drupal\viewsreference\Plugin\ViewsReferenceSetting\ViewsReferenceArgument::alterView() must implement interface Drupal\Core\Entity\EntityInterface, null given

That seems to happen because the entity isn't passed in the Ajax request. Since the entity is just for token replacement, I don't think we need it on subsequent Ajax calls anyways because the parameters that have already been set do get passed on future calls, so I adjusted the patch to just check and make sure we have an entity before trying to call the alterView functions.

jacobbell84’s picture

Version: 8.x-2.0-alpha4 » 8.x-2.x-dev
StatusFileSize
new8.67 KB

Re-rolling the patch to support the dev branch

jacobbell84’s picture

Re-rolling the patch to support the alpha5 release

wadator’s picture

Re-rolling the patch to support the 8.x-2.x-dev release

ecj’s picture

After enabling the modules (drupal-core 8.9.6) paragraph & token, I don't see or get a return value for the token [paragraph:id]. I did see this token in a distro where it later disappeard.

As I see a mentioning of this tken [paragraph:id] in this discussion - any idea how to enable the token paragraph:id, I suppose its defined somewhere already.. ?

ruslan piskarov’s picture

@ecj, look the screenshot in the description of this issue, enable argument for the field and put [paragraph:id] manually.

ecj’s picture

@ruslan, thank you for yout input, but I humbly fail to see the relationship between your answer and my question: where does this '[paragraph:id]' token get created & enabled, not in modules paragraphs or token as far as I can see/find. When you look at /admin/help/token under the 'paragraph' part, I only find URL and original parts.. no paragraph:id, although I did see it before.. so how to enable, where is it ?

ruslan piskarov’s picture

@ecj,
On /admin/help/token under Paragraph section I see https://take.ms/VXOIP.
Not sure why you can't see it.
On my project enabled token and paragraph module.

jacobbell84’s picture

someshver’s picture

Hi @all

When I applied #13 patch than my CSS stops loading on site. Can you please fix the issue my Drupal core version is 8.9.8

ruslan piskarov’s picture

Hey @someshver, I don't see any reason that could break the site styles. Could you try clear cache? What do you see in Drupal logs and console logs?

someshver’s picture

Hi @ruslan_piskarov

I have fixed the issue. I do have two installations on my root directory one is inside docroot/ and the other one is inside web/ so that is conflicting the changes to docroot/ and web/ .

dgaspara’s picture

#13 works for me. Thanks!

seanb’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/ViewsReferenceSetting/ViewsReferenceArgument.php
@@ -30,19 +31,25 @@ class ViewsReferenceArgument extends PluginBase implements ViewsReferenceSetting
+  public function alterView(ViewExecutable $view, $value, EntityInterface $entity) {

+++ b/src/Plugin/ViewsReferenceSetting/ViewsReferenceLimit.php
@@ -32,7 +33,7 @@ class ViewsReferenceLimit extends PluginBase implements ViewsReferenceSettingInt
+  public function alterView(ViewExecutable $view, $value, EntityInterface $entity) {

These changes would break the ViewsReferenceSettingInterface.

In #2957177: Pass view name and display id to alterFormField() method in ViewsReferenceSetting plugin we had a similar problem and decided to pass extra configuration to the plugins via the plugin configuration. I think we should probably do the same here.

socialnicheguru’s picture

with the latest dev version the patch from 13 no longer applies

someshver’s picture

The given patches are not working on the latest version

alphawebgroup’s picture

Status: Needs work » Needs review
StatusFileSize
new8.78 KB

re-rolled

someshver’s picture

I am getting the error after applying the patch.
TypeError: Argument 3 passed to Drupal\viewsreference\Plugin\ViewsReferenceSetting\ViewsReferenceArgument::alterView() must implement interface Drupal\Core\Entity\EntityInterface, array given, called in web\modules\contrib\viewsreference\viewsreference.module on line 82 in Drupal\viewsreference\Plugin\ViewsReferenceSetting\ViewsReferenceArgument->alterView() (line 34 of web\modules\contrib\viewsreference\src\Plugin\ViewsReferenceSetting\ViewsReferenceArgument.php)

socialnicheguru’s picture

Status: Needs review » Needs work
arunverma’s picture

StatusFileSize
new8.78 KB

Regenerated patch for version ^2.0@beta

ruslan piskarov’s picture

Thank you @arunverma :)

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

socialnicheguru’s picture

Patch in #29 is not applying for version 2.0-beta3:

Installing drupal/viewsreference (2.0.0-beta3): Extracting archive
- Applying patches for drupal/viewsreference
https://www.drupal.org/files/issues/2022-05-25/2985364-29.patch (Is there any way to pass the token from the current paragraph to the view?)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-05-25/2985364-29.patch

justskew’s picture

ruslan piskarov’s picture

Status: Needs work » Needs review
StatusFileSize
new8.79 KB

Re-rolled patch for version 2.0-beta3.
We can't apply #33 by the composer.

aaronpinero’s picture

I can confirm that patch #34 works for me with version 2.0-beta3.

seanb’s picture

In #3090713: Parent field entity in plugin interface we have a patch to pass the parent entity data to the view using $view->element['#viewsreference'] so other (custom) views alter hooks can do with the data whatever they want. This would at least allow a view alter to set arguments based on the parent entity.
This does not add token support though. Maybe we need to add support here for a custom "parent_entity" token?

socialnicheguru’s picture

Rerolled for dev version

aaronpinero’s picture

Patch #34 does not cleanly apply to the latest beta (6). I didn't check #40. I've been depending on patch #34 for quite a while now, it would be great if we could get an updated patch (or, better yet, something permanent merged).

Thanks.

seanb’s picture

Status: Needs review » Needs work

I would accept a patch that adds a custom token for the parent entity data passed in via $view->element['#viewsreference'].
See #3090713: Parent field entity in plugin interface:

     $view->element['#viewsreference'] = [
       'data' => $unserialized_data,
       'enabled_settings' => $unserialized_enabled_settings,
+      'parent_entity_type' => $parent_entity_type,
+      'parent_entity_id' => $parent_entity_id,
+      'parent_field_name' => $parent_field_name,
     ];

The latest patch and the MR uses the node from the route argument, which is not necessarily the parent entity (eg. when using paragraphs or layout builder). This also doesn't work for non-node entities.

ndewhurst’s picture

It seems that #40 applies to the latest release but causes an error with $items->getEntity() because $items does not exist in the lazyBuilder method.
Here is an updated patch that loads the entity based on the (newly?) provided parent_entity_* vars.

Note: I am not familiar with this module and I'm sure this is not the best solution. You probably don't need to pass the entity everywhere if the parent entity type and ID are available. I'm just trying to maintain compatibility in a project that has some dependencies declaring that they need this patch.

aaronpinero’s picture

I tried applying patch #43 to the beta6 release via composer. The patch applied cleanly, but my pages using the views reference field displayed the WSOD. The log recorded the following error:

AssertionError: When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #attached. in assert() (line 334 of /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php)
#0 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(334): assert(false, 'When a #lazy_bu...')
#1 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#2 /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php(934): Drupal\Core\Render\Renderer->render(Array)
#3 /var/www/html/web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(1170): Drupal\views\Plugin\views\field\EntityField->render_item(0, Array)
#4 /var/www/html/web/core/modules/views/views.theme.inc(238): Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object(Drupal\views\ResultRow))
#5 [internal function]: template_preprocess_views_view_field(Array, 'views_view_fiel...', Array)
#6 /var/www/html/web/core/lib/Drupal/Core/Theme/ThemeManager.php(287): call_user_func_array('template_prepro...', Array)
#7 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render('views_view_fiel...', Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#9 /var/www/html/web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(1746): Drupal\Core\Render\Renderer->render(Array)
#10 /var/www/html/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(777): Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object(Drupal\views\ResultRow))
#11 [internal function]: Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
#12 /var/www/html/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#13 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#14 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#15 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#16 /var/www/html/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(716): Drupal\Core\Render\Renderer->render(Array)
#17 /var/www/html/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(582): Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array)
#18 /var/www/html/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(473): Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, true)
#19 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2169): Drupal\views\Plugin\views\style\StylePluginBase->render(Array)
#20 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1538): Drupal\views\Plugin\views\display\DisplayPluginBase->render()
#21 /var/www/html/web/core/modules/views/src/Plugin/views/display/Block.php(131): Drupal\views\ViewExecutable->render()
#22 /var/www/html/web/core/modules/views/src/ViewExecutable.php(1635): Drupal\views\Plugin\views\display\Block->execute()
#23 /var/www/html/web/core/modules/views/src/Element/View.php(81): Drupal\views\ViewExecutable->executeDisplay('block_3', Array)
#24 /var/www/html/web/core/modules/views/src/Plugin/Block/ViewsBlock.php(59): Drupal\views\Element\View::preRenderViewElement(Array)
#25 /var/www/html/web/core/modules/block/src/BlockViewBuilder.php(171): Drupal\views\Plugin\Block\ViewsBlock->build()
#26 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array)
#27 /var/www/html/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#28 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#29 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#30 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\Core\Render\Renderer->doRender(Array)
#31 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#32 /var/www/html/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render(Array)
#33 /var/www/html/web/sites/default/files/php/twig/64f8e0a2e7225_page.html.twig_e7hh4y0wifva4a_ScRFDQ36Sd/zfFVEjIYHqdRX1anIHqxRCGpcFxi4utbCkf16f__ry0.php(147): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#34 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_4c484e285e34c1c517dfce0f56403aae->doDisplay(Array, Array)
#35 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#36 /var/www/html/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#37 /var/www/html/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array)
#38 /var/www/html/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/h...', Array)
#39 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render('page', Array)
#40 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#41 /var/www/html/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render(Array)
#42 /var/www/html/web/sites/default/files/php/twig/64f8e0a2e7225_html.html.twig_K7e0YUqNYNYFXZjaSejrhWCNJ/F9GmlgEUaQj5BFA8BJiV1mhKLHdT20aW1lYKJfOlhzk.php(87): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#43 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_e64b960fb8704841d8453d0d3f187c3c->doDisplay(Array, Array)
#44 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#45 /var/www/html/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#46 /var/www/html/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array)
#47 /var/www/html/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/h...', Array)
#48 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render('html', Array)
#49 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender(Array, false)
#50 /var/www/html/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(162): Drupal\Core\Render\Renderer->render(Array)
#51 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#52 /var/www/html/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(163): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#53 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#54 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#55 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#56 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(174): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#57 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#58 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#59 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#60 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#61 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#62 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#63 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#64 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#65 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#66 {main}

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

ysalamone’s picture

Patch #43 works well for me, I only added support for translated parent entity (it seems like the default translation was the one always used).

NB: This is my first contribution, any advice is appreciated!

Ruslan Piskarov changed the visibility of the branch 2985364- to hidden.

ruslan piskarov’s picture

I suggest working on a different approach as mentioned @seanB at #42.
Since parent_entity_type and parent_entity_id already are available, we can fix it more easily.
Not sure I covered all cases.
Need review.
Works with 2.0-beta7.

ruslan piskarov’s picture

Added support for a translated parent entity too.

ruslan piskarov’s picture

ruslan piskarov’s picture

StatusFileSize
new2.22 KB

Improvered. Covered more cases, like [paragraph:field_taxonomy_ref:target_id].

ruslan piskarov’s picture

StatusFileSize
new3.19 KB

Fixed the issue when a view has ajax enabled and pagination doesn't work.

jacobbell84’s picture

Patches 51 and 52 aren't working for me. I'm confused on some of the changes there. Patch 51 mentioned that it covers more bases, but the only change I see was this:

+      elseif (isset($view->element['#viewsreference']['entity'])
+        && $view->element['#viewsreference']['entity'] instanceof EntityInterface) {
+        $replacements[$view->element['#viewsreference']['entity']
+          ->getEntityTypeId()] = $view->element['#viewsreference']['entity'];
+      }

$view->element['#viewsreference']['entity'] is a holdover from an older patch though, it's not being set anywhere in this patch. Then 52 adds an additional check to fix ajax pagination:

-  $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
-  $plugin_definitions = $viewsreference_plugin_manager->getDefinitions();
-  if (isset($view->element['#viewsreference']['enabled_settings'])) {
+  if (isset($view->element['#viewsreference']['entity'])) {
+    $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
+    $plugin_definitions = $viewsreference_plugin_manager->getDefinitions();

Because of that check, and ['entity'] never being set, these plugins never execute for me anymore.

generalredneck’s picture

echoing @jacobbell84.
I fixed it by changing the check in hhok_views_pre_view like so:

    // Let all settings plugins alter the view.
-   if (isset($view->element['#viewsreference']['entity'])) {
+   if (isset($view->element['#viewsreference'])) {

I don't see where the ['entity'] key is being set anywhere either. I don't know if this is 100% correct. thoughts?

ruslan piskarov’s picture

If I remember correctly the ['entity'] will appear if embed a view with enabled ajax in pagination.
First time it mentioned at #10.
I can't test today. Need improve a patch.

socialnicheguru’s picture

No longer works with the dev version

scott_euser’s picture

Thanks everyone for the work on this! To help review it would be good to have a single branch, and other branches hidden as its unclear at the moment (+ mix of paches).

Looking at 2985364-pass-token-from-paragraph branch, it would be good for someone to explain better to me the aim here. From the issue summary, it seems it should be isolated to the ViewsReferenceArgument setting, but all settings are changed? So maybe issue summary needs an update, or scope needs to be more limited.

Now that we have test coverage everywhere, any merge requests coming in would also need to have test coverage please.

Thanks!

socialnicheguru’s picture

Reroll of 52 to apply to latest version of module

jv24’s picture

#58 looks like it was just missing the $token_service variable. Updated patch to include it

das-peter made their first commit to this issue’s fork.

das-peter changed the visibility of the branch 2985364-updates-for-beta6 to hidden.

das-peter’s picture

Issue summary: View changes

Review of: #59

  1. +++ b/src/Plugin/ViewsReferenceSetting/ViewsReferenceArgument.php
    @@ -77,11 +78,32 @@
    +      $token_service = \Drupal::token();
           if (is_array($arguments)) {
             foreach ($arguments as $index => $argument) {
               if (!empty($this->tokenService->scan($argument))) {
    -            $arguments[$index] = $this->tokenService->replace($argument, ['node' => $node]);
    +            $arguments[$index] = $token_service->replace($argument, $replacements);
    

    Why are we getting the token service while we already have the service via DI? It is even used in the condition before the replacement.

  2. +++ b/viewsreference.module
    @@ -95,9 +95,9 @@ function viewsreference_views_pre_view(ViewExecutable $view, $display_id, array
    -  $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
    -  $plugin_definitions = $viewsreference_plugin_manager->getDefinitions();
    -  if (isset($view->element['#viewsreference']['enabled_settings'])) {
    +  if (isset($view->element['#viewsreference']['entity'])) {
    +    $viewsreference_plugin_manager = \Drupal::service('plugin.manager.viewsreference.setting');
    +    $plugin_definitions = $viewsreference_plugin_manager->getDefinitions();
    

    Seems unnecessary - the ['entity'] addition came from the other approach it seems (pre #48).


If I get the general consensus the new approach started in #48 is the preferred one.
I'd agree with that since that approach needs less changes and seems to work in a generic approach while maintaining backward compatibility.
That said - I've created new branches in the fork:

  • 2985364-pass-token-from-paragraph-light-approach: Patch from #59 with the changes I mentioned above
  • 2985364-pass-token-from-paragraph-legacy-approach: Pre-#48 code

The MR branch 2985364-pass-token-from-paragraph contains now the light approach

@scott_euser There should be now only one Branch / MR - I've also added an update to the issue summary. Haven't gotten around to add tests yet - hence keeping on needs work.

das-peter changed the visibility of the branch 2985364-pass-token-from-paragraph-light-approach to hidden.

das-peter changed the visibility of the branch 2985364-pass-token-from-paragraph to hidden.

das-peter changed the visibility of the branch 2985364-pass-token-from-paragraph to active.

das-peter changed the visibility of the branch 2985364-pass-token-from-paragraph-legacy-approach to hidden.

chucksimply’s picture

I'm on 2.0-beta10...

#59 broke arguments entirely.
#60 MR works perfectly.

Thanks!

vlyalko’s picture

I have created a patch to be used until #60 MR created by daspeter is merged. It works perfectly. Thank you

scott_euser’s picture

Issue summary: View changes

I have attempted to update the issue summary to provide clarity as to what is needed to get this issue into a merge-able state.

jacobbell84’s picture

Issue summary: View changes

I've updated the PR with the comments from #69, moving the node replacement code out of the if statement to maintain existing functionality.

jacobbell84’s picture

Status: Needs work » Needs review
scott_euser’s picture

Status: Needs review » Needs work

Thanks! Looks like the remaining tasks in the issue summary are not complete though.