Commit fd9804d8 authored by alexpott's avatar alexpott

Issue #2014215 by sdboyer: Shift render array defaults back out onto BlockRenderController .

parent 0cc160db
......@@ -62,9 +62,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$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 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
// 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()) {
......
......@@ -67,9 +67,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
// @todo Clean up when http://drupal.org/node/1874498 lands.
list(, $uuid) = explode(':', $this->getPluginId());
if ($block = entity_load_by_uuid('custom_block', $uuid)) {
......
......@@ -224,33 +224,4 @@ public function submit($form, &$form_state) {
* @see \Drupal\block\BlockBase::submit()
*/
public function blockSubmit($form, &$form_state) {}
/**
* Implements \Drupal\block\BlockInterface::build().
*/
public function build() {
$build = array();
$plugin_id = $this->getPluginId();
if ($content = $this->blockBuild()) {
$build = array(
'#theme' => 'block',
'content' => $content,
'#configuration' => $this->configuration,
'#plugin_id' => $plugin_id,
);
$build['#configuration']['label'] = check_plain($this->configuration['label']);
}
list($base_id) = explode(':', $plugin_id);
drupal_alter(array('block_view', "block_view_$base_id"), $build, $this);
return $build;
}
/**
* 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();
}
......@@ -36,7 +36,25 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
$build = array();
foreach ($entities as $entity_id => $entity) {
$build[$entity_id] = $entity->getPlugin()->build();
$plugin = $entity->getPlugin();
$plugin_id = $plugin->getPluginId();
if ($content = $plugin->build()) {
$configuration = $plugin->getConfig();
$build[$entity_id] = array(
'#theme' => 'block',
'content' => $content,
'#configuration' => $configuration,
'#plugin_id' => $plugin_id,
);
$build[$entity_id]['#configuration']['label'] = check_plain($configuration['label']);
}
else {
$build[$entity_id] = array();
}
list($base_id) = explode(':', $plugin_id);
drupal_alter(array('block_view', "block_view_$base_id"), $build[$entity_id], $plugin);
// @todo Remove after fixing http://drupal.org/node/1989568.
$build[$entity_id]['#block'] = $entity;
......
......@@ -92,18 +92,7 @@ public function testBlockInterface() {
$this->assertIdentical($display_block->form(array(), $form_state), $expected_form, 'Only the expected form elements were present.');
$expected_build = array(
'#theme' => 'block',
'content' => array(
'#children' => 'My custom display message.',
),
'#configuration' => array(
'label' => 'Custom Display Message',
'display_message' => 'My custom display message.',
'module' => 'block_test',
'label_display' => BLOCK_LABEL_VISIBLE,
'cache' => DRUPAL_NO_CACHE,
),
'#plugin_id' => 'test_block_instantiation',
'#children' => 'My custom display message.',
);
// Ensure the build array is proper.
$this->assertIdentical($display_block->build(), $expected_build, 'The plugin returned the appropriate build array.');
......
......@@ -60,7 +60,7 @@ public function blockSubmit($form, &$form_state) {
/**
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#children' => $this->configuration['display_message'],
);
......
......@@ -34,9 +34,9 @@ public function settings() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#children' => \Drupal::state()->get('block_test.content'),
);
......
......@@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$current_bid = 0;
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
......
......@@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#theme' => 'comment_block',
'#number' => $this->configuration['block_count'],
......
......@@ -652,8 +652,8 @@ function forum_form_node_form_alter(&$form, &$form_state, $form_id) {
*
* This function can be used as a #pre_render callback.
*
* @see \Drupal\forum\Plugin\block\block\NewTopicsBlock::blockBuild()
* @see \Drupal\forum\Plugin\block\block\ActiveTopicsBlock::blockBuild()
* @see \Drupal\forum\Plugin\block\block\NewTopicsBlock::build()
* @see \Drupal\forum\Plugin\block\block\ActiveTopicsBlock::build()
*/
function forum_block_view_pre_render($elements) {
$result = $elements['#query']->execute();
......
......@@ -22,9 +22,9 @@
class ActiveTopicsBlock extends ForumBlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$query = db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
......
......@@ -22,9 +22,9 @@
class NewTopicsBlock extends ForumBlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$query = db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
......
......@@ -31,9 +31,9 @@ function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$build = array();
$path = drupal_is_front_page() ? '<front>' : current_path();
list($plugin_id, $type) = explode(':', $this->getPluginId());
......
......@@ -24,9 +24,9 @@
class MenuBlock extends SystemMenuBlock {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
list($plugin, $menu) = explode(':', $this->getPluginId());
return menu_tree($menu);
}
......
......@@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
if ($nodes = node_get_recent($this->configuration['block_count'])) {
return array(
'#theme' => 'node_recent_block',
......
......@@ -39,9 +39,9 @@ public function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#theme' => 'feed_icon',
'#url' => 'rss.xml',
......
......@@ -30,9 +30,9 @@ public function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(drupal_get_form('search_block_form'));
}
......
......@@ -23,9 +23,9 @@
class ShortcutsBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
shortcut_renderable_links(shortcut_current_displayed_set()),
);
......
......@@ -116,9 +116,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$content = array();
if ($this->day_list) {
......
......@@ -38,9 +38,9 @@ public function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#children' => $this->help,
);
......
......@@ -23,9 +23,9 @@
class SystemMainBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
drupal_set_page_content()
);
......
......@@ -33,9 +33,9 @@ public function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
list($plugin, $derivative) = explode(':', $this->getPluginId());
// Derivatives are prefixed with 'menu-'.
$menu = substr($derivative, 5);
......
......@@ -23,9 +23,9 @@
class SystemPoweredByBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
return array(
'#children' => theme('system_powered_by'),
);
......
......@@ -30,9 +30,9 @@ public function access() {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$form = drupal_get_form('user_login_form');
unset($form['name']['#attributes']['autofocus']);
unset($form['name']['#description']);
......
......@@ -62,9 +62,9 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
// 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 @@ public function blockSubmit($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
// Count users active within the defined period.
$interval = REQUEST_TIME - $this->configuration['seconds_online'];
......
......@@ -69,9 +69,9 @@ public function form($form, &$form_state) {
}
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
if ($output = $this->view->executeDisplay($this->displayID)) {
$output = $this->view->executeDisplay($this->displayID);
// Set the label to the title configured in the view.
......
......@@ -23,9 +23,9 @@
class ViewsExposedFilterBlock extends ViewsBlock {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
* {@inheritdoc}
*/
protected function blockBuild() {
public function build() {
$output = $this->view->display_handler->viewExposedFormBlocks();
// Before returning the block output, convert it to a renderable array with
// contextual links.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment