You are here

function _entityreference_field_settings_process in Entity reference 8

Same name and namespace in other branches
  1. 7 entityreference.module \_entityreference_field_settings_process()

Process handler; Add selection settings.

See also

entityreference_field_settings_form().

1 string reference to '_entityreference_field_settings_process'
entityreference_field_settings_form in ./entityreference.module
Implements hook_field_settings_form().

File

./entityreference.module, line 191
Provides a field that can reference other entities.

Code

function _entityreference_field_settings_process($form, $form_state) {
  $field = isset($form_state['entityreference']['field']) ? $form_state['entityreference']['field'] : $form['#field'];
  $instance = isset($form_state['entityreference']['instance']) ? $form_state['entityreference']['instance'] : $form['#instance'];
  $has_data = $form['#has_data'];
  $settings = $field['settings'];
  $settings += array(
    'handler' => 'base',
  );

  // Select the target entity type.
  $entity_type_options = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    $entity_type_options[$entity_type] = $entity_info['label'];
  }
  $form['target_type'] = array(
    '#type' => 'select',
    '#title' => t('Target type'),
    '#options' => $entity_type_options,
    '#default_value' => $field['settings']['target_type'],
    '#required' => TRUE,
    '#description' => t('The entity type that can be referenced through this field.'),
    '#disabled' => $has_data,
    '#size' => 1,
    '#ajax' => TRUE,
    '#limit_validation_errors' => array(),
  );
  $handlers = entityreference_get_plugin_manager('selection')
    ->getDefinitions();
  $handlers_options = array();
  foreach ($handlers as $handler => $handler_info) {
    $handlers_options[$handler] = check_plain($handler_info['label']);
  }
  $form['handler'] = array(
    '#type' => 'fieldset',
    '#title' => t('Entity selection'),
    '#tree' => TRUE,
    '#process' => array(
      '_entityreference_form_process_merge_parent',
    ),
  );
  $form['handler']['handler'] = array(
    '#type' => 'select',
    '#title' => t('Mode'),
    '#options' => $handlers_options,
    '#default_value' => $settings['handler'],
    '#required' => TRUE,
    '#ajax' => TRUE,
    '#limit_validation_errors' => array(),
  );
  $form['handler_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Change handler'),
    '#limit_validation_errors' => array(),
    '#attributes' => array(
      'class' => array(
        'js-hide',
      ),
    ),
    '#submit' => array(
      'entityreference_settings_ajax_submit',
    ),
  );
  $form['handler']['handler_settings'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'entityreference-settings',
      ),
    ),
  );
  $handler = entityreference_get_selection_handler($field, $instance);
  $form['handler']['handler_settings'] += $handler
    ->settingsForm($field, $instance);
  return $form;
}