OrganigramsController.php in Organigrams 8
File
src/Controller/OrganigramsController.php
View source
<?php
namespace Drupal\organigrams\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\VocabularyInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\organigrams\TaxonomyTermTree;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrganigramsController extends ControllerBase {
protected $taxonomyTermTree;
public function __construct(TaxonomyTermTree $taxonomyTermTree) {
$this->taxonomyTermTree = $taxonomyTermTree;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('organigrams.taxonomy_term_tree'));
}
public function addForm() {
$term = $this
->entityTypeManager()
->getStorage('taxonomy_vocabulary')
->create();
return $this
->entityFormBuilder()
->getForm($term);
}
public function viewOrganigram(VocabularyInterface $taxonomy_vocabulary) {
$output = [];
if (!$this
->currentUser()
->hasPermission('view organigrams')) {
return $output;
}
$organigram_settings = [
'organigram_settings' => $taxonomy_vocabulary
->getThirdPartySettings('organigrams'),
'nodes' => [],
];
$output = $this->taxonomyTermTree
->loadList($taxonomy_vocabulary
->id());
$output['#attached']['library'][] = 'organigrams/explorercanvas';
$output['#attached']['library'][] = 'organigrams/orgchart';
$output['#attached']['library'][] = 'organigrams/organigrams';
$output['#attached']['drupalSettings']['organigrams']['organigrams'] = [
$taxonomy_vocabulary
->id() => $organigram_settings,
];
return $output;
}
public function viewOrganigramAccess(VocabularyInterface $taxonomy_vocabulary) {
if (!empty($taxonomy_vocabulary
->getThirdPartySettings('organigrams'))) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
}