updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -10,8 +10,8 @@ dependencies:
|
||||
- user
|
||||
configure: entity.block_content.collection
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457826
|
||||
|
||||
@@ -6,6 +6,23 @@
|
||||
*/
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Implements hook_update_dependencies().
|
||||
*/
|
||||
function block_content_update_dependencies() {
|
||||
// The update function that adds the status field must run after
|
||||
// content_translation_update_8400() which fixes NULL values for the
|
||||
// 'content_translation_status' field.
|
||||
if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
|
||||
$dependencies['block_content'][8400] = [
|
||||
'content_translation' => 8400,
|
||||
];
|
||||
|
||||
return $dependencies;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'revision_translation_affected' field to 'block_content' entities.
|
||||
@@ -70,5 +87,54 @@ function block_content_update_8300() {
|
||||
$entity_type = $definition_update_manager->getEntityType('block_content');
|
||||
$entity_type->set('revision_data_table', 'block_content_field_revision');
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a publishing status field for block_content entities.
|
||||
*/
|
||||
function block_content_update_8400() {
|
||||
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
|
||||
// Add the published entity key to the block_content entity type.
|
||||
$entity_type = $definition_update_manager->getEntityType('block_content');
|
||||
$entity_keys = $entity_type->getKeys();
|
||||
$entity_keys['published'] = 'status';
|
||||
$entity_type->set('entity_keys', $entity_keys);
|
||||
$definition_update_manager->updateEntityType($entity_type);
|
||||
|
||||
// Add the publishing status field to the block_content entity type.
|
||||
$status = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(new TranslatableMarkup('Publishing status'))
|
||||
->setDescription(new TranslatableMarkup('A boolean indicating the published state.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(TRUE)
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
$has_content_translation_status_field = \Drupal::moduleHandler()->moduleExists('content_translation') && $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
if ($has_content_translation_status_field) {
|
||||
$status->setInitialValueFromField('content_translation_status');
|
||||
}
|
||||
else {
|
||||
$status->setInitialValue(TRUE);
|
||||
}
|
||||
$definition_update_manager->installFieldStorageDefinition('status', 'block_content', 'block_content', $status);
|
||||
|
||||
// Uninstall the 'content_translation_status' field if needed.
|
||||
$database = \Drupal::database();
|
||||
if ($has_content_translation_status_field) {
|
||||
// First we have to remove the field data.
|
||||
$database->update($entity_type->getDataTable())
|
||||
->fields(['content_translation_status' => NULL])
|
||||
->execute();
|
||||
|
||||
// A site may have disabled revisionability for this entity type.
|
||||
if ($entity_type->isRevisionable()) {
|
||||
$database->update($entity_type->getRevisionDataTable())
|
||||
->fields(['content_translation_status' => NULL])
|
||||
->execute();
|
||||
}
|
||||
|
||||
$content_translation_status = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
$definition_update_manager->uninstallFieldStorageDefinition($content_translation_status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ display:
|
||||
admin_label: ''
|
||||
empty: true
|
||||
tokenize: false
|
||||
content: 'There are no custom blocks available. '
|
||||
content: 'There are no custom blocks available.'
|
||||
plugin_id: text_custom
|
||||
block_content_listing_empty:
|
||||
admin_label: ''
|
||||
|
||||
+1
@@ -3,6 +3,7 @@ label: Block content body field configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
+1
@@ -3,6 +3,7 @@ label: Body field display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
+1
@@ -3,6 +3,7 @@ label: Body field form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
+1
@@ -3,6 +3,7 @@ label: Block content type
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: embedded_data
|
||||
data_rows:
|
||||
+2
@@ -1,7 +1,9 @@
|
||||
id: d6_custom_block
|
||||
label: Custom blocks
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
source:
|
||||
plugin: d6_box
|
||||
process:
|
||||
+2
@@ -1,7 +1,9 @@
|
||||
id: d7_custom_block
|
||||
label: Custom blocks
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
source:
|
||||
plugin: d7_block_custom
|
||||
process:
|
||||
@@ -19,7 +19,8 @@ class BlockContentAccessControlHandler extends EntityAccessControlHandler {
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
if ($operation === 'view') {
|
||||
return AccessResult::allowed();
|
||||
return AccessResult::allowedIf($entity->isPublished())->addCacheableDependency($entity)
|
||||
->orIf(AccessResult::allowedIfHasPermission($account, 'administer blocks'));
|
||||
}
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form handler for the custom block edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentForm extends ContentEntityForm {
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a custom block entity.
|
||||
*/
|
||||
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface {
|
||||
interface BlockContentInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityPublishedInterface {
|
||||
|
||||
/**
|
||||
* Returns the block revision log message.
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of custom block entities.
|
||||
@@ -13,8 +12,6 @@ use Drupal\Core\Routing\RedirectDestinationTrait;
|
||||
*/
|
||||
class BlockContentListBuilder extends EntityListBuilder {
|
||||
|
||||
use RedirectDestinationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -31,15 +28,4 @@ class BlockContentListBuilder extends EntityListBuilder {
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOperations(EntityInterface $entity) {
|
||||
$operations = parent::getDefaultOperations($entity);
|
||||
if (isset($operations['edit'])) {
|
||||
$operations['edit']['query']['destination'] = $this->getRedirectDestination()->get();
|
||||
}
|
||||
return $operations;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
|
||||
/**
|
||||
* Base form for category edit forms.
|
||||
* The block content type entity form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentTypeForm extends BundleEntityFormBase {
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\block_content;
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityViewBuilder;
|
||||
|
||||
@@ -41,18 +40,4 @@ class BlockContentViewBuilder extends EntityViewBuilder {
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
|
||||
parent::alterBuild($build, $entity, $display, $view_mode);
|
||||
// Add contextual links for this custom block.
|
||||
if (!$entity->isNew()) {
|
||||
$build['#contextual_links']['block_content'] = [
|
||||
'route_parameters' => ['block_content' => $entity->id()],
|
||||
'metadata' => ['changed' => $entity->getChangedTime()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Drupal\block_content\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EditorialContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
@@ -51,7 +50,8 @@ use Drupal\user\UserInterface;
|
||||
* "bundle" = "type",
|
||||
* "label" = "info",
|
||||
* "langcode" = "langcode",
|
||||
* "uuid" = "uuid"
|
||||
* "uuid" = "uuid",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* revision_metadata_keys = {
|
||||
* "revision_user" = "revision_user",
|
||||
@@ -68,9 +68,7 @@ use Drupal\user\UserInterface;
|
||||
* caching.
|
||||
* See https://www.drupal.org/node/2284917#comment-9132521 for more information.
|
||||
*/
|
||||
class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
class BlockContent extends EditorialContentEntityBase implements BlockContentInterface {
|
||||
|
||||
/**
|
||||
* The theme the block is being created in.
|
||||
@@ -174,6 +172,8 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
||||
$fields['type']->setLabel(t('Block type'))
|
||||
->setDescription(t('The block type.'));
|
||||
|
||||
$fields['revision_log']->setDescription(t('The log entry explaining the changes in this revision.'));
|
||||
|
||||
$fields['info'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Block description'))
|
||||
->setDescription(t('A brief description of your block.'))
|
||||
@@ -187,35 +187,12 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface {
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('UniqueField', []);
|
||||
|
||||
$fields['revision_log'] = BaseFieldDefinition::create('string_long')
|
||||
->setLabel(t('Revision log message'))
|
||||
->setDescription(t('The log entry explaining the changes in this revision.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textarea',
|
||||
'weight' => 25,
|
||||
'settings' => [
|
||||
'rows' => 4,
|
||||
],
|
||||
]);
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
->setDescription(t('The time that the custom block was last edited.'))
|
||||
->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);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a custom block entity.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Provides a confirmation form for deleting a custom block type entity.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BlockContentTypeDeleteForm extends EntityDeleteForm {
|
||||
|
||||
|
||||
+3
-3
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- block_content
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457826
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- block_content
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457826
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on block content.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentContextualLinksTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'contextual',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests contextual links.
|
||||
*/
|
||||
public function testBlockContentContextualLinks() {
|
||||
$block_content = $this->createBlockContent();
|
||||
|
||||
$block = $this->placeBlock('block_content:' . $block_content->uuid());
|
||||
|
||||
$user = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access contextual links',
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'block:block=' . $block->id() . ':langcode=en|block_content:block_content=' . $block_content->id() . ':');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,7 +63,9 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
||||
$this->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
@@ -143,7 +145,9 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]', 'test_view_mode', 'View mode changed to Test View Mode');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
@@ -178,7 +182,9 @@ class BlockContentCreationTest extends BlockContentTestBase {
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]);
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\simpletest\BlockCreationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests unpublishing of block_content entities.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class UnpublishedBlockTest extends BrowserTestBase {
|
||||
|
||||
use BlockCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* Tests unpublishing of block_content entities.
|
||||
*/
|
||||
public function testViewShowsCorrectStates() {
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Test block',
|
||||
'type' => 'basic',
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->placeBlock('block_content:' . $block_content->uuid());
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertTrue($page->has('css', '.block-block-content' . $block_content->uuid()));
|
||||
|
||||
$block_content->setPublished(FALSE);
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertFalse($page->has('css', '.block-block-content' . $block_content->uuid()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,4 +43,27 @@ class BlockContentUpdateTest extends UpdatePathTestBase {
|
||||
$this->assertEqual('block_content_field_revision', $entity_type->getRevisionDataTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding a status field to the block content entity type.
|
||||
*
|
||||
* @see block_content_update_8400()
|
||||
*/
|
||||
public function testStatusFieldAddition() {
|
||||
$schema = \Drupal::database()->schema();
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Check that the field exists and has the correct label.
|
||||
$updated_field = $entity_definition_update_manager->getFieldStorageDefinition('status', 'block_content');
|
||||
$this->assertEqual('Publishing status', $updated_field->getLabel());
|
||||
|
||||
$content_translation_status = $entity_definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
$this->assertNull($content_translation_status);
|
||||
|
||||
$this->assertFalse($schema->fieldExists('block_content_field_revision', 'content_translation_status'));
|
||||
$this->assertFalse($schema->fieldExists('block_content_field_data', 'content_translation_status'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user