Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0
This commit is contained in:
parent
2f563ab520
commit
f1c8716f57
1732 changed files with 52334 additions and 11780 deletions
|
@ -7,4 +7,5 @@ core: 8.x
|
|||
dependencies:
|
||||
- block
|
||||
- text
|
||||
- user
|
||||
configure: entity.block_content.collection
|
||||
|
|
|
@ -39,3 +39,25 @@ function block_content_update_8002() {
|
|||
// are stable.
|
||||
// @see https://www.drupal.org/node/2569469
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'revision_created' and 'revision_user' fields to 'block_content' entities.
|
||||
*/
|
||||
function block_content_update_8003() {
|
||||
$revision_created = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Revision create time'))
|
||||
->setDescription(t('The time that the current revision was created.'))
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_created', 'block_content', 'block_content', $revision_created);
|
||||
|
||||
$revision_user = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Revision user'))
|
||||
->setDescription(t('The user ID of the author of the current revision.'))
|
||||
->setSetting('target_type', 'user')
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
\Drupal::entityDefinitionUpdateManager()
|
||||
->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
|
||||
}
|
||||
|
|
|
@ -30,3 +30,6 @@ destination:
|
|||
migration_dependencies:
|
||||
required:
|
||||
- block_content_type
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
||||
|
|
|
@ -17,3 +17,6 @@ process:
|
|||
label: label
|
||||
destination:
|
||||
plugin: entity:block_content_type
|
||||
provider:
|
||||
- block_content
|
||||
- migrate_drupal
|
||||
|
|
|
@ -88,7 +88,7 @@ class BlockContentForm extends ContentEntityForm {
|
|||
// Set up default values, if required.
|
||||
$block_type = $this->blockContentTypeStorage->load($block->bundle());
|
||||
if (!$block->isNew()) {
|
||||
$block->setRevisionLog(NULL);
|
||||
$block->setRevisionLogMessage(NULL);
|
||||
}
|
||||
// Always use the default revision setting.
|
||||
$block->setNewRevision($block_type->shouldCreateNewRevision());
|
||||
|
@ -170,6 +170,9 @@ class BlockContentForm extends ContentEntityForm {
|
|||
// Save as a new revision if requested to do so.
|
||||
if (!$form_state->isValueEmpty('revision')) {
|
||||
$block->setNewRevision();
|
||||
// If a new revision is created, save the current user as revision author.
|
||||
$block->setRevisionCreationTime(REQUEST_TIME);
|
||||
$block->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
|
||||
$insert = $block->isNew();
|
||||
|
|
|
@ -4,17 +4,21 @@ namespace Drupal\block_content;
|
|||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a custom block entity.
|
||||
*/
|
||||
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface {
|
||||
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface {
|
||||
|
||||
/**
|
||||
* Returns the block revision log message.
|
||||
*
|
||||
* @return string
|
||||
* The revision log message.
|
||||
*
|
||||
* @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage() instead.
|
||||
*/
|
||||
public function getRevisionLog();
|
||||
|
||||
|
@ -37,6 +41,9 @@ interface BlockContentInterface extends ContentEntityInterface, EntityChangedInt
|
|||
*
|
||||
* @return \Drupal\block_content\BlockContentInterface
|
||||
* The class instance that this method is called on.
|
||||
*
|
||||
* @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage() instead.
|
||||
*/
|
||||
public function setRevisionLog($revision_log);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\block_content\BlockContentInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the custom block entity class.
|
||||
|
@ -119,7 +120,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInstances() {
|
||||
return entity_load_multiple_by_properties('block', array('plugin' => 'block_content:' . $this->uuid()));
|
||||
return \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(array('plugin' => 'block_content:' . $this->uuid()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +133,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
// If we are updating an existing block_content without adding a new
|
||||
// revision and the user did not supply a revision log, keep the existing
|
||||
// one.
|
||||
$record->revision_log = $this->original->getRevisionLog();
|
||||
$record->revision_log = $this->original->getRevisionLogMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,35 +151,20 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields['id'] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('Custom block ID'))
|
||||
->setDescription(t('The custom block ID.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['uuid'] = BaseFieldDefinition::create('uuid')
|
||||
->setLabel(t('UUID'))
|
||||
->setDescription(t('The custom block UUID.'))
|
||||
->setReadOnly(TRUE);
|
||||
$fields['id']->setLabel(t('Custom block ID'))
|
||||
->setDescription(t('The custom block ID.'));
|
||||
|
||||
$fields['revision_id'] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('Revision ID'))
|
||||
->setDescription(t('The revision ID.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
$fields['uuid']->setDescription(t('The custom block UUID.'));
|
||||
|
||||
$fields['langcode'] = BaseFieldDefinition::create('language')
|
||||
->setLabel(t('Language'))
|
||||
->setDescription(t('The custom block language code.'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayOptions('view', array(
|
||||
'type' => 'hidden',
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'language_select',
|
||||
'weight' => 2,
|
||||
));
|
||||
$fields['revision_id']->setDescription(t('The revision ID.'));
|
||||
|
||||
$fields['langcode']->setDescription(t('The custom block language code.'));
|
||||
|
||||
$fields['type']->setLabel(t('Block type'))
|
||||
->setDescription(t('The block type.'));
|
||||
|
||||
$fields['info'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Block description'))
|
||||
|
@ -193,12 +179,6 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('UniqueField', []);
|
||||
|
||||
|
||||
$fields['type'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Block type'))
|
||||
->setDescription(t('The block type.'))
|
||||
->setSetting('target_type', 'block_content_type');
|
||||
|
||||
$fields['revision_log'] = BaseFieldDefinition::create('string_long')
|
||||
->setLabel(t('Revision log message'))
|
||||
->setDescription(t('The log entry explaining the changes in this revision.'))
|
||||
|
@ -210,6 +190,17 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['revision_created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Revision create time'))
|
||||
->setDescription(t('The time that the current revision was created.'))
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['revision_user'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Revision user'))
|
||||
->setDescription(t('The user ID of the author of the current revision.'))
|
||||
->setSetting('target_type', 'user')
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Revision translation affected'))
|
||||
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
||||
|
@ -224,7 +215,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionLog() {
|
||||
return $this->get('revision_log')->value;
|
||||
return $this->getRevisionLogMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,7 +230,63 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionLog($revision_log) {
|
||||
$this->set('revision_log', $revision_log);
|
||||
return $this->setRevisionLogMessage($revision_log);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionCreationTime() {
|
||||
return $this->get('revision_created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp) {
|
||||
$this->set('revision_created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionUser() {
|
||||
return $this->get('revision_user')->entity;
|
||||
}
|
||||
|
||||
public function setRevisionUser(UserInterface $account) {
|
||||
$this->set('revision_user', $account);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionUserId() {
|
||||
return $this->get('revision_user')->entity->id();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionUserId($user_id) {
|
||||
$this->set('revision_user', $user_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRevisionLogMessage() {
|
||||
return $this->get('revision_log')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setRevisionLogMessage($revision_log_message) {
|
||||
$this->set('revision_log', $revision_log_message);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Create a block with revisions.
|
||||
|
@ -29,6 +31,9 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** @var UserInterface $user */
|
||||
$user = User::load(1);
|
||||
|
||||
// Create initial block.
|
||||
$block = $this->createBlockContent('initial');
|
||||
|
||||
|
@ -43,8 +48,10 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
$revision_count = 3;
|
||||
for ($i = 0; $i < $revision_count; $i++) {
|
||||
$block->setNewRevision(TRUE);
|
||||
$block->setRevisionLog($this->randomMachineName(32));
|
||||
$logs[] = $block->getRevisionLog();
|
||||
$block->setRevisionLogMessage($this->randomMachineName(32));
|
||||
$block->setRevisionUser($this->adminUser);
|
||||
$block->setRevisionCreationTime(REQUEST_TIME);
|
||||
$logs[] = $block->getRevisionLogMessage();
|
||||
$block->save();
|
||||
$blocks[] = $block->getRevisionId();
|
||||
}
|
||||
|
@ -62,11 +69,17 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
|
||||
foreach ($blocks as $delta => $revision_id) {
|
||||
// Confirm the correct revision text appears.
|
||||
/** @var \Drupal\block_content\BlockContentInterface $loaded */
|
||||
$loaded = entity_revision_load('block_content', $revision_id);
|
||||
// Verify revision log is the same.
|
||||
$this->assertEqual($loaded->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
|
||||
$this->assertEqual($loaded->getRevisionLogMessage(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
|
||||
'@revision' => $loaded->getRevisionId(),
|
||||
)));
|
||||
if ($delta > 0) {
|
||||
$this->assertTrue($loaded->getRevisionUser() instanceof UserInterface, 'Revision User found.');
|
||||
$this->assertTrue(is_numeric($loaded->getRevisionUserId()), 'Revision User ID found.');
|
||||
$this->assertTrue(is_numeric($loaded->getRevisionCreationTime()), 'Revision time found.');
|
||||
}
|
||||
}
|
||||
|
||||
// Confirm that this is the default revision.
|
||||
|
|
|
@ -19,7 +19,7 @@ abstract class BlockContentTestBase extends WebTestBase {
|
|||
/**
|
||||
* Admin user
|
||||
*
|
||||
* @var object
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
|
|
|
@ -179,7 +179,10 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestTranslationEdit() {
|
||||
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId);
|
||||
$storage->resetCache([$this->entityId]);
|
||||
$entity = $storage->load($this->entityId);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content\Tests;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests adding revision_user and revision_created fields.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class BlockContentUpdateEntityFields extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that email token in status_blocked of user.mail is updated.
|
||||
*/
|
||||
public function testAddingFields() {
|
||||
$this->runUpdates();
|
||||
|
||||
$post_revision_created = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_created', 'block_content');
|
||||
$post_revision_user = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('revision_user', 'block_content');
|
||||
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
|
||||
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
|
||||
|
||||
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
|
||||
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue