The "View" area handler in Views, which can be used to embed one view inside the header or footer of another, simply does not work in Drupal 8.

Adding it to a view and then trying to display that view results in a fatal error: Call to undefined method Drupal\views\Entity\View::setDisplay() in core/modules/views/lib/Drupal/views/Plugin/views/area/View.php on line 115

Comments

longwave’s picture

Status: Active » Needs review
StatusFileSize
new720 bytes

The attached patch fixes this, but I guess this means this handler has zero test coverage.

Status: Needs review » Needs work

The last submitted patch, 1: 2149107-views-view-area.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

1: 2149107-views-view-area.patch queued for re-testing.

dawehner’s picture

Issue tags: +VDC, +Needs tests

The fix looks perfect, though we need some tests, so that never happens again.

longwave’s picture

Added a test for this handler, including the "inherit arguments" feature.

The last submitted patch, 5: 2149107-views-view-area-5-test-only.patch, failed testing.

damiankloip’s picture

  1. +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaViewTest.php
    @@ -0,0 +1,62 @@
    +    $view = views_get_view('test_area_view');
    

    Can this use Views::getView()

  2. +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaViewTest.php
    @@ -0,0 +1,62 @@
    +    $view->setDisplay('default');
    ...
    +    $view->setDisplay('default');
    

    We could just ditch these as executeView will call setDisplay() anyway, which will just set 'default'.

longwave’s picture

StatusFileSize
new3.96 KB
new1.24 KB

Changes from #7 applied.

longwave’s picture

StatusFileSize
new3.96 KB

Reuploading, as testbot seems to have eaten the last patch.

Status: Needs review » Needs work

The last submitted patch, 9: 2149107-views-view-area-8.patch, failed testing.

longwave’s picture

Status: Needs work » Needs review

...and then HEAD was temporarily broken :(

9: 2149107-views-view-area-8.patch queued for re-testing.

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaViewTest.php
@@ -0,0 +1,62 @@
+  public static function getInfo() {
...
+  protected function setUp() {

Let's just add @inheritdoc there, so the commit is not blocked based on that.

+++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaViewTest.php
@@ -0,0 +1,62 @@
+    $this->assertTrue(strpos($output, 'John') !== FALSE, 'The test view is correctly embedded.');
...
+    $this->assertTrue(strpos($output, 'John') === FALSE, 'The test view is correctly embedded with inherited arguments.');
+    $this->assertTrue(strpos($output, 'George') !== FALSE, 'The test view is correctly embedded with inherited arguments.');

I wonder whether we should use some xpath here/

damiankloip’s picture

Hm, good point. I thought (assumed) this was a ViewsUnitTestBase test, maybe we could make it one of those?

longwave’s picture

I tried to use ViewsUnitTestBase but got stuck when Drupal\views\Plugin\views\area\View::render() checks access of the child view; it ended up calling user_access eventually and required the user and roles in the database, and I am not clever enough to figure out if there is a way to mock/stub that out yet.

longwave’s picture

StatusFileSize
new4.03 KB
new1.69 KB

I managed to convert it to a ViewUnitTestBase, turns out all I have to do is declare that the user module needs to be enabled. I couldn't find any xpath assertions available from unit tests, so I am still using strpos(), but I improved the first test to actually look for the class name of the embedded view.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

That is fine for now

xjm’s picture

Priority: Normal » Major

The whole functionality being completely broken is kinda major. ;) Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed cfd1c3a and pushed to 8.x. Thanks!

xjm’s picture

Title: "View" area handler in Views gives fatal error » HEAD BROKEN: "View" area handler in Views gives fatal error
Priority: Major » Critical
Status: Fixed » Reviewed & tested by the community

The new test added by this patch is currently failing in HEAD:

Drupal\views\Tests\Handler\AreaViewTest (4 pass(es), 0 fail(s), and 1 exception(s))
   - [exception] [Uncaught exception] "Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "field.info" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 875 of /var/lib/drupaltestbot/sites/default/files/checkout/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php). Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('field.info')
Symfony\Component\DependencyInjection\ContainerBuilder->get('field.info')
Drupal\user\UserStorageController::createInstance(Object, 'user', Array)
Drupal\Core\Entity\EntityManager->getController('user', 'storage')
Drupal\Core\Entity\EntityManager->getStorageController('user')
Drupal\user\Theme\UserNegotiator->__construct(Object, Object)
ReflectionClass->newInstanceArgs(Array)
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'theme.negotiator.user')
Symfony\Component\DependencyInjection\ContainerBuilder->get('theme.negotiator.user', 1)
Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Object)
Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Array)
Symfony\Component\DependencyInjection\ContainerBuilder->callMethod(Object, Array)
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'theme.negotiator')
Symfony\Component\DependencyInjection\ContainerBuilder->get('theme.negotiator')
Drupal::service('theme.negotiator')
drupal_theme_initialize()
Drupal\Core\Theme\Registry->init(NULL)
Drupal\Core\Theme\Registry->__construct(Object, Object, Object)
ReflectionClass->newInstanceArgs(Array)
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'theme.registry')
Symfony\Component\DependencyInjection\ContainerBuilder->get('theme.registry')
Drupal::service('theme.registry')
theme(Array, Array)
drupal_render(Array)
Drupal\views\Tests\Handler\AreaViewTest->testViewArea()
Drupal\simpletest\TestBase->run()
simpletest_script_run_one_test('755', 'Drupal\views\Tests\Handler\AreaViewTest')
" in ContainerBuilder.php on line 875 of Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition().

