In version 1.1 hook_field_formatter_view changed from

/**
 * Implements hook_field_formatter_view().
 */
function link_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $elements = array();
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      '#markup' => theme('link_formatter_'. $display['type'], array('element' => $item, 'field' => $instance)),
    );
  }
  return $elements;
}

to

/**
 * Implements hook_field_formatter_view().
 */
function link_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $elements = array();
  foreach ($items as $delta => $item) {
    $elements[$delta] = array(
      '#theme' => 'link_formatter_' . $display['type'],
      '#element' => $item,
      '#field' => $instance,
      '#display' => $display,
    );
  }
  return $elements;
}

In the view result this causes recursion when rendering a field. In the view results ($view->result) I get :


stdClass Object
(
    [nid] => 123456
    [field_my_link] => Array
        (
            [0] => Array
                (
                    [rendered] => Array
                        (
                          [#theme] => link_formatter_link_plain
                          [#element] => Array(/* snip */)
                          [#field] => Array(/* snip */)
                          [#display] => Array
                                (
                                    [type] => link_plain
                                    [settings] => Array
                                        (
                                            [skip_safe] => 0
                                            [skip_empty_values] => 0
                                        )

                                    [label] => hidden
                                    [views_view] => view Object
                                        (
                                            [result] => Array(
						/* Same view results again, recursion */
					    )

                                    ....

Anyone that can confirm this?

The only the function that uses the display info is theme_link_formatter_link_domain ($vars['display']['settings']['strip_www']). Instead of passing along the the entire display variable we can simply set a strip_www variable.

Comments

interx’s picture

Version: 7.x-1.1 » 7.x-1.2
StatusFileSize
new468 bytes

Patch added. I kept the existing structure of ['#display']['settings']['strip_www'] to make sure any overridden theme_link_formatter_link_domain() still works.

In views with a lot of link fields this gives a big performance benefit.

interx’s picture

Status: Active » Needs review
pifagor’s picture

Status: Needs review » Reviewed & tested by the community

look good for me

  • pifagor committed 2a31ed6 on 7.x-1.x
    Issue #2295071 by interX, pifagor: Recursion in field formatter with...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.