You are here

private function Dimension::_fieldSettings in Dimension 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/Field/FieldType/Dimension.php \Drupal\dimension\Plugin\Field\FieldType\Dimension::_fieldSettings()
  2. 2.0.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 150

Class

Dimension

Namespace

Drupal\dimension\Plugin\Field\FieldType

Code

private function _fieldSettings(&$element, $key, $label, $hide_constraints = FALSE) {
  $settings = $this
    ->getSetting($key);
  $storage_settings = $this
    ->getSetting('storage_' . $key);
  $element[$key] = array(
    '#type' => 'fieldset',
    '#title' => $label,
  );
  $element[$key]['factor'] = array(
    '#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', array(
      '@label' => $label,
      '@field' => $this
        ->getFieldDefinition()
        ->getLabel(),
    )),
    '#access' => !$hide_constraints,
  );
  $element[$key]['min'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Minimum'),
    '#default_value' => $settings['min'],
    '#step' => 0.1 ** $storage_settings['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'] = array(
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum'),
    '#default_value' => $settings['max'],
    '#step' => 0.1 ** $storage_settings['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'] = array(
    '#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'] = array(
    '#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')."),
  );
}