diff --git a/rabbit_hole.services.yml b/rabbit_hole.services.yml index 4d5b9ca..57c8882 100644 --- a/rabbit_hole.services.yml +++ b/rabbit_hole.services.yml @@ -1,4 +1,4 @@ services: - plugin.manager.rabbit_hole_behavior: - class: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorManager + plugin.manager.rabbit_hole_behavior_plugin: + class: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager parent: default_plugin_manager diff --git a/src/Annotation/RabbitHoleBehavior.php b/src/Annotation/RabbitHoleBehaviorPlugin.php similarity index 53% rename from src/Annotation/RabbitHoleBehavior.php rename to src/Annotation/RabbitHoleBehaviorPlugin.php index 660af2d..f7fcde8 100644 --- a/src/Annotation/RabbitHoleBehavior.php +++ b/src/Annotation/RabbitHoleBehaviorPlugin.php @@ -2,22 +2,22 @@ /** * @file - * Contains \Drupal\rabbit_hole\Annotation\RabbitHoleBehavior. + * Contains \Drupal\rabbit_hole\Annotation\RabbitHoleBehaviorPlugin. */ namespace Drupal\rabbit_hole\Annotation; -use Drupal\Component\Annotation; +use Drupal\Component\Annotation\Plugin; /** - * Defines a Rabbit hole action item annotation object. + * Defines a Rabbit hole behavior plugin item annotation object. * - * @see \Drupal\rabbit_hole\Plugin\RabbitHoleActionManager + * @see \Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager * @see plugin_api * * @Annotation */ -class RabbitHoleBehavior extends Plugin { +class RabbitHoleBehaviorPlugin extends Plugin { /** * The plugin ID. diff --git a/src/Plugin/RabbitHoleBehavior/DisplayPage.php b/src/Plugin/RabbitHoleBehavior/DisplayPage.php deleted file mode 100644 index 320e20c..0000000 --- a/src/Plugin/RabbitHoleBehavior/DisplayPage.php +++ /dev/null @@ -1,20 +0,0 @@ - 'details', - '#title' => $this->t('Redirect settings') + '#title' => $this->t('Redirect settings'), ]; $form['redirect']['redirect_path'] = [ '#type' => 'text', '#title' => $this->t('Redirect path'), - '#description' => $this->t('Enter the relative path or the full URL that the user should get redirected to. Query strings and fragments are supported, such as %example_url. You may enter tokens in this field.', [ - '%example_url' => 'http://www.example.com/?query=value#fragment', - ]), + '#description' => $this->t('Enter the relative path or the full URL that the user should get redirected to. Query strings and fragments are supported, such as %example_url. You may enter tokens in this field.', + ['%example_url' => 'http://www.example.com/?query=value#fragment']), '#default_value' => $this->path, ]; $form['redirect']['redirect_response'] = [ diff --git a/src/Plugin/RabbitHoleBehaviorBase.php b/src/Plugin/RabbitHoleBehaviorPluginBase.php similarity index 51% rename from src/Plugin/RabbitHoleBehaviorBase.php rename to src/Plugin/RabbitHoleBehaviorPluginBase.php index 7c1844d..ce5b771 100644 --- a/src/Plugin/RabbitHoleBehaviorBase.php +++ b/src/Plugin/RabbitHoleBehaviorPluginBase.php @@ -1,18 +1,17 @@ alterInfo('rabbit_hole_behavior_info'); - $this->setCacheBackend($cache_backend, 'rabbit_hole_behavior_plugins'); + $this->alterInfo('rabbit_hole_rabbit_hole_behavior_plugin_info'); + $this->setCacheBackend($cache_backend, 'rabbit_hole_rabbit_hole_behavior_plugin_plugins'); } } diff --git a/src/Tests/RabbitHoleBehaviorPluginTest.php b/src/Tests/RabbitHoleBehaviorPluginTest.php index 3d32cfd..13c3ab3 100644 --- a/src/Tests/RabbitHoleBehaviorPluginTest.php +++ b/src/Tests/RabbitHoleBehaviorPluginTest.php @@ -6,28 +6,21 @@ namespace Drupal\rabbit_hole\Tests; -use Drupal\simpletest\WebTestBase; +use Drupal\system\Tests\Plugin\PluginTestBase; /** * Test the functionality of the RabbitHoleBehavior plugin. * * @group rabbit_hole */ -class RabbitHoleBehaviorPluginTest extends WebTestBase { +class RabbitHoleBehaviorPluginTest extends PluginTestBase { /** * Modules to enable. * * @var array */ - public static $modules = ['rabbit_hole']; - - /** - * The installation profile to use with this test. - * - * @var string - */ - protected $profile = 'minimal'; + public static $modules = array('rabbit_hole'); /** * The plugin manager. @@ -39,11 +32,9 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { /** * {@inheritdoc} */ - public function setUp() { + protected function setUp() { parent::setUp(); - - // Set up the plugin manager. - $this->manager = \Drupal::service('plugin.manager.rabbit_hole_behavior'); + $this->manager = $this->container->get('plugin.manager.rabbit_hole_behavior_plugin'); } /** @@ -54,7 +45,7 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { $this->assertNotNull($this->manager, 'Drupal plugin service returned a rabbit hole behavior service.'); // Check that the behavior plugin manager is the type we expect. - $this->assertEqual(get_class($this->manager), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorManager'); + $this->assertEqual(get_class($this->manager), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginManager'); // Check the rabbit_hole module defines the expected number of behaviors. $behaviors = $this->manager->getDefinitions(); @@ -78,7 +69,7 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { public function testAccessDeniedPlugin() { // Check we can create an instance of the plugin. $plugin = $this->manager->createInstance('access_denied', ['of' => 'configuration values']); - $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehavior\AccessDenied', 'The access denied plugin is the correct type.'); + $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\AccessDenied', 'The access denied plugin is the correct type.'); // Test the settings form. $form = $form_state = []; @@ -97,7 +88,7 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { public function testDisplayPagePlugin() { // Check we can create an instance of the plugin. $plugin = $this->manager->createInstance('display_page', ['of' => 'configuration values']); - $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehavior\DisplayPage', 'The display page plugin is the correct type.'); + $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\DisplayPage', 'The display page plugin is the correct type.'); // Test the settings form. $form = $form_state = []; @@ -108,7 +99,6 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { // Check that the plugin performs the expected action. // TODO: Check that $plugin->performAction() throws nothing and returns // nothing. - } /** @@ -117,7 +107,7 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { public function testPageNotFoundPlugin() { // Check we can create an instance of the plugin. $plugin = $this->manager->createInstance('page_not_found', ['of' => 'configuration values']); - $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehavior\PageNotFound', 'The page not found plugin is the correct type.'); + $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageNotFound', 'The page not found plugin is the correct type.'); // Test the settings form. $form = $form_state = []; @@ -136,7 +126,7 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { public function testPageRedirectPlugin() { // Check we can create an instance of the plugin. $plugin = $this->manager->createInstance('page_redirect', ['of' => 'configuration values']); - $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehavior\PageRedirect', 'The page redirect plugin is the correct type.'); + $this->assertEqual(get_class($plugin), 'Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageRedirect', 'The page redirect plugin is the correct type.'); // Test the settings form. $form = $form_state = []; @@ -148,4 +138,5 @@ class RabbitHoleBehaviorPluginTest extends WebTestBase { // TODO: Check that $plugin->performAction() does what it's supposed to, // whatever that is. } + }