entity_test_delete_bundle example

$table = $table_mapping->getDedicatedDataTableName($entity->getFieldDefinition('custom_bundle_field')->getFieldStorageDefinition());
    $result = $this->database->select($table, 'f')
      ->fields('f')
      ->condition('f.entity_id', $entity->id())
      ->execute();
    $this->assertFalse($result->fetchAssoc(), 'Field data has been deleted');

    // Create another entity to test that values are marked as deleted when a     // bundle is deleted.     $entity = $storage->create(['type' => 'custom', 'custom_bundle_field' => 'new']);
    $entity->save();
    entity_test_delete_bundle('custom', 'entity_test_update');

    $table = $table_mapping->getDedicatedDataTableName($entity->getFieldDefinition('custom_bundle_field')->getFieldStorageDefinition(), TRUE);
    $result = $this->database->select($table, 'f')
      ->condition('f.entity_id', $entity->id())
      ->condition('deleted', 1)
      ->countQuery()
      ->execute();
    $this->assertEquals(1, $result->fetchField(), 'Field data has been deleted');

    // Ensure that the field no longer exists in the field map.     $field_map = \Drupal::service('entity_field.manager')->getFieldMap();
    
    $name = mb_strtolower($this->randomMachineName());
    $label = $this->randomString();
    $handler_settings = ['target_bundles' => [$this->customBundle => $this->customBundle]];
    $this->createEntityReferenceField('node', $this->nodeType->id()$name$label, 'entity_test', 'default', $handler_settings);

    // Check that the 'target_bundle' setting contains the custom bundle.     $field_config = FieldConfig::loadByName('node', $this->nodeType->id()$name);
    $actual_handler_settings = $field_config->getSetting('handler_settings');
    $this->assertEquals($handler_settings$actual_handler_settings);

    // Delete the custom bundle.     entity_test_delete_bundle($this->customBundle, 'entity_test');

    // Ensure that field_field_config_presave() logs the expected critical     // error.     $log_message = $this->container->get($this->testLogServiceName)->cleanLogs()[0];
    $this->assertEquals(RfcLogLevel::CRITICAL, $log_message[0]);
    $this->assertEquals('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', $log_message[1]);
    $this->assertEquals($field_config->getName()$log_message[2]['%field_name']);
    $this->assertEquals('node', $log_message[2]['%entity_type']);
    $this->assertEquals($this->nodeType->id()$log_message[2]['%bundle']);

    // Check that the deleted bundle is no longer present in the
/** * Tests the add page for an entity type not using bundle entities. */
  public function testAddPageWithoutBundleEntities() {
    $admin_user = $this->drupalCreateUser([
      'administer entity_test content',
    ]);
    $this->drupalLogin($admin_user);

    entity_test_create_bundle('test', 'Test label', 'entity_test_mul');
    // Delete the default bundle, so that we can rely on our own.     entity_test_delete_bundle('entity_test_mul', 'entity_test_mul');

    // One bundle exists, confirm redirection to the add-form.     $this->drupalGet('/entity_test_mul/add');
    $this->assertSession()->addressEquals('/entity_test_mul/add/test');

    // Two bundles exist, confirm both are shown.     entity_test_create_bundle('test2', 'Test2 label', 'entity_test_mul');
    $this->drupalGet('/entity_test_mul/add');

    $this->assertSession()->linkExists('Test label');
    $this->assertSession()->linkExists('Test2 label');

    
->create(['type' => $this->fieldTestData->field->getTargetBundle()]);
    $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
    $entity->{$this->fieldTestData->field_name} = $values;
    $entity->{$field_name} = $this->_generateTestFieldValues(1);
    $entity = $this->entitySaveReload($entity);

    // Verify the fields are present on load     $this->assertCount(4, $entity->{$this->fieldTestData->field_name}, 'First field got loaded');
    $this->assertCount(1, $entity->{$field_name}, 'Second field got loaded');

    // Delete the bundle.     entity_test_delete_bundle($this->fieldTestData->field->getTargetBundle()$entity_type);

    // Verify no data gets loaded     $controller = $this->container->get('entity_type.manager')->getStorage($entity->getEntityTypeId());
    $controller->resetCache();
    $entity = $controller->load($entity->id());

    $this->assertEmpty($entity->{$this->fieldTestData->field_name}, 'No data for first field');
    $this->assertEmpty($entity->{$field_name}, 'No data for second field');

    // Verify that the fields are gone.     $this->assertNull(FieldConfig::load('entity_test.' . $this->fieldTestData->field->getTargetBundle() . '.' . $this->fieldTestData->field_name), "First field is deleted");
    
'module' => [
        'content_moderation',
        'entity_test',
      ],
    ]$workflow->getDependencies());
    $this->assertEquals([
      'test_bundle',
    ]$workflow->getTypePlugin()->getBundlesForEntityType('entity_test'));

    // Delete the test bundle to ensure the workflow entity responds     // appropriately.     entity_test_delete_bundle('test_bundle');

    $workflow = Workflow::load('editorial');
    $this->assertEquals([]$workflow->getTypePlugin()->getBundlesForEntityType('entity_test'));
    $this->assertEquals([
      'module' => [
        'content_moderation',
      ],
    ]$workflow->getDependencies());
  }

  /** * Tests the revision default state of the moderation state entity revisions. * * @param string $entity_type_id * The ID of entity type to be tested. * * @dataProvider basicModerationTestCases */
Home | Imprint | This part of the site doesn't use cookies.