fieldSettingsForm example

'value' => [
          'type' => 'float',
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::fieldSettingsForm($form$form_state);

    $element['min']['#step'] = 'any';
    $element['max']['#step'] = 'any';

    return $element;
  }

  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    
/** * {@inheritdoc} */
  public static function defaultFieldSettings() {
    return ['allowed_formats' => []] + parent::defaultFieldSettings();
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::fieldSettingsForm($form$form_state);
    $settings = $this->getSettings();

    $element['allowed_formats'] = [
      '#type' => 'checkboxes',
      '#title' => $this->t('Allowed text formats'),
      '#options' => $this->get('format')->getPossibleOptions(),
      '#default_value' => !empty($settings['allowed_formats']) ? $settings['allowed_formats'] : [],
      '#description' => $this->t('Select the allowed text formats. If no formats are selected, all available text formats will be displayed to the user.'),
      '#element_validate' => [[static::class, 'validateAllowedFormats']],
    ];

    

  public function isEmpty() {
    $value = $this->get('summary')->getValue();
    return parent::isEmpty() && ($value === NULL || $value === '');
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::fieldSettingsForm($form$form_state);
    $settings = $this->getSettings();

    $element['display_summary'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Summary input'),
      '#default_value' => $settings['display_summary'],
      '#description' => $this->t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'),
    ];

    $element['required_summary'] = [
      '#type' => 'checkbox',
      

    $form['#entity'] = _field_create_entity_from_ids($ids);
    $items = $this->getTypedData($form['#entity']);
    $item = $items->first() ?: $items->appendItem();

    // Add field settings for the field type and a container for third party     // settings that modules can add to via hook_form_FORM_ID_alter().     $form['settings'] = [
      '#tree' => TRUE,
      '#weight' => 10,
    ];
    $form['settings'] += $item->fieldSettingsForm($form$form_state);
    $form['third_party_settings'] = [
      '#tree' => TRUE,
      '#weight' => 11,
    ];

    // Create a new instance of typed data for the field to ensure that default     // value widget is always rendered from a clean state.     $items = $this->getTypedData($form['#entity']);

    // Add handling for default value.     if ($element = $items->defaultValuesForm($form$form_state)) {
      

      ],
    ]);

    return $constraints;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::fieldSettingsForm($form$form_state);
    $settings = $this->getSettings();

    $element['min']['#step'] = pow(0.1, $settings['scale']);
    $element['max']['#step'] = pow(0.1, $settings['scale']);

    return $element;
  }

  /** * {@inheritdoc} */
  
    static::defaultImageForm($element$settings);
    $element['default_image']['#description'] = $this->t('If no image is uploaded, this image will be shown on display.');

    return $element;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    // Get base form from FileItem.     $element = parent::fieldSettingsForm($form$form_state);

    $settings = $this->getSettings();

    // Add maximum and minimum resolution settings.     $max_resolution = explode('x', $settings['max_resolution']) + ['', ''];
    $element['max_resolution'] = [
      '#type' => 'item',
      '#title' => $this->t('Maximum image resolution'),
      '#element_validate' => [[static::class, 'validateResolution']],
      '#weight' => 4.1,
      '#description' => $this->t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
    ];
Home | Imprint | This part of the site doesn't use cookies.