Verified Commit 49b64811 authored by quietone's avatar quietone
Browse files

Issue #3483299 by tstoeckler, mstrelan, nicxvan: Add void return type to all...

Issue #3483299 by tstoeckler, mstrelan, nicxvan: Add void return type to all preprocess hook implementations

(cherry picked from commit be64557b)
parent ba0c01ef
Loading
Loading
Loading
Loading
Loading
+0 −1536

File changed.

Preview size limit exceeded, changes collapsed.

+11 −11
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
 *     #multiple, #required, #name, #attributes, #size, #sort_options,
 *     #sort_start.
 */
function template_preprocess_select(&$variables) {
function template_preprocess_select(&$variables): void {
  $element = $variables['element'];
  Element::setAttributes($element, ['id', 'name', 'size']);
  RenderElementBase::setAttributes($element, ['form-select']);
@@ -191,7 +191,7 @@ function form_get_options($element, $key) {
 *     Properties used: #attributes, #children, #description, #id, #title,
 *     #value.
 */
function template_preprocess_fieldset(&$variables) {
function template_preprocess_fieldset(&$variables): void {
  $element = $variables['element'];
  Element::setAttributes($element, ['id']);
  RenderElementBase::setAttributes($element);
@@ -245,7 +245,7 @@ function template_preprocess_fieldset(&$variables) {
 *     Properties used: #attributes, #children, #description, #required,
 *     #summary_attributes, #title, #value.
 */
function template_preprocess_details(&$variables) {
function template_preprocess_details(&$variables): void {
  $element = $variables['element'];
  $variables['attributes'] = $element['#attributes'];
  $variables['summary_attributes'] = new Attribute($element['#summary_attributes']);
@@ -282,7 +282,7 @@ function template_preprocess_details(&$variables) {
 *     Properties used: #title, #value, #options, #description, #required,
 *     #attributes, #children.
 */
function template_preprocess_radios(&$variables) {
function template_preprocess_radios(&$variables): void {
  $element = $variables['element'];
  $variables['attributes'] = [];
  if (isset($element['#id'])) {
@@ -304,7 +304,7 @@ function template_preprocess_radios(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #children, #attributes.
 */
function template_preprocess_checkboxes(&$variables) {
function template_preprocess_checkboxes(&$variables): void {
  $element = $variables['element'];
  $variables['attributes'] = [];
  if (isset($element['#id'])) {
@@ -326,7 +326,7 @@ function template_preprocess_checkboxes(&$variables) {
 *   - element: An associative array containing the properties and children of
 *     the details element. Properties used: #children.
 */
function template_preprocess_vertical_tabs(&$variables) {
function template_preprocess_vertical_tabs(&$variables): void {
  $element = $variables['element'];
  $variables['children'] = (!empty($element['#children'])) ? $element['#children'] : '';
}
@@ -341,7 +341,7 @@ function template_preprocess_vertical_tabs(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #attributes.
 */
function template_preprocess_input(&$variables) {
function template_preprocess_input(&$variables): void {
  $element = $variables['element'];
  // Remove name attribute if empty, for W3C compliance.
  if (isset($variables['attributes']['name']) && empty((string) $variables['attributes']['name'])) {
@@ -360,7 +360,7 @@ function template_preprocess_input(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #action, #method, #attributes, #children
 */
function template_preprocess_form(&$variables) {
function template_preprocess_form(&$variables): void {
  $element = $variables['element'];
  if (isset($element['#action'])) {
    $element['#attributes']['action'] = UrlHelper::stripDangerousProtocols($element['#action']);
@@ -384,7 +384,7 @@ function template_preprocess_form(&$variables) {
 *     Properties used: #title, #value, #description, #rows, #cols, #maxlength,
 *     #placeholder, #required, #attributes, #resizable.
 */
function template_preprocess_textarea(&$variables) {
function template_preprocess_textarea(&$variables): void {
  $element = $variables['element'];
  $attributes = ['id', 'name', 'rows', 'cols', 'maxlength', 'placeholder'];
  Element::setAttributes($element, $attributes);
@@ -439,7 +439,7 @@ function template_preprocess_textarea(&$variables) {
 *     Properties used: #title, #title_display, #description, #id, #required,
 *     #children, #type, #name, #label_for.
 */
function template_preprocess_form_element(&$variables) {
function template_preprocess_form_element(&$variables): void {
  $element = &$variables['element'];

  // This function is invoked as theme wrapper, but the rendered form element
@@ -532,7 +532,7 @@ function template_preprocess_form_element(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #required, #title, #id, #value, #description, #for.
 */
function template_preprocess_form_element_label(&$variables) {
function template_preprocess_form_element_label(&$variables): void {
  $element = $variables['element'];
  // If title and required marker are both empty, output no label.
  if (isset($element['#title']) && $element['#title'] !== '') {
+20 −20
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ function theme_settings_convert_to_config(array $theme_settings, Config $config)
 *   - timestamp:
 *   - text:
 */
function template_preprocess_time(&$variables) {
function template_preprocess_time(&$variables): void {
  /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
  $date_formatter = \Drupal::service('date.formatter');
  // Format the 'datetime' attribute based on the timestamp.
@@ -371,7 +371,7 @@ function template_preprocess_time(&$variables) {
 *
 * @see form_process_datetime()
 */
function template_preprocess_datetime_form(&$variables) {
function template_preprocess_datetime_form(&$variables): void {
  $element = $variables['element'];

  $variables['attributes'] = [];
@@ -397,7 +397,7 @@ function template_preprocess_datetime_form(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #title, #children, #required, #attributes.
 */
function template_preprocess_datetime_wrapper(&$variables) {
function template_preprocess_datetime_wrapper(&$variables): void {
  $element = $variables['element'];

  if (!empty($element['#title'])) {
@@ -490,7 +490,7 @@ function template_preprocess_datetime_wrapper(&$variables) {
 * @see \Drupal\Core\Utility\LinkGenerator::generate()
 * @see system_page_attachments()
 */
function template_preprocess_links(&$variables) {
function template_preprocess_links(&$variables): void {
  $links = $variables['links'];
  $heading = &$variables['heading'];

@@ -621,7 +621,7 @@ function template_preprocess_links(&$variables) {
 *   - sizes: The sizes attribute for viewport-based selection of images.
 *     - http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content.html#introduction-3:viewport-based-selection-2
 */
function template_preprocess_image(&$variables) {
function template_preprocess_image(&$variables): void {
  /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
  $file_url_generator = \Drupal::service('file_url_generator');

@@ -757,7 +757,7 @@ function template_preprocess_image(&$variables) {
 *   - empty: The message to display in an extra row if table does not have any
 *     rows.
 */
function template_preprocess_table(&$variables) {
function template_preprocess_table(&$variables): void {
  // Format the table columns:
  if (!empty($variables['colgroups'])) {
    foreach ($variables['colgroups'] as &$colgroup) {
@@ -938,7 +938,7 @@ function template_preprocess_table(&$variables) {
 *
 * @see https://www.drupal.org/node/1842756
 */
function template_preprocess_item_list(&$variables) {
function template_preprocess_item_list(&$variables): void {
  $variables['wrapper_attributes'] = new Attribute($variables['wrapper_attributes']);
  foreach ($variables['items'] as &$item) {
    $attributes = [];
@@ -997,7 +997,7 @@ function template_preprocess_item_list(&$variables) {
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #id, #attributes, #children.
 */
function template_preprocess_container(&$variables) {
function template_preprocess_container(&$variables): void {
  $variables['has_parent'] = FALSE;
  $element = $variables['element'];
  // Ensure #attributes is set.
@@ -1028,7 +1028,7 @@ function template_preprocess_container(&$variables) {
 *     dangerous HTML such as <script> tags.
 *   - active: The key for the currently active maintenance task.
 */
function template_preprocess_maintenance_task_list(&$variables) {
function template_preprocess_maintenance_task_list(&$variables): void {
  $items = $variables['items'];
  $active = $variables['active'];

@@ -1118,7 +1118,7 @@ function _template_preprocess_default_variables() {
 *   An associative array containing:
 *   - page: A render element representing the page.
 */
function template_preprocess_html(&$variables) {
function template_preprocess_html(&$variables): void {
  $variables['page'] = $variables['html']['page'];
  unset($variables['html']['page']);
  $variables['page_top'] = NULL;
@@ -1208,7 +1208,7 @@ function template_preprocess_html(&$variables) {
 *
 * See the page.html.twig template for the list of variables.
 */
function template_preprocess_page(&$variables) {
function template_preprocess_page(&$variables): void {
  $language_interface = \Drupal::languageManager()->getCurrentLanguage();

  foreach (\Drupal::theme()->getActiveTheme()->getRegions() as $region) {
@@ -1318,7 +1318,7 @@ function theme_get_suggestions($args, $base, $delimiter = '__') {
 *
 * @see system_page_attachments()
 */
function template_preprocess_maintenance_page(&$variables) {
function template_preprocess_maintenance_page(&$variables): void {
  // @todo Rename the templates to page--maintenance + page--install.
  template_preprocess_page($variables);

@@ -1348,7 +1348,7 @@ function template_preprocess_maintenance_page(&$variables) {
 *
 * @see template_preprocess_maintenance_page()
 */
function template_preprocess_install_page(&$variables) {
function template_preprocess_install_page(&$variables): void {
  $installer_active_task = NULL;
  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE === 'install' && InstallerKernel::installationAttempted()) {
    $installer_active_task = $GLOBALS['install_state']['active_task'];
@@ -1376,7 +1376,7 @@ function template_preprocess_install_page(&$variables) {
 *   An associative array containing:
 *   - elements: An associative array containing properties of the region.
 */
function template_preprocess_region(&$variables) {
function template_preprocess_region(&$variables): void {
  // Create the $content variable that templates expect.
  $variables['content'] = $variables['elements']['#children'];
  $variables['region'] = $variables['elements']['#region'];
@@ -1393,7 +1393,7 @@ function template_preprocess_region(&$variables) {
 *   - attributes: A string containing the attributes for the wrapping div.
 *   - title_attributes: A string containing the attributes for the title.
 */
function template_preprocess_field(&$variables, $hook) {
function template_preprocess_field(&$variables, $hook): void {
  $element = $variables['element'];

  // Creating variables for the template.
@@ -1454,7 +1454,7 @@ function template_preprocess_field(&$variables, $hook) {
 *   An associative array containing:
 *   - element: A render element representing the form element.
 */
function template_preprocess_field_multiple_value_form(&$variables) {
function template_preprocess_field_multiple_value_form(&$variables): void {
  $element = $variables['element'];
  $variables['multiple'] = $element['#cardinality_multiple'];
  $variables['attributes'] = $element['#attributes'];
@@ -1569,7 +1569,7 @@ function template_preprocess_field_multiple_value_form(&$variables) {
 *   An associative array containing:
 *   - links: A list of \Drupal\Core\Link objects which should be rendered.
 */
function template_preprocess_breadcrumb(&$variables) {
function template_preprocess_breadcrumb(&$variables): void {
  $variables['breadcrumb'] = [];
  /** @var \Drupal\Core\Link $link */
  foreach ($variables['links'] as $key => $link) {
@@ -1598,7 +1598,7 @@ function template_preprocess_breadcrumb(&$variables) {
 *     - #route_parameters: An associative array of the route parameters.
 *     - #quantity: The number of pages in the list.
 */
function template_preprocess_pager(&$variables) {
function template_preprocess_pager(&$variables): void {
  $element = $variables['pager']['#element'];
  $parameters = $variables['pager']['#parameters'];
  $quantity = empty($variables['pager']['#quantity']) ? 0 : $variables['pager']['#quantity'];
@@ -1742,7 +1742,7 @@ function template_preprocess_pager(&$variables) {
 *       'localized_options' keys.
 *     - #active: A boolean indicating whether the local task is active.
 */
function template_preprocess_menu_local_task(&$variables) {
function template_preprocess_menu_local_task(&$variables): void {
  $link = $variables['element']['#link'];
  $link += [
    'localized_options' => [],
@@ -1774,7 +1774,7 @@ function template_preprocess_menu_local_task(&$variables) {
 *     - #link: A menu link array with 'title', 'url', and (optionally)
 *       'localized_options' keys.
 */
function template_preprocess_menu_local_action(&$variables) {
function template_preprocess_menu_local_action(&$variables): void {
  $link = $variables['element']['#link'];
  $link += [
    'localized_options' => [],
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ function _drupal_maintenance_theme() {
 *   An associative array containing:
 *   - messages: An array of result messages.
 */
function template_preprocess_authorize_report(&$variables) {
function template_preprocess_authorize_report(&$variables): void {
  $messages = [];
  if (!empty($variables['messages'])) {
    foreach ($variables['messages'] as $heading => $logs) {
+1 −1
Original line number Diff line number Diff line
@@ -602,7 +602,7 @@ function hook_preprocess(&$variables, $hook) {
 * @param $variables
 *   The variables array (modify in place).
 */
function hook_preprocess_HOOK(&$variables) {
function hook_preprocess_HOOK(&$variables): void {
  // This example is from node_preprocess_html(). It adds the node type to
  // the body classes, when on an individual node page or node preview page.
  if (($node = \Drupal::routeMatch()->getParameter('node')) || ($node = \Drupal::routeMatch()->getParameter('node_preview'))) {
Loading