OrganigramsBlocks.php in Organigrams 8
File
src/Plugin/Block/OrganigramsBlocks.php
View source
<?php
namespace Drupal\organigrams\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\organigrams\Controller\OrganigramsController;
use Drupal\organigrams\TaxonomyTermTree;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrganigramsBlocks extends BlockBase implements ContainerFactoryPluginInterface {
private $taxonomyVocabulary;
protected $taxonomyTermTree;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_manager, TaxonomyTermTree $taxonomyTermTree) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->taxonomyVocabulary = $entity_manager
->getStorage('taxonomy_vocabulary')
->load($this
->getDerivativeId());
$this->taxonomyTermTree = $taxonomyTermTree;
}
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('organigrams.taxonomy_term_tree'));
}
public function build() {
if (empty($this->taxonomyVocabulary
->getThirdPartySettings('organigrams'))) {
return;
}
$organigramsController = new OrganigramsController($this->taxonomyTermTree);
$build = $organigramsController
->viewOrganigram($this->taxonomyVocabulary);
return $build;
}
public function blockAccess(AccountInterface $account, $return_as_object = FALSE) {
if ($account
->hasPermission('view organigrams')) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
}