You are here

function multifield_list_page in Multifield 7

Same name and namespace in other branches
  1. 7.2 multifield.admin.inc \multifield_list_page()

@file Administation pages and forms for the Multifield module.

1 string reference to 'multifield_list_page'
multifield_menu in ./multifield.module
Implements hook_menu().

File

./multifield.admin.inc, line 8
Administation pages and forms for the Multifield module.

Code

function multifield_list_page() {
  $header = array(
    t('Label'),
    t('Machine name'),
    t('Subfields'),
    t('Used as field in'),
    t('Operations'),
  );
  $rows = array();
  foreach (multifield_load_all() as $machine_name => $multifield) {
    $row = array(
      'data' => array(),
    );
    $row['data'][] = check_plain($multifield->label);
    $row['data'][] = check_plain($machine_name);
    $subfields = field_info_instances('multifield', $machine_name);
    $row['data'][] = count($subfields);
    switch (count($subfields)) {
      case 0:
        $row['class'][] = 'error';
        $row['title'] = t('You will not be able to use this multifield until it has at least one subfield.');
        break;
      case 1:
        $row['class'][] = 'warning';
        $row['title'] = t('A multifield with only one subfield does not make a lot of sense. You should add more fields or just use a normal field.');
        break;
    }
    $fields = _multifield_get_usage_summary($machine_name, TRUE);
    $row['data'][] = !empty($fields) ? theme('item_list', array(
      'items' => $fields,
    )) : t('None');
    $base = 'admin/structure/multifield/manage/' . $machine_name;
    $operations = array();
    if (multifield_edit_access($multifield)) {
      $operations['edit'] = array(
        'title' => t('Edit'),
        'href' => $base,
      );
    }
    if (module_exists('field_ui')) {
      $operations['manage fields'] = array(
        'title' => t('Manage subfields'),
        'href' => $base . '/fields',
      );
      $operations['manage display'] = array(
        'title' => t('Manage display'),
        'href' => $base . '/display',
      );
    }
    if (multifield_edit_access($multifield)) {
      $operations['delete'] = array(
        'title' => t('Delete'),
        'href' => $base . '/delete',
      );
    }
    if (!empty($operations)) {
      $row['data'][] = theme('links', array(
        'links' => $operations,
        'attributes' => array(
          'class' => array(
            'links',
            'inline',
            'nowrap',
          ),
        ),
      ));
    }
    else {
      $row['data'][] = '';
    }
    $rows[] = $row;
  }
  $build['table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No multifield types available.'),
  );
  return $build;
}