diff --git a/core/includes/theme.inc b/core/includes/theme.inc index d8f3136..f481902 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -492,27 +492,14 @@ function template_preprocess_datetime_form(&$variables) { * * @param array $variables * An associative array containing: - * - element: An associative array containing the properties of the element. - * Properties used: #title, #children, #required, #attributes. + * - title: The title text. + * - title_attributes: An Attribute object for the title element. + * - description: The help text description of the field. + * - required: A required boolean state for the date field. + * - children: The form element content. */ function template_preprocess_datetime_wrapper(&$variables) { - $element = $variables['element']; - - if (!empty($element['#title'])) { - $variables['title'] = $element['#title']; - } - - if (!empty($element['#description'])) { - $variables['description'] = $element['#description']; - } - - $variables['required'] = FALSE; - // For required datetime fields a 'form-required' class is appended to the - // label attributes. - if (!empty($element['#required'])) { - $variables['required'] = TRUE; - } - $variables['content'] = $element['#children']; + $variables['content'] = $variables['children']; } /** @@ -1222,8 +1209,6 @@ function _template_preprocess_default_variables() { // Variables that don't depend on a database connection. $variables = array( 'attributes' => array(), - 'title_attributes' => array(), - 'content_attributes' => array(), 'title_prefix' => array(), 'title_suffix' => array(), 'db_is_active' => !defined('MAINTENANCE_MODE'), @@ -1584,6 +1569,9 @@ function template_preprocess_field(&$variables, $hook) { $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); $delta++; } + + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; } /** @@ -1734,9 +1722,15 @@ function drupal_common_theme() { 'datetime_form' => array( 'render element' => 'element', ), - 'datetime_wrapper' => array( - 'render element' => 'element', - ), + 'datetime_wrapper' => [ + 'variables' => [ + 'title' => '', + 'title_attributes' => new Attribute(), + 'description' => '', + 'required' => FALSE, + 'children' => '', + ], + ], 'status_messages' => array( 'variables' => ['status_headings' => [], 'message_list' => NULL], ), diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index 6850fcb..aa8ed7c 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -355,15 +355,13 @@ protected function theme($hook, $variables = array()) { if (!isset($default_attributes)) { $default_attributes = new Attribute(); } - foreach (array('attributes', 'title_attributes', 'content_attributes') as $key) { - if (isset($variables[$key]) && !($variables[$key] instanceof Attribute)) { - if ($variables[$key]) { - $variables[$key] = new Attribute($variables[$key]); - } - else { - // Create empty attributes. - $variables[$key] = clone $default_attributes; - } + if (isset($variables['attributes']) && !($variables['attributes'] instanceof Attribute)) { + if ($variables['attributes']) { + $variables['attributes'] = new Attribute($variables['attributes']); + } + else { + // Create empty attributes. + $variables['attributes'] = clone $default_attributes; } } diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index ab6c3dc..b7b6f73 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -7,6 +7,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Render\Element; +use Drupal\Core\Template\Attribute; /** * Prepares variables for aggregator item templates. @@ -27,6 +28,7 @@ function template_preprocess_aggregator_item(&$variables) { $variables['url'] = check_url($item->getLink()); $variables['title'] = SafeMarkup::checkPlain($item->label()); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); } /** @@ -47,4 +49,5 @@ function template_preprocess_aggregator_feed(&$variables) { } $variables['full'] = $variables['elements']['#view_mode'] == 'full'; $variables['title'] = SafeMarkup::checkPlain($feed->label()); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index e65d07a..3456dc4 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -13,6 +13,7 @@ use Drupal\language\ConfigurableLanguageInterface; use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; +use Drupal\Core\Template\Attribute; /** * Implements hook_help(). @@ -258,6 +259,8 @@ function template_preprocess_block(&$variables) { $variables['attributes']['aria-describedby'] = $variables['title_attributes']['id']; } + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index ad82046..60999ab 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -24,6 +24,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldConfigInterface; @@ -708,6 +709,8 @@ function template_preprocess_comment(&$variables) { // Add comment author user ID. Necessary for the comment-by-viewer library. $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index aa26ce4..de83d5b 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -613,6 +613,9 @@ function template_preprocess_node(&$variables) { // Add article ARIA role. $variables['attributes']['role'] = 'article'; + + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); } /** diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 462e4db..afe514d 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -11,6 +11,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Template\Attribute; /** * Matches all 'N' Unicode character classes (numbers) @@ -103,7 +104,12 @@ function search_help($route_name, RouteMatchInterface $route_match) { function search_theme() { return array( 'search_result' => array( - 'variables' => array('result' => NULL, 'plugin_id' => NULL), + 'variables' => [ + 'result' => NULL, + 'plugin_id' => NULL, + 'title_attributes' => new Attribute(), + 'content_attributes' => new Attribute(), + ], 'file' => 'search.pages.inc', ), );