storageSettingsForm example

$element = [];

    $element['max_length'] = [
      '#type' => 'number',
      '#title' => $this->t('Maximum length'),
      '#default_value' => $this->getSetting('max_length'),
      '#required' => TRUE,
      '#description' => $this->t('The maximum length of the field in characters.'),
      '#min' => 1,
      '#disabled' => $has_data,
    ];
    $element += parent::storageSettingsForm($form$form_state$has_data);

    return $element;
  }

}
 + $schema['columns']['value'];

    $schema['indexes']['end_value'] = ['end_value'];

    return $schema;
  }

  /** * {@inheritdoc} */
  public function storageSettingsForm(array &$form, FormStateInterface $form_state$has_data) {
    $element = parent::storageSettingsForm($form$form_state$has_data);

    $element['datetime_type']['#options'][static::DATETIME_TYPE_ALLDAY] = $this->t('All Day');

    return $element;
  }

  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $type = $field_definition->getSetting('datetime_type');

    

    // Create an arbitrary entity object, so that we can have an instantiated     // FieldItem.     $ids = (object) [
      'entity_type' => $form_state->get('entity_type_id'),
      'bundle' => $form_state->get('bundle'),
      'entity_id' => NULL,
    ];
    $entity = _field_create_entity_from_ids($ids);
    $items = $entity->get($this->entity->getName());
    $item = $items->first() ?: $items->appendItem();
    $form['settings'] += $item->storageSettingsForm($form$form_state$this->entity->hasData());

    // Add the cardinality sub-form.     $form['cardinality_container'] = $this->getCardinalityForm();

    return $form;
  }

  /** * Builds the cardinality form. * * @return array * The cardinality form render array. */
Home | Imprint | This part of the site doesn't use cookies.