applyEntityUpdates example

break;
    }
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    // Set flag so that internal field 'internal_string_field' is created.     // @see entity_test_entity_base_field_info()     $this->container->get('state')->set('entity_test.internal_field', TRUE);
    $this->applyEntityUpdates('entity_test');

    $entity_test = \Drupal::entityTypeManager()
      ->getStorage(static::$entityTypeId)
      ->create([
        'name' => 'Llama',
        'type' => static::$entityTypeId,
        // Set a value for the internal field to confirm that it will not be         // returned in normalization.         // @see entity_test_entity_base_field_info().         'internal_string_field' => [
          'value' => 'This value shall not be internal!',
        ],
case EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED:
        \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionDelete($original_storage_definition);
        break;
    }
  }

  /** * Enables a new entity type definition. */
  protected function enableNewEntityType() {
    $this->state->set('entity_test_new', TRUE);
    $this->applyEntityUpdates('entity_test_new');
  }

  /** * Resets the entity type definition. */
  protected function resetEntityType() {
    $updated_entity_type = $this->getUpdatedEntityTypeDefinition(FALSE, FALSE);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(FALSE, FALSE);
    $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions);
  }

  
->condition('non_rev_field', 'Superior')
      ->sort('revision_id', 'DESC')
      ->execute();
    $this->assertEquals($expected_non_rev_field_revision_ids$non_rev_field_revision_ids, 'Revision ids found');
  }

  /** * Tests multi column non revisionable base field for revisionable entity. */
  public function testMultiColumnNonRevisionableBaseField() {
    \Drupal::state()->set('entity_test.multi_column', TRUE);
    $this->applyEntityUpdates('entity_test_mulrev');
    // Refresh the storage.     $this->mulRev = $this->entityTypeManager->getStorage('entity_test_mulrev');
    $user1 = $this->createUser();

    // Create a test entity.     $entity = EntityTestMulRev::create([
      'name' => $this->randomString(),
      'user_id' => $user1->id(),
      'language' => 'en',
      'non_rev_field' => 'Huron',
      'description' => [
        
    $this->assertFalse($views['test_view_entity_test']->status());
    $this->assertFalse($views['test_view_entity_test_revision']->status());
    $this->assertFalse($views['test_view_entity_test_data']->status());
    $this->assertFalse($views['test_view_entity_test_additional_base_field']->status());
  }

  /** * Tests that renaming base tables adapts the views. */
  public function testBaseTableRename() {
    $this->renameBaseTable();
    $this->applyEntityUpdates('entity_test_update');

    /** @var \Drupal\views\Entity\View $view */
    $entity_storage = $this->entityTypeManager->getStorage('view');
    $view = $entity_storage->load('test_view_entity_test');

    // Ensure the base table got renamed, so also the views fields.     $this->assertEquals('entity_test_update_new', $view->get('base_table'));
    $display = $view->getDisplay('default');
    $this->assertEquals('entity_test_update_new', $display['display_options']['fields']['id']['table']);
    $this->assertEquals('entity_test_update_new', $display['display_options']['fields']['name']['table']);

    
->setTargetBundle('entity_test_mulrev')
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      // Base fields are non-translatable and non-revisionable by default, but       // we explicitly set these values here for extra clarity.       ->setTranslatable(FALSE)
      ->setRevisionable(FALSE);
    $this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);

    $this->tableMapping = $this->entityTypeManager->getStorage('entity_test_mulrev')->getTableMapping();

    // Ensure that the tables for the new field are created.     $this->applyEntityUpdates('entity_test_mulrev');
  }

  /** * Tests DefaultTableMapping::getFieldTableName(). * * @covers ::getFieldTableName */
  public function testGetFieldTableName() {
    // Test the field table name for a single-valued base field, which is stored     // in the entity's base table.     $expected = 'entity_test_mulrev';
    
/** * Tests creating, updating, and deleting a base field if no entities exist. */
  public function testBaseFieldCreateUpdateDeleteWithoutData() {
    // Add a base field, ensure the update manager reports it, and the update     // creates its schema.     $this->addBaseField();
    $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
    $changes = $this->entityDefinitionUpdateManager->getChangeSummary();
    $this->assertCount(1, $changes['entity_test_update']);
    $this->assertEquals('The A new base field field needs to be installed.', strip_tags($changes['entity_test_update'][0]));
    $this->applyEntityUpdates();
    $this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Column created in shared table for new_base_field.');

    // Add an index on the base field, ensure the update manager reports it,     // and the update creates it.     $this->addBaseFieldIndex();
    $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
    $changes = $this->entityDefinitionUpdateManager->getChangeSummary();
    $this->assertCount(1, $changes['entity_test_update']);
    $this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
    $this->applyEntityUpdates();
    $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index created.');

    
Home | Imprint | This part of the site doesn't use cookies.