You are here

function theme_flag_admin_listing in Flag 7.3

Same name and namespace in other branches
  1. 6.2 includes/flag.admin.inc \theme_flag_admin_listing()
  2. 7.2 includes/flag.admin.inc \theme_flag_admin_listing()

Theme the output of the normal, database flags into a table.

File

includes/flag.admin.inc, line 72
Contains administrative pages for creating, editing, and deleting flags.

Code

function theme_flag_admin_listing($variables) {
  $form = $variables['form'];
  $flags = $form['#flags'];
  $output = '';
  foreach ($flags as $flag) {
    $ops = array(
      'flags_edit' => array(
        'title' => t('edit'),
        'href' => $flag
          ->admin_path('edit'),
      ),
      'flags_fields' => array(
        'title' => t('manage fields'),
        'href' => $flag
          ->admin_path('fields'),
      ),
      'flags_delete' => array(
        'title' => t('delete'),
        'href' => $flag
          ->admin_path('delete'),
      ),
      'flags_export' => array(
        'title' => t('export'),
        'href' => $flag
          ->admin_path('export'),
      ),
    );
    if (!module_exists('field_ui')) {
      unset($ops['flags_fields']);
    }
    $permission = "flag {$flag->name}";
    $roles = user_roles(FALSE, $permission);
    $row = array();
    $row[] = check_plain($flag->title) . ' <small>(' . t('Machine name: @name', array(
      '@name' => $flag->name,
    )) . ')</small>';
    if (count($flags) > 1) {
      $row[] = drupal_render($form['flags'][$flag->name]['weight']);
    }
    $row[] = $flag->entity_type;
    $row[] = empty($roles) ? '<em>' . t('No roles') . '</em>' : implode(', ', $roles);
    $row[] = $flag->types ? implode(', ', $flag->types) : '-';
    $row[] = $flag->global ? t('Yes') : t('No');
    $row[] = theme('links', array(
      'links' => $ops,
    ));
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'draggable',
      ),
    );
  }
  if (!$flags) {
    $rows[] = array(
      array(
        'data' => t('No flags are currently defined.'),
        'colspan' => 7,
      ),
    );
  }
  elseif (count($flags) > 1) {
    drupal_add_tabledrag('flag-admin-listing-table', 'order', 'sibling', 'flag-weight');
  }
  $header = array(
    t('Flag'),
  );
  if (count($flags) > 1) {
    $header[] = t('Weight');
  }
  $header = array_merge($header, array(
    t('Flag type'),
    t('Roles'),
    t('Entity bundles'),
    t('Global?'),
    t('Operations'),
  ));
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'flag-admin-listing-table',
    ),
  ));
  $output .= drupal_render_children($form);
  return $output;
}