Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I had the error "Argument 1 passed to drupal_attributes() must be an array, null given" due to unclear reasons in url.module fields.
I'm sorry that I can not cleanly reproduce it, but obviously there are some parts in the code of url.module that should never return NULL but an empty array for attributes to match the requirements of drupal_attributes().
These are the lines that need a review from my point of view:
Line 214:
function url_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => &$item) {
// Split out the link into the parts required for url(): path and options.
$parsed = drupal_parse_url($item['value']);
$item['path'] = $parsed['path'];
$item['options'] = array(
'query' => $parsed['query'],
'fragment' => $parsed['fragment'],
'attributes' = &$item['attributes'],
);
}
}
}
Line 214:
function url_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => &$item) {
// Split out the link into the parts required for url(): path and options.
$parsed = drupal_parse_url($item['value']);
$item['path'] = $parsed['path'];
$item['options'] = array(
'query' => $parsed['query'],
'fragment' => $parsed['fragment'],
);
if(is_array($item['attributes'])){
$item['options']['attributes'] = &$item['attributes'];
}
}
}
}
After this change the errors were successfully gone.
Comment | File | Size | Author |
---|---|---|---|
#4 | url-n2480693-4.patch | 507 bytes | DamienMcKenna |
Comments
Comment #1
AnybodyComment #2
AnybodyPatch attached. Please review and let's get this RTBC together asap. :)
Comment #3
AnybodyComment #4
DamienMcKennaIt needed a little work per the Drupal coding standards.
Comment #5
DamienMcKennaComment #6
RecursiveMeta CreditAttribution: RecursiveMeta as a volunteer commentedPatch #4 worked fixed the issue I had.