You are here

public function WeatherUserDisplayBlock::__construct in Weather 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Block/WeatherUserDisplayBlock.php \Drupal\weather\Plugin\Block\WeatherUserDisplayBlock::__construct()

WeatherSystemDisplayBlock constructor.

Parameters

array $configuration: The plugin configuration.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

\Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager: Entity Type Manager service.

\Drupal\Core\Session\AccountProxyInterface $currentUser: Current user.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

Overrides BlockPluginTrait::__construct

File

src/Plugin/Block/WeatherUserDisplayBlock.php, line 43

Class

WeatherUserDisplayBlock
Provides a 'WeatherUserDisplayBlock' block plugin.

Namespace

Drupal\weather\Plugin\Block

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, AccountProxyInterface $currentUser) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);
  $this->currentUser = $currentUser;
  $weatherDisplay = $entityTypeManager
    ->getStorage('weather_display')
    ->loadByProperties([
    'type' => WeatherDisplayInterface::USER_TYPE,
    'number' => $this->currentUser
      ->id(),
  ]);
  $this->weatherDisplay = reset($weatherDisplay);
  $this->weatherDisplayPlaceStorage = $entityTypeManager
    ->getStorage('weather_display_place');
  $this->destination = WeatherDisplayInterface::USER_TYPE;
}