You are here

public function ViewfieldFormatterDefault::settingsForm in Viewfield 8.3

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/ViewfieldFormatterDefault.php, line 37

Class

ViewfieldFormatterDefault
Viewfield Default Formatter plugin definition.

Namespace

Drupal\viewfield\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['view_title'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('View title'),
    '#options' => $this
      ->getFieldLabelOptions(),
    '#default_value' => $this
      ->getSetting('view_title'),
    '#description' => $this
      ->t('Option to render the view display title.'),
  ];
  $form['always_build_output'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Always build output'),
    '#default_value' => $this
      ->getSetting('always_build_output'),
    '#description' => $this
      ->t('Produce renderable output even if the view produces no results.<br>This option may be useful for some specialized cases, e.g., to force rendering of an attachment display even if there are no view results.'),
  ];
  $always_build_output_name = 'fields[' . $this->fieldDefinition
    ->getName() . '][settings_edit_form][settings][always_build_output]';
  $form['empty_view_title'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Empty view title'),
    '#options' => $this
      ->getFieldLabelOptions(),
    '#default_value' => $this
      ->getSetting('empty_view_title'),
    '#description' => $this
      ->t('Option to output the view display title even when the view produces no results.<br>This option has an effect only when <em>Always build output</em> is also selected.'),
    '#states' => [
      'visible' => [
        ':input[name="' . $always_build_output_name . '"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}