TaxonomyController.php

Same filename in other branches
  1. 9 core/modules/taxonomy/src/Controller/TaxonomyController.php
  2. 8.9.x core/modules/taxonomy/src/Controller/TaxonomyController.php
  3. 10 core/modules/taxonomy/src/Controller/TaxonomyController.php

Namespace

Drupal\taxonomy\Controller

File

core/modules/taxonomy/src/Controller/TaxonomyController.php

View source
<?php

namespace Drupal\taxonomy\Controller;

use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;

/**
 * Provides route responses for taxonomy.module.
 */
class TaxonomyController extends ControllerBase {
    
    /**
     * Returns a form to add a new term to a vocabulary.
     *
     * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
     *   The vocabulary this term will be added to.
     *
     * @return array
     *   The taxonomy term add form.
     */
    public function addForm(VocabularyInterface $taxonomy_vocabulary) {
        $term = $this->entityTypeManager()
            ->getStorage('taxonomy_term')
            ->create([
            'vid' => $taxonomy_vocabulary->id(),
        ]);
        return $this->entityFormBuilder()
            ->getForm($term);
    }
    
    /**
     * Route title callback.
     *
     * @param \Drupal\taxonomy\TermInterface $taxonomy_term
     *   The taxonomy term.
     *
     * @return array
     *   The term label as a render array.
     */
    public function termTitle(TermInterface $taxonomy_term) {
        return [
            '#markup' => $taxonomy_term->getName(),
            '#allowed_tags' => Xss::getHtmlTagList(),
        ];
    }

}

Classes

Title Deprecated Summary
TaxonomyController Provides route responses for taxonomy.module.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.