So we need to either fix it or:
git revert cfd1c3ae
@andypost is currently debugging but it might be better to revert and then fix the test. This patch last ran on testbot on Dec. 8.

berdir’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new848 bytes
new1.87 KB

Attached is a patch that fixes it.

Quite sure that this is related to the base theme/theme callback issue that went in recently. it attempts to do a user_load(0) there, for some reason in \Drupal\user\Theme\UserNegotiator. Doesn't make sense, we should prevent that. Seems actually easy to do, so attaching an alternative patch that fixes a test by doing that. Note that I changed the constructor as well, because the current code already instantiates the user storage controller including it's dependencies (field.info service) even though we'll never nead that. Nicely shows the problem with injecting services that will not be needed, so a a lot of processing on for nothing.

berdir’s picture

Note that the $user->theme thing there is also quite probably wrong, that's the field item list object, not the value. No test coverage for this?

EDIT: What it should be using is $user->getDefaultTheme()

webchick’s picture

Title: HEAD BROKEN: "View" area handler in Views gives fatal error » "View" area handler in Views gives fatal error
Status: Needs review » Needs work

Reverted c47f5c70e for now.

andypost’s picture

+1 to alternative patch, anonymous user should not have theme fallback.

Not sure about $user->theme seems we have user.data for that

berdir’s picture

As discussed in IRC, my vote is on committing the bandaid test fix, open a major or critical (functional and performance regression) issue about the UserNegotiator.

xjm’s picture

Discussed with @berdir. We'll open a separate followup for #1954892: Replace 'theme callback' and hook_custom_theme() with a clean theme negotiation system, which did also add the same workaround as in @berdir's first patch above:
+ public static $modules = array('user', 'field');

Meanwhile, we'll add that same workaround to this patch.

xjm’s picture

Priority: Critical » Major

Thanks @webchick!

Edit:

Reverted c47f5c70e for now.

Dunno where that commit hash came from, but the correct commit did actually get reverted:

commit 8aab1a030eef2bb08b8022025d5da991c56c1715
Author: webchick <webchick@24967.no-reply.drupal.org>
Date:   Thu Dec 26 09:47:10 2013 -0800

    Revert "Issue #2149107 by longwave: "View" area handler in Views gives fatal error."
    
    Busted HEAD.
    
    This reverts commit cfd1c3ae1def7d59d603aa150f353e2e1a37a507.

:)

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new4.18 KB
new848 bytes

Here's @longwave's patch rerolled with @berdir's fix.

berdir’s picture

berdir’s picture

That issue should now be an easy patch, I'd suggest to postpone this on that and then go back to the previous patch in #15 that doesn't need the workaround.

longwave’s picture

15: 2149107-views-view-area-15.patch queued for re-testing.

#15 should be safe to commit again now #2163035: Remove $user->theme and Drupal\user\Theme\UserNegotiator is fixed.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Yes, the patch in #15 is RTBC again. Hidding all other patches that were posted in the meantime.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2d92955 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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