diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 35a0166f53328cb13eaffff3017894202ed72c7d..5c1447c8f6019f6d58e254b51f58d8acc11119d8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -2,6 +2,9 @@ Metatag 2.1.x, 202x-xx-xx ------------------------- #3515603 by claudiu.cristea, damienmckenna: PHP 8.4 support. #3518526 by sleitner, damienmckenna: Resolve access check errors. +#3503253 by joegraduate, damienmckenna, qaiser iqbal: TypeError: uasort(): + Argument #1 ($array) must be of type array, null given in uasort() (line 285 + of modules\metatag\src\MetatagManager.php). Metatag 2.1.0, 2024-11-07 diff --git a/src/MetatagManager.php b/src/MetatagManager.php index f612aef2a28a130171fd6075a0f77306e28c2c08..0d40ededc4d00aceb7aaa57a5a35370fd94b17a9 100644 --- a/src/MetatagManager.php +++ b/src/MetatagManager.php @@ -279,15 +279,23 @@ class MetatagManager implements MetatagManagerInterface { foreach ($this->sortedGroups() as $group_name => $group) { $tag_weight = $group['weight'] * 100; - // First, sort the tags within the group according to the original sort - // order provided by the tag's definition. - uasort($tags[$group_name], [ - 'Drupal\Component\Utility\SortArray', - 'sortByWeightElement', - ]); - foreach ($tags[$group_name] as $tag_name => $tag_info) { - $tag_info['weight'] = $tag_weight++; - $sorted_tags[$tag_name] = $tag_info; + // Make sure the tag group is in the correct structure. + if (isset($tags[$group_name]) && is_array($tags[$group_name])) { + // First, sort the tags within the group according to the original sort + // order provided by the tag's definition. + uasort($tags[$group_name], [ + 'Drupal\Component\Utility\SortArray', + 'sortByWeightElement', + ]); + foreach ($tags[$group_name] as $tag_name => $tag_info) { + $tag_info['weight'] = $tag_weight++; + $sorted_tags[$tag_name] = $tag_info; + } + } + + // Log an error message because this shouldn't happen. + else { + $this->logger->error('Expected an array but got null or other type for group: @group_name', ['@group_name' => $group_name]); } }