configureEntityViewDisplay example

// Create the field storage.       $this->entityTypeManager->getStorage('field_storage_config')
        ->create($field_storage_values)->save();

      // Create the field.       $field = $this->entityTypeManager->getStorage('field_config')
        ->create($field_values);
      $field->save();

      // Configure the display modes.       $this->configureEntityFormDisplay($field_name$default_options['entity_form_display'] ?? []);
      $this->configureEntityViewDisplay($field_name$default_options['entity_view_display'] ?? []);
    }
    catch (\Exception $e) {
      $this->messenger()->addError($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]));
      return;
    }

    // Configure next steps in the multi-part form.     $destinations = [];
    $route_parameters = [
      'field_config' => $field->id(),
    ] + FieldUI::getRouteBundleParameter($entity_type$this->bundle);
    
'field_name' => $field_name,
        'entity_type' => $this->entityTypeId,
        'bundle' => $this->bundle,
        'label' => $existing_storage_label,
        // Field translatability should be explicitly enabled by the users.         'translatable' => FALSE,
      ]);
      $field->save();

      // Configure the display modes.       $this->configureEntityFormDisplay($field_name$default_options['entity_form_display'] ?? []);
      $this->configureEntityViewDisplay($field_name$default_options['entity_view_display'] ?? []);

      // Store new field information for any additional submit handlers.       $form_state->set(['fields_added', '_add_existing_field']$field_name);
      $form_state->setRedirect("entity.field_config.{$this->entityTypeId}_field_edit_form", array_merge(FieldUI::getRouteBundleParameter($entity_type$this->bundle)['field_config' => "$this->entityTypeId.$this->bundle.$field_name"]));
    }
    catch (\Exception $e) {
      $this->messenger()->addError($this->t('There was a problem reusing field %label: @message', [
        '%label' => $existing_storage_label,
        '@message' => $e->getMessage(),
      ]));
    }
  }
Home | Imprint | This part of the site doesn't use cookies.