Skip to content

Commit

Permalink
Issue #2206809 by damiankloip: Convert broken handlers to use a trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Catchpole committed Mar 7, 2014
1 parent a66e958 commit 9065f49
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 356 deletions.
@@ -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;
}

}
71 changes: 3 additions & 68 deletions core/modules/views/lib/Drupal/views/Plugin/views/area/Broken.php
Expand Up @@ -7,6 +7,8 @@

namespace Drupal\views\Plugin\views\area;

use Drupal\views\Plugin\views\BrokenHandlerTrait;

/**
* A special handler to take the place of missing or broken handlers.
*
Expand All @@ -15,30 +17,7 @@
* @PluginID("broken")
*/
class Broken extends AreaPluginBase {

/**
* {@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.
}
use BrokenHandlerTrait;

/**
* {@inheritdoc}
Expand All @@ -48,48 +27,4 @@ public function render($empty = FALSE) {
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;
}

}
Expand Up @@ -7,6 +7,8 @@

namespace Drupal\views\Plugin\views\argument;

use Drupal\views\Plugin\views\BrokenHandlerTrait;

/**
* A special handler to take the place of missing or broken handlers.
*
Expand All @@ -15,58 +17,6 @@
* @PluginID("broken")
*/
class Broken extends ArgumentPluginBase {

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; }
use BrokenHandlerTrait;

}
56 changes: 3 additions & 53 deletions core/modules/views/lib/Drupal/views/Plugin/views/field/Broken.php
Expand Up @@ -7,6 +7,8 @@

namespace Drupal\views\Plugin\views\field;

use Drupal\views\Plugin\views\BrokenHandlerTrait;

/**
* A special handler to take the place of missing or broken handlers.
*
Expand All @@ -15,58 +17,6 @@
* @PluginID("broken")
*/
class Broken extends FieldPluginBase {

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; }
use BrokenHandlerTrait;

}

0 comments on commit 9065f49

Please sign in to comment.