You are here

class WeatherSystemDisplayBlock in Weather 8

Same name in this branch
  1. 8 src/Plugin/Derivative/WeatherSystemDisplayBlock.php \Drupal\weather\Plugin\Derivative\WeatherSystemDisplayBlock
  2. 8 src/Plugin/Block/WeatherSystemDisplayBlock.php \Drupal\weather\Plugin\Block\WeatherSystemDisplayBlock
Same name and namespace in other branches
  1. 2.0.x src/Plugin/Derivative/WeatherSystemDisplayBlock.php \Drupal\weather\Plugin\Derivative\WeatherSystemDisplayBlock

Provides block plugin definitions for nodes.

Hierarchy

Expanded class hierarchy of WeatherSystemDisplayBlock

See also

\Drupal\weather\Plugin\Block\WeatherSystemDisplayBlock

File

src/Plugin/Derivative/WeatherSystemDisplayBlock.php, line 17

Namespace

Drupal\weather\Plugin\Derivative
View source
class WeatherSystemDisplayBlock extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The node storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $weatherDisplayStorage;

  /**
   * Constructs new WeatherSystemDisplayBlock.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $weatherDisplayStorage
   *   The weather displays storage.
   */
  public function __construct(EntityStorageInterface $weatherDisplayStorage) {
    $this->weatherDisplayStorage = $weatherDisplayStorage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('weather_display'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $weatherDisplays = $this->weatherDisplayStorage
      ->loadByProperties([
      'type' => WeatherDisplayInterface::SYSTEM_WIDE_TYPE,
    ]);
    foreach ($weatherDisplays as $weatherDisplay) {
      $display_number = $weatherDisplay->number->value;
      $this->derivatives[$weatherDisplay
        ->id()] = $base_plugin_definition;
      $this->derivatives[$weatherDisplay
        ->id()]['admin_label'] = $this
        ->t('Weather: system-wide display (#@number)', [
        '@number' => $display_number,
      ]);
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.
WeatherSystemDisplayBlock::$weatherDisplayStorage protected property The node storage.
WeatherSystemDisplayBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
WeatherSystemDisplayBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
WeatherSystemDisplayBlock::__construct public function Constructs new WeatherSystemDisplayBlock.