Adding several instances of the same block with different ids might end in not being able to group them and apply the same css.

Let's say I add the recent comments block twice, one with the id "recent_comments" and other with "latest_comments", the resultant blocks will have css ids "block-recent-comments" and "block-latest-comments", and will share css classes "block" and "block-comment", to add common styles I need to add another preprocess call to make them share a class or use the generic "block-comment" class that might affect other blocks if comment module provided more

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

Status: Active » Needs review
Issue tags: +Blocks-Layouts, +Plugin system, +Block plugins
FileSize
646 bytes

Patch attached adds a new class based in plugin so we have a block-recent-comments class.

Status: Needs review » Needs work

The last submitted patch, 1896098_block_add_common_css_class.patch, failed testing.

pcambra’s picture

Status: Needs work » Needs review
FileSize
1.85 KB

Tests updated, hopefully now is green

pcambra’s picture

salvis’s picture

Status: Needs review » Reviewed & tested by the community

Indeed, the block's css ID is derived from the machine name, and the proposed machine name is derived from the block title, which is initially set by the subject line in the @Plugin section. The block's css class attribute has only "block block-module". The class is useless for a module that defines more than one block, and the ID is not fixed.

I'm not sure how it will work with translation, but if I have a block with a title of "Switch user" and I change this into "Benutzer wechseln" at block-creation time, then the proposed machine name changes from 'switch_user' to 'benutzer_wechseln', and the block's css ID becomes 'block-benutzer-wechseln'.

The user can change the machine name to anything he wants — personally, I'd be tempted to prepend the name of the defining module.

There's no way for a module to provide any css to its blocks.

pcambra's patch adds a "block-pluginid" class, turning
<div id="block-machinename" class="block block-module">
into
<div id="block-machinename" class="block block-module block-pluginid">

tim.plunkett’s picture

+1 on the RTBC. I'm so glad I added those renderTests()!

sun’s picture

re: #5: The machine name is not supposed to be translated. If that happens in HEAD currently and you're able to cleanly reproduce it, then we need to file a major bug, please.

Aside from that, this patch looks good to me. That said:

  1. I wonder whether the block-$module class remains to be of any value. I don't really see the point of it from a themer perspective.
  2. Instead of that, we most probably want to add a HTML class for block instances that are derivatives of an abstract block plugin type; e.g., menu blocks. From a themer perspective, I can totally see the need for styling all block-$base_plugin in the same way. Let's create an issue for that.
  3. In addition to all of this, I think we badly need a trivially simple textfield on the block instance settings form that allows to configure an (additional) custom CSS class for each block instance. Let's create an issue for that.
salvis’s picture

re: #5: The machine name is not supposed to be translated. If that happens in HEAD currently and you're able to cleanly reproduce it, then we need to file a major bug, please.

No, this does not currently happen. However, when you do "Add Block", the block title and the machine name are pre-set. Any changes you make to the block title are immediately (!) carried over to the machine name.

