createFieldWithStorage example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a field and a storage of type 'test_field', on the 'entity_test'     // entity type.     $this->entityType = 'entity_test';
    $this->bundle = 'entity_test';
    $this->createFieldWithStorage('', $this->entityType, $this->bundle);

    // Create a second field on 'entity_test_rev'.     $this->installEntitySchema('entity_test_rev');
    $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev');
  }

  /** * Makes sure a field definition is exposed for a configurable field. */
  public function testBundleFieldDefinition() {
    $definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityType, $this->bundle);
    
$this->installEntitySchema('entity_test_rev');
  }

  /** * Check field values insert, update and load. * * Works independently of the underlying field storage backend. Inserts or * updates random field data and then loads and verifies the data. */
  public function testFieldAttachSaveLoad() {
    $entity_type = 'entity_test_rev';
    $this->createFieldWithStorage('', $entity_type);
    $cardinality = $this->fieldTestData->field_storage->getCardinality();

    // TODO : test empty values filtering and "compression" (store consecutive deltas).     // Preparation: create three revisions and store them in $revision array.     $values = [];
    $entity = $this->container->get('entity_type.manager')
      ->getStorage($entity_type)
      ->create();
    for ($revision_id = 0; $revision_id < 3; $revision_id++) {
      // Note: we try to insert one extra value.       $current_values = $this->_generateTestFieldValues($cardinality + 1);
      
// Ensure the methods work on deleted fields.     $field_storage->delete();
    $this->assertTrue($field_storage->hasdata(), 'There are entities with deleted field data.');
    $this->assertEquals(12, $this->storage->countFieldData($field_storage), 'There are 12 entities with deleted field data.');

    field_purge_batch(6);
    $this->assertTrue($field_storage->hasdata(), 'There are entities with deleted field data.');
    $this->assertEquals(6, $this->storage->countFieldData($field_storage), 'There are 6 entities with deleted field data.');

    $entity_type = 'entity_test_rev';
    $this->createFieldWithStorage('_2', $entity_type);

    $entity_init = $this->container->get('entity_type.manager')
      ->getStorage($entity_type)
      ->create(['type' => $entity_type]);
    $cardinality = $this->fieldTestData->field_storage_2->getCardinality();

    $this->assertFalse($this->fieldTestData->field_storage_2->hasData(), 'There are no entities with field data.');
    $this->assertSame(0, $this->storageRev->countFieldData($this->fieldTestData->field_storage_2), 'There are 0 entities with field data.');

    // Create 1 entity with the field.     $entity = clone($entity_init);
    

class FieldAttachOtherTest extends FieldKernelTestBase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('entity_test_rev');
    $this->createFieldWithStorage();
  }

  /** * Tests rendering fields with EntityDisplay build(). */
  public function testEntityDisplayBuild() {
    $this->createFieldWithStorage('_2');

    $entity_type = 'entity_test';
    $entity_init = $this->container->get('entity_type.manager')
      ->getStorage($entity_type)
      
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a field and storage of type 'test_field', on the 'entity_test'     // entity type.     $this->entityType = 'entity_test';
    $this->bundle = 'entity_test';
    $this->createFieldWithStorage('', $this->entityType, $this->bundle);

    // Create an 'entity_test' entity.     $this->entity = \Drupal::entityTypeManager()->getStorage($this->entityType)->create([
      'type' => $this->bundle,
    ]);
  }

  /** * Tests that the number of values is validated against the field cardinality. */
  public function testCardinalityConstraint() {
    
Home | Imprint | This part of the site doesn't use cookies.