Problem/Motivation

CTools and Rules both add additional contextual condition plugins. Core's block visibility UI does not get conditions based on available contexts and instead simply asks for all Conditions.

Proposed resolution

Update the block form to ask the ConditionManager for only contextually relevant plugins instead of all plugins.

Remaining tasks

  1. Patch
  2. Review
  3. Commit

User interface changes

This should appropriately reduce the number of conditions displayed in the block placement UI which will likely fix some issues seen when installing various contrib modules like CTools and Rules. No functional changes though.

API changes

None

Data model changes

None

Original Report

CTools are creating context for every existing entity which results in duplicated entries in the block form. Instead of doing this full-in, it should see if there aren't already contexts defined by other modules for their entities to prevent this.

Comments

Anonymous’s picture

ivanjaros created an issue. See original summary.

Anonymous’s picture

Issue summary: View changes
StatusFileSize
new8.38 KB
eclipsegc’s picture

Project: Chaos Tool Suite (ctools) » Drupal core
Version: 8.x-3.x-dev » 9.x-dev
Component: Code » ajax system
Status: Active » Needs review
StatusFileSize
new808 bytes

This is actually a core bug and stems from the fact that the BlockForm asks for all conditions regardless of its ability to satisfy their contexts. Easily fixed though.

Eclipse

eclipsegc’s picture

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

Also, this is an outright bug in 8.0.x and doesn't change apis or anything so I think this can be safely done in 8.0.x.

Eclipse

eclipsegc’s picture

Issue summary: View changes
tim.plunkett’s picture

Component: ajax system » block.module
Issue tags: +Needs screenshots, +Needs tests

No comment on 8.0.x vs 8.1.x, just putting it in the right place.

Also, for anyone wondering where that value comes, it's in the same class:

core/modules/block/src/BlockForm.php
125:    $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
dawehner’s picture

Status: Needs review » Needs work
berdir’s picture

Note that there are really two things here.

First is the problem that ctools adds all those conditions that then show up even if context for them is missing. The patch above fixes that.

However, content types are still duplicated. Because ctools adds a second one, with a different name. Does the one in ctools offer any benefit over the one in core? I don't think so, so I think we should exclude that one from being defined in ctools?

eclipsegc’s picture

Or ctools should override the node_type condition in favor of the generic one. The ctools one does actually have some additional functionality that tracks constraints based upon context. I'll look into it.

Eclipse

Anonymous’s picture

What would be the recommended quickfix for now? I cannot let my users see this mess, it would be too confusing for them so I have to remove those ctools tabs asap.
--

Looks like hook_condition_info_alter does the trick just fine.

eclipsegc’s picture

I'd apply the patch from 3.

Anonymous’s picture

Seems like I have no choice since my solution "broke" Pathauto.
--
Even with that patch is see node bundles twice.

eclipsegc’s picture

Yes, that's exactly berdir's comment from 8.

Eclipse

berdir’s picture

For which he also already openend an issue for: #2669758: Switch bundle condition for nodes to node_type instead of entity_bundle:node. Patches welcome.

eclipsegc’s picture

Title: The EntityType condition plugin duplicates contexts in block form » Conditions are not limited by available contexts.

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.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

johnchque’s picture

Assigned: Unassigned » johnchque

Will upload a patch with tests soon.

johnchque’s picture

Assigned: johnchque » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.34 KB
new3.13 KB

Tests added. This should make it fail.

tim.plunkett’s picture

The last submitted patch, 19: conditions_are_not-2632434-19-test-only.patch, failed testing.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php
    @@ -232,6 +232,11 @@ public function testViewsBlockForm() {
    +
    +    // Tests conditions with no existing context are not displayed.
    +    $this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
    

    Tests that conditions...

    no existing => missing.

    Why is this in a views tests? Should be in one of the tests in block.module IMHO.

  2. +++ b/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/ConditionTestNoExistingType.php
    @@ -0,0 +1,34 @@
    +    return $this->t('Condition with no existing context.');
    

    Condition that requires a non-existent context.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new2.1 KB
new2.89 KB
new2.53 KB

Changes made based on comment above.

The last submitted patch, 23: conditions_are_not-2632434-23-test-only.patch, failed testing.

berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs screenshots, -Needs tests

That works for me.

Removed the needs screenshots tag, I think it is pretty obvious. Having ctools enabled adds a bunch of additional vertical tabs that actually don't work. This patch hides those that wouldn't work because nobody provides a vocabulary, a block_content or whatever to get the bundle from. Note that there are still two content type conditions, that we can't fix in core as ctools adds a duplicate and it has context.

That means we need to fix that in ctools, not in core.

The last submitted patch, 3: 2632434-3.patch, failed testing.

  • catch committed 7076c70 on 8.3.x
    Issue #2632434 by yongt9412, EclipseGc, ivanjaros, Berdir: Conditions...

  • catch committed ecb1179 on 8.2.x
    Issue #2632434 by yongt9412, EclipseGc, ivanjaros, Berdir: Conditions...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.3.x and cherry-picked to 8.2.x, thanks!

eclipsegc’s picture

Cherry-picked ++

Status: Fixed » Closed (fixed)

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

idcm’s picture

I installed the 3.0 version, assuming this issue had been resolved. It is still showing the extra content types vertical tab in blocks.

I am on 8.3.3. My friends are on 8.3.4. We each see it.

berdir’s picture

Yes, because both are content type, and there is a content available. What this fixed is that it also shows vocabulary, block content type, and many other vertical tabs.

This is something that only ctools module can solve, as it defines a second condition with a different name. Or when it moves to core, in #1932810: Add entity bundles condition plugin for entities with bundles.