You are here

protected function FarmFieldFactory::modifyBooleanField in farmOS 2.x

Boolean field modifier.

Parameters

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

array $options: An array of options.

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

File

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

Class

FarmFieldFactory
Factory for generating farmOS field definitions.

Namespace

Drupal\farm_field

Code

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

  // Set the on/off labels.
  $field
    ->setSetting('on_label', 'Yes');
  $field
    ->setSetting('off_label', 'No');

  // Build form and view display settings.
  $field
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'settings' => [
      'display_label' => TRUE,
    ],
    'weight' => $options['weight']['form'] ?? 0,
  ]);
  $field
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'boolean',
    'settings' => [
      'format' => 'default',
      'format_custom_false' => '',
      'format_custom_true' => '',
    ],
    'weight' => $options['weight']['view'] ?? 0,
  ]);
}