class ViewEmbed in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Dashboard/ViewEmbed.php \Drupal\dashboards\Plugin\Dashboard\ViewEmbed
Show account info.
Plugin annotation
@Dashboard(
id = "view_embed",
label = @Translation("Embed a view"),
category = @Translation("Views")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
- class \Drupal\dashboards\Plugin\Dashboard\ViewEmbed
- class \Drupal\dashboards\Plugin\DashboardBase implements ContainerFactoryPluginInterface, DashboardInterface uses StringTranslationTrait
Expanded class hierarchy of ViewEmbed
File
- src/
Plugin/ Dashboard/ ViewEmbed.php, line 23
Namespace
Drupal\dashboards\Plugin\DashboardView source
class ViewEmbed extends DashboardBase {
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $entityQuery;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache_backend, QueryInterface $query) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $cache_backend);
$this->entityQuery = $query;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('dashboards.cache'), $container
->get('entity_type.manager')
->getStorage('view')
->getQuery());
}
/**
* {@inheritdoc}
*/
public function buildRenderArray($configuration) : array {
$viewId = explode(':', $configuration['view']);
$view = Views::getView($viewId[0]);
if (!$view) {
return [
'#markup' => 'View do not exist anymore',
];
}
return views_embed_view($viewId[0], $viewId[1]);
}
/**
* {@inheritdoc}
*/
public function validateForm(array $form, FormStateInterface $form_state, array $configuration) : void {
if (!$form_state
->getValue('view')) {
$form_state
->setErrorByName('view', $this
->t('Please provide a view.'));
}
}
/**
* {@inheritdoc}
*/
public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
$views = $this->entityQuery
->condition('status', TRUE)
->condition("display.*.display_plugin", [
'embed',
], 'IN')
->execute();
$views = View::loadMultiple($views);
$options = [];
foreach ($views as $view) {
foreach ($view
->get('display') as $display) {
if ($display['display_plugin'] != 'embed') {
continue;
}
$options[$view
->id() . ':' . $display['id']] = $view
->label() . ': ' . $display['display_title'];
}
}
if (empty($options)) {
$form['view'] = [
'#markup' => $this
->t('Please add a embed view to use this plugin.'),
];
return $form;
}
$form['view'] = [
'#type' => 'select',
'#required' => TRUE,
'#options' => $options,
'#default_value' => isset($configuration['view']) ? $configuration['view'] : FALSE,
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DashboardBase:: |
protected | property | Cache backend. | |
DashboardBase:: |
protected | function | Get cache for cid. | |
DashboardBase:: |
public | function | Validate settings form. | |
DashboardBase:: |
protected | function | Set a new cache entry. Cache is prefixed by pluginid. | |
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:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ViewEmbed:: |
protected | property | Entity query. | |
ViewEmbed:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
ViewEmbed:: |
public | function |
Build render array. Overrides DashboardBase:: |
|
ViewEmbed:: |
public static | function |
Creates an instance of the plugin. Overrides DashboardBase:: |
|
ViewEmbed:: |
public | function |
Validate settings form. Overrides DashboardBase:: |
|
ViewEmbed:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides DashboardBase:: |