Verified Commit 0793e1e2 authored by Jess's avatar Jess
Browse files

Issue #3529714 by mstrelan, xjm, smustgrave, acbramley: Add return types to...

Issue #3529714 by mstrelan, xjm, smustgrave, acbramley: Add return types to EntityDefinitionTestTrait
parent 8d70081b
Loading
Loading
Loading
Loading
Loading
+0 −1848

File changed.

Preview size limit exceeded, changes collapsed.

+28 −28
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ trait EntityDefinitionTestTrait {
   *   (optional) Applies changes only for the specified entity type ID.
   *   Defaults to NULL.
   */
  protected function applyEntityUpdates($entity_type_id = NULL) {
  protected function applyEntityUpdates($entity_type_id = NULL): void {
    $complete_change_list = \Drupal::entityDefinitionUpdateManager()->getChangeList();
    if ($complete_change_list) {
      // In case there are changes, explicitly invalidate caches.
@@ -68,7 +68,7 @@ protected function applyEntityUpdates($entity_type_id = NULL) {
   * @param string $entity_type_id
   *   The entity type ID.
   */
  protected function doEntityUpdate($op, $entity_type_id) {
  protected function doEntityUpdate($op, $entity_type_id): void {
    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
    switch ($op) {
@@ -96,7 +96,7 @@ protected function doEntityUpdate($op, $entity_type_id) {
   * @param array|null $original_storage_definition
   *   The original field storage definition.
   */
  protected function doFieldUpdate($op, $storage_definition = NULL, $original_storage_definition = NULL) {
  protected function doFieldUpdate($op, $storage_definition = NULL, $original_storage_definition = NULL): void {
    switch ($op) {
      case EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED:
        \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
@@ -115,7 +115,7 @@ protected function doFieldUpdate($op, $storage_definition = NULL, $original_stor
  /**
   * Enables a new entity type definition.
   */
  protected function enableNewEntityType() {
  protected function enableNewEntityType(): void {
    $this->state->set('entity_test_new', TRUE);
    $this->applyEntityUpdates('entity_test_new');
  }
@@ -123,7 +123,7 @@ protected function enableNewEntityType() {
  /**
   * Resets the entity type definition.
   */
  protected function resetEntityType() {
  protected function resetEntityType(): void {
    $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);
@@ -136,7 +136,7 @@ protected function resetEntityType() {
   *   (optional) Whether the change should be performed by the entity
   *   definition update manager.
   */
  protected function updateEntityTypeToRevisionable($perform_update = FALSE) {
  protected function updateEntityTypeToRevisionable($perform_update = FALSE): void {
    $translatable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isTranslatable();

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition(TRUE, $translatable);
@@ -154,7 +154,7 @@ protected function updateEntityTypeToRevisionable($perform_update = FALSE) {
   *   (optional) Whether the change should be performed by the entity
   *   definition update manager.
   */
  protected function updateEntityTypeToNotRevisionable($perform_update = FALSE) {
  protected function updateEntityTypeToNotRevisionable($perform_update = FALSE): void {
    $translatable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isTranslatable();

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition(FALSE, $translatable);
@@ -172,7 +172,7 @@ protected function updateEntityTypeToNotRevisionable($perform_update = FALSE) {
   *   (optional) Whether the change should be performed by the entity
   *   definition update manager.
   */
  protected function updateEntityTypeToTranslatable($perform_update = FALSE) {
  protected function updateEntityTypeToTranslatable($perform_update = FALSE): void {
    $revisionable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isRevisionable();

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition($revisionable, TRUE);
@@ -190,7 +190,7 @@ protected function updateEntityTypeToTranslatable($perform_update = FALSE) {
   *   (optional) Whether the change should be performed by the entity
   *   definition update manager.
   */
  protected function updateEntityTypeToNotTranslatable($perform_update = FALSE) {
  protected function updateEntityTypeToNotTranslatable($perform_update = FALSE): void {
    $revisionable = $this->entityDefinitionUpdateManager->getEntityType('entity_test_update')->isRevisionable();

    $updated_entity_type = $this->getUpdatedEntityTypeDefinition($revisionable, FALSE);
@@ -208,7 +208,7 @@ protected function updateEntityTypeToNotTranslatable($perform_update = FALSE) {
   *   (optional) Whether the change should be performed by the entity
   *   definition update manager.
   */
  protected function updateEntityTypeToRevisionableAndTranslatable($perform_update = FALSE) {
  protected function updateEntityTypeToRevisionableAndTranslatable($perform_update = FALSE): void {
    $updated_entity_type = $this->getUpdatedEntityTypeDefinition(TRUE, TRUE);
    $updated_field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(TRUE, TRUE);

@@ -235,7 +235,7 @@ protected function updateEntityTypeToRevisionableAndTranslatable($perform_update
   *   (optional) If the base field should be translatable or not. Defaults to
   *   FALSE.
   */
  protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE, $set_label = TRUE, $is_translatable = FALSE) {
  protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE, $set_label = TRUE, $is_translatable = FALSE): void {
    $definitions['new_base_field'] = BaseFieldDefinition::create($type)
      ->setName('new_base_field')
      ->setRevisionable($is_revisionable)
@@ -251,7 +251,7 @@ protected function addBaseField($type = 'string', $entity_type_id = 'entity_test
  /**
   * Adds a long-named base field to the 'entity_test_update' entity type.
   */
  protected function addLongNameBaseField() {
  protected function addLongNameBaseField(): void {
    $key = 'entity_test_update.additional_base_field_definitions';
    $definitions = $this->state->get($key, []);
    $definitions['new_long_named_entity_reference_base_field'] = BaseFieldDefinition::create('entity_reference')
@@ -268,7 +268,7 @@ protected function addLongNameBaseField() {
   * @param string $type
   *   (optional) The field type for the new field. Defaults to 'string'.
   */
  protected function addRevisionableBaseField($type = 'string') {
  protected function addRevisionableBaseField($type = 'string'): void {
    $definitions['new_base_field'] = BaseFieldDefinition::create($type)
      ->setName('new_base_field')
      ->setLabel(t('A new revisionable base field'))
@@ -279,14 +279,14 @@ protected function addRevisionableBaseField($type = 'string') {
  /**
   * Modifies the new base field from 'string' to 'text'.
   */
  protected function modifyBaseField() {
  protected function modifyBaseField(): void {
    $this->addBaseField('text');
  }

  /**
   * Promotes a field to an entity key.
   */
  protected function makeBaseFieldEntityKey() {
  protected function makeBaseFieldEntityKey(): void {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');
    $entity_keys = $entity_type->getKeys();
    $entity_keys['new_base_field'] = 'new_base_field';
@@ -300,21 +300,21 @@ protected function makeBaseFieldEntityKey() {
   * @param string $entity_type_id
   *   (optional) The entity type ID the base field should be attached to.
   */
  protected function removeBaseField($entity_type_id = 'entity_test_update') {
  protected function removeBaseField($entity_type_id = 'entity_test_update'): void {
    $this->state->delete($entity_type_id . '.additional_base_field_definitions');
  }

  /**
   * Adds a single-field index to the base field.
   */
  protected function addBaseFieldIndex() {
  protected function addBaseFieldIndex(): void {
    $this->state->set('entity_test_update.additional_field_index.entity_test_update.new_base_field', TRUE);
  }

  /**
   * Removes the index added in addBaseFieldIndex().
   */
  protected function removeBaseFieldIndex() {
  protected function removeBaseFieldIndex(): void {
    $this->state->delete('entity_test_update.additional_field_index.entity_test_update.new_base_field');
  }

@@ -328,7 +328,7 @@ protected function removeBaseFieldIndex() {
   * @param bool $translatable
   *   (optional) Whether the field should be translatable. Defaults to FALSE.
   */
  protected function addBundleField($type = 'string', $revisionable = FALSE, $translatable = FALSE) {
  protected function addBundleField($type = 'string', $revisionable = FALSE, $translatable = FALSE): void {
    $definitions['new_bundle_field'] = FieldStorageDefinition::create($type)
      ->setName('new_bundle_field')
      ->setLabel(t('A new bundle field'))
@@ -342,14 +342,14 @@ protected function addBundleField($type = 'string', $revisionable = FALSE, $tran
  /**
   * Modifies the new bundle field from 'string' to 'text'.
   */
  protected function modifyBundleField() {
  protected function modifyBundleField(): void {
    $this->addBundleField('text');
  }

  /**
   * Removes the new bundle field from the 'entity_test_update' entity type.
   */
  protected function removeBundleField() {
  protected function removeBundleField(): void {
    $this->state->delete('entity_test_update.additional_field_storage_definitions');
    $this->state->delete('entity_test_update.additional_bundle_field_definitions.test_bundle');
  }
@@ -359,7 +359,7 @@ protected function removeBundleField() {
   *
   * @see \Drupal\entity_test\EntityTestStorageSchema::getEntitySchema()
   */
  protected function addEntityIndex() {
  protected function addEntityIndex(): void {
    $indexes = [
      'entity_test_update__new_index' => ['name', 'test_single_property'],
    ];
@@ -369,14 +369,14 @@ protected function addEntityIndex() {
  /**
   * Removes the index added in addEntityIndex().
   */
  protected function removeEntityIndex() {
  protected function removeEntityIndex(): void {
    $this->state->delete('entity_test_update.additional_entity_indexes');
  }

  /**
   * Renames the base table to 'entity_test_update_new'.
   */
  protected function renameBaseTable() {
  protected function renameBaseTable(): void {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');

    $entity_type->set('base_table', 'entity_test_update_new');
@@ -387,7 +387,7 @@ protected function renameBaseTable() {
  /**
   * Renames the data table to 'entity_test_update_data_new'.
   */
  protected function renameDataTable() {
  protected function renameDataTable(): void {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');

    $entity_type->set('data_table', 'entity_test_update_data_new');
@@ -398,7 +398,7 @@ protected function renameDataTable() {
  /**
   * Renames the revision table to 'entity_test_update_revision_new'.
   */
  protected function renameRevisionBaseTable() {
  protected function renameRevisionBaseTable(): void {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');

    $entity_type->set('revision_table', 'entity_test_update_revision_new');
@@ -409,7 +409,7 @@ protected function renameRevisionBaseTable() {
  /**
   * Renames the revision data table to 'entity_test_update_revision_data_new'.
   */
  protected function renameRevisionDataTable() {
  protected function renameRevisionDataTable(): void {
    $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_update');

    $entity_type->set('revision_data_table', 'entity_test_update_revision_data_new');
@@ -420,7 +420,7 @@ protected function renameRevisionDataTable() {
  /**
   * Removes the entity type.
   */
  protected function deleteEntityType() {
  protected function deleteEntityType(): void {
    $this->state->set('entity_test_update.entity_type', 'null');
  }