Problem/Motivation

When adding multiple handlers to a view area (i.e. "Header") you are able to change the order of the handlers. Unfortunately Views doesn't respect this order but prints the items based on the weight each handler sets while rending (i.e. the weight of a block).

Proposed resolution

Update the weight of each area based on its position.

Patch follows.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stBorchert created an issue. See original summary.

stBorchert’s picture

Status: Active » Needs review
FileSize
756 bytes

Update weight after area rendering. Unfortunately I couldn't find a way to do this directly on render, since each handler does different things.

dawehner’s picture

Issue tags: +Needs tests

This patch looks perfect, but given it fixes a bug, we should have a test.

dawehner’s picture

Status: Needs review » Needs work

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

k4v’s picture

Assigned: Unassigned » k4v
Issue tags: +DrupalCampES
k4v’s picture

k4v’s picture

Status: Needs work » Needs review
dawehner’s picture

Issue tags: -Needs tests

The setup of the test in general looks pretty good. Here are some comments, but after that this is totally perfect.

  1. +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_area_order.yml
    @@ -0,0 +1,53 @@
    +        entity_block_1:
    +          field: entity_block
    +          id: entity_block
    +          table: views
    +          target: 'bartik_powered'
    +          view_mode: full
    +          plugin_id: entity
    +        entity_block_2:
    +          field: entity_block
    +          id: entity_block
    +          table: views
    +          target: 'bartik_branding'
    +          view_mode: full
    +          plugin_id: entity
    

    In order to test that properly we should add position: for the two cases.

  2. +++ b/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php
    @@ -0,0 +1,79 @@
    +/**
    + * @file
    + * Contains \Drupal\Tests\views\Kernel\Handler\AreaOrderTest.
    + */
    

    We can remove/drop that bit now.

  3. +++ b/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php
    @@ -0,0 +1,79 @@
    +    $this->executeView($view);
    +    $rendered_view = $view->render();
    +    $output = $renderer->renderRoot($rendered_view);
    

    You should be able to achieve the same by just using $output = $this->render($view->buildRenderable())

  4. +++ b/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php
    @@ -0,0 +1,79 @@
    +    $this->assertTrue($position_powered != 0, 'ID bartik-powered found.');
    +    $this->assertTrue($position_branding != 0, 'ID bartik-branding found');
    +    $this->assertTrue($position_powered < $position_branding, 'Block bartik-powered is positioned before block bartik-branding');
    

    Just a quick comment: You could have used assertNotEquals($position_powered, 0) and assertGreaterThan. This makes it a bit easier to read at the end.

k4v’s picture

Updated. I prefer the test with <. "assertGreaterThan" requires to swap the order which confuses me...

stBorchert’s picture

k4v++
I owe you a beer (or something similar) for writing the test ;)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

@k4v
Okay sure, no worries

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

#9.1 hasn't been addressed - is position saved to the view - I think it is. Also I think entity_block_2 should be positioned before entity_block_1 as that is more of a test. Note that changing the position should not affect the order of the blocks in the view.

dawehner’s picture

#9.1 hasn't been addressed - is position saved to the view - I think it is. Also I think entity_block_2 should be positioned before entity_block_1 as that is more of a test. Note that changing the position should not affect the order of the blocks in the view.

@k4v explained me that in person. The position is not setable via configuration, but rather just the order in the files is taken into account there. Given that the testcase itself makes totally sense IMHO, but yeah I agree using the keys in a different order would be nice, just to ensure that we don't sort by keys.

k4v’s picture

I changed the labels in the yml. As dawehner mentioned, I cannot set 'position' in the yml. The order of the blocks is taken from the position in the yml.

k4v’s picture

Status: Needs work » Needs review
k4v’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

Committed f21cdec and pushed to 8.1.x and 8.2.x. Thanks!

Can we get a followup to add a position key instead of reordering whole sections - doing that making looking configuration changesets much easier. atm the diff is unreadable.

FILE: ...al/core/modules/views/tests/src/Kernel/Handler/AreaOrderTest.php
----------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
 65 | ERROR | [x] No space found after comma in function call
 65 | ERROR | [x] Expected one space after the comma, 0 found
 66 | ERROR | [x] No space found after comma in function call
 66 | ERROR | [x] Expected one space after the comma, 0 found
 75 | ERROR | [x] The closing brace for the class must have an empty
    |       |     line before it
----------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 34ms; Memory: 4.25Mb

Fix all of this on commit.

  • alexpott committed 84258cb on 8.2.x
    Issue #2680227 by k4v, stBorchert, dawehner: Views does not respect...

  • alexpott committed f21cdec on 8.1.x
    Issue #2680227 by k4v, stBorchert, dawehner: Views does not respect...

Status: Fixed » Closed (fixed)

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