1 field.block.inc FieldBlock::form(&$form, &$form_state)

Builds the block's configuration form.

Overrides Block::form

File

core/modules/field/field.block.inc, line 112

Class

FieldBlock
FieldBlock extends Block

Code

function form(&$form, &$form_state) {
  parent::form($form, $form_state);

  // Clarify what the default title type is.
  $form['title_display']['title_display']['#options'][LAYOUT_TITLE_DEFAULT] = t('Use field label as title');
  $form['title_display']['title_display']['#description'] = t('The block title is displayed outside of the block content area.');

  $settings = $this->settings;
  $fields = field_get_block_list();

  list($entity_type, $field_name) = explode('-', $this->childDelta);
  $field = field_info_field($field_name);

  // Get formatter info.
  $formatters = field_info_formatter_types();
  $formatter_options = array();
  foreach ($formatters as $formatter_name => $formatter) {
    if (in_array($field['type'], $formatter['field types'])) {
      $formatter_options[$formatter_name] = $formatter['label'];
    }
  }

  $form['label'] = array(
    '#type' => 'select',
    '#title' => t('Field label display'),
    '#default_value' => $settings['label'],
    '#options' => array(
      'hidden' => 'None',
      'above' => 'Above',
      'inline' => 'Inline',
    ),
    '#description' => t('The field label is displayed within the block content area.'),
  );

  // Get the currently selected formatter.
  $formatter_name = isset($form_state['values']['formatter']) ? $form_state['values']['formatter'] : $settings['formatter'];
  if (empty($formatter_name)) {
    $formatter_name = key($formatter_options);
  }
  $formatter = $formatters[$formatter_name];
  $formatter_settings = (array) $settings['formatter_settings'] + field_info_formatter_settings($formatter_name);

  $form['formatter'] = array(
    '#type' => 'select',
    '#title' => t('Field display format'),
    '#default_value' => $formatter_name,
    '#options' => $formatter_options,
    '#ajax' => array(
      'callback' => 'FieldBlock::formatterFormAjax',
    ),
    '#access' => count($formatter_options) > 1,
  );

  // Provide an instance array for hook_field_formatter_settings_form().
  $pseudo_instance = $this->createPseudoInstance($formatter_name, $formatter_settings);

  // Store the settings in a '_custom' display mode.
  $pseudo_instance['display']['_custom'] = array(
    'type' => $formatter_name,
    'settings' => $formatter_settings,
  );

  // Get the settings form.
  $formatter_settings_form = array(
    '#type' => 'value',
    '#value' => array(),
  );
  $function = $formatter['module'] . '_field_formatter_settings_form';
  if (function_exists($function)) {
    $formatter_settings_form = $function($field, $pseudo_instance, '_custom', $form, $form_state);
  }
  $formatter_settings_form['#prefix'] = '<div id="formatter-settings">';
  $formatter_settings_form['#suffix'] = '</div>';
  $form['formatter_settings'] = $formatter_settings_form;

  // Settings that are only shown for multiple field
  if (isset($field['cardinality']) && $field['cardinality'] != 1) {
    list($prefix, $suffix) = explode('@count', t('Skip the first @count item(s)'));
    $form['trim_output'] = array(
      '#type' => 'fieldset',
      '#title' => t('Trim the output values'),
    );
    $form['trim_output']['delta_offset'] = array(
      '#type' => 'textfield',
      '#size' => 5,
      '#field_prefix' => $prefix,
      '#field_suffix' => $suffix,
      '#default_value' => $settings['delta_offset'],
    );

    list($prefix, $suffix) = explode('@count', t('Then display at most @count item(s)'));
    $form['trim_output']['delta_limit'] = array(
      '#type' => 'textfield',
      '#size' => 5,
      '#field_prefix' => $prefix,
      '#field_suffix' => $suffix,
      '#description' => t('Enter 0 to display all items.'),
      '#default_value' => $settings['delta_limit'],
    );

    $form['delta_reversed'] = array(
      '#type' => 'fieldset',
      '#title' => t('Reverse the output values'),
    );
    $form['delta_reversed']['delta_reversed'] = array(
      '#title' => t('Display in reverse order'),
      '#type' => 'checkbox',
      '#default_value' => !empty($settings['delta_reversed']),
      '#description' => t('(start from last values)'),
    );
  }
}