You are here

function ds_field_formatter_third_party_settings_form in Display Suite 8.3

Same name and namespace in other branches
  1. 8.4 ds.module \ds_field_formatter_third_party_settings_form()
  2. 8.2 ds.module \ds_field_formatter_third_party_settings_form()

Implements hook_field_formatter_third_party_settings_form().

File

./ds.module, line 1011
Display Suite core functions.

Code

function ds_field_formatter_third_party_settings_form(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state) {
  $element = [];

  // Don't process the form if it's a layout builder FieldBlock and field
  // template support is disabled
  if ($form_state
    ->getBuildInfo()['base_form_id'] == 'layout_builder_configure_block' && !\Drupal::config('ds.settings')
    ->get('ft-layout-builder')) {
    return $element;
  }
  $field_info = $field_definition
    ->getFieldStorageDefinition();
  if (!empty($field_info) && $field_info
    ->getCardinality() != 1) {
    $name = $field_info
      ->getName();
    $settings = $form_state
      ->get('plugin_settings');
    $element['ds_limit'] = [
      '#type' => 'textfield',
      '#title' => t('UI limit'),
      '#size' => 2,
      '#description' => t("Enter a number to limit the number of items or 'delta' to print a specific delta (usually configured in views or found in entity->ds_delta).<br />Leave empty to display them all. Note that depending on the formatter settings, this option might not always work."),
      '#default_value' => !empty($settings[$name]['ds_limit']) ? $settings[$name]['ds_limit'] : '',
    ];
  }
  if (\Drupal::config('ds.settings')
    ->get('field_template')) {
    $context = [
      'instance' => $field_definition,
      'formatter' => $plugin,
    ];
    ds_field_template_settings_form($element, $form_state, $context);
  }
  return $element;
}