You are here

function fico_condition_settings_form in Field Formatter Condition 8

Field template settings form.

Parameters

array $form: The form array.

object $form_state: The form_state object.

array $context: The context array.

2 calls to fico_condition_settings_form()
fico_field_formatter_third_party_settings_form in ./fico.module
Implements hook_field_formatter_third_party_settings_form().
fico_form_entity_view_display_edit_form_alter in ./fico.module
Implements hook_form_FORMID_alter().

File

./fico.module, line 72
Contains fico.module.

Code

function fico_condition_settings_form(array &$form, FormStateInterface &$form_state, array $context) {
  $instance = isset($context['instance']) ? $context['instance'] : NULL;
  $conditions = fico_field_options($instance);
  $settings = isset($context['settings']) ? $context['settings'] : [];
  $default_field_function = !empty($settings['condition']) ? $settings['condition'] : NULL;
  $key = is_array($context['instance']) ? $context['instance']['field_name'] : $context['instance']
    ->getName();
  $values = $form_state
    ->getValues();
  if (isset($values['fields'][$key]['settings_edit_form']['third_party_settings']['fico']['fico']['condition'])) {
    $field_function = $values['fields'][$key]['settings_edit_form']['third_party_settings']['fico']['fico']['condition'];
  }
  elseif (isset($values['fields'][$key]['settings_edit_form']['settings']['fico']['condition'])) {
    $field_function = $values['fields'][$key]['settings_edit_form']['settings']['fico']['condition'];
  }
  else {
    $field_function = $default_field_function;
  }
  $form['fico']['#open'] = $field_function ? TRUE : FALSE;
  $form['fico']['condition'] = [
    '#title' => t('Condition'),
    '#empty_option' => t('- Select a condition -'),
    '#type' => 'select',
    '#options' => $conditions,
    '#default_value' => $field_function ? $field_function : [],
    '#submit' => array(
      'fico_ajax_submit',
    ),
    '#weight' => 1,
    '#ajax' => array(
      'callback' => 'fico_ajax_callback',
      'wrapper' => 'field-display-overview-wrapper',
    ),
  ];
  $formatterPlugin = $field_function ? \Drupal::service('plugin.manager.field_formatter_condition')
    ->createInstance($field_function, $settings) : NULL;
  $form['fico']['settings'] = [
    '#type' => 'container',
    '#weight' => '2',
    '#attributes' => [
      'id' => 'fico-settings',
    ],
  ];
  if ($formatterPlugin) {
    $formatterPlugin
      ->alterForm($form['fico']['settings'], $settings);
  }
}