WeatherSystemDisplayBlock.php in Weather 2.0.x
File
src/Plugin/Block/WeatherSystemDisplayBlock.php
View source
<?php
namespace Drupal\weather\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\weather\Entity\WeatherDisplayInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WeatherSystemDisplayBlock extends BlockBase implements ContainerFactoryPluginInterface {
use WeatherDisplayBlockTrait;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, AccountProxyInterface $currentUser) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->weatherDisplay = $entityTypeManager
->getStorage('weather_display')
->load($this
->getDerivativeId());
$this->weatherDisplayPlaceStorage = $entityTypeManager
->getStorage('weather_display_place');
$this->currentUser = $currentUser;
$this->destination = WeatherDisplayInterface::SYSTEM_WIDE_TYPE;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('current_user'));
}
public function blockAccess(AccountInterface $account, $return_as_object = FALSE) {
return AccessResult::allowedIfHasPermission($this->currentUser, 'access content');
}
}