The block title is taken from the "subject" line (http://drupal.org/node/1880620):

/**
* Provides a "Who's online" block.
*
* @todo Move this block to the Statistics module and remove its dependency on
*   {users}.access.
*
* @Plugin(
*   id = "user_online_block",
*   subject = @Translation("Who's online"),
*   module = "user"
* )
*/

The @Translation() syntax seems to indicate that "Who's online" will be translated, i.e. it will show up in the UI language and will presumably be carried over into the machine name. Any other behavior would be, well, unexpected...

I wonder whether the block-$module class remains to be of any value.

While the example in the change record shows a plugin ID that starts with the module name, it is unclear whether that's an error, a coincidence, a recommendation, or a requirement. There's some additional discussion here:
#1879496: Do we need to worry about plugin ID collisions?
#1880646: [meta] Update block HTML IDs now that they're plugins

If we don't have block-$module and we don't have an enforced requirement to put the module name (and probably a separator) into the plugin ID, then we cannot reliably select the block. The selector is
div.block-$module.block-$pluginid (e.g.
div.block-devel.block-switch-user or
div.block-user.block-user-online-block), nothing less.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Looks like this needs more discussion. I'd quite like to kill off the block-$module class if we can too. If there's plugin ID collisions then the class added here is going to be prone to error - that could happen at any time just by enabling a new module.

benjy’s picture

Status: Needs review » Needs work

bumping this to try and get some more discussion happening as catch suggests.

klonos’s picture

Issue summary: View changes
Related issues: +#1053648: Convert site elements (site name, slogan, site logo) into blocks
Antti J. Salminen’s picture

Status: Needs work » Needs review
FileSize
1.77 KB

Here's a rerolled patch that moves to replacing the current block-$provider class with block-$provider-$pluginid. I understood this to be sun's suggestion in #1880646-59: [meta] Update block HTML IDs now that they're plugins. The plan he outlined there would be a clear way forward and seems worth discussing. Marking to needs review to see what the testbot thinks about it...

In my opinion dropping the "block-" prefix as redundant like Fidelix proposed in that issue's comments might also be a good idea.

sun’s picture

alexpott’s picture

Status: Needs review » Needs work

We also need to review all the css and js...

eg: bartik's style.css

.region-header .block-locale ul li {
dawehner’s picture

+++ b/core/modules/block/block.module
@@ -355,7 +355,7 @@ function template_preprocess_block(&$variables) {
+  $variables['attributes']['class'][] = drupal_html_class('block-' . $variables['configuration']['provider'] . '-' . $variables['plugin_id']);

According to #1880646-59: [meta] Update block HTML IDs now that they're plugins we have to apply some special replacement for derivative IDs. This for sure also has to be tested.

Here is a list of css files, which needs updates:

  • [ ] modules/views_ui/css/views_ui.admin.theme.css:335:.form-item-block-create {
  • [ ] modules/views_ui/css/views_ui.admin.theme.css:340:.form-item-block-create label,
  • [ ] modules/views_ui/css/views_ui.admin.theme.css:347:.form-item-block-style-style-plugin > label {
  • [ ] modules/block/css/block.admin.css:1:.block-region {
  • [ ] modules/block/css/block.admin.css:7:a.block-demo-backlink,
  • [ ] modules/block/css/block.admin.css:8:a.block-demo-backlink:link,
  • [ ] modules/block/css/block.admin.css:9:a.block-demo-backlink:visited {
  • [ ] modules/block/css/block.admin.css:21:a.block-demo-backlink:hover {
  • [ ] modules/block/css/block.admin.css:30:.block-list-secondary {
  • [ ] modules/block/css/block.admin.css:34:.block-list {
  • [ ] modules/block/css/block.admin.css:38:.block-list li {
  • [ ] modules/block/css/block.admin.css:42:.block-list a:before {
  • [ ] modules/block/css/block.admin.css:45:.block-list-secondary .form-type-search {
  • [ ] modules/block/css/block.admin.css:48:#block-placed {
  • [ ] modules/block/css/block.admin.css:63: .block-list-primary {
  • [ ] modules/block/css/block.admin.css:68: [dir="rtl"] .block-list-primary {
  • [ ] modules/block/css/block.admin.css:74: .block-list-secondary {
  • [ ] modules/block/css/block.admin.css:78: [dir="rtl"] .block-list-secondary {
  • [ ] modules/block/css/block.admin.css:83: .block-list-secondary .form-autocomplete,
  • [ ] modules/block/css/block.admin.css:84: .block-list-secondary .form-text,
  • [ ] modules/block/css/block.admin.css:85: .block-list-secondary .form-tel,
  • [ ] modules/block/css/block.admin.css:86: .block-list-secondary .form-email,
  • [ ] modules/block/css/block.admin.css:87: .block-list-secondary .form-url,
  • [ ] modules/block/css/block.admin.css:88: .block-list-secondary .form-search,
  • [ ] modules/block/css/block.admin.css:89: .block-list-secondary .form-number,
  • [ ] modules/block/css/block.admin.css:90: .block-list-secondary .form-color,
  • [ ] modules/block/css/block.admin.css:91: .block-list-secondary textarea {
  • [ ] modules/block/css/block.admin.css:109: .toolbar-vertical.toolbar-tray-open .block-list-primary,
  • [ ] modules/block/css/block.admin.css:110: .toolbar-vertical.toolbar-tray-open .block-list-secondary {
  • [x] modules/views/src/Tests/Plugin/DisplayPageWebTest.php:111: $menu_link = $this->cssSelect('div.block-menu ul.menu a');
  • [x] modules/views/src/Tests/Plugin/DisplayPageWebTest.php:120: $menu_link = $this->cssSelect('div.block-menu ul.menu a');
  • [ ] themes/bartik/color/preview.css:100:#preview .preview-block-menu .preview-content,
  • [ ] themes/bartik/color/preview.css:101:#preview .preview-block-menu .preview-content ul {
  • [ ] themes/bartik/color/preview.css:144:#preview-footer-columns .preview-block-menu {
  • [x] themes/bartik/css/style.css:446:.region-header .block-menu {
  • [x] themes/bartik/css/style.css:453:.region-header .block-menu li a {
  • [x] themes/bartik/css/style.css:460:.region-header .block-menu li a:hover,
  • [x] themes/bartik/css/style.css:461:.region-header .block-menu li a:active,
  • [x] themes/bartik/css/style.css:462:.region-header .block-menu li a:focus {
  • [x] themes/bartik/css/style.css:466:.region-header .block-menu li:last-child a {
  • [x] themes/bartik/css/style.css:470:.region-header #block-user-login {
  • [x] themes/bartik/css/style.css:473:.region-header #block-user-login .content {
  • [x] themes/bartik/css/style.css:476:.region-header #block-user-login .form-item {
  • [x] themes/bartik/css/style.css:481:.region-header #block-user-login div.item-list,
  • [x] themes/bartik/css/style.css:482:.region-header #block-user-login div.description {
  • [x] themes/bartik/css/style.css:486:.region-header #block-user-login div.item-list {
  • [x] themes/bartik/css/style.css:489:.region-header #block-user-login div.description {
  • [x] themes/bartik/css/style.css:492:.region-header #block-user-login .item-list ul {
  • [x] themes/bartik/css/style.css:496:.region-header #block-user-login .item-list li {
  • [x] themes/bartik/css/style.css:501:.region-header #block-user-login .item-list li:last-child {
  • [x] themes/bartik/css/style.css:504:[dir="rtl"] .region-header #block-user-login .item-list li:last-child {
  • [x] themes/bartik/css/style.css:508:.region-header #block-user-login .form-actions {
  • [x] themes/bartik/css/style.css:513:.region-header #block-user-login input.form-submit {
  • [x] themes/bartik/css/style.css:522:.region-header #block-user-login input.form-submit:hover,
  • [x] themes/bartik/css/style.css:523:.region-header #block-user-login input.form-submit:focus {
  • [x] themes/bartik/css/style.css:528:.region-header #block-search-form {
  • [x] themes/bartik/css/style.css:531:.region-header #block-search-form .form-text {
  • [x] themes/bartik/css/style.css:535:.region-header .block-locale ul li {
  • [x] themes/bartik/css/style.css:545:[dir="rtl"] .region-header #block-user-login .form-item,
  • [x] themes/bartik/css/style.css:546:[dir="rtl"] .region-header #block-user-login .item-list li {
  • [x] themes/bartik/css/style.css:1061:#triptych #block-user-login .form-text {
  • [x] themes/bartik/css/style.css:1064:#triptych #block-user-online p {
  • [x] themes/bartik/css/style.css:1067:#triptych #block-node-syndicate h2 {
  • [x] themes/bartik/css/style.css:1072:#triptych-last #block-node-syndicate {
  • [x] themes/bartik/css/style.css:1075:#triptych #block-search-form .form-type-search input {
  • [x] themes/bartik/css/style.css:1078:#triptych-middle #block-system-powered-by {
  • [x] themes/bartik/css/style.css:1081:#triptych-last #block-system-powered-by {
  • [x] themes/bartik/css/style.css:1107:#footer-columns .block-menu,
  • [x] themes/bartik/css/style.css:1659:#block-search-form {
  • [x] themes/bartik/css/style.css:1662:#block-search-form .content {
  • [x] themes/bartik/css/style.css:1666:#block-search-form input[type="search"] {
  • [x] themes/bartik/css/style.css:1672:#block-search-form input[type="search"]::-webkit-search-decoration {
  • [x] themes/bartik/css/style.css:1676:#block-search-form .form-item-search-block-form input {
  • [x] themes/bartik/css/style.css:1682:[dir="rtl"] #block-search-form .form-item-search-block-form input {
  • [ ] themes/bartik/css/style.css:1687:#search-block-form input.form-submit,
  • [ ] themes/bartik/css/style.css:1700:#search-block-form input.form-submit:hover,
  • [ ] themes/bartik/css/style.css:1701:#search-block-form input.form-submit:focus,
  • [ ] themes/bartik/css/style.css:1785:.page-admin-structure-block-demo .block-region {
  • [ ] themes/bartik/css/style.css:1795:.page-admin-structure-block-demo #featured .block-region {
  • [ ] themes/bartik/css/style.css:1798:.page-admin-structure-block-demo #header .block-region {
  • [x] themes/seven/css/jquery.ui.theme.css:279:#block-system-main h3.ui-accordion-header {
  • [x] themes/seven/css/jquery.ui.theme.css:283:#block-system-main .ui-accordion h3.ui-state-active,
  • [x] themes/seven/css/style.css:1148:#block-node-recent table,
  • [x] themes/seven/css/style.css:1149:#block-node-recent tr {
  • [x] themes/seven/css/style.css:1152:#block-node-recent .more-link {
  • [x] themes/seven/css/style.css:1155:[dir="rtl"] #block-node-recent .more-link {
  • [ ] themes/seven/css/style.css:1442:.form-item-block-create {
  • [ ] themes/seven/css/style.css:1549: .toolbar-vertical .block-list-secondary,

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.

tim.plunkett’s picture

Issue tags: -Blocks-Layouts

Not actively part of the Blocks-Layouts work.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

It has been 10 years since there was discussion on this issue.

Is this still relevant to Drupal 10?

Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!