Issue #2206809 by damiankloip: Convert broken handlers to use a trait.

8.0.x
Nathaniel Catchpole 2014-03-07 12:21:41 +00:00
parent a66e9586ec
commit 9065f499af
7 changed files with 121 additions and 356 deletions

View File

@ -0,0 +1,103 @@
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\BrokenHandlerTrait.
*/
namespace Drupal\views\Plugin\views;
/**
* A Trait for Views broken handlers.
*/
trait BrokenHandlerTrait {
/**
* Returns this handlers name in the UI.
*
* @see \Drupal\views\Plugin\views\PluginBase::defineOptions().
*/
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
/**
* The option definition for this handler.
*
* @see \Drupal\views\Plugin\views\PluginBase::defineOptions().
*/
public function defineOptions() {
return array();
}
/**
* Ensure the main table for this handler is in the query. This is used
* a lot.
*
* @see \Drupal\views\Plugin\views\HandlerBase::ensureMyTable().
*/
public function ensureMyTable() {
// No table to ensure.
}
/**
* Modify the views query.
*/
public function query($group_by = FALSE) {
/* No query to run */
}
/**
* Provides a form to edit options for this plugin.
*
* @see \Drupal\views\Plugin\views\PluginBase::defineOptions().
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* Determines if the handler is considered 'broken'.
*
* This means it's a placeholder used when a handler can't be found.
*
* @see \Drupal\views\Plugin\views\HandlerBase::broken().
*/
public function broken() {
return TRUE;
}
}

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Plugin\views\area; namespace Drupal\views\Plugin\views\area;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
/** /**
* A special handler to take the place of missing or broken handlers. * A special handler to take the place of missing or broken handlers.
* *
@ -15,30 +17,7 @@ namespace Drupal\views\Plugin\views\area;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends AreaPluginBase { class Broken extends AreaPluginBase {
use BrokenHandlerTrait;
/**
* {@inheritdoc}
*/
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
/**
* {@inheritdoc}
*/
public function defineOptions() {
return array();
}
/**
* {@inheritdoc}
*/
public function ensureMyTable() {
// No table to ensure.
}
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -48,48 +27,4 @@ class Broken extends AreaPluginBase {
return array(); return array();
} }
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* {@inheritdoc}
*/
public function broken() {
return TRUE;
}
} }

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Plugin\views\argument; namespace Drupal\views\Plugin\views\argument;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
/** /**
* A special handler to take the place of missing or broken handlers. * A special handler to take the place of missing or broken handlers.
* *
@ -15,58 +17,6 @@ namespace Drupal\views\Plugin\views\argument;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends ArgumentPluginBase { class Broken extends ArgumentPluginBase {
use BrokenHandlerTrait;
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
public function defineOptions() { return array(); }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* Determine if the handler is considered 'broken'
*/
public function broken() { return TRUE; }
} }

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Plugin\views\field; namespace Drupal\views\Plugin\views\field;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
/** /**
* A special handler to take the place of missing or broken handlers. * A special handler to take the place of missing or broken handlers.
* *
@ -15,58 +17,6 @@ namespace Drupal\views\Plugin\views\field;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends FieldPluginBase { class Broken extends FieldPluginBase {
use BrokenHandlerTrait;
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
public function defineOptions() { return array(); }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* Determine if the handler is considered 'broken'
*/
public function broken() { return TRUE; }
} }

View File

@ -7,6 +7,7 @@
namespace Drupal\views\Plugin\views\filter; namespace Drupal\views\Plugin\views\filter;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
@ -18,64 +19,12 @@ use Drupal\views\ViewExecutable;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends FilterPluginBase { class Broken extends FilterPluginBase {
use BrokenHandlerTrait;
/**
* Overrides \Drupal\views\Plugin\views\filter\FilterPluginBase::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
}
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
public function defineOptions() { return array(); }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildOptionsForm(&$form, &$form_state) { public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
} }
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* Determine if the handler is considered 'broken'
*/
public function broken() { return TRUE; }
} }

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Plugin\views\relationship; namespace Drupal\views\Plugin\views\relationship;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
/** /**
* A special handler to take the place of missing or broken handlers. * A special handler to take the place of missing or broken handlers.
* *
@ -15,80 +17,6 @@ namespace Drupal\views\Plugin\views\relationship;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends RelationshipPluginBase { class Broken extends RelationshipPluginBase {
use BrokenHandlerTrait;
/**
* {@inheritdoc}
*/
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
return array();
}
/**
* {@inheritdoc}
*/
public function ensureMyTable() {
// No table to ensure.
}
/**
* {@inheritdoc}
*/
public function query() {
// No query to run.
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* {@inheritdoc}
*/
public function broken() {
return TRUE;
}
} }

View File

@ -7,6 +7,8 @@
namespace Drupal\views\Plugin\views\sort; namespace Drupal\views\Plugin\views\sort;
use Drupal\views\Plugin\views\BrokenHandlerTrait;
/** /**
* A special handler to take the place of missing or broken handlers. * A special handler to take the place of missing or broken handlers.
* *
@ -15,58 +17,6 @@ namespace Drupal\views\Plugin\views\sort;
* @PluginID("broken") * @PluginID("broken")
*/ */
class Broken extends SortPluginBase { class Broken extends SortPluginBase {
use BrokenHandlerTrait;
public function adminLabel($short = FALSE) {
$args = array(
'@module' => $this->definition['original_configuration']['provider'],
);
return $this->isOptional() ? t('Optional handler is missing (Module: @module) …', $args) : t('Broken/missing handler (Module: @module) …', $args);
}
public function defineOptions() { return array(); }
public function ensureMyTable() { /* No table to ensure! */ }
public function query($group_by = FALSE) { /* No query to run */ }
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, &$form_state) {
if ($this->isOptional()) {
$description_top = t('The handler for this item is optional. The following details are available:');
}
else {
$description_top = t('The handler for this item is broken or missing. The following details are available:');
}
$items = array(
t('Module: @module', array('@module' => $this->definition['original_configuration']['provider'])),
t('Table: @table', array('@table' => $this->definition['original_configuration']['table'])),
t('Field: @field', array('@field' => $this->definition['original_configuration']['field'])),
);
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('form-item', 'description'),
),
'description_top' => array(
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
}
/**
* Determine if the handler is considered 'broken'
*/
public function broken() { return TRUE; }
} }