installFieldableEntityType example


  public function testInstallAdditionalBaseFieldDuringFieldableEntityTypeInstallation() {
    $entity_type = clone $this->entityTypeManager->getDefinition('entity_test_update');
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');

    // Enable the creation of a new base field during the installation of a     // fieldable entity type.     $this->state->set('entity_test_update.install_new_base_field_during_create', TRUE);

    // Install the entity type and check that the additional base field was also     // installed.     $this->entityDefinitionUpdateManager->installFieldableEntityType($entity_type$field_storage_definitions);

    // Check whether the 'new_base_field' field has been installed correctly.     $field_storage_definition = $this->entityDefinitionUpdateManager->getFieldStorageDefinition('new_base_field', 'entity_test_update');
    $this->assertNotNull($field_storage_definition);
  }

  /** * Tests creating a fieldable entity type that doesn't exist in code anymore. * * @covers ::installFieldableEntityType */
  
        // database tables.         // @todo Clean this up in https://www.drupal.org/node/2350111.         $entity_type_manager = \Drupal::entityTypeManager();
        $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) {
                
Home | Imprint | This part of the site doesn't use cookies.