Problem/Motivation

When we place a block and set it to show only under some content type conditions, it does never show.

Steps to reproduce:

1 - Move to admin->structure->block.
2 - Click on any block example Who's new block.
3 - In settings page checked Content types as Basic Page.
4 - select any region to display the block and do other configurations.
5 - Visit the site the block will not display.

6 - Go back to configuration page and remove that content type.
7 - Move to the pages, Block will be there.

Proposed resolution

Fix the context used, using a namespaced one: node.node.

Remaining tasks

User interface changes

The blocks are shown as expected.

API changes

None.

Original report by @sidharthap

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because is a regression from D7
Issue priority Major because it will affect lots of sites.
Disruption Non disruptive.

Comments

sidharthap’s picture

Assigned: Unassigned » sidharthap
Status: Active » Needs review
StatusFileSize
new989 bytes

Here is the patch to fix it.

Status: Needs review » Needs work

The last submitted patch, 1: block-display-2391289-1.patch, failed testing.

sidharthap’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: block-display-2391289-1.patch, failed testing.

sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new1.54 KB

Change in test file to cover node type test for Block display.

swentel’s picture

Hmm, so why didn't this test fail before then ?

spadxiii’s picture

Quick guess why the test did not fail: probably because it sets the block configuration up in a different way from the interface?
The patch also changes the test to set the context mapping as 'node' not 'node.node'

Besides the unclear reason for this change, it seems to work fine!

Side note: shouldn't the test use assertBlockAppears and assertNoBlockAppears instead of assertText/assertNoText with the block-label ?

penyaskito’s picture

Looks like both the code and the set up of the test had the same error (using node.node). In the test we are creating the settings via entity API instead of posting to the block settings page, that's why it didn't fail. But NodeRouteContext::onBlockAdministrativeContext uses node (see http://cgit.drupalcode.org/drupal/diff/?id=633d842, #2339151: Conditions / context system does not allow for multiple configurable contexts, eg. language types).

I suggest to use node as the patch already does, as this is also used as an example in Drupal/block/EventSubscriber/BlockContextSubscriberBase docblocks. If we decide to switch to node.node that should be changed too.

Do we really need to alter the tests for using a post to the block settings form?

morbus iff’s picture

Issue tags: +SprintWeekend2015

morbus iff’s picture

Status: Needs review » Reviewed & tested by the community

Attached patch allowed me to select content type block filters again. All worked as I expected.

RavindraSingh’s picture

Issue tags: +Needs reroll
StatusFileSize
new10.94 KB

Patch needs reroll for latest drupal 8.0.x

RavindraSingh’s picture

Status: Reviewed & tested by the community » Needs work
sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new1.54 KB

Here is the new patch.

morbus iff’s picture

Status: Needs review » Reviewed & tested by the community

You beat me to it. Thanks @sidharthap.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think this is the wrong fix. Contexts need to be namespaced otherwise once contrib comes in we're going to have problems.

alexpott’s picture

Priority: Normal » Major

Also this is at least a major bug.

RavindraSingh’s picture

eclipsegc’s picture

I agree with alex, let me look at this today, and I'll see if I can make sense of the problem.

Eclipse

lokapujya’s picture

<?php
public function onBlockAdministrativeContext(BlockContextEvent $event) {
    $context = new Context(new ContextDefinition('entity:node'));
    $event->setContext('node', $context);
  }
?>

Maybe this can change to node.node? Just a guess, not too sure. I tried it, seems to work.

Side note: shouldn't the test use assertBlockAppears and assertNoBlockAppears instead of assertText/assertNoText with the block-label ?

Could be a good improvement.

RavindraSingh’s picture

StatusFileSize
new2.07 KB

Agreed with @alexpott, so I have added context as namespace

RavindraSingh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: 2391289-blocks-invisible.patch, failed testing.

penyaskito’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.38 KB
new2.13 KB

Sorry, I didn't understand the change in #23, this uses #15 as base.

I used the namespaced context 'node.node' and changed the example as said in #9. IMHO the improvement of the test is not a major, so let's do that in a follow-up and get this fixed.

tim.plunkett’s picture

Issue tags: +Needs tests

This needs tests in this issue, not in a follow-up.

lokapujya’s picture

We could also make it more clear what we are using as a namespace (module name, etc.) Add doc to setContext() ?

So for tests, we add the block settings form post?

penyaskito’s picture

We have tests, is only that they are bogus. Let's do what I suggested at #9 for posting the block config instead of (ab)using the API.

penyaskito’s picture

Status: Needs review » Needs work
penyaskito’s picture

Assigned: sidharthap » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.49 KB
new1.36 KB

The attached patch creates the block by posting to the block settings form instead of using the entity API. The only-test patch exposes the bug as it is in core.

penyaskito’s picture

Issue summary: View changes

Updated issue summary and added beta evaluation template.

Status: Needs review » Needs work

The last submitted patch, 31: block-display-2391289-31.only-test.patch, failed testing.

tim.plunkett’s picture

  1. +++ b/core/modules/node/src/Tests/NodeBlockFunctionalTest.php
    @@ -120,18 +120,15 @@ public function testRecentNodeBlock() {
    +    $theme = $this->config('system.theme')->get('default');
    

    Please use \Drupal::service('theme_handler')->getDefault();

  2. +++ b/core/modules/node/src/Tests/NodeBlockFunctionalTest.php
    @@ -120,18 +120,15 @@ public function testRecentNodeBlock() {
    +    $block = entity_load('block', $edit['id']);
    

    Please use Block::load($edit['id']);

penyaskito’s picture

Status: Needs work » Needs review
StatusFileSize
new3.61 KB
new1.48 KB
new1.06 KB

Sure, thanks!

Status: Needs review » Needs work

The last submitted patch, 35: block-display-2391289-35.only-test.patch, failed testing.

penyaskito’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Good find, good fix, good test coverage.
Thanks!

lokapujya’s picture

StatusFileSize
new3.81 KB
new1.2 KB

Minor comment length fix.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed a4df58b and pushed to 8.0.x. Thanks!

  • alexpott committed a4df58b on 8.0.x
    Issue #2391289 by penyaskito, sidharthap, RavindraSingh, lokapujya:...

Status: Fixed » Closed (fixed)

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