You are here

public function ImageCaptionItem::fieldSettingsForm in Image Field Caption 8

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides ImageItem::fieldSettingsForm

File

src/ImageCaptionItem.php, line 31
Contains \Drupal\image_field_caption\ImageCaptionItem.

Class

ImageCaptionItem

Namespace

Drupal\image_field_caption

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {

  // Get base form from ImageItem.
  $element = parent::fieldSettingsForm($form, $form_state);

  // Get field settings.
  $settings = $this
    ->getSettings();

  // Get the default field settings.
  $settings_default = self::defaultFieldSettings();

  // Add caption option.
  $element['caption_field'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable <em>Caption</em> field'),
    '#default_value' => !empty($settings['caption_field']) ? $settings['caption_field'] : $settings_default['caption_field'],
    '#description' => t('Adds an extra text area for captions on image fields.'),
    '#weight' => 13,
  );

  // Add caption (required) option.
  $element['caption_field_required'] = array(
    '#type' => 'checkbox',
    '#title' => t('<em>Caption</em> field required'),
    '#default_value' => $settings['caption_field_required'],
    '#description' => '',
    '#weight' => 14,
    '#states' => array(
      'visible' => array(
        ':input[name="settings[image_caption_field]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Add default caption.
  $element['default_image']['caption'] = array(
    '#type' => 'value',
    '#value' => !empty($settings['default_image']['caption']) ? $settings['default_image']['caption'] : $settings_default['default_image']['caption'],
  );
  return $element;
}