You are here

function command_buttons_entity_view in Command Buttons 7

Implements hook_entity_view().

File

./command_buttons.module, line 594

Code

function command_buttons_entity_view($entity, $type, $view_mode, $langcode) {
  if ($type == 'fieldable_panels_pane' && $entity->bundle == 'command_buttons') {
    $classes = command_buttons_get_button_class($entity, $type, $view_mode, $langcode);
    $items = array();
    $use_dropdowns = field_get_items($type, $entity, 'field_use_dropdowns', $langcode);
    $dropdown_label = field_get_items($type, $entity, 'field_dropdown_label', $langcode);
    $commands = array();

    // Get all command_button entity references attached to this pane.
    $values = field_get_items($type, $entity, 'field_commands', $langcode);
    if (count($values)) {
      foreach ($values as $value) {
        $commands[] = $value['entity'];
      }
    }
    if (!empty($use_dropdowns[0]['value']) && !empty($dropdown_label[0]['value'])) {
      $classes['use_dropdowns'] = TRUE;
      $classes['dropdown_label'] = $dropdown_label[0]['value'];
    }
    else {
      $classes['use_dropdowns'] = FALSE;
      $classes['dropdown_label'] = '';
    }
    $output = command_buttons_render_buttons($commands, $classes);
    if (!empty($output)) {
      $entity->content['field_commands'] = array(
        '#markup' => $output,
      );
    }
    else {

      // If no items were present, they either don't exist or the use doesn't have
      // access to them. Just unset the field.
      unset($entity->content['field_commands']);
    }
  }
}