Issue #3092934 by longwave, gilesmc, ravi.shankar, andypost, Wim Leers: Remove all @deprecated code in the Block module

merge-requests/2419/head
Lee Rowlands 2019-11-29 21:57:49 +11:00
parent 576c1e0e4b
commit f526412389
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
7 changed files with 8 additions and 375 deletions

View File

@ -377,16 +377,6 @@ class BlockForm extends EntityForm {
$condition = $form_state->get(['conditions', $condition_id]);
$condition->submitConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state));
// Setting conditions' context mappings is the plugins' responsibility.
// This code exists for backwards compatibility, because
// \Drupal\Core\Condition\ConditionPluginBase::submitConfigurationForm()
// did not set its own mappings until Drupal 8.2
// @todo Remove the code that sets context mappings in Drupal 9.0.0.
if ($condition instanceof ContextAwarePluginInterface) {
$context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : [];
$condition->setContextMapping($context_mapping);
}
$condition_configuration = $condition->getConfiguration();
// Update the visibility conditions on the block.
$this->entity->getVisibilityConditions()->addInstanceId($condition_id, $condition_configuration);

View File

@ -2,7 +2,6 @@
namespace Drupal\block;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
@ -10,23 +9,6 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
*/
interface BlockInterface extends ConfigEntityInterface {
/**
* Indicates the block label (title) should be displayed to end users.
*
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\Block\BlockPluginInterface::BLOCK_LABEL_VISIBLE.
*
* @see https://www.drupal.org/node/2829775
*/
const BLOCK_LABEL_VISIBLE = BlockPluginInterface::BLOCK_LABEL_VISIBLE;
/**
* Denotes that a block is not enabled in any region and should not be shown.
*
* @deprecated in drupal:8.?.? and is removed from drupal:9.0.0.
*/
const BLOCK_REGION_NONE = -1;
/**
* Returns the plugin instance.
*

View File

@ -7,7 +7,6 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -19,21 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The migration process plugin.
*
* The plugin is configured for lookups in d6_custom_block and
* d7_custom_block.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The migrate lookup service.
*
@ -62,17 +46,8 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
* @param \Drupal\migrate\MigrateLookupInterface $migrate_lookup
* The migrate lookup service.
*/
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, $migrate_lookup) {
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityStorageInterface $storage, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fifth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fifth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
$this->blockContentStorage = $storage;
$this->migrateLookup = $migrate_lookup;
}
@ -112,24 +87,9 @@ class BlockPluginId extends ProcessPluginBase implements ContainerFactoryPluginI
case 'block':
if ($this->blockContentStorage) {
// This BC layer is included because if the plugin constructor was
// called in the legacy way with a migration_lookup process plugin,
// it may have been preconfigured with a different migration to
// look up against. While this is unlikely, for maximum BC we will
// continue to use the plugin to do the lookup if it is provided,
// and support for this will be removed in Drupal 9.
if ($this->migrationPlugin) {
$block_id = $this->migrationPlugin
->transform($delta, $migrate_executable, $row, $destination_property);
}
else {
$lookup_result = $this->migrateLookup->lookup(['d6_custom_block', 'd7_custom_block'], [$delta]);
if ($lookup_result) {
$block_id = $lookup_result[0]['id'];
}
}
if (!empty($block_id)) {
$lookup_result = $this->migrateLookup->lookup(['d6_custom_block', 'd7_custom_block'], [$delta]);
if ($lookup_result) {
$block_id = $lookup_result[0]['id'];
return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
}
}

View File

@ -8,7 +8,6 @@ use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -27,21 +26,6 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
*/
protected $moduleHandler;
/**
* The migration process plugin.
*
* The plugin is configured for lookups in the d6_user_role and d7_user_role
* migrations.
*
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
*
* @deprecated in drupal:8.8.x and is removed from drupal:9.0.0. Use
* the migrate.lookup service instead.
*
* @see https://www.drupal.org/node/3047268
*/
protected $migrationPlugin;
/**
* The migrate lookup service.
*
@ -72,16 +56,8 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
* The migrate lookup service.
*/
// @codingStandardsIgnoreLine
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, $migrate_lookup) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, MigrateLookupInterface $migrate_lookup) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if ($migrate_lookup instanceof MigrateProcessInterface) {
@trigger_error('Passing a migration process plugin as the fifth argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268', E_USER_DEPRECATED);
$this->migrationPlugin = $migrate_lookup;
$migrate_lookup = \Drupal::service('migrate.lookup');
}
elseif (!$migrate_lookup instanceof MigrateLookupInterface) {
throw new \InvalidArgumentException("The fifth argument to " . __METHOD__ . " must be an instance of MigrateLookupInterface.");
}
$this->moduleHandler = $module_handler;
$this->migrateLookup = $migrate_lookup;
@ -123,22 +99,10 @@ class BlockVisibility extends ProcessPluginBase implements ContainerFactoryPlugi
];
foreach ($roles as $key => $role_id) {
// This BC layer is included because if the plugin constructor was
// called in the legacy way with a migration_lookup process plugin, it
// may have been preconfigured with a different migration to look up
// against. While this is unlikely, for maximum BC we will continue to
// use the plugin to do the lookup if it is provided, and support for
// this will be removed in Drupal 9.
if ($this->migrationPlugin) {
$roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
$lookup_result = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'], [$role_id]);
if ($lookup_result) {
$roles[$key] = $lookup_result[0]['id'];
}
else {
$lookup_result = $this->migrateLookup->lookup(['d6_user_role', 'd7_user_role'], [$role_id]);
if ($lookup_result) {
$roles[$key] = $lookup_result[0]['id'];
}
}
}
$visibility['user_role']['roles'] = array_combine($roles, $roles);
}

