abstract class ViewBlockBase in Content Planner 8
Class ViewBlockBase.
@package Drupal\content_planner\Plugin\DashboardBlock
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\content_planner\DashboardBlockBase implements DashboardBlockInterface, ContainerFactoryPluginInterface uses ConfigFormBaseTrait
- class \Drupal\content_planner\Plugin\DashboardBlock\ViewBlockBase
- class \Drupal\content_planner\DashboardBlockBase implements DashboardBlockInterface, ContainerFactoryPluginInterface uses ConfigFormBaseTrait
Expanded class hierarchy of ViewBlockBase
File
- src/
Plugin/ DashboardBlock/ ViewBlockBase.php, line 15
Namespace
Drupal\content_planner\Plugin\DashboardBlockView source
abstract class ViewBlockBase extends DashboardBlockBase {
/**
* ID for the block.
*
* @var string
*/
protected $blockID = 'ID-HERE';
/*
* Builds the content for the views block.
*
* @return array|null
* The render for the views block.
*/
public function build() {
$content = [];
$config = $this
->getConfiguration();
// Get view from config.
$view_config = $this
->getCustomConfigByKey($config, $this->blockID);
// Syntax is view_id.display_id.
$view_array = explode('.', $view_config);
if ($view_array && is_array($view_array) && isset($view_array[0]) && isset($view_array[1])) {
$view_id = $view_array[0];
$view_display_id = $view_array[1];
$view = Views::getView($view_id);
if (is_object($view)) {
$content = $view
->render($view_display_id);
}
}
return $content;
}
/**
* {@inheritdoc}
*/
public function getConfigSpecificFormFields(FormStateInterface &$form_state, Request &$request, array $block_configuration) {
$form = [];
// View.
$view_default_value = $this
->getCustomConfigByKey($block_configuration, $this->blockID);
$view_options = [];
$views = Views::getAllViews();
foreach ($views as $view) {
$displays = $view
->get('display');
if (is_array($displays)) {
foreach ($displays as $display) {
$view_options[$view
->id() . '.' . $display['id']] = $view
->label() . ' (' . $display['display_title'] . ')';
}
}
}
$form[$this->blockID] = [
'#type' => 'select',
'#title' => t('View'),
'#options' => $view_options,
'#required' => TRUE,
'#default_value' => $view_default_value,
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DashboardBlockBase:: |
protected | property | The route match. | |
DashboardBlockBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
DashboardBlockBase:: |
public static | function | Get basic configuration structure for the block configuration. | |
DashboardBlockBase:: |
public | function |
Get Configuration passed in by Plugin Manager. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
protected | function | Get custom config. | |
DashboardBlockBase:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
DashboardBlockBase:: |
public | function |
Return the name of the block. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
public | function |
Determines if the plugin is configurable. Overrides PluginBase:: |
|
DashboardBlockBase:: |
public | function |
Submit form handler. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
public | function |
Validates teh plugin config form. Overrides DashboardBlockInterface:: |
|
DashboardBlockBase:: |
public | function |
Constructs a new UserLoginBlock instance. Overrides PluginBase:: |
2 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
ViewBlockBase:: |
protected | property | ID for the block. | 10 |
ViewBlockBase:: |
public | function |
Build the block and return a renderable array. Overrides DashboardBlockBase:: |
|
ViewBlockBase:: |
public | function |
Add additonal form elements specific to the Plugin. Overrides DashboardBlockBase:: |