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

Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu,...

Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
parent a7c51121
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
Showing
with 16 additions and 2026 deletions
...@@ -644,8 +644,6 @@ function hook_install_tasks_alter(&$tasks, $install_state) { ...@@ -644,8 +644,6 @@ function hook_install_tasks_alter(&$tasks, $install_state) {
* @see hook_update_last_removed() * @see hook_update_last_removed()
* @see update_get_update_list() * @see update_get_update_list()
* @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface * @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
* @see node_update_8001
* @see system_update_8004
* @see https://www.drupal.org/node/2535316 * @see https://www.drupal.org/node/2535316
*/ */
function hook_update_N(&$sandbox) { function hook_update_N(&$sandbox) {
...@@ -759,25 +757,10 @@ function hook_post_update_NAME(&$sandbox) { ...@@ -759,25 +757,10 @@ function hook_post_update_NAME(&$sandbox) {
$result = t('Node %nid saved', ['%nid' => $node->id()]); $result = t('Node %nid saved', ['%nid' => $node->id()]);
// Example of disabling blocks with missing condition contexts. Note: The // Example of updating some config.
// block itself is in a state which is valid at that point. if (\Drupal::moduleHandler()->moduleExists('taxonomy')) {
// @see block_update_8001() // Update the dependencies of all Vocabulary configuration entities.
// @see block_post_update_disable_blocks_with_missing_contexts() \Drupal::classResolver(\Drupal\Core\Config\Entity\ConfigEntityUpdater::class)->update($sandbox, 'taxonomy_vocabulary');
$block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []);
$block_ids = array_keys($block_update_8001);
$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$blocks = $block_storage->loadMultiple($block_ids);
/** @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $block) {
// This block has had conditions removed due to an inability to resolve
// contexts in block_update_8001() so disable it.
// Disable currently enabled blocks.
if ($block_update_8001[$block->id()]['status']) {
$block->setStatus(FALSE);
$block->save();
}
} }
return $result; return $result;
......
...@@ -23,30 +23,8 @@ function aggregator_requirements($phase) { ...@@ -23,30 +23,8 @@ function aggregator_requirements($phase) {
} }
/** /**
* The simple presence of this update function clears cached field definitions. * Implements hook_update_last_removed().
*/ */
function aggregator_update_8001() { function aggregator_update_last_removed() {
// Feed ID base field is now required. return 8501;
}
/**
* Make the 'Source feed' field for aggregator items required.
*/
function aggregator_update_8200() {
// aggregator_update_8001() did not update the last installed field storage
// definition for the aggregator item's 'Source feed' field.
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('fid', 'aggregator_item');
$field_definition->setRequired(TRUE);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
}
/**
* Add a default value for the 'Refresh' field for aggregator feed entities.
*/
function aggregator_update_8501() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('refresh', 'aggregator_feed');
$field_definition->setDefaultValue(3600);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
} }
<?php
namespace Drupal\Tests\aggregator\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that node settings are properly updated during database updates.
*
* @group aggregator
* @group legacy
*/
class AggregatorUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
];
}
/**
* Tests that the 'Source feed' field is required.
*
* @see aggregator_update_8200()
*/
public function testSourceFeedRequired() {
// Check that the 'fid' field is not required prior to the update.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
$this->assertFalse($field_definition->isRequired());
// Run updates.
$this->runUpdates();
// Check that the 'fid' field is now required.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
$this->assertTrue($field_definition->isRequired());
}
/**
* Tests that the 'Update interval' field has a default value.
*/
public function testUpdateIntervalDefaultValue() {
// Check that the 'refresh' field does not have a default value prior to the
// update.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([], $field_definition->getDefaultValueLiteral());
// Run updates.
$this->runUpdates();
// Check that the 'refresh' has a default value now.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([['value' => 3600]], $field_definition->getDefaultValueLiteral());
}
}
...@@ -18,102 +18,8 @@ function block_install() { ...@@ -18,102 +18,8 @@ function block_install() {
} }
/** /**
* Update block visibility context mapping. * Implements hook_update_last_removed().
*/ */
function block_update_8001() { function block_update_last_removed() {
// This update function updates blocks for the change from return 8003;
// https://www.drupal.org/node/2354889.
// Core visibility context plugins are updated automatically; blocks with
// unknown plugins are disabled and their previous visibility settings are
// saved in key value storage; see change record
// https://www.drupal.org/node/2527840 for more explanation.
// These are all the contexts that Drupal core provides.
$context_service_id_map = [
'node.node' => '@node.node_route_context:node',
'user.current_user' => '@user.current_user_context:current_user',
];
foreach (array_keys(\Drupal::languageManager()->getDefinedLanguageTypesInfo()) as $language_type_id) {
$context_service_id_map['language.' . $language_type_id] = '@language.current_language_context:' . $language_type_id;
}
// Contributed modules should leverage hook_update_dependencies() in order to
// be executed after block_update_8001(). The blocks are then disabled if the
// contexts are still missing via
// block_post_update_disable_blocks_with_missing_contexts().
$config_factory = \Drupal::configFactory();
$backup_values = $update_backup = [];
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
if ($visibility = $block->get('visibility')) {
foreach ($visibility as $condition_plugin_id => &$condition) {
foreach ($condition['context_mapping'] as $key => $context) {
if (!isset($context_service_id_map[$context])) {
// Remove the visibility condition for unknown context mapping
// entries, so the update process itself runs through and users can
// fix their block placements manually OR alternatively contributed
// modules can run their own update functions to update mappings
// that they provide.
$backup_values[$context][] = $condition_plugin_id;
unset($visibility[$condition_plugin_id]);
continue;
}
// Replace the context ID based on the defined mapping.
$condition['context_mapping'][$key] = $context_service_id_map[$context];
}
}
$block->set('visibility', $visibility);
if ($backup_values) {
// We not only store the missing context mappings but also the previous
// block status, in order to allow contributed and custom modules to do
// their own updates.
$update_backup[$block->get('id')] = [
'missing_context_ids' => $backup_values,
'status' => $block->get('status'),
];
}
}
// Mark the resulting configuration as trusted data. This avoids issues with
// future schema changes.
$block->save(TRUE);
}
if ($update_backup) {
\Drupal::keyValue('update_backup')->set('block_update_8001', $update_backup);
}
return t('Block context IDs updated.');
}
/**
* Placeholder for the previous 8002 update.
*/
function block_update_8002() {
\Drupal::state()->set('block_update_8002_placeholder', TRUE);
}
/**
* Remove 'cache' setting.
*/
function block_update_8003() {
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
// Remove the 'cache' setting.
$settings = $block->get('settings');
unset($settings['cache']);
$block->set('settings', $settings);
// Mark the resulting configuration as trusted data. This avoids issues with
// future schema changes.
$block->save(TRUE);
}
return t('Block settings updated.');
} }
uuid: 1a6c0f14-78dc-4ede-bade-b8ce83881453
langcode: en
status: true
dependencies:
module:
- block_test
- system
theme:
- bartik
id: missing_schema
theme: bartik
region: sidebar_first
weight: 0
provider: null
plugin: system_branding_block
settings:
id: system_branding_block
label: 'Test missing schema on conditions'
provider: system
label_display: visible
use_site_logo: true
use_site_name: true
use_site_slogan: true
visibility:
missing_schema:
id: missing_schema
negate: 0
context_mapping: { }
<?php
/**
* @file
* Partial database to mimic the installation of the block_test module.
*/
use Drupal\Core\Database\Database;
use Symfony\Component\Yaml\Yaml;
$connection = Database::getConnection();
// Set the schema version.
$connection->insert('key_value')
->fields([
'collection' => 'system.schema',
'name' => 'block_test',
'value' => 'i:8000;',
])
->execute();
// Update core.extension.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions['module']['block_test'] = 8000;
$connection->update('config')
->fields([
'data' => serialize($extensions),
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
// Install the block configuration.
$config = file_get_contents(__DIR__ . '/block.block.missing_schema.yml');
$config = Yaml::parse($config);
$connection->insert('config')
->fields(['data', 'name', 'collection'])
->values([
'name' => 'block.block.missing_schema',
'data' => serialize($config),
'collection' => '',
])
->execute();
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for block with conditions missing context.
*
* @see https://www.drupal.org/node/2811519
*
* @group Update
* @group legacy
*/
class BlockConditionMissingSchemaUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.block-test-enabled-missing-schema.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
$this->drupalGet('<front>');
// If the block is fixed by block_post_update_fix_negate_in_conditions()
// then it will be visible.
$this->assertText('Test missing schema on conditions');
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
/**
* Runs BlockContextMappingUpdateTest with a dump filled with content.
*
* @group Update
* @group legacy
*/
class BlockContextMappingUpdateFilledTest extends BlockContextMappingUpdateTest {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
parent::setDatabaseDumpFiles();
$this->databaseDumpFiles[0] = __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz';
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\block\Entity\Block;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\node\Entity\Node;
/**
* Tests the upgrade path for block context mapping renames.
*
* @see https://www.drupal.org/node/2354889
*
* @group Update
* @group legacy
*/
class BlockContextMappingUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-context-manager-2354889.php',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.language-enabled.php',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.block-test-enabled.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
$this->assertRaw('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:<ul><li>User login (Visibility: Baloney spam)</li></ul>');
// Disable maintenance mode.
\Drupal::state()->set('system.maintenance_mode', FALSE);
// We finished updating so we can log in the user now.
$this->drupalLogin($this->rootUser);
// The block that we are testing has the following visibility rules:
// - only visible on node pages
// - only visible to authenticated users.
$block_title = 'Test for 2354889';
// Create two nodes, a page and an article.
$page = Node::create([
'type' => 'page',
'title' => 'Page node',
]);
$page->save();
$article = Node::create([
'type' => 'article',
'title' => 'Article node',
]);
$article->save();
// Check that the block appears only on Page nodes for authenticated users.
$this->drupalGet('node/' . $page->id());
$this->assertRaw($block_title, 'Test block is visible on a Page node as an authenticated user.');
$this->drupalGet('node/' . $article->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Article node as an authenticated user.');
$this->drupalLogout();
// Check that the block does not appear on any page for anonymous users.
$this->drupalGet('node/' . $page->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Page node as an anonymous user.');
$this->drupalGet('node/' . $article->id());
$this->assertNoRaw($block_title, 'Test block is not visible on a Article node as an anonymous user.');
// Ensure that all the context mappings got updated properly.
$block = Block::load('testfor2354889');
$visibility = $block->get('visibility');
$this->assertEqual('@node.node_route_context:node', $visibility['node_type']['context_mapping']['node']);
$this->assertEqual('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
$this->assertEqual('@language.current_language_context:language_interface', $visibility['language']['context_mapping']['language']);
// Check that a block with invalid context is being disabled and that it can
// still be edited afterward.
$disabled_block = Block::load('thirdtestfor2354889');
$this->assertFalse($disabled_block->status(), 'Block with invalid context is disabled');
$this->assertEqual(['thirdtestfor2354889' => ['missing_context_ids' => ['baloney_spam' => ['node_type']], 'status' => TRUE]], \Drupal::keyValue('update_backup')->get('block_update_8001'));
$disabled_block_visibility = $disabled_block->get('visibility');
$this->assertTrue(!isset($disabled_block_visibility['node_type']), 'The problematic visibility condition has been removed.');
$admin_user = $this->drupalCreateUser(['administer blocks']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/structure/block/manage/thirdtestfor2354889');
$this->assertResponse('200');
}
}
<?php
namespace Drupal\Tests\block\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests the upgrade path for removal of disabled region.
*
* @see https://www.drupal.org/node/2513534
*
* @group Update
* @group legacy
*/
class BlockRemoveDisabledRegionUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['block_test', 'language'];
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.update-test-block-disabled-2513534.php',
];
}
/**
* Tests that block context mapping is updated properly.
*/
public function testUpdateHookN() {
$this->runUpdates();
// Disable maintenance mode.
\Drupal::state()->set('system.maintenance_mode', FALSE);
// We finished updating so we can login the user now.
$this->drupalLogin($this->rootUser);
// Verify that a disabled block is in the default region.
$this->drupalGet('admin/structure/block');
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
[':block' => 'edit-blocks-pagetitle-1', ':status' => 'block-disabled', ':region' => 'header']);
$this->assertTrue(!empty($element));
// Verify that an enabled block is now disabled and in the default region.
$this->drupalGet('admin/structure/block');
$element = $this->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]",
[':block' => 'edit-blocks-pagetitle-2', ':status' => 'block-disabled', ':region' => 'header']);
$this->assertTrue(!empty($element));
}
}
...@@ -5,136 +5,9 @@ ...@@ -5,136 +5,9 @@
* Install, update and uninstall functions for the block_content module. * Install, update and uninstall functions for the block_content module.
*/ */
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Add 'revision_translation_affected' field to 'block_content' entities.
*/
function block_content_update_8001() {
// Install the definition that this field had in
// \Drupal\block_content\Entity\BlockContent::baseFieldDefinitions()
// at the time that this update function was written. If/when code is
// deployed that changes that definition, the corresponding module must
// implement an update function that invokes
// \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
// with the new definition.
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Revision translation affected'))
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
}
/**
* Generalizes the d6_block_content_type and d6_block_content_body_field
* migrations.
*/
function block_content_update_8002() {
// Removed in issue #2569605. The Migrate and Migrate Drupal modules are
// marked experimental and do not need to support the update path until they
// 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);
}
/**
* Fix the block_content entity type to specify its revision data table.
*/
function block_content_update_8300() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$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 = $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
if ($has_content_translation_status_field) {
$status->setInitialValueFromField('content_translation_status', TRUE);
}
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);
}
}
/** /**
* Add 'reusable' field to 'block_content' entities. * Implements hook_update_last_removed().
*/ */
function block_content_update_8600() { function block_content_update_last_removed() {
$reusable = BaseFieldDefinition::create('boolean') return 8600;
->setLabel(t('Reusable'))
->setDescription(t('A boolean indicating whether this block is reusable.'))
->setTranslatable(FALSE)
->setRevisionable(FALSE)
->setDefaultValue(TRUE)
->setInitialValue(TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('reusable', 'block_content', 'block_content', $reusable);
} }
<?php
/**
* @file
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
* upgrade path of https://www.drupal.org/project/drupal/issues/2976334.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Override configuration for 'block_content' View with extra display with with
// overridden filters.
$config = Yaml::decode(file_get_contents(__DIR__ . '/views.view.block_content_2976334.yml'));
$connection->update('config')
->fields([
'data' => serialize($config),
])
->condition('name', 'views.view.' . $config['id'])
->execute();
langcode: en
status: true
dependencies:
module:
- block_content
- user
id: block_content
label: 'Custom block library'
module: views
description: 'Find and manage custom blocks.'
tag: default
base_table: block_content_field_data
base_field: id
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'administer blocks'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 50
offset: 0
id: 0
total_pages: null
tags:
previous: ' Previous'
next: 'Next ›'
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
info: info
type: type
changed: changed
operations: operations
info:
info:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
type:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
changed:
sortable: true
default_sort_order: desc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
default: changed
empty_table: true
row:
type: fields
fields:
info:
id: info
table: block_content_field_data
field: info
relationship: none
group_type: group
admin_label: ''
label: 'Block description'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings:
link_to_entity: true
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: null
entity_field: info
plugin_id: field
type:
id: type
table: block_content_field_data
field: type
relationship: none
group_type: group
admin_label: ''
label: 'Block type'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: false
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: block_content
entity_field: type
plugin_id: field
changed:
id: changed
table: block_content_field_data
field: changed
relationship: none
group_type: group
admin_label: ''
label: Updated
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
entity_type: block_content
entity_field: changed
type: timestamp
settings:
date_format: short
custom_date_format: ''
timezone: ''
plugin_id: field
operations:
id: operations
table: block_content
field: operations
relationship: none
group_type: group
admin_label: ''
label: Operations
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
destination: true
entity_type: block_content
plugin_id: entity_operations
filters:
info:
id: info
table: block_content_field_data
field: info
relationship: none
group_type: group
admin_label: ''
operator: contains
value: ''
group: 1
exposed: true
expose:
operator_id: info_op
label: 'Block description'
description: ''
use_operator: false
operator: info_op
identifier: info
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: block_content
entity_field: info
plugin_id: string
type:
id: type
table: block_content_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value: { }
group: 1
exposed: true
expose:
operator_id: type_op
label: 'Block type'
description: ''
use_operator: false
operator: type_op
identifier: type
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: block_content
entity_field: type
plugin_id: bundle
sorts: { }
title: 'Custom block library'
header: { }
footer: { }
empty:
area_text_custom:
id: area_text_custom
table: views
field: area_text_custom
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content: 'There are no custom blocks available.'
plugin_id: text_custom
block_content_listing_empty:
admin_label: ''
empty: true
field: block_content_listing_empty
group_type: group
id: block_content_listing_empty
label: ''
relationship: none
table: block_content
plugin_id: block_content_listing_empty
entity_type: block_content
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
max-age: 0
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: admin/structure/block/block-content
menu:
type: tab
title: 'Custom block library'
description: ''
parent: block.admin_display
weight: 0
context: '0'
menu_name: admin
cache_metadata:
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
max-age: 0
tags: { }
page_2:
display_plugin: page
id: page_2
display_title: 'Page 2'
position: 2
display_options:
display_extenders: { }
path: extra-view-display
filters:
type:
id: type
table: block_content_field_data
field: type
relationship: none
group_type: group
admin_label: ''
operator: in
value: { }
group: 1
exposed: true
expose:
operator_id: type_op
label: 'Block type'
description: ''
use_operator: false
operator: type_op
identifier: type
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: block_content
entity_field: type
plugin_id: bundle
info:
id: info
table: block_content_field_data
field: info
relationship: none
group_type: group
admin_label: ''
operator: 'contains'
value: block2
group: 1
exposed: false
expose:
operator_id: ''
label: ''
description: ''
use_operator: false
operator: ''
identifier: ''
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: block_content
entity_field: info
plugin_id: string
defaults:
filters: false
filter_groups: false
filter_groups:
operator: AND
groups:
1: AND
cache_metadata:
max-age: 0
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags: { }
<?php
namespace Drupal\Tests\block_content\Functional\Update;
use Drupal\block_content\Entity\BlockContent;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests 'reusable' field related update functions for the Block Content module.
*
* @group Update
* @group block_content
* @group legacy
*/
class BlockContentReusableUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
// Override the 'block_content' view with an extra display with overridden
// filters. This extra display should also have a filter added for
// 'reusable' field so that it does not expose non-reusable fields. This
// display also has a filter that only shows blocks that contain 'block2'
// in the 'info' field.
__DIR__ . '/../../../fixtures/update/drupal-8.views_block_content-2976334.php',
];
}
/**
* Tests adding 'reusable' entity base field to the block content entity type.
*
* @see block_content_update_8600()
* @see block_content_post_update_add_views_reusable_filter()
*/
public function testReusableFieldAddition() {
$assert_session = $this->assertSession();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Ensure that 'reusable' field is not present before updates.
$this->assertEmpty($entity_definition_update_manager->getFieldStorageDefinition('reusable', 'block_content'));
// Ensure that 'reusable' filter is not present before updates.
$view_config = \Drupal::configFactory()->get('views.view.block_content');
$this->assertFalse($view_config->isNew());
$this->assertEmpty($view_config->get('display.default.display_options.filters.reusable'));
$this->assertEmpty($view_config->get('display.page_2.display_options.filters.reusable'));
// Run updates.
$this->runUpdates();
// Ensure that 'reusable' filter is present after updates.
\Drupal::configFactory()->clearStaticCache();
$view_config = \Drupal::configFactory()->get('views.view.block_content');
$this->assertNotEmpty($view_config->get('display.default.display_options.filters.reusable'));
$this->assertNotEmpty($view_config->get('display.page_2.display_options.filters.reusable'));
// Check that the field exists and is configured correctly.
$reusable_field = $entity_definition_update_manager->getFieldStorageDefinition('reusable', 'block_content');
$this->assertEquals('Reusable', $reusable_field->getLabel());
$this->assertEquals('A boolean indicating whether this block is reusable.', $reusable_field->getDescription());
$this->assertEquals(FALSE, $reusable_field->isRevisionable());
$this->assertEquals(FALSE, $reusable_field->isTranslatable());
$after_block1 = BlockContent::create([
'info' => 'After update block1',
'type' => 'basic_block',
]);
$after_block1->save();
// Add second block that will be shown with the 'info' filter on the
// additional view display.
$after_block2 = BlockContent::create([
'info' => 'After update block2',
'type' => 'basic_block',
]);
$after_block2->save();
$this->assertTrue($after_block1->isReusable());
$this->assertTrue($after_block2->isReusable());
$admin_user = $this->drupalCreateUser(['administer blocks']);
$this->drupalLogin($admin_user);
$block_non_reusable = BlockContent::create([
'info' => 'block1 non reusable',
'type' => 'basic_block',
'reusable' => FALSE,
]);
$block_non_reusable->save();
// Add second block that would be shown with the 'info' filter on the
// additional view display if the 'reusable' filter was not added.
$block2_non_reusable = BlockContent::create([
'info' => 'block2 non reusable',
'type' => 'basic_block',
'reusable' => FALSE,
]);
$block2_non_reusable->save();
$this->assertFalse($block_non_reusable->isReusable());
$this->assertFalse($block2_non_reusable->isReusable());
// Ensure the Custom Block view shows the reusable blocks only.
$this->drupalGet('admin/structure/block/block-content');
$assert_session->statusCodeEquals('200');
$assert_session->responseContains('view-id-block_content');
$assert_session->pageTextContains($after_block1->label());
$assert_session->pageTextContains($after_block2->label());
$assert_session->pageTextNotContains($block_non_reusable->label());
$assert_session->pageTextNotContains($block2_non_reusable->label());
// Ensure the view's other display also only shows reusable blocks and still
// filters on the 'info' field.
$this->drupalGet('extra-view-display');
$assert_session->statusCodeEquals('200');
$assert_session->responseContains('view-id-block_content');
$assert_session->pageTextNotContains($after_block1->label());
$assert_session->pageTextContains($after_block2->label());
$assert_session->pageTextNotContains($block_non_reusable->label());
$assert_session->pageTextNotContains($block2_non_reusable->label());
// Ensure the Custom Block listing without Views installed shows the only
// reusable blocks.
$this->drupalGet('admin/structure/block/block-content');
$this->container->get('module_installer')->uninstall(['views_ui', 'views']);
$this->drupalGet('admin/structure/block/block-content');
$assert_session->statusCodeEquals('200');
$assert_session->responseNotContains('view-id-block_content');
$assert_session->pageTextContains($after_block1->label());
$assert_session->pageTextContains($after_block2->label());
$assert_session->pageTextNotContains($block_non_reusable->label());
$assert_session->pageTextNotContains($block2_non_reusable->label());
$this->drupalGet('block/' . $after_block1->id());
$assert_session->statusCodeEquals('200');
// Ensure the non-reusable block is not accessible in the form.
$this->drupalGet('block/' . $block_non_reusable->id());
$assert_session->statusCodeEquals('403');
$this->drupalLogout();
$this->drupalLogin($this->createUser([
'access user profiles',
'administer blocks',
]));
$this->drupalGet('block/' . $after_block1->id());
$assert_session->statusCodeEquals('200');
$this->drupalGet('block/' . $block_non_reusable->id());
$assert_session->statusCodeEquals('403');
}
/**
* Tests that the update succeeds even if Views is not installed.
*/
public function testReusableFieldAdditionWithoutViews() {
$this->container->get('module_installer')->uninstall(['views']);
$this->runUpdates();
}
}
<?php
namespace Drupal\Tests\block_content\Functional\Update;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests update functions for the Block Content module.
*
* @group Update
* @group legacy
*/
class BlockContentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
];
}
/**
* Tests the revision metadata fields and revision data table additions.
*/
public function testSimpleUpdates() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
$this->assertNull($entity_type->getRevisionDataTable());
$this->runUpdates();
$post_revision_created = $entity_definition_update_manager->getFieldStorageDefinition('revision_created', 'block_content');
$post_revision_user = $entity_definition_update_manager->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");
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
$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'));
}
}
...@@ -5,39 +5,9 @@ ...@@ -5,39 +5,9 @@
* Install, update and uninstall functions for the Comment module. * Install, update and uninstall functions for the Comment module.
*/ */
use Drupal\comment\Entity\Comment;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
/**
* Implements hook_requirements().
*/
function comment_requirements($phase) {
$requirements = [];
if ($phase === 'update' && drupal_get_installed_schema_version('comment') < 8701) {
$has_empty_columns = \Drupal::entityQuery('comment', 'OR')
->condition('entity_type', NULL, 'IS NULL')
->condition('field_name', NULL, 'IS NULL')
->range(0, 1)
->accessCheck(FALSE)
->execute();
if ($has_empty_columns) {
$requirements['comment_update_8701'] = [
'title' => t('Comment required fields update'),
'description' => t('The comment_update_8701() function requires that the %field_1 and %field_2 fields have values for all comment entities. See the <a href=":change_record">change record</a> for more information.', [
'%field_1' => 'entity_type',
'%field_2' => 'field_name',
':change_record' => 'https://www.drupal.org/node/3053046',
]),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/** /**
* Implements hook_uninstall(). * Implements hook_uninstall().
*/ */
...@@ -141,122 +111,8 @@ function comment_schema() { ...@@ -141,122 +111,8 @@ function comment_schema() {
} }
/** /**
* Clear caches to fix Comment entity list builder and operations Views field. * Implements hook_update_last_removed().
*/
function comment_update_8001() {
// Empty update to cause a cache flush to rebuild comment entity handler
// information, so that comment operation links work.
}
/**
* Clear caches to fix Comment Views context filter.
*/
function comment_update_8002() {
// Empty update to cause a cache flush.
}
/**
* Add the 'view_mode' setting to displays having 'comment_default' formatter.
*/
function comment_update_8200() {
$config_factory = \Drupal::configFactory();
$displays = [];
// Iterate on all entity view displays.
foreach ($config_factory->listAll('core.entity_view_display.') as $name) {
$changed = FALSE;
$display = $config_factory->getEditable($name);
$components = $display->get('content') ?: [];
foreach ($components as $field_name => $component) {
if (isset($component['type']) && ($component['type'] === 'comment_default')) {
if (empty($display->get("content.{$field_name}.settings.view_mode"))) {
$display->set("content.{$field_name}.settings.view_mode", 'default');
$displays[] = $display->get('id');
$changed = TRUE;
}
}
}
if ($changed) {
$display->save(TRUE);
}
}
if ($displays) {
return new PluralTranslatableMarkup(count($displays), '1 entity display updated: @displays.', '@count entity displays updated: @displays.', ['@displays' => implode(', ', $displays)]);
}
else {
return new TranslatableMarkup('No entity view display updated.');
}
}
/**
* Update status field.
*/ */
function comment_update_8300() { function comment_update_last_removed() {
$entity_definition_update_manager = \Drupal::service('entity.definition_update_manager'); return 8701;
$field_definition = $entity_definition_update_manager->getFieldStorageDefinition('status', 'comment');
$field_definition->setDescription(new TranslatableMarkup('A boolean indicating the published state.'))
->setRevisionable(TRUE);
$entity_definition_update_manager->updateFieldStorageDefinition($field_definition);
}
/**
* Set the 'published' entity key.
*/
function comment_update_8301() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $definition_update_manager->getEntityType('comment');
$keys = $entity_type->getKeys();
$keys['published'] = 'status';
$entity_type->set('entity_keys', $keys);
$definition_update_manager->updateEntityType($entity_type);
}
/**
* Update the status field.
*/
function comment_update_8400() {
// The status field was promoted to an entity key in comment_update_8301(),
// which makes it NOT NULL in the default SQL storage, which means its storage
// definition needs to be updated as well.
$entity_definition_update_manager = \Drupal::service('entity.definition_update_manager');
$entity_definition_update_manager->updateFieldStorageDefinition($entity_definition_update_manager->getFieldStorageDefinition('status', 'comment'));
}
/**
* Configure the comment hostname base field to use a default value callback.
*/
function comment_update_8600() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
/** @var \Drupal\Core\Field\BaseFieldDefinition $field_storage_definition */
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('hostname', 'comment');
$field_storage_definition->setDefaultValueCallback(Comment::class . '::getDefaultHostname');
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
}
/**
* Set the 'owner' entity key and update the field.
*/
function comment_update_8700() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $definition_update_manager->getEntityType('comment');
$keys = $entity_type->getKeys();
$keys['owner'] = 'uid';
$entity_type->set('entity_keys', $keys);
$definition_update_manager->updateEntityType($entity_type);
$definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('uid', 'comment'));
}
/**
* Make the 'entity_type' and 'field_name' comment fields required.
*/
function comment_update_8701() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('entity_type', 'comment');
$field_definition->setRequired(TRUE);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
$field_definition = $definition_update_manager->getFieldStorageDefinition('field_name', 'comment');
$field_definition->setRequired(TRUE);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
} }
<?php
/**
* @file
* Contains database additions to drupal-8-rc1.filled.standard.php.gz for the
* upgrade path in https://www.drupal.org/project/drupal/issues/2885809.
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
$connection->insert('comment')
->fields([
'cid',
'comment_type',
'uuid',
'langcode',
])
->values([
'cid' => '5',
'comment_type' => 'comment',
'uuid' => '2f0505ad-fdc7-49fc-9d39-571bfc3e0f88',
'langcode' => 'en',
])
->values([
'cid' => '6',
'comment_type' => 'comment',
'uuid' => '3be94e6b-4506-488a-a861-9742a18f0507',
'langcode' => 'en',
])
->execute();
$connection->insert('comment__comment_body')
->fields([
'bundle',
'deleted',
'entity_id',
'revision_id',
'langcode',
'delta',
'comment_body_value',
'comment_body_format',
])
->values([
'bundle' => 'comment',
'deleted' => '0',
'entity_id' => '5',
'revision_id' => '5',
'langcode' => 'en',
'delta' => '0',
'comment_body_value' => "<p>Comment body</p>\r\n",
'comment_body_format' => 'basic_html',
])
->values([
'bundle' => 'comment',
'deleted' => '0',
'entity_id' => '6',
'revision_id' => '6',
'langcode' => 'en',
'delta' => '0',
'comment_body_value' => "<p>Comment body</p>\r\n",
'comment_body_format' => 'basic_html',
])
->execute();
$connection->insert('comment_field_data')
->fields([
'cid',
'comment_type',
'langcode',
'pid',
'entity_id',
'subject',
'uid',
'name',
'mail',
'homepage',
'hostname',
'created',
'changed',
'status',
'thread',
'entity_type',
'field_name',
'default_langcode',
])
->values([
'cid' => '5',
'comment_type' => 'comment',
'langcode' => 'en',
'pid' => NULL,
'entity_id' => '8',
'subject' => 'Comment with no entity_type',
'uid' => '1',
'name' => 'drupal',
'mail' => NULL,
'homepage' => NULL,
'hostname' => '127.0.0.1',
'created' => '1557218256',
'changed' => '1557218256',
'status' => '1',
'thread' => '02/',
'entity_type' => NULL,
'field_name' => 'field_test_2',
'default_langcode' => '1',
])
->values([
'cid' => '6',
'comment_type' => 'comment',
'langcode' => 'en',
'pid' => NULL,
'entity_id' => '8',
'subject' => 'Comment with no field_name',
'uid' => '1',
'name' => 'drupal',
'mail' => NULL,
'homepage' => NULL,
'hostname' => '127.0.0.1',
'created' => '1557218266',
'changed' => '1557218266',
'status' => '1',
'thread' => '03/',
'entity_type' => 'node',
'field_name' => NULL,
'default_langcode' => '1',
])
->execute();
<?php
namespace Drupal\Tests\comment\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that comment admin view is enabled after update.
*
* @see comment_post_update_enable_comment_admin_view()
*
* @group Update
* @group legacy
*/
class CommentAdminViewUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['comment', 'views'];
/**
* {@inheritdoc}
*/
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
];
}
/**
* Tests that comment admin view is enabled after update.
*/
public function testCommentAdminPostUpdateHook() {
$this->runUpdates();
// Ensure we can load the view from the storage after the update and it's
// enabled.
$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Drupal\views\ViewEntityInterface $comment_admin_view */
$comment_admin_view = $entity_type_manager->getStorage('view')->load('comment');
$this->assertNotNull($comment_admin_view, 'Comment admin view exist in storage.');
$this->assertTrue((bool) $comment_admin_view->enable()->get('status'), 'Comment admin view is enabled.');
$comment_delete_action = $entity_type_manager->getStorage('action')->load('comment_delete_action');
$this->assertNotNull($comment_delete_action, 'Comment delete action imported');
// Verify comment admin page is working after updates.
$account = $this->drupalCreateUser(['administer comments']);
$this->drupalLogin($account);
$this->drupalGet('admin/content/comment');
$this->assertText(t('No comments available.'));
}
}
<?php
namespace Drupal\Tests\comment\Functional\Update;
use Drupal\comment\Entity\Comment;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that comment hostname settings are properly updated.
*
* @group comment
* @group legacy
*/
class CommentHostnameUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz',
];
}
/**
* Tests comment_update_8600().
*
* @see comment_update_8600
*/
public function testCommentUpdate8600() {
/** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $manager */
$manager = $this->container->get('entity.definition_update_manager');
/** @var \Drupal\Core\Field\BaseFieldDefinition $definition */
$definition = $manager->getFieldStorageDefinition('hostname', 'comment');
// Check that 'hostname' base field doesn't have a default value callback.
$this->assertNull($definition->getDefaultValueCallback());
$this->runUpdates();
$definition = $manager->getFieldStorageDefinition('hostname', 'comment');
// Check that 'hostname' base field default value callback was set.
$this->assertEquals(Comment::class . '::getDefaultHostname', $definition->getDefaultValueCallback());
}
/**
* Tests comment_post_update_add_ip_address_setting().
*
* @see comment_post_update_add_ip_address_setting()
*/
public function testCommentPostUpdateAddIpAddressSetting() {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $factory */
$factory = $this->container->get('config.factory');
$settings = $factory->listAll('comment.settings');
$this->assertEmpty($settings);
$this->runUpdates();
$settings = $factory->get('comment.settings');
// Check that settings default value was set.
$this->assertEquals(TRUE, $settings->get('log_ip_addresses'));
}
}
<?php
namespace Drupal\Tests\comment\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests that comment settings are properly updated during database updates.
*
* @group comment
* @group legacy
*/
class CommentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz',
];
}
/**
* Tests comment_update_8200().
*
* @see comment_update_8200()
*/
public function testCommentUpdate8101() {
// Load the 'node.article.default' entity view display config, and check
// that component 'comment' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertNull($config->get('content.comment.settings.view_mode'));
// Load the 'node.forum.default' entity view display config, and check that
// component 'comment_forum' does not contain the 'view_mode' setting.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertNull($config->get('content.comment_forum.settings.view_mode'));
// Run updates.
$this->runUpdates();
// Check that 'node.article.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.article.default');
$this->assertIdentical($config->get('content.comment.settings.view_mode'), 'default');
// Check that 'node.forum.default' entity view display setting 'view_mode'
// has the value 'default'.
$config = $this->config('core.entity_view_display.node.forum.default');
$this->assertIdentical($config->get('content.comment_forum.settings.view_mode'), 'default');
}
/**
* Tests that the comment entity type has a 'published' entity key.
*
* @see comment_update_8301()
*/
public function testPublishedEntityKey() {
// Check that the 'published' entity key does not exist prior to the update.
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
$this->assertFalse($entity_type->getKey('published'));
// Run updates.
$this->runUpdates();
// Check that the entity key exists and it has the correct value.
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
$this->assertEqual('status', $entity_type->getKey('published'));
// Check that the {comment_field_data} table status index has been created.
$this->assertTrue(\Drupal::database()->schema()->indexExists('comment_field_data', 'comment__status_comment_type'));
}
/**
* Tests that the comment entity type has an 'owner' entity key.
*
* @see comment_update_8700()
*/
public function testOwnerEntityKey() {
// Check that the 'owner' entity key does not exist prior to the update.
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
$this->assertFalse($entity_type->getKey('owner'));
// Run updates.
$this->runUpdates();
// Check that the entity key exists and it has the correct value.
$entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
$this->assertEquals('uid', $entity_type->getKey('owner'));
}
/**
* Tests whether the 'entity_type' and 'field_name' columns are required.
*
* @see comment_update_8701()
*/
public function testCommentEntityTypeAndFieldNameRequired() {
$database = \Drupal::database();
$this->assertEquals(2, $database->query('SELECT count(*) FROM {comment_field_data}')->fetchField());
if ($database->driver() === 'mysql') {
$table_description = $database
->query('DESCRIBE {comment_field_data}')
->fetchAllAssoc('Field');
$this->assertEquals('YES', $table_description['entity_type']->Null);
$this->assertEquals('YES', $table_description['field_name']->Null);
}
$this->runUpdates();
$this->assertEquals(2, $database->query('SELECT count(*) FROM {comment_field_data}')->fetchField());
if ($database->driver() === 'mysql') {
$table_description = $database
->query('DESCRIBE {comment_field_data}')
->fetchAllAssoc('Field');
$this->assertEquals('NO', $table_description['entity_type']->Null);
$this->assertEquals('NO', $table_description['field_name']->Null);
}
}
/**
* Test the update hook requirements check for 8701.
*
* @see comment_update_8701()
* @see comment_requirements()
*/
public function testCommentEntityTypeAndFieldUpdateRequirementsCheck() {
require_once __DIR__ . '/../../../fixtures/update/drupal-8.empty-comment-fields.3052147.php';
$this->writeSettings([
'settings' => [
'update_free_access' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this->drupalGet($this->updateUrl);
$this->assertSession()->pageTextContains('Errors found');
$this->assertSession()->elementContains('css', '.system-status-report__entry--error', 'The comment_update_8701() function requires that the <em class="placeholder">entity_type</em> and <em class="placeholder">field_name</em> fields have values for all comment entities.');
}
}
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