Issue #1934420 by derhasi: Allow area handlers to return a render array.
parent
32111ed049
commit
467590dc10
|
@ -37,8 +37,9 @@ class ListingEmpty extends AreaPluginBase {
|
|||
) ,
|
||||
'#access' => _node_add_access()
|
||||
);
|
||||
return drupal_render($element);
|
||||
return $element;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -159,7 +159,13 @@ abstract class AreaPluginBase extends HandlerBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Render the area
|
||||
* Render the area.
|
||||
*
|
||||
* @param bool $empty
|
||||
* (optional) Indicator if view result is empty or not. Defaults to FALSE.
|
||||
*
|
||||
* @return array
|
||||
* In any case we need a valid Drupal render array to return.
|
||||
*/
|
||||
public abstract function render($empty = FALSE);
|
||||
|
||||
|
|
|
@ -27,7 +27,13 @@ class Broken extends AreaPluginBase {
|
|||
public function defineOptions() { return array(); }
|
||||
public function ensureMyTable() { /* No table to ensure! */ }
|
||||
public function query($group_by = FALSE) { /* No query to run */ }
|
||||
function render($empty = FALSE) { return ''; }
|
||||
/**
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
// Simply render nothing by returning an empty render array.
|
||||
return array();
|
||||
}
|
||||
public function buildOptionsForm(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
|
|
|
@ -103,13 +103,11 @@ class Entity extends AreaPluginBase {
|
|||
}
|
||||
$entity_id = $this->globalTokenReplace($entity_id);
|
||||
if ($entity = entity_load($this->entityType, $entity_id)) {
|
||||
$build = entity_view($entity, $this->options['view_mode']);
|
||||
// @todo Support to just return a render array.
|
||||
return drupal_render($build);
|
||||
return entity_view($entity, $this->options['view_mode']);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,12 +57,12 @@ class Result extends AreaPluginBase {
|
|||
|
||||
|
||||
/**
|
||||
* Find out the information to render.
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
// Must have options and does not work on summaries.
|
||||
if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
|
||||
return;
|
||||
return array();
|
||||
}
|
||||
$output = '';
|
||||
$format = $this->options['content'];
|
||||
|
@ -99,7 +99,10 @@ class Result extends AreaPluginBase {
|
|||
if (!empty($total)) {
|
||||
$output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format));
|
||||
}
|
||||
return $output;
|
||||
// Return as render array.
|
||||
return array(
|
||||
'#markup' => $output,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,12 +49,18 @@ class Text extends AreaPluginBase {
|
|||
parent::submitOptionsForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
$format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
return $this->render_textarea($this->options['content'], $format);
|
||||
return array(
|
||||
'#markup' => $this->render_textarea($this->options['content'], $format),
|
||||
);
|
||||
}
|
||||
return '';
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,12 +44,17 @@ class TextCustom extends AreaPluginBase {
|
|||
public function submitOptionsForm(&$form, &$form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
return $this->render_textarea($this->options['content']);
|
||||
return array(
|
||||
'#markup' => $this->render_textarea($this->options['content']),
|
||||
);
|
||||
}
|
||||
|
||||
return '';
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,10 +59,11 @@ class Title extends AreaPluginBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements \Drupal\views\Plugins\views\area\AreaPluginBase::render();
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
// Do nothing for this handler.
|
||||
// Do nothing for this handler by returning an empty render array.
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class View extends AreaPluginBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Render the area
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
if (!empty($this->options['view_to_insert'])) {
|
||||
|
@ -64,7 +64,7 @@ class View extends AreaPluginBase {
|
|||
|
||||
$view = views_get_view($view_name);
|
||||
if (empty($view) || !$view->access($display_id)) {
|
||||
return;
|
||||
return array();
|
||||
}
|
||||
$view->setDisplay($display_id);
|
||||
|
||||
|
@ -78,15 +78,21 @@ class View extends AreaPluginBase {
|
|||
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
|
||||
}
|
||||
else {
|
||||
// Current $view->preview() does not return a render array, so we have
|
||||
// to build a markup out if it.
|
||||
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
|
||||
return $view->preview($display_id, $this->view->args);
|
||||
return array(
|
||||
'#markup' => $view->preview($display_id, $this->view->args),
|
||||
);
|
||||
}
|
||||
else {
|
||||
return $view->preview($display_id);
|
||||
return array(
|
||||
'#markup' => $view->preview($display_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2466,10 +2466,22 @@ abstract class DisplayPluginBase extends PluginBase {
|
|||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render one of the available areas.
|
||||
*
|
||||
* @param string $area
|
||||
* Identifier of the specific area to render.
|
||||
* @param bool $empty
|
||||
* (optional) Indicator whether or not the view result is empty. Defaults to
|
||||
* FALSE
|
||||
*
|
||||
* @return array
|
||||
* A render array for the given area.
|
||||
*/
|
||||
public function renderArea($area, $empty = FALSE) {
|
||||
$return = '';
|
||||
foreach ($this->getHandlers($area) as $area) {
|
||||
$return .= $area->render($empty);
|
||||
$return = array();
|
||||
foreach ($this->getHandlers($area) as $key => $area_handler) {
|
||||
$return[$key] = $area_handler->render($empty);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
|
|
@ -58,16 +58,16 @@ class AreaTextTest extends ViewUnitTestBase {
|
|||
$this->executeView($view);
|
||||
|
||||
$view->display_handler->handlers['header']['area']->options['format'] = $this->randomString();
|
||||
$this->assertEqual(NULL, $view->display_handler->handlers['header']['area']->render(), 'Non existant format should return nothing');
|
||||
$this->assertEqual(array('#markup' => ''), $view->display_handler->handlers['header']['area']->render(), 'Non existant format should return empty markup.');
|
||||
|
||||
$view->display_handler->handlers['header']['area']->options['format'] = filter_default_format();
|
||||
$this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(), 'Existant format should return something');
|
||||
$this->assertEqual(array('#markup' => check_markup($string)), $view->display_handler->handlers['header']['area']->render(), 'Existant format should return something');
|
||||
|
||||
// Empty results, and it shouldn't be displayed .
|
||||
$this->assertEqual('', $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
|
||||
$this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
|
||||
// Empty results, and it should be displayed.
|
||||
$view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
|
||||
$this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result, but empty enabled lead to a full header');
|
||||
$this->assertEqual(array('#markup' => check_markup($string)), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result, but empty enabled lead to a full header');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<?php print render($title_suffix); ?>
|
||||
<?php if ($header): ?>
|
||||
<div class="view-header">
|
||||
<?php print $header; ?>
|
||||
<?php print render($header); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
|||
</div>
|
||||
<?php elseif ($empty): ?>
|
||||
<div class="view-empty">
|
||||
<?php print $empty; ?>
|
||||
<?php print render($empty); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
@ -77,7 +77,7 @@
|
|||
|
||||
<?php if ($footer): ?>
|
||||
<div class="view-footer">
|
||||
<?php print $footer; ?>
|
||||
<?php print render($footer); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -40,12 +40,15 @@ class TestExample extends AreaPluginBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overrides Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
* Implements \Drupal\views\Plugin\views\area\AreaPluginBase::render().
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
return $this->globalTokenReplace($this->options['string']);
|
||||
return array(
|
||||
'#markup' => $this->globalTokenReplace($this->options['string']),
|
||||
);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue