Can't get hook_field_attach_view_alter to set the value of the field I'm using some hook code I got from Drupal 7 show empty fields in order to show all of the empty fields on my node when viewing it. I would like to put a simple - as the displayed value when the field is empty.

function mymodule_field_attach_view_alter(&amp;$output, $context) {
    // other stuff clipped...
    $output[$field_name] = array(
        '#theme' =&gt; 'field',
        '#title' =&gt; $instance['label'],
        '#label_display' =&gt; 'inline',
        '#field_type' =&gt; $field['type'],
        '#field_name' =&gt; $field_name,
        '#bundle' =&gt; $node-&gt;type,
        '#object' =&gt; $node,
        '#items' =&gt; array(),
        '#entity_type' =&gt; 'node',
        '#weight' =&gt; $display['weight'],
        0 =&gt; array('#markup' =&gt; '-'),
    );
}


I pulled the code from the linked page above and just changed the one line at the end that has #markup. As far as I can tell from the api docs, this code should work, but nothing that I put into that #markup value shows up.

All of the empty fields DO show up, it's just that the value shown is empty instead of - or blah or foo, because I've tried those as well. :)

How do I set the value to display when I use hook_field_attach_view_alter?
Ok, I found the answer: the key "#items" in the output array needs to have an array with an array as the value - not just the array:

$output[$field_name] = array(
    '#theme' =&gt; 'field',
    '#title' =&gt; $instance['label'],
    '#label_display' =&gt; 'above',
    '#field_type' =&gt; $field['type'],
    '#field_name' =&gt; $field_name,
    '#bundle' =&gt; $node-&gt;type,
    '#object' =&gt; $node,
    '#items' =&gt; array(),
    '#entity_type' =&gt; 'node',
    '#weight' =&gt; $display['weight'],
    0 =&gt; array('#markup' =&gt; '&amp;nbsp;'),
  );


becomes

$output[$field_name] = array(
    '#theme' =&gt; 'field',
    '#title' =&gt; $instance['label'],
    '#label_display' =&gt; 'above',
    '#field_type' =&gt; $field['type'],
    '#field_name' =&gt; $field_name,
    '#bundle' =&gt; $node-&gt;type,
    '#object' =&gt; $node,
    '#items' =&gt; array(array()),
    '#entity_type' =&gt; 'node',
    '#weight' =&gt; $display['weight'],
    0 =&gt; array('#markup' =&gt; '&amp;nbsp;'),
  );