You are here

function field_tools_alter_fields_ui_table in Field tools 7

Form after_build callback to add an export link to a fields table.

1 string reference to 'field_tools_alter_fields_ui_table'
field_tools_form_field_ui_field_overview_form_alter in ./field_tools.module
Implements hook_form_FORM_ID_alter(): field_ui_field_overview_form

File

./field_tools.module, line 318
field_tools.module Contains useful tools for working with fields.

Code

function field_tools_alter_fields_ui_table($form, $form_state) {

  // Figure out the key for the operations column in the table header, as other
  // modules may be adding more columns too.
  $header = $form['fields']['#header'];
  foreach ($header as $key => $header_cell) {
    if (is_array($header_cell) && $header_cell['data'] == t('Operations')) {
      break;
    }
  }

  // Increate the colspan of the 'operations' column.
  $form['fields']['#header'][$key]['colspan']++;

  // For each field, add an 'export' operation link after the 'delete' link.
  foreach (element_children($form['fields']) as $field_name) {
    if (!in_array($form['fields'][$field_name]['#row_type'], array(
      'field',
      'group',
    ))) {
      $export_cell = array(
        '#markup' => NULL,
      );
      $insert_array = array(
        'export' => $export_cell,
      );
      field_tools_array_insert($form['fields'][$field_name], 'delete', $insert_array);
      continue;
    }
    $bundle = $form['#bundle'];
    $entity_type = $form['#entity_type'];
    $admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
    switch ($form['fields'][$field_name]['#row_type']) {
      case 'field':
        if (!isset($form['fields'][$field_name]['edit']) || isset($form['fields'][$field_name]['edit']['#value']) && $form['fields'][$field_name]['edit']['#value'] == t('Locked')) {
          $export_cell = array(
            '#markup' => NULL,
          );
          $insert_array = array(
            'export' => $export_cell,
          );
          field_tools_array_insert($form['fields'][$field_name], 'delete', $insert_array);
          continue 2;
        }
        $instance = field_info_instance($entity_type, $field_name, $bundle);
        $admin_field_path = $admin_path . '/fields/' . $instance['field_name'];
        $export_cell = array(
          '#type' => 'link',
          '#title' => t('export'),
          '#href' => $admin_field_path . '/export',
          '#options' => array(
            'attributes' => array(
              'title' => t('Export instance'),
            ),
          ),
        );
        $insert_array = array(
          'export' => $export_cell,
        );
        field_tools_array_insert($form['fields'][$field_name], 'delete', $insert_array);
        break;
      case 'group':
        $admin_field_path = $admin_path . '/groups/' . $field_name;
        $export_cell = array(
          '#type' => 'link',
          '#title' => t('export'),
          '#href' => $admin_field_path . '/export/form',
          '#options' => array(
            'attributes' => array(
              'title' => t('Export group'),
            ),
          ),
        );
        $insert_array = array(
          'export' => $export_cell,
        );
        field_tools_array_insert($form['fields'][$field_name], 'delete', $insert_array);
        break;
    }
  }
  return $form;
}