Issue #2325185 by dawehner, tim.plunkett: Convert views_element_info() to Element classes.
parent
dfecbdd429
commit
eb23f0e816
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\views\Element\View.
|
||||
*/
|
||||
|
||||
namespace Drupal\views\Element;
|
||||
|
||||
use Drupal\Core\Render\Element\RenderElement;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Provides a render element to display a view.
|
||||
*
|
||||
* @todo Annotate once https://www.drupal.org/node/2326409 is in.
|
||||
* RenderElement("view")
|
||||
*/
|
||||
class View extends RenderElement {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getInfo() {
|
||||
$class = get_class($this);
|
||||
return array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#pre_render' => array(
|
||||
array($class, 'preRenderViewElement'),
|
||||
),
|
||||
'#name' => NULL,
|
||||
'#display_id' => 'default',
|
||||
'#arguments' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* View element pre render callback.
|
||||
*/
|
||||
public static function preRenderViewElement($element) {
|
||||
$element['#attributes']['class'][] = 'views-element-container';
|
||||
|
||||
$view = Views::getView($element['#name']);
|
||||
if ($view && $view->access($element['#display_id'])) {
|
||||
$element['view'] = $view->preview($element['#display_id'], $element['#arguments']);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
|
@ -47,11 +47,13 @@ function views_help($route_name, RouteMatchInterface $route_match) {
|
|||
|
||||
/**
|
||||
* Implements hook_element_info().
|
||||
*
|
||||
* @todo Remove once https://www.drupal.org/node/2326409 is in.
|
||||
*/
|
||||
function views_element_info() {
|
||||
$types['view'] = array(
|
||||
'#theme_wrappers' => array('container'),
|
||||
'#pre_render' => array('views_pre_render_view_element'),
|
||||
'#pre_render' => array('\Drupal\views\Element\View::preRenderViewElement'),
|
||||
'#name' => NULL,
|
||||
'#display_id' => 'default',
|
||||
'#arguments' => array(),
|
||||
|
@ -90,20 +92,6 @@ function views_views_pre_render($view) {
|
|||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* View element pre render callback.
|
||||
*/
|
||||
function views_pre_render_view_element($element) {
|
||||
$element['#attributes']['class'][] = 'views-element-container';
|
||||
|
||||
$view = Views::getView($element['#name']);
|
||||
if ($view && $view->access($element['#display_id'])) {
|
||||
$element['view'] = $view->preview($element['#display_id'], $element['#arguments']);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue