You are here

private function Dimension::_fieldSettings in Dimension 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::_fieldSettings()
  2. 2.1.x src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::_fieldSettings()
1 call to Dimension::_fieldSettings()
Dimension::fieldSettingsForm in src/Plugin/Field/FieldType/Dimension.php
Returns a form for the field-level settings.

File

src/Plugin/Field/FieldType/Dimension.php, line 140

Class

Dimension

Namespace

Drupal\dimension\Plugin\Field\FieldType

Code

private function _fieldSettings(&$element, $key, $label, $hide_constraints = FALSE) : void {
  $settings = $this
    ->getSetting($key);
  $element[$key] = [
    '#type' => 'fieldset',
    '#title' => $label,
  ];
  $element[$key]['factor'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Factor'),
    '#default_value' => $settings['factor'],
    '#step' => 0.1 ** 2,
    '#required' => TRUE,
    '#description' => $this
      ->t('A factor to multiply the @label with when calculating the @field', [
      '@label' => $label,
      '@field' => $this
        ->getFieldDefinition()
        ->getLabel(),
    ]),
    '#access' => !$hide_constraints,
  ];
  $element[$key]['min'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Minimum'),
    '#default_value' => $settings['min'],
    '#step' => 0.1 ** $this
      ->getSetting($key . '_scale'),
    '#description' => $this
      ->t('The minimum value that should be allowed in this field. Leave blank for no minimum.'),
    '#access' => !$hide_constraints,
  ];
  $element[$key]['max'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum'),
    '#default_value' => $settings['max'],
    '#step' => 0.1 ** $this
      ->getSetting($key . '_scale'),
    '#description' => $this
      ->t('The maximum value that should be allowed in this field. Leave blank for no maximum.'),
    '#access' => !$hide_constraints,
  ];
  $element[$key]['prefix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Prefix'),
    '#default_value' => $settings['prefix'],
    '#size' => 60,
    '#description' => $this
      ->t("Define a string that should be prefixed to the value, like 'cm ' or 'inch '. Leave blank for none. Separate singular and plural values with a pipe ('inch|inches')."),
  ];
  $element[$key]['suffix'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Suffix'),
    '#default_value' => $settings['suffix'],
    '#size' => 60,
    '#description' => $this
      ->t("Define a string that should be suffixed to the value, like ' mm', ' inch'. Leave blank for none. Separate singular and plural values with a pipe ('inch|inches')."),
  ];
}