Chris@0: getStorage($entity_type->id())); Chris@14: Chris@14: $this->currentUser = $current_user; Chris@14: $this->entityTypeManager = $entity_type_manager; Chris@14: $this->renderer = $renderer; Chris@17: $this->messenger = $messenger; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { Chris@14: return new static( Chris@14: $entity_type, Chris@14: $container->get('current_user'), Chris@14: $container->get('entity_type.manager'), Chris@17: $container->get('renderer'), Chris@17: $container->get('messenger') Chris@14: ); Chris@14: } Chris@14: Chris@14: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getFormId() { Chris@0: return 'taxonomy_overview_vocabularies'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefaultOperations(EntityInterface $entity) { Chris@0: $operations = parent::getDefaultOperations($entity); Chris@0: Chris@0: if (isset($operations['edit'])) { Chris@0: $operations['edit']['title'] = t('Edit vocabulary'); Chris@0: } Chris@0: Chris@14: if ($entity->access('access taxonomy overview')) { Chris@14: $operations['list'] = [ Chris@14: 'title' => t('List terms'), Chris@14: 'weight' => 0, Chris@14: 'url' => $entity->toUrl('overview-form'), Chris@14: ]; Chris@14: } Chris@14: Chris@14: $taxonomy_term_access_control_handler = $this->entityTypeManager->getAccessControlHandler('taxonomy_term'); Chris@14: if ($taxonomy_term_access_control_handler->createAccess($entity->id())) { Chris@14: $operations['add'] = [ Chris@14: 'title' => t('Add terms'), Chris@14: 'weight' => 10, Chris@14: 'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]), Chris@14: ]; Chris@14: } Chris@14: Chris@0: unset($operations['delete']); Chris@0: Chris@0: return $operations; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildHeader() { Chris@0: $header['label'] = t('Vocabulary name'); Chris@0: $header['description'] = t('Description'); Chris@14: Chris@16: if ($this->currentUser->hasPermission('administer vocabularies') && !empty($this->weightKey)) { Chris@14: $header['weight'] = t('Weight'); Chris@14: } Chris@14: Chris@0: return $header + parent::buildHeader(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildRow(EntityInterface $entity) { Chris@0: $row['label'] = $entity->label(); Chris@0: $row['description']['data'] = ['#markup' => $entity->getDescription()]; Chris@0: return $row + parent::buildRow($entity); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function render() { Chris@0: $entities = $this->load(); Chris@0: // If there are not multiple vocabularies, disable dragging by unsetting the Chris@0: // weight key. Chris@0: if (count($entities) <= 1) { Chris@0: unset($this->weightKey); Chris@0: } Chris@0: $build = parent::render(); Chris@14: Chris@14: // If the weight key was unset then the table is in the 'table' key, Chris@14: // otherwise in vocabularies. The empty message is only needed if the table Chris@14: // is possibly empty, so there is no need to support the vocabularies key Chris@14: // here. Chris@14: if (isset($build['table'])) { Chris@14: $access_control_handler = $this->entityTypeManager->getAccessControlHandler('taxonomy_vocabulary'); Chris@14: $create_access = $access_control_handler->createAccess(NULL, NULL, [], TRUE); Chris@14: $this->renderer->addCacheableDependency($build['table'], $create_access); Chris@14: if ($create_access->isAllowed()) { Chris@14: $build['table']['#empty'] = t('No vocabularies available. Add vocabulary.', [ Chris@17: ':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString(), Chris@14: ]); Chris@14: } Chris@14: else { Chris@14: $build['table']['#empty'] = t('No vocabularies available.'); Chris@14: } Chris@14: } Chris@14: Chris@0: return $build; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildForm(array $form, FormStateInterface $form_state) { Chris@0: $form = parent::buildForm($form, $form_state); Chris@0: $form['vocabularies']['#attributes'] = ['id' => 'taxonomy']; Chris@0: $form['actions']['submit']['#value'] = t('Save'); Chris@0: Chris@0: return $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function submitForm(array &$form, FormStateInterface $form_state) { Chris@0: parent::submitForm($form, $form_state); Chris@0: Chris@17: $this->messenger->addStatus($this->t('The configuration options have been saved.')); Chris@0: } Chris@0: Chris@0: }