You are here

protected function FarmFieldFactory::modifyFractionField in farmOS 2.x

Fraction field modifier.

Parameters

\Drupal\Core\Field\BaseFieldDefinition &$field: A base field definition object.

array $options: An array of options.

1 call to FarmFieldFactory::modifyFractionField()
FarmFieldFactory::buildFieldDefinition in modules/core/field/src/FarmFieldFactory.php
Builds a field definition with farmOS opinions.

File

modules/core/field/src/FarmFieldFactory.php, line 624

Class

FarmFieldFactory
Factory for generating farmOS field definitions.

Namespace

Drupal\farm_field

Code

protected function modifyFractionField(BaseFieldDefinition &$field, array $options = []) {

  // Build form and view display settings.
  $field
    ->setDisplayOptions('form', [
    'type' => 'fraction_decimal',
    'weight' => $options['weight']['form'] ?? 0,
    'settings' => [
      'precision' => 0,
      'auto_precision' => TRUE,
    ],
  ]);
  $field
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'fraction_decimal',
    'settings' => [
      'precision' => 0,
      'auto_precision' => TRUE,
      'separator' => '/',
      'prefix_suffix' => FALSE,
    ],
    'weight' => $options['weight']['view'] ?? 0,
  ]);
}