You are here

abstract class DashboardBase in Dashboards with Layout Builder 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/DashboardBase.php \Drupal\dashboards\Plugin\DashboardBase

Base class for Dashboard plugins.

Hierarchy

Expanded class hierarchy of DashboardBase

13 files declare their use of DashboardBase
Account.php in src/Plugin/Dashboard/Account.php
AddContentMenu.php in src/Plugin/Dashboard/AddContentMenu.php
Browser.php in modules/dashboards_matomo/src/Plugin/Dashboard/Browser.php
Comments.php in modules/dashboards_comments/src/Plugin/Dashboard/Comments.php
Country.php in modules/dashboards_matomo/src/Plugin/Dashboard/Country.php

... See full list

File

src/Plugin/DashboardBase.php, line 15

Namespace

Drupal\dashboards\Plugin
View source
abstract class DashboardBase extends PluginBase implements DashboardInterface, ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * {@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'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * Cache backend.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cache;

  /**
   * Build render array.
   *
   * @param array $configuration
   *   Plugin configuration.
   *
   * @return array
   *   Return render array.
   */
  public abstract function buildRenderArray(array $configuration) : array;

  /**
   * Build render array.
   *
   * @param array $form
   *   Default form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   Default form.
   * @param array $configuration
   *   Configuration.
   *
   * @return array
   *   Return form array.
   */
  public function buildSettingsForm(array $form, FormStateInterface $form_state, array $configuration) : array {
    return $form;
  }

  /**
   * Validate settings form.
   *
   * @param array $form
   *   Default form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   Default form.
   * @param array $configuration
   *   Configuration.
   */
  public function validateForm(array $form, FormStateInterface $form_state, array $configuration) : void {
  }

  /**
   * Validate settings form.
   *
   * @param array $form
   *   Default form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   Default form.
   * @param array $configuration
   *   Configuration.
   */
  public function massageFormValues(array $form, FormStateInterface $form_state, array $configuration) : void {
  }

  /**
   * Get cache for cid.
   *
   * @param string $cid
   *   Cache id.
   *
   * @return mixed
   *   Return cache data.
   */
  protected function getCache(string $cid) {
    return $this->cache
      ->get($this
      ->getPluginId() . ':' . $cid);
  }

  /**
   * Set a new cache entry. Cache is prefixed by pluginid.
   *
   * @param string $cid
   *   Cache id.
   * @param mixed $data
   *   Data to cache.
   * @param int $expire
   *   Expire data. Default to 3600.
   * @param array $tags
   *   Tags for invalidation.
   */
  protected function setCache(string $cid, $data, int $expire = 3600, array $tags = []) : void {
    $this->cache
      ->set($this
      ->getPluginId() . ':' . $cid, $data, $expire, $tags);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DashboardBase::$cache protected property Cache backend.
DashboardBase::buildRenderArray abstract public function Build render array. 8
DashboardBase::buildSettingsForm public function Build render array. 9
DashboardBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 8
DashboardBase::getCache protected function Get cache for cid.
DashboardBase::massageFormValues public function Validate settings form.
DashboardBase::setCache protected function Set a new cache entry. Cache is prefixed by pluginid.
DashboardBase::validateForm public function Validate settings form. 1
DashboardBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 8
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.