Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner to the BlockContent entity type"
This reverts commit b8d5c0e425
.
merge-requests/6959/head
parent
44999a9a2e
commit
a1a138cf87
|
@ -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.');
|
||||
}
|
||||
|
|
|
@ -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'],
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.'));
|
||||
|
|
|
@ -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(),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue