Commit 281c6f09 authored by catch's avatar catch

Issue #2815379 by andypost, jibran, naveenvalecha, tim.plunkett: Move message,...

Issue #2815379 by andypost, jibran, naveenvalecha, tim.plunkett: Move message, goto, and email action plugins to Drupal\Core\Action
parent e5b70636
......@@ -379,3 +379,33 @@ block.settings.field_block:*:*:*:
action.configuration.entity:*:*:
type: action_configuration_default
label: 'Entity action'
action.configuration.action_send_email_action:
type: mapping
label: 'Send email configuration'
mapping:
recipient:
type: string
label: 'Recipient'
subject:
type: label
label: 'Subject'
message:
type: text
label: 'Message'
action.configuration.action_goto_action:
type: mapping
label: 'Redirect to URL configuration'
mapping:
url:
type: string
label: 'URL'
action.configuration.action_message_action:
type: mapping
label: 'Display a message to the user configuration'
mapping:
message:
type: text
label: 'Message'
<?php
namespace Drupal\action\Plugin\Action;
namespace Drupal\Core\Action\Plugin\Action;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Component\Utility\EmailValidatorInterface;
......
<?php
namespace Drupal\action\Plugin\Action;
namespace Drupal\Core\Action\Plugin\Action;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Access\AccessResult;
......
<?php
namespace Drupal\action\Plugin\Action;
namespace Drupal\Core\Action\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Action\ConfigurableActionBase;
......
<?php
/**
* @file
* Post update functions for Action module.
*/
use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\system\ActionConfigEntityInterface;
/**
* Moves action plugins to core.
*/
function action_post_update_move_plugins(&$sandbox = NULL) {
$resave_ids = [
'action_goto_action',
'action_message_action',
'action_send_email_action',
];
\Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'action', function (ActionConfigEntityInterface $action) use ($resave_ids) {
// Save entity to recalculate dependencies.
return $action->isConfigurable() && in_array($action->getPlugin()->getPluginId(), $resave_ids, TRUE);
});
}
......@@ -7,34 +7,3 @@ action.settings:
recursion_limit:
type: integer
label: 'Recursion limit for actions'
action.configuration.action_send_email_action:
type: mapping
label: 'Send email configuration'
mapping:
recipient:
type: string
label: 'Recipient'
subject:
type: label
label: 'Subject'
message:
type: text
label: 'Message'
action.configuration.action_goto_action:
type: mapping
label: 'Redirect to URL configuration'
mapping:
url:
type: string
label: 'URL'
action.configuration.action_message_action:
type: mapping
label: 'Display a message to the user configuration'
mapping:
message:
type: text
label: 'Message'
<?php
/**
* @file
* Contains database additions to for testing upgrade path for action plugins.
*
* @see https://www.drupal.org/node/2815379
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
// Structure of configured email, goto, and message actions.
$actions[] = Yaml::decode(file_get_contents(__DIR__ . '/system.action.goto_2815379.yml'));
$actions[] = Yaml::decode(file_get_contents(__DIR__ . '/system.action.message_2815379.yml'));
$actions[] = Yaml::decode(file_get_contents(__DIR__ . '/system.action.send_email_2815379.yml'));
foreach ($actions as $action) {
$connection->insert('config')
->fields([
'collection',
'name',
'data',
])
->values([
'collection' => '',
'name' => 'system.action.' . $action['id'],
'data' => serialize($action),
])
->execute();
}
// Enable action module.
$extensions = $connection->select('config')
->fields('config', ['data'])
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['module' => ['action' => 0]])),
])
->condition('name', 'core.extension')
->execute();
uuid: 2573293e-c7b6-4f53-905a-10ec7c55f3d0
langcode: en
status: true
dependencies:
module:
- action
id: goto_2815379
label: 'Goto action'
type: system
plugin: action_goto_action
configuration:
url: /user
uuid: e34302d4-3afc-40ec-bdf0-cbd23e2f7f52
langcode: en
status: true
dependencies:
module:
- action
id: message_2815379
label: 'Display message'
type: system
plugin: action_message_action
configuration:
message: 'Test message'
uuid: 741d330c-9260-45f8-8a81-67d2cd430f4a
langcode: en
status: true
dependencies:
module:
- action
id: send_email_2815379
label: 'Send email'
type: system
plugin: action_send_email_action
configuration:
recipient: drupal@example.com
subject: Subject
message: Message
<?php
namespace Drupal\Tests\system\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\system\Entity\Action;
/**
* Tests moving email, goto, and message actions to core namespace.
*
* @group Update
* @group legacy
*/
class MoveActionsToCoreTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../../tests/fixtures/update/drupal-8.actions-2815379.php',
];
}
/**
* Tests upgrading actions to core namespace.
*
* @see action_post_update_move_plugins()
*/
public function testUpdateActionPlugins() {
$actions = ['goto_2815379', 'message_2815379', 'send_email_2815379'];
$before = [];
$dependencies = ['module' => ['action']];
foreach ($actions as $key) {
$config = \Drupal::configFactory()->get('system.action.' . $key);
$this->assertSame($dependencies, $config->get('dependencies'));
$before[$key] = $config->getRawData();
}
$this->runUpdates();
foreach ($actions as $key) {
/** @var \Drupal\system\Entity\Action $key */
$action = Action::load($key);
$this->assertSame([], $action->getDependencies());
// Tests that other properties remains the same.
$config = \Drupal::configFactory()->get('system.action.' . $key);
$after = $before[$key];
$after['dependencies'] = [];
$this->assertSame($after, $config->getRawData());
}
}
}
<?php
namespace Drupal\Tests\action\Kernel\Plugin\Action;
namespace Drupal\KernelTests\Core\Action;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\KernelTests\KernelTestBase;
......@@ -16,7 +16,7 @@ class EmailActionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system', 'user', 'action', 'dblog'];
public static $modules = ['system', 'user', 'dblog'];
/**
* {@inheritdoc}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment