Unverified Commit 18d53198 authored by alexpott's avatar alexpott
Browse files

Issue #3097752 by andypost, longwave, Stefdewa, Wim Leers, Berdir, alexpott:...

Issue #3097752 by andypost, longwave, Stefdewa, Wim Leers, Berdir, alexpott: Remove views.module BC layers
parent 1d1f2222
......@@ -5,9 +5,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\views\Plugin\DependentWithRemovalPluginInterface;
use Drupal\views\Views;
......@@ -295,10 +293,6 @@ public function preSave(EntityStorageInterface $storage) {
$displays = $this->get('display');
// @todo Remove this line and support for pre-8.3 table names in Drupal 9.
// @see https://www.drupal.org/project/drupal/issues/3069405 .
$this->fixTableNames($displays);
// Sort the displays.
ksort($displays);
$this->set('display', ['default' => $displays['default']] + $displays);
......@@ -311,48 +305,6 @@ public function preSave(EntityStorageInterface $storage) {
}
}
/**
* Fixes table names for revision metadata fields of revisionable entities.
*
* Views for revisionable entity types using revision metadata fields might
* be using the wrong table to retrieve the fields after system_update_8300
* has moved them correctly to the revision table. This method updates the
* views to use the correct tables.
*
* @param array &$displays
* An array containing display handlers of a view.
*
* @todo Remove this method and its usage in Drupal 9. See
* https://www.drupal.org/project/drupal/issues/3069405.
* @see https://www.drupal.org/node/2831499
*/
private function fixTableNames(array &$displays) {
// Fix wrong table names for entity revision metadata fields.
foreach ($displays as $display => $display_data) {
if (isset($display_data['display_options']['fields'])) {
foreach ($display_data['display_options']['fields'] as $property_name => $property_data) {
if (isset($property_data['entity_type']) && isset($property_data['field']) && isset($property_data['table'])) {
$entity_type = $this->entityTypeManager()->getDefinition($property_data['entity_type']);
// We need to update the table name only for revisionable entity
// types, otherwise the view is already using the correct table.
if (($entity_type instanceof ContentEntityTypeInterface) && is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) && $entity_type->isRevisionable()) {
$revision_metadata_fields = $entity_type->getRevisionMetadataKeys();
// @see \Drupal\Core\Entity\Sql\SqlContentEntityStorage::initTableLayout()
$revision_table = $entity_type->getRevisionTable() ?: $entity_type->id() . '_revision';
// Check if this is a revision metadata field and if it uses the
// wrong table.
if (in_array($property_data['field'], $revision_metadata_fields) && $property_data['table'] != $revision_table) {
@trigger_error('Support for pre-8.3.0 revision table names in imported views is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Imported views must reference the correct tables. See https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$displays[$display]['display_options']['fields'][$property_name]['table'] = $revision_table;
}
}
}
}
}
}
}
/**
* Fills in the cache metadata of this view.
*
......
......@@ -91,12 +91,8 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LoggerInterface $logger = NULL) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, LoggerInterface $logger) {
$this->entityTypeManager = $entity_type_manager;
if (!$logger) {
@trigger_error('Calling ViewsEntitySchemaSubscriber::__construct() with the $logger argument is supported in drupal:8.7.1 and will be required before drupal:9.0.0. See https://www.drupal.org/project/drupal/issues/3052492.', E_USER_DEPRECATED);
$logger = \Drupal::service('logger.channel.default');
}
$this->logger = $logger;
}
......
......@@ -41,12 +41,8 @@ class ViewsExposedForm extends FormBase {
* @param \Drupal\Core\Path\CurrentPathStack $current_path_stack
* The current path stack.
*/
public function __construct(ExposedFormCache $exposed_form_cache, CurrentPathStack $current_path_stack = NULL) {
public function __construct(ExposedFormCache $exposed_form_cache, CurrentPathStack $current_path_stack) {
$this->exposedFormCache = $exposed_form_cache;
if ($current_path_stack === NULL) {
@trigger_error('The path.current service must be passed to ViewsExposedForm::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/3066604', E_USER_DEPRECATED);
$current_path_stack = \Drupal::service('path.current');
}
$this->currentPathStack = $current_path_stack;
}
......
......@@ -79,20 +79,15 @@ class ViewsSelection extends SelectionPluginBase implements ContainerFactoryPlug
* The module handler service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Render\RendererInterface|null $renderer
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, RendererInterface $renderer = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->currentUser = $current_user;
if (!$renderer) {
@trigger_error('Calling ' . __METHOD__ . ' without the $renderer argument is deprecated in drupal:8.8.0 and is required in drupal:9.0.0. See https://www.drupal.org/node/2791359', E_USER_DEPRECATED);
$renderer = \Drupal::service('renderer');
}
$this->renderer = $renderer;
}
......
<?php
namespace Drupal\views\Plugin\views;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0.
*/
interface PluginInterface extends PluginInspectionInterface {
}
......@@ -2180,22 +2180,6 @@ protected function applyDisplayCacheabilityMetadata(array &$element) {
->applyTo($element);
}
/**
* Applies the cacheability of the current display to the given render array.
*
* @param array $element
* The render array with updated cacheability metadata.
*
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. Use
* DisplayPluginBase::applyDisplayCacheabilityMetadata instead.
*
* @see \Drupal\views\Plugin\views\display\DisplayPluginBase::applyDisplayCacheabilityMetadata()
*/
protected function applyDisplayCachablityMetadata(array &$element) {
@trigger_error('The DisplayPluginBase::applyDisplayCachablityMetadata method is deprecated since version 8.4 and will be removed in 9.0. Use DisplayPluginBase::applyDisplayCacheabilityMetadata instead.', E_USER_DEPRECATED);
$this->applyDisplayCacheabilityMetadata($element);
}
/**
* {@inheritdoc}
*/
......
<?php
namespace Drupal\views\Plugin\views\field;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\RendererInterface;
/**
* A stub class to provide backward compatibility for EntityField.
*
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0.
* Use \Drupal\views\Plugin\views\field\EntityField instead.
*
* @see https://www.drupal.org/node/3089106
*/
class Field extends EntityField {
/**
* Field constructor.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, FormatterPluginManager $formatter_plugin_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, LanguageManagerInterface $language_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $formatter_plugin_manager, $field_type_plugin_manager, $language_manager, $renderer);
@trigger_error(__CLASS__ . ' is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\views\Plugin\views\field\EntityField instead. See https://www.drupal.org/node/3089106', E_USER_DEPRECATED);
}
}
......@@ -69,31 +69,18 @@ abstract class LinkBase extends FieldPluginBase {
* The plugin implementation definition.
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
* The access manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface|null $entity_repository
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\Language\LanguageManagerInterface|null $language_manager
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, EntityTypeManagerInterface $entity_type_manager = NULL, EntityRepositoryInterface $entity_repository = NULL, LanguageManagerInterface $language_manager = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->accessManager = $access_manager;
if (!$entity_type_manager) {
@trigger_error('Passing the entity type manager service to \Drupal\views\Plugin\views\field\LinkBase::__construct is required since 8.7.0, see https://www.drupal.org/node/3023427.', E_USER_DEPRECATED);
$entity_type_manager = \Drupal::service('entity_type.manager');
}
$this->entityTypeManager = $entity_type_manager;
if (!$entity_repository) {
@trigger_error('Passing the entity repository service to \Drupal\views\Plugin\views\field\LinkBase::__construct is required since 8.7.0, see https://www.drupal.org/node/3023427.', E_USER_DEPRECATED);
$entity_repository = \Drupal::service('entity.repository');
}
$this->entityRepository = $entity_repository;
if (!$language_manager) {
@trigger_error('Passing the language manager service to \Drupal\views\Plugin\views\field\LinkBase::__construct is required since 8.7.0, see https://www.drupal.org/node/3023427.', E_USER_DEPRECATED);
$language_manager = \Drupal::service('language_manager');
}
$this->languageManager = $language_manager;
}
......
<?php
namespace Drupal\views\Tests\Handler;
@trigger_error('\Drupal\views\Tests\Handler\HandlerTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase;
/**
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*/
abstract class HandlerTestBase extends ViewTestBase {
}
<?php
namespace Drupal\views\Tests\Plugin;
@trigger_error(__NAMESPACE__ . '\PluginKernelTestBase is deprecated for removal before Drupal 9.0.0. Use \Drupal\Tests\views\Kernel\ViewsKernelTestBase instead.', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewKernelTestBase;
/**
* Base test class for views plugin unit tests.
*
* @deprecated in drupal:8.?.? and is removed from drupal:9.0.0.
* Use \Drupal\Tests\views\Kernel\ViewsKernelTestBase instead.
*/
abstract class PluginKernelTestBase extends ViewKernelTestBase {
}
<?php
namespace Drupal\views\Tests\Plugin;
@trigger_error('\Drupal\views\Tests\Plugin\PluginTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\views\Tests\ViewTestBase;
/**
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*/
abstract class PluginTestBase extends ViewTestBase {
}
<?php
namespace Drupal\views\Tests;
@trigger_error(__NAMESPACE__ . '\ViewKernelTestBase is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\views\Kernel\ViewsKernelTestBase instead.', E_USER_DEPRECATED);
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\simpletest\KernelTestBase;
/**
* Defines a base class for Views unit testing.
*
* Use this test class for unit tests of Views functionality. If a test
* requires the full web test environment provided by WebTestBase, extend
* ViewTestBase instead.
*
* @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use
* \Drupal\Tests\views\Kernel\ViewsKernelTestBase instead.
*
* @see \Drupal\Tests\views\Kernel\ViewsKernelTestBase
*/
abstract class ViewKernelTestBase extends KernelTestBase {
use ViewResultAssertionTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['system', 'views', 'views_test_config', 'views_test_data', 'user'];
/**
* {@inheritdoc}
*
* @param bool $import_test_views
* Should the views specified on the test class be imported. If you need
* to setup some additional stuff, like fields, you need to call false and
* then call createTestViews for your own.
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$this->installSchema('system', ['sequences']);
$this->setUpFixtures();
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['views_test_config']);
}
}
/**
* Sets up the configuration and schema of views and views_test_data modules.
*
* Because the schema of views_test_data.module is dependent on the test
* using it, it cannot be enabled normally.
*/
protected function setUpFixtures() {
// First install the system module. Many Views have Page displays have menu
// links, and for those to work, the system menus must already be present.
$this->installConfig(['system']);
// Define the schema and views data variable before enabling the test module.
\Drupal::state()->set('views_test_data_schema', $this->schemaDefinition());
\Drupal::state()->set('views_test_data_views_data', $this->viewsData());
$this->installConfig(['views', 'views_test_config', 'views_test_data']);
foreach ($this->schemaDefinition() as $table => $schema) {
$this->installSchema('views_test_data', $table);
}
\Drupal::service('router.builder')->rebuild();
// Load the test dataset.
$data_set = $this->dataSet();
$query = Database::getConnection()->insert('views_test_data')
->fields(array_keys($data_set[0]));
foreach ($data_set as $record) {
$query->values($record);
}
$query->execute();
}
/**
* Orders a nested array containing a result set based on a given column.
*
* @param array $result_set
* An array of rows from a result set, with each row as an associative
* array keyed by column name.
* @param string $column
* The column name by which to sort the result set.
* @param bool $reverse
* (optional) Boolean indicating whether to sort the result set in reverse
* order. Defaults to FALSE.
*
* @return array
* The sorted result set.
*/
protected function orderResultSet($result_set, $column, $reverse = FALSE) {
$order = $reverse ? -1 : 1;
usort($result_set, function ($a, $b) use ($column, $order) {
if ($a[$column] == $b[$column]) {
return 0;
}
return $order * (($a[$column] < $b[$column]) ? -1 : 1);
});
return $result_set;
}
/**
* Executes a view with debugging.
*
* @param \Drupal\views\ViewExecutable $view
* The view object.
* @param array $args
* (optional) An array of the view arguments to use for the view.
*/
protected function executeView($view, array $args = []) {
$view->setDisplay();
$view->preExecute($args);
$view->execute();
$verbose_message = '<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>';
if ($view->build_info['query'] instanceof SelectInterface) {
$verbose_message .= '<pre>Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '</pre>';
}
$this->verbose($verbose_message);
}
/**
* Returns the schema definition.
*
* @internal
*/
protected function schemaDefinition() {
return ViewTestData::schemaDefinition();
}
/**
* Returns the views data definition.
*/
protected function viewsData() {
return ViewTestData::viewsData();
}
/**
* Returns a very simple test dataset.
*/
protected function dataSet() {
return ViewTestData::dataSet();
}
}
<?php
namespace Drupal\views\Tests;
@trigger_error('\Drupal\views\Tests\ViewTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\views\Functional\ViewTestBase', E_USER_DEPRECATED);
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\views\ViewExecutable;
/**
* Defines a base class for Views testing in the full web test environment.
*
* Use this base test class if you need to emulate a full Drupal installation.
* When possible, ViewsKernelTestBase should be used instead. Both base classes
* include the same methods.
*
* @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0.
* Use \Drupal\Tests\views\Functional\ViewTestBase.
*
* @see \Drupal\Tests\views\Kernel\ViewsKernelTestBase
* @see \Drupal\simpletest\WebTestBase
*/
abstract class ViewTestBase extends WebTestBase {
use ViewResultAssertionTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['views', 'views_test_config'];
protected function setUp($import_test_views = TRUE) {
parent::setUp();
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['views_test_config']);
}
}
/**
* Sets up the views_test_data.module.
*
* Because the schema of views_test_data.module is dependent on the test
* using it, it cannot be enabled normally.
*/
protected function enableViewsTestModule() {
// Define the schema and views data variable before enabling the test module.
\Drupal::state()->set('views_test_data_schema', $this->schemaDefinition());
\Drupal::state()->set('views_test_data_views_data', $this->viewsData());
\Drupal::service('module_installer')->install(['views_test_data']);
$this->resetAll();
$this->rebuildContainer();
$this->container->get('module_handler')->reload();
// Load the test dataset.
$data_set = $this->dataSet();
$query = Database::getConnection()->insert('views_test_data')
->fields(array_keys($data_set[0]));
foreach ($data_set as $record) {
$query->values($record);
}
$query->execute();
}
/**
* Orders a nested array containing a result set based on a given column.
*
* @param array $result_set
* An array of rows from a result set, with each row as an associative
* array keyed by column name.
* @param string $column
* The column name by which to sort the result set.
* @param bool $reverse
* (optional) Boolean indicating whether to sort the result set in reverse
* order. Defaults to FALSE.
*
* @return array
* The sorted result set.
*/
protected function orderResultSet($result_set, $column, $reverse = FALSE) {
$order = $reverse ? -1 : 1;
usort($result_set, function ($a, $b) use ($column, $order) {
if ($a[$column] == $b[$column]) {
return 0;
}
return $order * (($a[$column] < $b[$column]) ? -1 : 1);
});
return $result_set;
}
/**
* Asserts the existence of a button with a certain ID and label.
*
* @param string $id
* The HTML ID of the button
* @param string $expected_label
* The expected label for the button.
* @param string $message
* (optional) A custom message to display with the assertion. If no custom
* message is provided, the message will indicate the button label.
*
* @return bool
* TRUE if the assertion was successful, or FALSE on failure.
*/
protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') {
return $this->assertFieldById($id, $expected_label, t($message, ['%label' => $expected_label]));
}
/**
* Executes a view with debugging.
*
* @param \Drupal\views\ViewExecutable $view
* The view object.
* @param array $args
* (optional) An array of the view arguments to use for the view.
*/
protected function executeView(ViewExecutable $view, $args = []) {
// A view does not really work outside of a request scope, due to many
// dependencies like the current user.
$view->setDisplay();
$view->preExecute($args);
$view->execute();
$verbose_message = '<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>';
if ($view->build_info['query'] instanceof SelectInterface) {
$verbose_message .= '<pre>Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '</pre>';
}
$this->verbose($verbose_message);
}
/**
* Returns the schema definition.
*
* @internal
*/
protected function schemaDefinition() {
return ViewTestData::schemaDefinition();
}
/**
* Returns the views data definition.
*/
protected function viewsData() {
return ViewTestData::viewsData();
}
/**
* Returns a very simple test dataset.
*/
protected function dataSet() {
return ViewTestData::dataSet();
}
}