diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index 2525071..c71a9d2 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -74,11 +74,19 @@ public $relationship = NULL; /** + * Whether or not this handler is optional. + * + * @var bool + */ + protected $optional = FALSE; + + /** * Constructs a Handler object. */ public function __construct(array $configuration, $plugin_id, array $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->is_handler = TRUE; + $this->optional = isset($configuration['optional']) ? $configuration['optional'] : FALSE; } /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php index 64a63a0..b22f97f 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php @@ -19,7 +19,7 @@ class Broken extends AreaPluginBase { public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument/Broken.php index d74ab95..50f0081 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument/Broken.php @@ -19,7 +19,7 @@ class Broken extends ArgumentPluginBase { public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/field/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/field/Broken.php index 6310248..070a1eb 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/field/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/Broken.php @@ -19,7 +19,7 @@ class Broken extends FieldPluginBase { public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/Broken.php index 701cabb..1dab067 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/Broken.php @@ -27,7 +27,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o } public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/relationship/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/relationship/Broken.php index c891f00..fd582c0 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/relationship/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/relationship/Broken.php @@ -19,7 +19,7 @@ class Broken extends RelationshipPluginBase { public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/sort/Broken.php b/core/modules/views/lib/Drupal/views/Plugin/views/sort/Broken.php index 341bc8b..b598ddc 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/sort/Broken.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/sort/Broken.php @@ -19,7 +19,7 @@ class Broken extends SortPluginBase { public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->optional ? t('Optional handler is missing') : t('Broken/missing handler'); } public function defineOptions() { return array(); } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index fe5a233..6860ea5 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -888,7 +888,7 @@ function views_get_handler($item, $type, $override = NULL) { } // Finally, use the 'broken' handler. - return $manager->createInstance('broken'); + return $manager->createInstance('broken', array('optional' => $optional)); } /** diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Tests/HandlerTest.php b/core/modules/views_ui/lib/Drupal/views_ui/Tests/HandlerTest.php index b8ab21e..49a5998 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Tests/HandlerTest.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/HandlerTest.php @@ -7,6 +7,7 @@ namespace Drupal\views_ui\Tests; +use Drupal\Component\Utility\String; use Drupal\views\ViewExecutable; /** @@ -21,7 +22,7 @@ class HandlerTest extends UITestBase { * * @var array */ - public static $testViews = array('test_view_empty'); + public static $testViews = array('test_view_empty', 'test_view_broken', 'test_view_optional'); public static function getInfo() { return array( @@ -146,4 +147,34 @@ public function testUICRUD() { $this->assertTrue(isset($display['display_options'][$type_info['plural']][$id]), 'Ensure the field was added to the view itself.'); } + /** + * Test broken handlers. + */ + public function testBrokenHandlers() { + $this->drupalGet('admin/structure/views/view/test_view_broken/edit'); + + $handler_types = ViewExecutable::viewsHandlerTypes(); + foreach ($handler_types as $type => $type_info) { + $result = $this->xpath('//a[contains(@href, :href)]', array(':href' => url("admin/structure/views/nojs/config-item/test_view_broken/default/$type/id_broken"))); + $this->assertEqual(count($result), 1, String::format('Handler (%type) edit link found.', array('%type' => $type))); + debug((string) $result[0]); + $this->assertTrue(strpos((string) $result[0], t('Broken/missing handler')) !== FALSE, 'Ensure the broken handler text was found.'); + } + } + + /** + * Test optional handlers. + */ + public function testOptionalHandlers() { + $this->drupalGet('admin/structure/views/view/test_view_optional/edit'); + + $handler_types = ViewExecutable::viewsHandlerTypes(); + foreach ($handler_types as $type => $type_info) { + $result = $this->xpath('//a[contains(@href, :href)]', array(':href' => url("admin/structure/views/nojs/config-item/test_view_optional/default/$type/id_broken"))); + $this->assertEqual(count($result), 1, String::format('Handler (%type) edit link found.', array('%type' => $type))); + debug((string) $result[0]); + $this->assertTrue(strpos((string) $result[0], t('Optional handler is missing')) !== FALSE, 'Ensure the optional handler text was found.'); + } + } + }