Create a double field type for a custom entity

Created on 8 February 2021, almost 4 years ago
Updated 10 October 2024, about 1 month ago

I have a custom entity and wanted to add a field of type "double field" with unlimited values. Any suggestions? I tried using the below sample code but I get this error when about to create content of the custom entity.

"Notice: Undefined index: list /double_field/src/Plugin/Field/FieldWidget/DoubleField.php on line 505 Call Stack: 0.2006 424392 1. {main}() /app/web/index.php:0 0.2098 598240 2. Drupal\Core\DrupalKernel->handle() /app/web/index.php:19 0.2259 2254168 3. Stack\StackedHttpKernel->handle()......"
$fields['File'] = BaseFieldDefinition::create('double_field')
      ->setLabel(t('File'))
      ->setSettings([
        'first' => [
          'type' => 'string',
          'label' => 'File name',
          'maxlength' => 255,
        ],
        'second' => [
          'type' => 'string',
          'label' => 'File ID',
          'maxlength' => 255,
        ],
      ])
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'double_field_unformatted_list',
        'weight' => 3,
      ])
      ->setDisplayOptions('form', [
        'type' => 'double_field',
        'weight' => 3,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
💬 Support request
Status

Fixed

Version

3.0

Component

Documentation

Created by

🇬🇭Ghana jnrfred

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.71.5 2024