You are here

protected function FarmFieldFactory::modifyStringField in farmOS 2.x

String field modifier.

Parameters

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

array $options: An array of options.

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

File

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

Class

FarmFieldFactory
Factory for generating farmOS field definitions.

Namespace

Drupal\farm_field

Code

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

  // Set default settings.
  $field
    ->setSetting('max_length', 255);
  $field
    ->setSetting('is_ascii', FALSE);
  $field
    ->setSetting('case_sensitive', FALSE);

  // Build form and view display settings.
  $field
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'settings' => [
      'size' => 60,
      'placeholder' => '',
    ],
    'weight' => $options['weight']['form'] ?? 0,
  ]);
  $field
    ->setDisplayOptions('view', [
    'label' => 'inline',
    'type' => 'string',
    'weight' => $options['weight']['view'] ?? 0,
  ]);
}