From a1a138cf87b9f0387708ac558de5099878c905fc Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 7 Mar 2024 14:59:31 +0000 Subject: [PATCH] Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner to the BlockContent entity type" This reverts commit b8d5c0e4256563ff31b2c32173374253860d910a. --- .../block_content/block_content.install | 17 ------ .../block_content.post_update.php | 58 ------------------- .../src/BlockContentInterface.php | 3 +- .../block_content/src/Entity/BlockContent.php | 4 -- .../Rest/BlockContentResourceTestBase.php | 10 ---- .../Update/BlockContentUpdateTest.php | 58 ------------------- .../tests/src/Functional/BlockContentTest.php | 13 ----- 7 files changed, 1 insertion(+), 162 deletions(-) diff --git a/core/modules/block_content/block_content.install b/core/modules/block_content/block_content.install index a15e06a08dc..fe4526e41f0 100644 --- a/core/modules/block_content/block_content.install +++ b/core/modules/block_content/block_content.install @@ -9,7 +9,6 @@ use Drupal\block_content\BlockContentStorageSchema; use Drupal\Core\Entity\Form\RevisionDeleteForm; use Drupal\Core\Entity\Form\RevisionRevertForm; use Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider; -use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; /** @@ -64,19 +63,3 @@ function block_content_update_10300(): void { $manager->updateFieldStorageDefinition(\Drupal::service('entity_field.manager') ->getBaseFieldDefinitions('block_content')['reusable']); } - -/** - * Install owner field. - */ -function block_content_update_10301(): TranslatableMarkup { - $entityDefinitionUpdateManager = \Drupal::entityDefinitionUpdateManager(); - $entityType = $entityDefinitionUpdateManager->getEntityType('block_content'); - - $storage_definition = BaseFieldDefinition::create('entity_reference') - ->setLabel(new TranslatableMarkup('User ID')) - ->setSetting('target_type', 'user') - ->setTranslatable($entityType->isTranslatable()); - $entityDefinitionUpdateManager - ->installFieldStorageDefinition('uid', 'block_content', 'block_content', $storage_definition); - return \t('Installed uid field for BlockContent entities.'); -} diff --git a/core/modules/block_content/block_content.post_update.php b/core/modules/block_content/block_content.post_update.php index e318c2280cc..3955a7033bd 100644 --- a/core/modules/block_content/block_content.post_update.php +++ b/core/modules/block_content/block_content.post_update.php @@ -7,8 +7,6 @@ use Drupal\block_content\BlockContentTypeInterface; use Drupal\Core\Config\Entity\ConfigEntityUpdater; -use Drupal\Core\Site\Settings; -use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\user\Entity\Role; use Drupal\views\Entity\View; @@ -94,59 +92,3 @@ function block_content_post_update_revision_type(&$sandbox = NULL) { return TRUE; }); } - -/** - * Set a default author for block content entities. - */ -function block_content_post_update_set_owner(&$sandbox = NULL): TranslatableMarkup { - $blockContentStorage = \Drupal::entityTypeManager() - ->getStorage('block_content'); - - if (!isset($sandbox['total'])) { - $sandbox['total'] = $blockContentStorage - ->getQuery() - ->accessCheck(FALSE) - ->condition('uid', NULL, 'IS NULL') - ->count() - ->execute(); - $sandbox['progress'] = 0; - - // Handle the case of 0 block to process. - if ($sandbox['total'] == 0) { - $sandbox['total'] = 1; - $sandbox['progress'] = 1; - } - } - - $ids = $blockContentStorage - ->getQuery() - ->accessCheck(FALSE) - ->condition('uid', NULL, 'IS NULL') - ->range(0, (int) Settings::get('entity_update_batch_size', 50)) - ->execute(); - - $database = \Drupal::database(); - /** @var \Drupal\block_content\BlockContentInterface $blockContent */ - foreach ($blockContentStorage->loadMultiple($ids) as $blockContent) { - // Get the revision_user from the first revision of this block to use - // as the author. - $query = $database->select('block_content_revision', 'bcr') - ->condition('id', $blockContent->id()); - $query->addExpression('MIN(revision_id)', 'revision_id'); - $revisionId = $query->execute()->fetchField(); - /** @var \Drupal\block_content\BlockContentInterface $revision */ - $revision = $blockContentStorage->loadRevision($revisionId); - - $blockContent->setOwnerId($revision->getRevisionUserId() ?? 0) - ->setSyncing(TRUE) - ->save(); - $sandbox['progress'] += 1; - } - - $sandbox['#finished'] = empty($sandbox['total']) ? 1 : ($sandbox['progress'] / $sandbox['total']); - - return new TranslatableMarkup('Processed Block Content Entities (@count/@total)', [ - '@count' => $sandbox['progress'], - '@total' => $sandbox['total'], - ]); -} diff --git a/core/modules/block_content/src/BlockContentInterface.php b/core/modules/block_content/src/BlockContentInterface.php index ec8a9236cf4..f6763f451c5 100644 --- a/core/modules/block_content/src/BlockContentInterface.php +++ b/core/modules/block_content/src/BlockContentInterface.php @@ -7,12 +7,11 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\RevisionLogInterface; -use Drupal\user\EntityOwnerInterface; /** * Provides an interface defining a content block entity. */ -interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityPublishedInterface, RefinableDependentAccessInterface, EntityOwnerInterface { +interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityPublishedInterface, RefinableDependentAccessInterface { /** * Sets the block description. diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index df539e7cda0..81e6bfcdaea 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -8,7 +8,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\block_content\BlockContentInterface; -use Drupal\user\EntityOwnerTrait; /** * Defines the content block entity class. @@ -70,7 +69,6 @@ use Drupal\user\EntityOwnerTrait; * "langcode" = "langcode", * "uuid" = "uuid", * "published" = "status", - * "owner" = "uid", * }, * revision_metadata_keys = { * "revision_user" = "revision_user", @@ -90,7 +88,6 @@ use Drupal\user\EntityOwnerTrait; class BlockContent extends EditorialContentEntityBase implements BlockContentInterface { use RefinableDependentAccessTrait; - use EntityOwnerTrait; /** * The theme the block is being created in. @@ -194,7 +191,6 @@ class BlockContent extends EditorialContentEntityBase implements BlockContentInt public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ $fields = parent::baseFieldDefinitions($entity_type); - $fields += static::ownerBaseFieldDefinitions($entity_type); $fields['id']->setLabel(t('Content block ID')) ->setDescription(t('The content block ID.')); diff --git a/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php b/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php index ddc8d183ecd..f3af50a1f58 100644 --- a/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php +++ b/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php @@ -8,7 +8,6 @@ use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContentType; use Drupal\Core\Cache\Cache; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; -use Drupal\user\Entity\User; /** * ResourceTestBase for BlockContent entity. @@ -93,7 +92,6 @@ abstract class BlockContentResourceTestBase extends EntityResourceTestBase { * {@inheritdoc} */ protected function getExpectedNormalizedEntity() { - $author = User::load($this->entity->getOwnerId()); return [ 'id' => [ [ @@ -173,14 +171,6 @@ abstract class BlockContentResourceTestBase extends EntityResourceTestBase { 'value' => FALSE, ], ], - 'uid' => [ - [ - 'target_id' => (int) $author->id(), - 'target_type' => 'user', - 'target_uuid' => $author->uuid(), - 'url' => base_path() . 'user/' . $author->id(), - ], - ], ]; } diff --git a/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php index 8e4048039d6..4fa00b2f0f9 100644 --- a/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Drupal\Tests\block_content\Functional\Update; -use Drupal\block_content\Entity\BlockContent; use Drupal\block_content\Entity\BlockContentType; use Drupal\FunctionalTests\Update\UpdatePathTestBase; use Drupal\user\Entity\User; @@ -126,61 +125,4 @@ class BlockContentUpdateTest extends UpdatePathTestBase { $this->assertTrue($user->hasPermission('access block library')); } - /** - * Tests adding an owner to block content. - * - * @see block_content_update_10201() - * @see block_content_post_update_set_owner() - */ - public function testAddAndSetOwnerField(): void { - $user1 = $this->drupalCreateUser(); - $user2 = $this->drupalCreateUser(); - $user3 = $this->drupalCreateUser(); - - $block1 = BlockContent::create([ - 'info' => 'Test 1', - 'type' => 'basic', - 'revision_user' => $user1->id(), - ]); - $block1->save(); - $block1->setNewRevision(); - $block1->setRevisionUserId($user2->id())->save(); - - $block2 = BlockContent::create([ - 'info' => 'Test 2', - 'type' => 'basic', - 'revision_user' => $user2->id(), - ]); - $block2->save(); - $block2->setNewRevision(); - $block2->setRevisionUserId($user3->id())->save(); - - $block3 = BlockContent::create([ - 'info' => 'Test 3', - 'type' => 'basic', - 'revision_user' => $user3->id(), - ]); - $block3->save(); - $block3->setNewRevision(); - $block3->setRevisionUserId($user1->id())->save(); - - $block4 = BlockContent::create([ - 'info' => 'Test 4', - 'type' => 'basic', - 'revision_user' => NULL, - ]); - $block4->save(); - - $this->runUpdates(); - - $block1 = BlockContent::load($block1->id()); - $this->assertEquals($user1->id(), $block1->getOwnerId()); - $block2 = BlockContent::load($block2->id()); - $this->assertEquals($user2->id(), $block2->getOwnerId()); - $block3 = BlockContent::load($block3->id()); - $this->assertEquals($user3->id(), $block3->getOwnerId()); - $block4 = BlockContent::load($block4->id()); - $this->assertEquals(0, $block4->getOwnerId()); - } - } diff --git a/core/modules/jsonapi/tests/src/Functional/BlockContentTest.php b/core/modules/jsonapi/tests/src/Functional/BlockContentTest.php index 5a6ca80e388..4a870fdea63 100644 --- a/core/modules/jsonapi/tests/src/Functional/BlockContentTest.php +++ b/core/modules/jsonapi/tests/src/Functional/BlockContentTest.php @@ -194,19 +194,6 @@ class BlockContentTest extends ResourceTestBase { 'self' => ['href' => $base_url->toString() . '/relationships/revision_user' . $version_query_string], ], ], - 'uid' => [ - 'data' => [ - 'id' => $this->entity->getOwner()->uuid(), - 'meta' => [ - 'drupal_internal__target_id' => $this->entity->getOwnerId(), - ], - 'type' => 'user--user', - ], - 'links' => [ - 'related' => ['href' => $base_url->toString() . '/uid' . $version_query_string], - 'self' => ['href' => $base_url->toString() . '/relationships/uid' . $version_query_string], - ], - ], ], ], ];