Drupal Current theme condition plugin should provide an option to select all themes

Created on 14 August 2016, almost 9 years ago
Updated 4 February 2023, over 2 years ago

Problem/Motivation

Currently it is not possible to exclude theme condition from evaluation. Though the select list with themes is not marked as required the user is always bound to select some theme because there is no "empty" option. For other condition plugins there is a workaround. For instance for Node bundle plugin you can uncheck all content types so the condition will always evaluate to TRUE. Same for User role condition plugin. And for Request path you can leave empty pages textarea.

Proposed resolution

Add "- Any -" option to theme select list of the plugin configuration form.

API changes

None.

๐Ÿ› Bug report
Status

Needs review

Version

9.2

Component
Systemย  โ†’

Last updated about 5 hours ago

No maintainer
Created by

๐Ÿ‡ท๐Ÿ‡บRussia Chi

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Tagging for framework input. If this is a path we want to go down.

  • Status changed to Needs work over 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    Think it will help for steps to reproduce this bug.

    With a UI change before/after screenshots should be added to the issue summary.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    The current theme condition is not shown on blocks because of:
    https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/blo...

        // @todo Allow list of conditions to be configured in
        //   https://www.drupal.org/node/2284687.
        $visibility = $this->entity->getVisibility();
        $definitions = $this->manager->getFilteredDefinitions('block_ui', $form_state->getTemporaryValue('gathered_contexts'), ['block' => $this->entity]);
        foreach ($definitions as $condition_id => $definition) {
          // Don't display the current theme condition.
          if ($condition_id == 'current_theme') {
            continue;
          }
    
    

    Should we recover this condition?

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    We are changing the plugin because of https://www.drupal.org/project/google_tag/issues/3263122 โœจ Recovery the current theme condition plugin Active , to be able to load the google tag on any theme, and recover this plugin on the module. Now is excluded because is not possible to select any theme.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Updated to apply to the last drupal version

  • last update almost 2 years ago
    29,800 pass, 4 fail
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Added patch also and diff between last commit and the current one, allowing blocks to use the current theme condition.

  • Status changed to Needs review almost 2 years ago
  • last update almost 2 years ago
    29,800 pass, 4 fail
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Added steps to test and captures as asked by @smustgrave

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ
  • last update almost 2 years ago
    29,801 pass, 2 fail
  • last update almost 2 years ago
    29,801 pass, 2 fail
  • last update almost 2 years ago
    29,802 pass
  • Status changed to Needs review almost 2 years ago
  • last update almost 2 years ago
    29,802 pass
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Fixed tests, ready to review

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    I think the test coverage is okay.

    But found the workflow a little odd.
    I did a Standard install
    Went to block layout
    Added a block under the Olivero tab but have it only appear on the claro theme.
    Tagging for usability for that

    Now if we had a global block layout tab then this setting would make sense I think.

    Will leave in review for framework manager thoughts.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    @smustgrave Do you think the options should be "current theme" or "any" in the case of block layout? instead of the list of all themes.
    For the block layout, it have sense because it has theme tabs, for other cases, the list should have all themes

  • Status changed to Postponed: needs info almost 2 years ago
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Could someone expand the issue summary to explain why is this setting needed? Drupal Block UI is built so that blocks are intended to be specific to a theme. If we want to change that, it would be helpful to understand why that's desired.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    @lauriii You are totally right, I miss the original scope of the issue.

    We use current theme condition on google_tag module, but we need the "- any -" option https://www.drupal.org/project/google_tag/issues/3263122 โœจ Recovery the current theme condition plugin Active to have the ability to use google_tag on all themes or only on a theme, for blocks the current_theme condition does not have any sense at all, I will remove the logic that I changed related with blocks and update the summary.

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ
  • last update almost 2 years ago
    29,804 pass
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Add MR changes as patch

  • last update almost 2 years ago
    29,804 pass
  • Status changed to Needs review almost 2 years ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ

    Seems like the block is the only drupal core entity that uses the "plugin.manager.condition", and the current theme is excluded in this case as explained in previous comments so in the example I will use the google_tag scenario.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ช๐Ÿ‡ธSpain eduardo morales alberti Spain, ๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands yoroy

    Why a select list here when all the other variations of this use checkboxes?

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10
    1. +++ b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
      @@ -111,11 +112,18 @@ public function evaluate() {
      +      $summary = $this->isNegated() ?
      +        $this->t('The current theme is not @theme.', ['@theme' => $theme]) : $this->t('The current theme is @theme.', ['@theme' => $theme]);
      +    }
      +    else {
      +      $summary = $this->isNegated() ?
      +        $this->t('The current theme is not one of the enabled themes.') : $this->t('The current theme is one of the enabled themes.');
           }
       
      -    return $this->t('The current theme is @theme', ['@theme' => $this->configuration['theme']]);
      +    return $summary;
      

      we can return early here and avoid using else

    2. +++ b/core/tests/Drupal/KernelTests/Core/Plugin/Condition/CurrentThemeConditionTest.php
      @@ -27,12 +27,20 @@ public function testCurrentTheme() {
      +    $this->assertEquals(new FormattableMarkup('The current theme is not one of the enabled themes.', ['@theme' => '']), $condition_any_negated->summary());
      

      This feels like a UX WTF?

      How can a current theme not be one of the enabled themes?

      So as such I think we probably want to prevent the negate option when 'Any' is selected

    Nice work folks

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada smulvih2 Canada ๐Ÿ

    #37 works for me on 10.2.2

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    Just ran into this when working on โœจ Create an admin route condition plugin or add generic "Current theme" options for admin and default theme Active and I think we should rate this as major issue, because currently once you saved the conditions, this condition is always added and evaluated and user has no way to disable this rule?!

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    One important addition: The form element should be checkboxes, not radio!
    It makes no sense to force selecting only one theme!

    Selecting no theme at all should always evaluate to TRUE!

  • First commit to issue fork.
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    grevil โ†’ changed the visibility of the branch 2783897-drupal-current-theme to hidden.

  • Pipeline finished with Failed
    24 days ago
    Total: 191s
    #490201
  • Pipeline finished with Failed
    24 days ago
    #490299
  • Pipeline finished with Failed
    24 days ago
    #490301
  • Pipeline finished with Failed
    24 days ago
    #490325
  • Pipeline finished with Failed
    24 days ago
    #490351
  • Pipeline finished with Running
    24 days ago
    #490374
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    Ok, I adjusted the code, so that we now use checkboxes instead of the select. As @anybody and @yoroy already mentioned, this makes much more sense UX wise.

    The only problem is, that this change requires an update hook, as we can now select multiple themes instead of only one. But I can't seem to find a good way on how to update a condition configuration, as it usually just gets merged into the form it was used. @larowlan do you know of a good way on how to update all form configs using the condition? If not, we could alternatively leave the "theme" config in as a fallback (simply wrapping an array around it) and deprecate it. Although I am not super keen to do so...

    Anyway, apart from the update hook this can go back to "Needs Review", note that I did a total rewrite, so this needs to get reviewed throughout again.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil
  • Pipeline finished with Failed
    24 days ago
    #490400
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    Thanks @grevil totally makes sense and code LGTM so far. Sadly, I have no clue, how an update hook for a condition plugin can be written. I'm also unaware of any existing examples, while I think they possibly exist.

    Is there maybe any core maintainer or someone else experienced with that? We'd really like to finish this, for UX and bugfixing reasons, as currently it's kind of broken by design ;)

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany rkoller Nรผrnberg, Germany

    i saw the needs usability review tag, and we can put the issue on the shortlist for the meetings on friday. but only one question, i've tried to quickly test the MR on 11.x now, but i have a hard time to see any actual change in the ui. the proposed resolution section in the issue summary is not very clear, i then tried to follow the instructions in #32 ๐Ÿ› Drupal Current theme condition plugin should provide an option to select all themes Needs review , but again i see nothing in the ui of a block configuration page on a block layout page enabling me to choose a theme (nothing theme related in the vertical tabs nor in the select for the region - and i ran an drush updatedb as well as a drush cr).

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    @rkoller thanks, yes that's because this condition plugin doesn't seem to be applied on blocks, if I remember correctly.
    We ran into this in contrib modules that allow all condition plugins, e.g. https://www.drupal.org/project/posthog โ†’ or https://www.drupal.org/project/context โ†’ - unsure if there's also a place in core where it's shown.

    @Grevil can you please update the IS accordingly by time, if I'm right?

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    @anybody I updated the IS just yesterday:

    Only instance in core would be BlockForm, but there the condition is manually unset, so it needs to be manually set again before testing

    I will add the info, that it needs to get manually set in code first, together with the line.

  • Pipeline finished with Failed
    22 days ago
    Total: 604s
    #492098
  • Pipeline finished with Failed
    22 days ago
    Total: 3809s
    #492171
  • Pipeline finished with Canceled
    22 days ago
    Total: 71s
    #492258
  • Pipeline finished with Failed
    22 days ago
    Total: 3722s
    #492260
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany rkoller Nรผrnberg, Germany

    the update to the issue summary helped, i am able to reproduce and test now. thanks a lot for the updated instructions @grevil!

  • Does there need to be a BC layer for the old theme property? I think this might be especially tricky because I don't think there's anything in core that uses this condition plugin's configuration, so there's nothing to write update hooks. Contrib/custom will have to write to own update hooks as needed, most likely.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    Ok, I will prepare everything to declare "theme" deprecated. Thanks for your feedback!

    EDIT: I created a CR draft: https://www.drupal.org/node/3523553 โ†’

  • Pipeline finished with Canceled
    21 days ago
    Total: 131s
    #493109
  • Pipeline finished with Failed
    21 days ago
    Total: 450s
    #493111
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Grevil

    Alright, that should be it!

  • Pipeline finished with Failed
    21 days ago
    Total: 3738s
    #493116
  • Pipeline finished with Canceled
    21 days ago
    Total: 127s
    #493224
  • We should be able to allow BC for the theme key in the plugin itself and throw a deprecation if it's set, and automatically translate it to themes at runtime?

    I made suggestions to handle translating the value to "themes" in the form and deleting in the submit, but I forget about translation at runtime. I'm not sure how this can be done, since I'm not sure how to know which property/subproperty in a config entity would correspond to this. And similarly outside of the form submit, how can the property be identified in a config save?

    Separately, it might make sense to create a follow up to add constraints to the config schema for the new property, reusing the ExtensionAvailable work in ๐Ÿ“Œ [PP-1] core.extension should be validatable Postponed once that's in.

  • Pipeline finished with Failed
    21 days ago
    Total: 3738s
    #493225
Production build 0.71.5 2024