diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 6545a19..c65eabd 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -5,6 +5,7 @@ * Contains install and update functions for Block. */ +use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Cache\Cache; /** @@ -117,3 +118,26 @@ function block_update_8003() { return t('Block settings updated.'); } + +/** + * Convert hidden label_display setting. + */ +function block_update_8004() { + $config_factory = \Drupal::configFactory(); + foreach ($config_factory->listAll('block.block.') as $block_config_name) { + $block = $config_factory->getEditable($block_config_name); + + // Convert the 'label_display' setting. + $settings = $block->get('settings'); + if ($settings['label_display'] == 0) { + $settings['label_display'] = BlockPluginInterface::BLOCK_LABEL_HIDDEN; + } + $block->set('settings', $settings); + + // Mark the resulting configuration as trusted data. This avoids issues with + // future schema changes. + $block->save(TRUE); + } + + return t('Block settings updated.'); +} diff --git a/core/modules/block/block.module b/core/modules/block/block.module index afa24dc..430d33a 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\Html; +use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\language\ConfigurableLanguageInterface; @@ -212,16 +213,16 @@ function template_preprocess_block(&$variables) { $variables['plugin_id'] = $variables['elements']['#plugin_id']; $variables['base_plugin_id'] = $variables['elements']['#base_plugin_id']; $variables['derivative_plugin_id'] = $variables['elements']['#derivative_plugin_id']; - $variables['label'] = $variables['configuration']['label_display'] != BlockInterface::BLOCK_LABEL_HIDDEN ? $variables['configuration']['label'] : ''; + $variables['label'] = $variables['configuration']['label_display'] != BlockPluginInterface::BLOCK_LABEL_HIDDEN ? $variables['configuration']['label'] : ''; $variables['content'] = $variables['elements']['content']; // A block's label is configuration: it is static. Allow dynamic labels to be // set in the render array. - if (isset($variables['elements']['content']['#title']) && !empty($variables['configuration']['label_display'])) { + if (isset($variables['elements']['content']['#title']) && $variables['configuration']['label_display'] != BlockPluginInterface::BLOCK_LABEL_HIDDEN) { $variables['label'] = $variables['elements']['content']['#title']; } // Add class visually-hidden class (if needed) to improve accessibility. - if (isset($variables['label']) && $variables['configuration']['label_display'] == BlockInterface::BLOCK_LABEL_VISUALLY_HIDDEN) { + if (isset($variables['label']) && $variables['configuration']['label_display'] == BlockPluginInterface::BLOCK_LABEL_VISUALLY_HIDDEN) { $variables['title_attributes']['class'] = 'visually-hidden'; } diff --git a/core/modules/system/templates/block--system-menu-block.html.twig b/core/modules/system/templates/block--system-menu-block.html.twig index 6113bc2..a0bd200 100644 --- a/core/modules/system/templates/block--system-menu-block.html.twig +++ b/core/modules/system/templates/block--system-menu-block.html.twig @@ -36,7 +36,7 @@ {% set heading_id = attributes.id ~ '-menu'|clean_id %}