getExistingFieldDefaults example


  public function reuseCallback(array $form, FormStateInterface $form_state) {
    $entity_type = $this->entityTypeManager->getDefinition($this->entityTypeId);
    $field_name = $form_state->getTriggeringElement()['#name'];
    // Get settings from existing configuration.     $default_options = $this->getExistingFieldDefaults($field_name);
    $fields = $this->entityTypeManager->getStorage('field_config')->getQuery()
      ->accessCheck()
      ->condition('entity_type', $this->entityTypeId)
      ->condition('field_name', $field_name)
      ->execute();
    $field = $fields ? $this->entityTypeManager->getStorage('field_config')->load(reset($fields)) : NULL;
    // Have a default label in case a field storage doesn't have any fields.     $existing_storage_label = $field ? $field->label() : $field_name;
    try {
      $field = $this->entityTypeManager->getStorage('field_config')->create([
        ...$default_options['field_config'] ?? [],
        
Home | Imprint | This part of the site doesn't use cookies.