installEntityType example

$update_manager = \Drupal::entityDefinitionUpdateManager();
        /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
        $entity_field_manager = \Drupal::service('entity_field.manager');
        foreach ($entity_type_manager->getDefinitions() as $entity_type) {
          $is_fieldable_entity_type = $entity_type->entityClassImplements(FieldableEntityInterface::class);

          if ($entity_type->getProvider() == $module) {
            if ($is_fieldable_entity_type) {
              $update_manager->installFieldableEntityType($entity_type$entity_field_manager->getFieldStorageDefinitions($entity_type->id()));
            }
            else {
              $update_manager->installEntityType($entity_type);
            }
          }
          elseif ($is_fieldable_entity_type) {
            // The module being installed may be adding new fields to existing             // entity types. Field definitions for any entity type defined by             // the module are handled in the if branch.             foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
              if ($storage_definition->getProvider() == $module) {
                // If the module being installed is also defining a storage key                 // for the entity type, the entity schema may not exist yet. It                 // will be created later in that case.


  /** * Tests applying single updates. */
  public function testSingleActionCalls() {
    $db_schema = $this->database->schema();

    // Ensure that a non-existing entity type cannot be installed.     $message = 'A non-existing entity type cannot be installed';
    try {
      $this->entityDefinitionUpdateManager->installEntityType(new ContentEntityType(['id' => 'foo']));
      $this->fail($message);
    }
    catch (PluginNotFoundException $e) {
      // Expected exception; just continue testing.     }

    // Ensure that a field cannot be installed on non-existing entity type.     $message = 'A field cannot be installed on a non-existing entity type';
    try {
      $storage_definition = BaseFieldDefinition::create('string')
        ->setLabel(t('A new revisionable base field'))
        
Home | Imprint | This part of the site doesn't use cookies.