View File

@ -1,78 +0,0 @@
<?php
namespace Drupal\block\Tests;
@trigger_error(__NAMESPACE__ . '\BlockTestBase is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\block\Functional\BlockTestBase, see https://www.drupal.org/node/2901823.', E_USER_DEPRECATED);
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat;
/**
* Provides setup and helper methods for block module tests.
*
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
* Use \Drupal\Tests\block\Functional\BlockTestBase.
*
* @see https://www.drupal.org/node/2901823
*/
abstract class BlockTestBase extends WebTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['block', 'filter', 'test_page_test', 'help', 'block_test'];
/**
* A list of theme regions to test.
*
* @var array
*/
protected $regions;
/**
* A test user with administrative privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
// Use the test page as the front page.
$this->config('system.site')->set('page.front', '/test-page')->save();
// Create Full HTML text format.
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
]);
$full_html_format->save();
// Create and log in an administrative user having access to the Full HTML
// text format.
$this->adminUser = $this->drupalCreateUser([
'administer blocks',
$full_html_format->getPermissionName(),
'access administration pages',
]);
$this->drupalLogin($this->adminUser);
// Define the existing regions.
$this->regions = [
'header',
'sidebar_first',
'content',
'sidebar_second',
'footer',
];
$block_storage = $this->container->get('entity_type.manager')->getStorage('block');
$blocks = $block_storage->loadByProperties(['theme' => $this->config('system.theme')->get('default')]);
foreach ($blocks as $block) {
$block->delete();
}
}
}

View File

@ -1,50 +0,0 @@
<?php
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockPluginId;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests legacy usage of BlockPluginId.
*
* @group block
* @group legacy
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockPluginId
*/
class LegacyBlockPluginIdTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$container = new ContainerBuilder();
$container->set('migrate.lookup', $migrate_lookup->reveal());
\Drupal::setContainer($container);
}
/**
* Tests legacy construction.
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockPluginId::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testConstruct() {
$process_plugin = $this->prophesize(MigrateProcessInterface::class);
$process_plugin->transform(1, $this->migrateExecutable, $this->row, 'destination_property')->willReturn(3);
$block = $this->prophesize(BlockContent::class);
$block->uuid()->willReturn('123456789');
$storage = $this->prophesize(EntityStorageInterface::class);
$storage->load(3)->willReturn($block->reveal());
$plugin = new BlockPluginId([], '', [], $storage->reveal(), $process_plugin->reveal());
$this->assertSame('block_content:123456789', $plugin->transform(['block', 1], $this->migrateExecutable, $this->row, 'destination_property'));
}
}

View File

@ -1,135 +0,0 @@
<?php
namespace Drupal\Tests\block\Unit\Plugin\migrate\process;
use Drupal\block\Plugin\migrate\process\BlockVisibility;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate\MigrateLookupInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
/**
* Tests the block_visibility process plugin.
*
* @coversDefaultClass \Drupal\block\Plugin\migrate\process\BlockVisibility
*
* @group block
* @group legacy
*/
class LegacyBlockVisibilityTest extends MigrateProcessTestCase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$migrate_lookup = $this->prophesize(MigrateLookupInterface::class);
$container = new ContainerBuilder();
$container->set('migrate.lookup', $migrate_lookup->reveal());
\Drupal::setContainer($container);
$this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->plugin = new BlockVisibility([], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformNoData() {
$transformed_value = $this->plugin->transform([0, '', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformSinglePageWithFront() {
$visibility = $this->plugin->transform([0, '<front>', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertTrue($visibility['request_path']['negate']);
$this->assertSame('<front>', $visibility['request_path']['pages']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformMultiplePagesWithFront() {
$visibility = $this->plugin->transform([1, "foo\n/bar\rbaz\r\n<front>", []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('request_path', $visibility['request_path']['id']);
$this->assertFalse($visibility['request_path']['negate']);
$this->assertSame("/foo\n/bar\n/baz\n<front>", $visibility['request_path']['pages']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformPhpEnabled() {
$this->moduleHandler->moduleExists('php')->willReturn(TRUE);
$visibility = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame('php', $visibility['php']['id']);
$this->assertFalse($visibility['php']['negate']);
$this->assertSame('<?php', $visibility['php']['php']);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformPhpDisabled() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$transformed_value = $this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertEmpty($transformed_value);
}
/**
* Tests Transform.
*
* @covers ::transform
*
* @expectedDeprecation Passing a migration process plugin as the fifth argument to Drupal\block\Plugin\migrate\process\BlockVisibility::__construct is deprecated in drupal:8.8.0 and will throw an error in drupal:9.0.0. Pass the migrate.lookup service instead. See https://www.drupal.org/node/3047268
*/
public function testTransformException() {
$this->moduleHandler->moduleExists('php')->willReturn(FALSE);
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
$this->row = $this->getMockBuilder('Drupal\migrate\Row')
->disableOriginalConstructor()
->setMethods(['getSourceProperty'])
->getMock();
$this->row->expects($this->exactly(2))
->method('getSourceProperty')
->willReturnMap([['bid', 99], ['module', 'foobar']]);
$this->plugin = new BlockVisibility(['skip_php' => TRUE], 'block_visibility_pages', [], $this->moduleHandler->reveal(), $migration_plugin->reveal());
$this->expectException(MigrateSkipRowException::class);
$this->expectExceptionMessage("The block with bid '99' from module 'foobar' will have no PHP or request_path visibility configuration.");
$this->plugin->transform([2, '<?php', []], $this->migrateExecutable, $this->row, 'destinationproperty');
}
}