You are here

function ief_table_view_mode_form_field_ui_field_edit_form_alter in Inline Entity Form Table View Mode 7

Implements hook_form_FORM_ID_alter().

File

./ief_table_view_mode.module, line 166
Defines a view mode to set up the columns of the table for the IEF widget.

Code

function ief_table_view_mode_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  if ($form['#instance']['widget']['type'] != 'inline_entity_form') {
    return;
  }
  if ($form['#field']['type'] == 'commerce_product_reference') {
    $entity_type = 'commerce_product';
  }
  else {
    $entity_type = $form['#field']['settings']['target_type'];
  }
  $entity_info = entity_get_info($entity_type);
  if (!$entity_info['fieldable']) {
    return;
  }
  $ief_settings =& $form['instance']['widget']['settings'];
  $widget = $form['#instance']['widget'];
  $message = t('Define which fields you want to display by configuring the view mode %name_view_name in the following bundles:', array(
    '%name_view_name' => t('Inline Entity Form Table'),
  ));
  $ief_settings['type_settings']['ief_table_view_mode'] = array(
    '#type' => 'fieldset',
    '#title' => t('Inline Entity Form Table View Mode'),
    '#description' => $message,
  );
  $options_link = array(
    'attributes' => array(
      'target' => '_blank',
    ),
  );
  $bundle_admin_link = array();
  $bundles = array();
  foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
    $view_mode = field_view_mode_settings($entity_type, $bundle);
    $path = $bundle_info['admin']['path'] . '/display';
    $info = '';
    $disabled = TRUE;
    if (isset($view_mode[IEF_TABLE_VIEW_MODE_NAME]) && $view_mode[IEF_TABLE_VIEW_MODE_NAME]['custom_settings']) {
      $path .= '/' . IEF_TABLE_VIEW_MODE_NAME;
      $description = t('This <a href="!path" target="_blank">bundle</a> has the view mode activated.', array(
        '!path' => url($path),
      ));
      $disabled = FALSE;
    }
    else {
      $description = t('This <a href="!path" target="_blank">bundle</a> does <strong>not have</strong> activated the view mode.', array(
        '!path' => url($path),
      ));
    }
    $bundles[$bundle] = array(
      '#type' => 'checkbox',
      '#title' => $bundle_info['label'],
      '#disabled' => $disabled,
      '#default_value' => !$disabled && isset($widget['settings']['type_settings']['ief_table_view_mode']['bundles'][$bundle]) ? $widget['settings']['type_settings']['ief_table_view_mode']['bundles'][$bundle] : 0,
      '#description' => $description,
    );
  }
  $ief_settings['type_settings']['ief_table_view_mode']['bundles'] = array(
    '#type' => 'container',
  ) + $bundles;
  $ief_settings['type_settings']['ief_table_view_mode']['note'] = array(
    '#prefix' => '<em>',
    '#suffix' => '</em>',
    '#markup' => t('Select the bundle(s) to limit the fields you want to add. If you do not select any bundle(s), all displayed fields from activated bundles will appear in the widget. The latest bundle will define the order of fields.'),
  );
}