DashboardBase.php in Dashboards with Layout Builder 8
File
src/Plugin/DashboardBase.php
View source
<?php
namespace Drupal\dashboards\Plugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class DashboardBase extends PluginBase implements DashboardInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('dashboards.cache'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache_backend) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $plugin_definition);
$this->cache = $cache_backend;
}
protected $cache;
public abstract function buildRenderArray(array $configuration) : array;
public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
return $form;
}
public function validateForm(array $form, FormStateInterface $form_state, array $configuration) : void {
}
public function massageFormValues(array $form, FormStateInterface $form_state, array $configuration) : void {
}
protected function getCache(string $cid) {
return $this->cache
->get($this
->getPluginId() . ':' . $cid);
}
protected function setCache(string $cid, $data, int $expire = 3600, array $tags = []) : void {
$this->cache
->set($this
->getPluginId() . ':' . $cid, $data, $expire, $tags);
}
}