Issue #1969276 by effulgentsia, tim.plunkett, EclipseGc: Refactor block plugins to make room for a BlockBase::build() implementation.
parent
e52e0fc463
commit
2212a5fed8
|
@ -62,9 +62,9 @@ class AggregatorCategoryBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$id = $this->getPluginId();
|
||||
if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
|
||||
$result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid));
|
||||
|
|
|
@ -62,9 +62,9 @@ class AggregatorFeedBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
// Plugin IDs look something like this: aggregator_feed_block:1.
|
||||
list(, $id) = explode(':', $this->getPluginId());
|
||||
if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
|
||||
|
|
|
@ -73,9 +73,9 @@ class CustomBlockBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
// @todo Clean up when http://drupal.org/node/1874498 lands.
|
||||
list(, $uuid) = explode(':', $this->getPluginId());
|
||||
if ($block = entity_load_by_uuid('custom_block', $uuid)) {
|
||||
|
|
|
@ -496,4 +496,21 @@ abstract class BlockBase extends PluginBase implements BlockInterface {
|
|||
*/
|
||||
public function blockSubmit($form, &$form_state) {}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockInterface::build().
|
||||
*/
|
||||
public function build() {
|
||||
// @todo Move block rendering code common to all blocks from
|
||||
// BlockRenderController to here: http://drupal.org/node/1927608.
|
||||
return $this->blockBuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds block-type-specific render handling for the block plugin.
|
||||
*
|
||||
* @return array
|
||||
* A renderable array representing the content of this block.
|
||||
*/
|
||||
abstract protected function blockBuild();
|
||||
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ class TestCacheBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
'#children' => state()->get('block_test.content'),
|
||||
);
|
||||
|
|
|
@ -59,9 +59,9 @@ class BookNavigationBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$current_bid = 0;
|
||||
if ($node = menu_get_object()) {
|
||||
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
|
||||
|
|
|
@ -59,9 +59,9 @@ class RecentCommentsBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
'#theme' => 'comment_block',
|
||||
'#number' => $this->configuration['block_count'],
|
||||
|
|
|
@ -22,9 +22,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class ActiveTopicsBlock extends ForumBlockBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$query = db_select('forum_index', 'f')
|
||||
->fields('f')
|
||||
->addTag('node_access')
|
||||
|
|
|
@ -22,9 +22,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class NewTopicsBlock extends ForumBlockBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$query = db_select('forum_index', 'f')
|
||||
->fields('f')
|
||||
->addTag('node_access')
|
||||
|
|
|
@ -31,9 +31,9 @@ class LanguageBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$build = array();
|
||||
$path = drupal_is_front_page() ? '<front>' : current_path();
|
||||
list($plugin_id, $type) = explode(':', $this->getPluginId());
|
||||
|
|
|
@ -24,9 +24,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class MenuBlock extends SystemMenuBlock {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
list($plugin, $menu) = explode(':', $this->getPluginId());
|
||||
return menu_tree($menu);
|
||||
}
|
||||
|
|
|
@ -59,9 +59,9 @@ class RecentContentBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
if ($nodes = node_get_recent($this->configuration['block_count'])) {
|
||||
return array(
|
||||
'#theme' => 'node_recent_block',
|
||||
|
|
|
@ -39,9 +39,9 @@ class SyndicateBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
'#theme' => 'feed_icon',
|
||||
'#url' => 'rss.xml',
|
||||
|
|
|
@ -30,9 +30,9 @@ class SearchBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(drupal_get_form('search_block_form'));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class ShortcutsBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
shortcut_renderable_links(shortcut_current_displayed_set()),
|
||||
);
|
||||
|
|
|
@ -116,9 +116,9 @@ class StatisticsPopularBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$content = array();
|
||||
|
||||
if ($this->day_list) {
|
||||
|
|
|
@ -38,9 +38,9 @@ class SystemHelpBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
'#children' => $this->help,
|
||||
);
|
||||
|
|
|
@ -23,9 +23,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class SystemMainBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
drupal_set_page_content()
|
||||
);
|
||||
|
|
|
@ -33,9 +33,9 @@ class SystemMenuBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
list($plugin, $derivative) = explode(':', $this->getPluginId());
|
||||
// Derivatives are prefixed with 'menu-'.
|
||||
$menu = substr($derivative, 5);
|
||||
|
|
|
@ -23,9 +23,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class SystemPoweredByBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
return array(
|
||||
'#children' => theme('system_powered_by'),
|
||||
);
|
||||
|
|
|
@ -30,9 +30,9 @@ class UserLoginBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$form = drupal_get_form('user_login_form');
|
||||
unset($form['name']['#attributes']['autofocus']);
|
||||
unset($form['name']['#description']);
|
||||
|
|
|
@ -62,9 +62,9 @@ class UserNewBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
// Retrieve a list of new users who have accessed the site successfully.
|
||||
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])->fetchAll();
|
||||
$build = array(
|
||||
|
|
|
@ -76,9 +76,9 @@ class UserOnlineBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
// Count users active within the defined period.
|
||||
$interval = REQUEST_TIME - $this->configuration['seconds_online'];
|
||||
|
||||
|
|
|
@ -71,9 +71,9 @@ class ViewsBlock extends BlockBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$output = $this->view->executeDisplay($this->displayID);
|
||||
// Set the label to the title configured in the view.
|
||||
$this->entity->set('label', filter_xss_admin($this->view->getTitle()));
|
||||
|
|
|
@ -23,9 +23,9 @@ use Drupal\Core\Annotation\Translation;
|
|||
class ViewsExposedFilterBlock extends ViewsBlock {
|
||||
|
||||
/**
|
||||
* Implements \Drupal\block\BlockBase::build().
|
||||
* Implements \Drupal\block\BlockBase::blockBuild().
|
||||
*/
|
||||
public function build() {
|
||||
protected function blockBuild() {
|
||||
$output = $this->view->display_handler->viewExposedFormBlocks();
|
||||
// Before returning the block output, convert it to a renderable array with
|
||||
// contextual links.
|
||||
|
|
Loading…
Reference in New Issue