-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applying drupal-7-count-function-deprecation-fixes-2885610-19.patch (…
…from https://www.drupal.org/project/drupal/issues/2885610) to fix count() calls on uncountable variables.
- Loading branch information
Showing
3 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
drupal-7-count-function-deprecation-fixes-2885610-19.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
diff --git a/includes/form.inc b/includes/form.inc | ||
index 3b2032eb72..e4ab8c8dac 100644 | ||
--- a/includes/form.inc | ||
+++ b/includes/form.inc | ||
@@ -1440,10 +1440,12 @@ function _form_validate(&$elements, &$form_state, $form_id = NULL) { | ||
// length if it's a string, and the item count if it's an array. | ||
// An unchecked checkbox has a #value of integer 0, different than string | ||
// '0', which could be a valid value. | ||
- $is_empty_multiple = (!count($elements['#value'])); | ||
+ $is_countable = is_array($elements['#value']) || $elements['#value'] instanceof \Countable; | ||
+ $is_empty_multiple = $is_countable && count($elements['#value']) == 0; | ||
$is_empty_string = (is_string($elements['#value']) && drupal_strlen(trim($elements['#value'])) == 0); | ||
$is_empty_value = ($elements['#value'] === 0); | ||
- if ($is_empty_multiple || $is_empty_string || $is_empty_value) { | ||
+ $is_empty_null = is_null($elements['#value']); | ||
+ if ($is_empty_multiple || $is_empty_string || $is_empty_value || $is_empty_null) { | ||
// Although discouraged, a #title is not mandatory for form elements. In | ||
// case there is no #title, we cannot set a form error message. | ||
// Instead of setting no #title, form constructors are encouraged to set | ||
diff --git a/includes/theme.inc b/includes/theme.inc | ||
index 9b606e9fb1..9bb31d9d75 100644 | ||
--- a/includes/theme.inc | ||
+++ b/includes/theme.inc | ||
@@ -1995,7 +1995,7 @@ function theme_table($variables) { | ||
$empty = $variables['empty']; | ||
|
||
// Add sticky headers, if applicable. | ||
- if (count($header) && $sticky) { | ||
+ if (!empty($header) && $sticky) { | ||
drupal_add_js('misc/tableheader.js'); | ||
// Add 'sticky-enabled' class to the table to identify it for JS. | ||
// This is needed to target tables constructed by this function. | ||
@@ -2009,7 +2009,7 @@ function theme_table($variables) { | ||
} | ||
|
||
// Format the table columns: | ||
- if (count($colgroups)) { | ||
+ if (!empty($colgroups)) { | ||
foreach ($colgroups as $number => $colgroup) { | ||
$attributes = array(); | ||
|
||
@@ -2044,38 +2044,40 @@ function theme_table($variables) { | ||
} | ||
|
||
// Add the 'empty' row message if available. | ||
- if (!count($rows) && $empty) { | ||
+ if (empty($rows) && $empty) { | ||
$header_count = 0; | ||
- foreach ($header as $header_cell) { | ||
- if (is_array($header_cell)) { | ||
- $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1; | ||
- } | ||
- else { | ||
- $header_count++; | ||
+ if (!empty($header)) { | ||
+ foreach ($header as $header_cell) { | ||
+ if (is_array($header_cell)) { | ||
+ $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1; | ||
+ } | ||
+ else { | ||
+ $header_count++; | ||
+ } | ||
} | ||
} | ||
$rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message'))); | ||
} | ||
|
||
// Format the table header: | ||
- if (count($header)) { | ||
+ if (!empty($header)) { | ||
$ts = tablesort_init($header); | ||
// HTML requires that the thead tag has tr tags in it followed by tbody | ||
// tags. Using ternary operator to check and see if we have any rows. | ||
- $output .= (count($rows) ? ' <thead><tr>' : ' <tr>'); | ||
+ $output .= (!empty($rows) ? ' <thead><tr>' : ' <tr>'); | ||
foreach ($header as $cell) { | ||
$cell = tablesort_header($cell, $header, $ts); | ||
$output .= _theme_table_cell($cell, TRUE); | ||
} | ||
// Using ternary operator to close the tags based on whether or not there are rows | ||
- $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n"); | ||
+ $output .= (!empty($rows) ? " </tr></thead>\n" : "</tr>\n"); | ||
} | ||
else { | ||
$ts = array(); | ||
} | ||
|
||
// Format the table rows: | ||
- if (count($rows)) { | ||
+ if (!empty($rows)) { | ||
$output .= "<tbody>\n"; | ||
$flip = array('even' => 'odd', 'odd' => 'even'); | ||
$class = 'even'; | ||
@@ -2095,7 +2097,7 @@ function theme_table($variables) { | ||
$attributes = array(); | ||
$no_striping = FALSE; | ||
} | ||
- if (count($cells)) { | ||
+ if (!empty($cells)) { | ||
// Add odd/even class | ||
if (!$no_striping) { | ||
$class = $flip[$class]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters