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
| Issue category | Bug because is a regression from D7 |
|---|---|
| Issue priority | Major because it will affect lots of sites. |
| Disruption | Non disruptive. |
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | interdiff-2391289-39.txt | 1.2 KB | lokapujya |
| #39 | 2391289-39.patch | 3.81 KB | lokapujya |
| #35 | block-display-2391289-35.only-test.patch | 1.48 KB | penyaskito |
| #35 | block-display-2391289-35.patch | 3.61 KB | penyaskito |
Comments
Comment #1
sidharthapHere is the patch to fix it.
Comment #3
sidharthapComment #6
sidharthapChange in test file to cover node type test for Block display.
Comment #7
swentel commentedHmm, so why didn't this test fail before then ?
Comment #8
spadxiii commentedQuick 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 ?
Comment #9
penyaskitoLooks 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. ButNodeRouteContext::onBlockAdministrativeContextusesnode(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
nodeas the patch already does, as this is also used as an example inDrupal/block/EventSubscriber/BlockContextSubscriberBasedocblocks. If we decide to switch tonode.nodethat should be changed too.Do we really need to alter the tests for using a post to the block settings form?
Comment #10
morbus iffComment #12
morbus iffAttached patch allowed me to select content type block filters again. All worked as I expected.
Comment #13
RavindraSingh commentedPatch needs reroll for latest drupal 8.0.x
Comment #14
RavindraSingh commentedComment #15
sidharthapHere is the new patch.
Comment #16
morbus iffYou beat me to it. Thanks @sidharthap.
Comment #17
alexpottI think this is the wrong fix. Contexts need to be namespaced otherwise once contrib comes in we're going to have problems.
Comment #18
alexpottAlso this is at least a major bug.
Comment #19
RavindraSingh commentedComment #20
eclipsegc commentedI agree with alex, let me look at this today, and I'll see if I can make sense of the problem.
Eclipse
Comment #21
lokapujyaMaybe this can change to node.node? Just a guess, not too sure. I tried it, seems to work.
Could be a good improvement.
Comment #23
RavindraSingh commentedAgreed with @alexpott, so I have added context as namespace
Comment #24
RavindraSingh commentedComment #26
penyaskitoSorry, 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.Comment #27
tim.plunkettThis needs tests in this issue, not in a follow-up.
Comment #28
lokapujyaWe 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?
Comment #29
penyaskitoWe 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.
Comment #30
penyaskitoComment #31
penyaskitoThe 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.
Comment #32
penyaskitoUpdated issue summary and added beta evaluation template.
Comment #34
tim.plunkettPlease use
\Drupal::service('theme_handler')->getDefault();Please use
Block::load($edit['id']);Comment #35
penyaskitoSure, thanks!
Comment #37
penyaskitoComment #38
tim.plunkettGood find, good fix, good test coverage.
Thanks!
Comment #39
lokapujyaMinor comment length fix.
Comment #41
alexpottThis 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!