1 field_permission_example.module field_permission_example_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)

Implements hook_field_formatter_view().

Here we output the field for general consumption.

The field will have a sticky note appearance, thanks to some simple CSS.

Note that all of the permissions and access logic happens in hook_field_access(), and none of it is here.

Related topics

File

modules/examples/field_permission_example/field_permission_example.module, line 220
Hook implementations for the Field Permission Example module.

Code

function field_permission_example_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  switch ($display['type']) {
    case 'field_permission_example_formatter':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          // We wrap the fieldnote content up in a div tag.
          '#type' => 'head_tag',
          '#tag' => 'div',
          '#value' => check_plain($item['notes']),
          // Let's give the note a nice sticky-note CSS appearance.
          '#attributes' => array(
            'class' => 'stickynote',
          ),
          // This is the CSS for the sticky note.
          '#attached' => array(
            'css' => array(backdrop_get_path('module', 'field_permission_example') .
              '/field_permission_example.css'),
          ),
        );
      }
      break;
  }
  return $element;
}