Skip to content
Snippets Groups Projects
Commit a1a138cf authored by catch's avatar catch
Browse files

Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner...

Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner to the BlockContent entity type"

This reverts commit b8d5c0e4.
parent 44999a9a
No related branches found
No related tags found
26 merge requests!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!23Issue #2879087: Use comment access handler instead of hardcoding permissions
Pipeline #113870 canceled with stages
in 2 minutes and 4 seconds
......@@ -9,7 +9,6 @@
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\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\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 @@
* "langcode" = "langcode",
* "uuid" = "uuid",
* "published" = "status",
* "owner" = "uid",
* },
* revision_metadata_keys = {
* "revision_user" = "revision_user",
......@@ -90,7 +88,6 @@
class BlockContent extends EditorialContentEntityBase implements BlockContentInterface {
use RefinableDependentAccessTrait;
use EntityOwnerTrait;
/**
* The theme the block is being created in.
......@@ -194,7 +191,6 @@ public function preSaveRevision(EntityStorageInterface $storage, \stdClass $reco
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\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 @@ protected function createEntity() {
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$author = User::load($this->entity->getOwnerId());
return [
'id' => [
[
......@@ -173,14 +171,6 @@ protected function getExpectedNormalizedEntity() {
'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 @@
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 @@ public function testBlockLibraryPermissionsUpdate(): void {
$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 @@ protected function getExpectedDocument() {
'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],
],
],
],
],
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment