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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anybody’s picture

Issue summary: View changes
Anybody’s picture

Patch attached. Please review and let's get this RTBC together asap. :)

Anybody’s picture

Status: Active » Needs review
DamienMcKenna’s picture

Status: Needs review » Needs work
FileSize
507 bytes

It needed a little work per the Drupal coding standards.

DamienMcKenna’s picture

Status: Needs work » Needs review
RecursiveMeta’s picture

Patch #4 worked fixed the issue I had.