Issue #2322105 by rpayanm, prics, Upchuk, Temoor, seanB, pcambra, jamesdixon: Replace all instances of taxonomy_vocabulary_load(), taxonomy_vocabulary_load_multiple(), entity_load('taxonomy_vocabulary') and entity_load_multiple('taxonomy_vocabulary') with static method calls

8.0.x
Alex Pott 2015-01-11 13:36:43 +00:00
parent 204569108b
commit 3b53231aac
20 changed files with 202 additions and 46 deletions

View File

@ -13,6 +13,7 @@ use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\FieldUnitTestBase; use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests the new entity API for the entity reference field type. * Tests the new entity API for the entity reference field type.
@ -170,7 +171,7 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$entity->field_test_taxonomy_vocabulary->entity->set('name', $new_name); $entity->field_test_taxonomy_vocabulary->entity->set('name', $new_name);
$entity->field_test_taxonomy_vocabulary->entity->save(); $entity->field_test_taxonomy_vocabulary->entity->save();
// Verify it is the correct name. // Verify it is the correct name.
$vocabulary = entity_load('taxonomy_vocabulary', $referenced_entity_id); $vocabulary = Vocabulary::load($referenced_entity_id);
$this->assertEqual($vocabulary->label(), $new_name); $this->assertEqual($vocabulary->label(), $new_name);
// Make sure the computed term reflects updates to the term id. // Make sure the computed term reflects updates to the term id.

View File

@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Create, view, edit, delete, and change forum entries and verify its * Create, view, edit, delete, and change forum entries and verify its
@ -218,7 +219,7 @@ class ForumTest extends WebTestBase {
// Test the root forum page title change. // Test the root forum page title change.
$this->drupalGet('forum'); $this->drupalGet('forum');
$this->assertTitle(t('Forums | Drupal')); $this->assertTitle(t('Forums | Drupal'));
$vocabulary = entity_load('taxonomy_vocabulary', $this->forum['vid']); $vocabulary = Vocabulary::load($this->forum['vid']);
$vocabulary->set('name', 'Discussions'); $vocabulary->set('name', 'Discussions');
$vocabulary->save(); $vocabulary->save();
$this->drupalGet('forum'); $this->drupalGet('forum');
@ -344,7 +345,7 @@ class ForumTest extends WebTestBase {
function editForumVocabulary() { function editForumVocabulary() {
// Backup forum taxonomy. // Backup forum taxonomy.
$vid = $this->config('forum.settings')->get('vocabulary'); $vid = $this->config('forum.settings')->get('vocabulary');
$original_vocabulary = entity_load('taxonomy_vocabulary', $vid); $original_vocabulary = Vocabulary::load($vid);
// Generate a random name and description. // Generate a random name and description.
$edit = array( $edit = array(
@ -358,7 +359,7 @@ class ForumTest extends WebTestBase {
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited'); $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited');
// Grab the newly edited vocabulary. // Grab the newly edited vocabulary.
$current_vocabulary = entity_load('taxonomy_vocabulary', $vid); $current_vocabulary = Vocabulary::load($vid);
// Make sure we actually edited the vocabulary properly. // Make sure we actually edited the vocabulary properly.
$this->assertEqual($current_vocabulary->label(), $edit['name'], 'The name was updated'); $this->assertEqual($current_vocabulary->label(), $edit['name'], 'The name was updated');
@ -369,7 +370,7 @@ class ForumTest extends WebTestBase {
$current_vocabulary->set('description', $original_vocabulary->getDescription()); $current_vocabulary->set('description', $original_vocabulary->getDescription());
$current_vocabulary->save(); $current_vocabulary->save();
// Reload vocabulary to make sure changes are saved. // Reload vocabulary to make sure changes are saved.
$current_vocabulary = entity_load('taxonomy_vocabulary', $vid); $current_vocabulary = Vocabulary::load($vid);
$this->assertEqual($current_vocabulary->label(), $original_vocabulary->label(), 'The original vocabulary settings were restored'); $this->assertEqual($current_vocabulary->label(), $original_vocabulary->label(), 'The original vocabulary settings were restored');
} }

View File

@ -9,6 +9,7 @@ namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml. * Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
@ -44,14 +45,14 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupalTestBase {
public function testTaxonomyVocabulary() { public function testTaxonomyVocabulary() {
for ($i = 0; $i < 3; $i++) { for ($i = 0; $i < 3; $i++) {
$j = $i + 1; $j = $i + 1;
$vocabulary = entity_load('taxonomy_vocabulary', "vocabulary_{$j}_i_{$i}_"); $vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
$this->assertEqual(array($vocabulary->id()), entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j))); $this->assertEqual(array($vocabulary->id()), entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)));
$this->assertEqual($vocabulary->label(), "vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->label(), "vocabulary $j (i=$i)");
$this->assertEqual($vocabulary->getDescription(), "description of vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->getDescription(), "description of vocabulary $j (i=$i)");
$this->assertEqual($vocabulary->getHierarchy(), $i); $this->assertEqual($vocabulary->getHierarchy(), $i);
$this->assertEqual($vocabulary->get('weight'), 4 + $i); $this->assertEqual($vocabulary->get('weight'), 4 + $i);
} }
$vocabulary = entity_load('taxonomy_vocabulary', 'vocabulary_name_much_longer_than'); $vocabulary = Vocabulary::load('vocabulary_name_much_longer_than');
$this->assertEqual($vocabulary->label(), 'vocabulary name much longer than thirty two characters'); $this->assertEqual($vocabulary->label(), 'vocabulary name much longer than thirty two characters');
$this->assertEqual($vocabulary->getDescription(), 'description of vocabulary name much longer than thirty two characters'); $this->assertEqual($vocabulary->getDescription(), 'description of vocabulary name much longer than thirty two characters');
$this->assertEqual($vocabulary->getHierarchy(), 3); $this->assertEqual($vocabulary->getHierarchy(), 3);

View File

@ -7,6 +7,8 @@
namespace Drupal\path\Tests; namespace Drupal\path\Tests;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests URL aliases for taxonomy terms. * Tests URL aliases for taxonomy terms.
* *
@ -41,7 +43,7 @@ class PathTaxonomyTermTest extends PathTestBase {
*/ */
function testTermAlias() { function testTermAlias() {
// Create a term in the default 'Tags' vocabulary with URL alias. // Create a term in the default 'Tags' vocabulary with URL alias.
$vocabulary = entity_load('taxonomy_vocabulary', 'tags'); $vocabulary = Vocabulary::load('tags');
$description = $this->randomMachineName(); $description = $this->randomMachineName();
$edit = array( $edit = array(
'name[0][value]' => $this->randomMachineName(), 'name[0][value]' => $this->randomMachineName(),

View File

@ -14,6 +14,7 @@ use Drupal\Core\Language\LanguageInterface;
use Drupal\block\Entity\Block; use Drupal\block\Entity\Block;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests the invocation of hooks when creating, inserting, loading, updating or * Tests the invocation of hooks when creating, inserting, loading, updating or
@ -442,7 +443,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
)); ));
$GLOBALS['entity_crud_hook_test'] = array(); $GLOBALS['entity_crud_hook_test'] = array();
$vocabulary = entity_load('taxonomy_vocabulary', $vocabulary->id()); $vocabulary = Vocabulary::load($vocabulary->id());
$this->assertHookMessageOrder(array( $this->assertHookMessageOrder(array(
'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary', 'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary',

View File

@ -8,6 +8,7 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Mail\MailFormatHelper; use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* @addtogroup hooks * @addtogroup hooks
@ -419,7 +420,7 @@ function hook_mail($key, &$message, $params) {
); );
if ($context['hook'] == 'taxonomy') { if ($context['hook'] == 'taxonomy') {
$entity = $params['entity']; $entity = $params['entity'];
$vocabulary = entity_load('taxonomy_vocabulary', $entity->id()); $vocabulary = Vocabulary::load($entity->id());
$variables += array( $variables += array(
'%term_name' => $entity->name, '%term_name' => $entity->name,
'%term_description' => $entity->description, '%term_description' => $entity->description,

View File

@ -13,6 +13,8 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup; use Drupal\Core\Form\OptGroup;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\OptionsProviderInterface; use Drupal\Core\TypedData\OptionsProviderInterface;
use Drupal\Core\TypedData\AllowedValuesInterface;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Plugin implementation of the 'term_reference' field type. * Plugin implementation of the 'term_reference' field type.
@ -83,7 +85,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements OptionsPr
else { else {
$options = array(); $options = array();
foreach ($this->getSetting('allowed_values') as $tree) { foreach ($this->getSetting('allowed_values') as $tree) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { if ($vocabulary = Vocabulary::load($tree['vocabulary'])) {
if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) { if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) {
foreach ($terms as $term) { foreach ($terms as $term) {
$options[$term->id()] = str_repeat('-', $term->depth) . $term->getName(); $options[$term->id()] = str_repeat('-', $term->depth) . $term->getName();
@ -122,7 +124,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements OptionsPr
* {@inheritdoc} * {@inheritdoc}
*/ */
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = Vocabulary::loadMultiple();
$options = array(); $options = array();
foreach ($vocabularies as $vocabulary) { foreach ($vocabularies as $vocabulary) {
$options[$vocabulary->id()] = $vocabulary->label(); $options[$vocabulary->id()] = $vocabulary->label();

View File

@ -13,8 +13,7 @@ use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase; use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\VocabularyStorageInterface;
use Drupal\taxonomy\Plugin\Field\FieldType\TaxonomyTermReferenceItem;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
@ -36,13 +35,21 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP
*/ */
protected $termStorage; protected $termStorage;
/**
* The vocabulary storage.
*
* @var VocabularyStorageInterface
*/
protected $vocabularyStorage;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityStorageInterface $term_storage) { public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityStorageInterface $term_storage, VocabularyStorageInterface $vocabulary_storage) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings); parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->termStorage = $term_storage; $this->termStorage = $term_storage;
$this->vocabularyStorage = $vocabulary_storage;
} }
/** /**
@ -55,7 +62,8 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP
$configuration['field_definition'], $configuration['field_definition'],
$configuration['settings'], $configuration['settings'],
$configuration['third_party_settings'], $configuration['third_party_settings'],
$container->get('entity.manager')->getStorage('taxonomy_term') $container->get('entity.manager')->getStorage('taxonomy_term'),
$container->get('entity.manager')->getStorage('taxonomy_vocabulary')
); );
} }
@ -138,7 +146,7 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP
// Collect candidate vocabularies. // Collect candidate vocabularies.
foreach ($this->getFieldSetting('allowed_values') as $tree) { foreach ($this->getFieldSetting('allowed_values') as $tree) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { if ($vocabulary = $this->vocabularyStorage->load($tree['vocabulary'])) {
$vocabularies[$vocabulary->id()] = $vocabulary; $vocabularies[$vocabulary->id()] = $vocabulary;
} }
} }

View File

@ -11,6 +11,7 @@ use Drupal\Component\Utility\String;
use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase; use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Provides specific access control for the taxonomy_term entity type. * Provides specific access control for the taxonomy_term entity type.
@ -64,7 +65,7 @@ class TermSelection extends SelectionBase {
$bundle_names = !empty($handler_settings['target_bundles']) ? $handler_settings['target_bundles'] : array_keys($bundles); $bundle_names = !empty($handler_settings['target_bundles']) ? $handler_settings['target_bundles'] : array_keys($bundles);
foreach ($bundle_names as $bundle) { foreach ($bundle_names as $bundle) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) { if ($vocabulary = Vocabulary::load($bundle)) {
if ($terms = taxonomy_get_tree($vocabulary->id(), 0, NULL, TRUE)) { if ($terms = taxonomy_get_tree($vocabulary->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) { foreach ($terms as $term) {
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->getName()); $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->getName());

View File

@ -9,6 +9,8 @@ namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\Numeric; use Drupal\views\Plugin\views\argument\Numeric;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\taxonomy\VocabularyStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Argument handler to accept a vocabulary id. * Argument handler to accept a vocabulary id.
@ -19,11 +21,47 @@ use Drupal\Component\Utility\String;
*/ */
class VocabularyVid extends Numeric { class VocabularyVid extends Numeric {
/**
* The vocabulary storage.
*
* @var \Drupal\taxonomy\VocabularyStorageInterface
*/
protected $vocabularyStorage;
/**
* Constructs the VocabularyVid object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param VocabularyStorageInterface $vocabulary_storage
* The vocabulary storage.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->vocabularyStorage = $vocabulary_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('taxonomy_vocabulary')
);
}
/** /**
* Override the behavior of title(). Get the name of the vocabulary. * Override the behavior of title(). Get the name of the vocabulary.
*/ */
function title() { function title() {
$vocabulary = entity_load('taxonomy_vocabulary', $this->argument); $vocabulary = $this->vocabularyStorage->load($this->argument);
if ($vocabulary) { if ($vocabulary) {
return String::checkPlain($vocabulary->label()); return String::checkPlain($vocabulary->label());
} }

View File

@ -17,6 +17,8 @@ use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\VocabularyStorageInterface;
/** /**
* Taxonomy tid default argument. * Taxonomy tid default argument.
@ -37,21 +39,31 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface
/** /**
* Constructs a new Date instance. * Constructs a new Date instance.
* The vocary storage.
*
* @var \Drupal\taxonomy\VocabularyStorageInterface.
*/
protected $vocabularyStorage;
/**
* Constructs a Tid object.
* *
* @param array $configuration * @param array $configuration
* A configuration array containing information about the plugin instance. * A configuration array containing information about the plugin instance.
* @param string $plugin_id * @param string $plugin_id
* The plugin_id for the plugin instance. * The plugin_id for the plugin instance.
* @param mixed $plugin_definition * @param mixed $plugin_definition
* The plugin implementation definition. * The plugin implementation definition. *
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match. * The route match.
* @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage
* The vocabulary storage.
*/ */
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) { public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, VocabularyStorageInterface $vocabulary_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $route_match; $this->routeMatch = $route_match;
$this->vocabularyStorage = $vocabulary_storage;
} }
/** /**
@ -62,7 +74,8 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface
$configuration, $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('current_route_match') $container->get('current_route_match'),
$container->get('entity.manager')->getStorage('taxonomy_vocabulary')
); );
} }
@ -120,7 +133,7 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface
); );
$options = array(); $options = array();
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = $this->vocabularyStorage->loadMultiple();
foreach ($vocabularies as $voc) { foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label(); $options[$voc->id()] = $voc->label();
} }

View File

@ -12,6 +12,9 @@ use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\PrerenderList; use Drupal\views\Plugin\views\field\PrerenderList;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\taxonomy\VocabularyStorageInterface;
/** /**
* Field handler to display all taxonomy terms of a node. * Field handler to display all taxonomy terms of a node.
@ -22,6 +25,42 @@ use Drupal\Component\Utility\String;
*/ */
class TaxonomyIndexTid extends PrerenderList { class TaxonomyIndexTid extends PrerenderList {
/**
* The vocabulary storage.
*
* @var \Drupal\taxonomy\VocabularyStorageInterface.
*/
protected $vocabularyStorage;
/**
* Constructs a TaxonomyIndexTid object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage
* The vocabulary storage.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->vocabularyStorage = $vocabulary_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('taxonomy_vocabulary')
);
}
/** /**
* Overrides \Drupal\views\Plugin\views\field\PrerenderList::init(). * Overrides \Drupal\views\Plugin\views\field\PrerenderList::init().
*/ */
@ -64,7 +103,7 @@ class TaxonomyIndexTid extends PrerenderList {
); );
$options = array(); $options = array();
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = $this->vocabularyStorage->loadMultiple();
foreach ($vocabularies as $voc) { foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label(); $options[$voc->id()] = $voc->label();
} }
@ -93,7 +132,7 @@ class TaxonomyIndexTid extends PrerenderList {
} }
public function preRender(&$values) { public function preRender(&$values) {
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = $this->vocabularyStorage->loadMultiple();
$this->field_alias = $this->aliases['nid']; $this->field_alias = $this->aliases['nid'];
$nids = array(); $nids = array();
foreach ($values as $result) { foreach ($values as $result) {

View File

@ -106,7 +106,7 @@ class TaxonomyIndexTid extends ManyToOne {
} }
public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) { public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = $this->vocabularyStorage->loadMultiple();
$options = array(); $options = array();
foreach ($vocabularies as $voc) { foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label(); $options[$voc->id()] = $voc->label();
@ -150,7 +150,7 @@ class TaxonomyIndexTid extends ManyToOne {
} }
protected function valueForm(&$form, FormStateInterface $form_state) { protected function valueForm(&$form, FormStateInterface $form_state) {
$vocabulary = entity_load('taxonomy_vocabulary', $this->options['vid']); $vocabulary = $this->vocabularyStorage->load($this->options['vid']);
if (empty($vocabulary) && $this->options['limit']) { if (empty($vocabulary) && $this->options['limit']) {
$form['markup'] = array( $form['markup'] = array(
'#markup' => '<div class="form-item">' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '</div>', '#markup' => '<div class="form-item">' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '</div>',

View File

@ -84,7 +84,7 @@ class NodeTermData extends RelationshipPluginBase {
} }
public function buildOptionsForm(&$form, FormStateInterface $form_state) { public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = $this->vocabularyStorage->loadMultiple();
$options = array(); $options = array();
foreach ($vocabularies as $voc) { foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label(); $options[$voc->id()] = $voc->label();

View File

@ -14,6 +14,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests load, save and delete for taxonomy terms. * Tests load, save and delete for taxonomy terms.
@ -71,7 +72,7 @@ class TermTest extends TaxonomyTestBase {
$term2 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary);
// Check that hierarchy is flat. // Check that hierarchy is flat.
$vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id()); $vocabulary = Vocabulary::load($this->vocabulary->id());
$this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.'); $this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.');
// Edit $term2, setting $term1 as parent. // Edit $term2, setting $term1 as parent.

View File

@ -9,6 +9,7 @@ namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests loading, saving and deleting vocabularies. * Tests loading, saving and deleting vocabularies.
@ -37,7 +38,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
*/ */
function testTaxonomyVocabularyDeleteWithTerms() { function testTaxonomyVocabularyDeleteWithTerms() {
// Delete any existing vocabularies. // Delete any existing vocabularies.
foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary->delete(); $vocabulary->delete();
} }
@ -68,7 +69,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
* Ensure that the vocabulary static reset works correctly. * Ensure that the vocabulary static reset works correctly.
*/ */
function testTaxonomyVocabularyLoadStaticReset() { function testTaxonomyVocabularyLoadStaticReset() {
$original_vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id()); $original_vocabulary = Vocabulary::load($this->vocabulary->id());
$this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.'); $this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.');
$this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.'); $this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.');
@ -79,12 +80,12 @@ class VocabularyCrudTest extends TaxonomyTestBase {
$vocabulary->save(); $vocabulary->save();
// Load the vocabulary. // Load the vocabulary.
$new_vocabulary = entity_load('taxonomy_vocabulary', $original_vocabulary->id()); $new_vocabulary = Vocabulary::load($original_vocabulary->id());
$this->assertEqual($new_vocabulary->label(), $vocabulary->label(), 'The vocabulary was loaded.'); $this->assertEqual($new_vocabulary->label(), $vocabulary->label(), 'The vocabulary was loaded.');
// Delete the vocabulary. // Delete the vocabulary.
$this->vocabulary->delete(); $this->vocabulary->delete();
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = Vocabulary::loadMultiple();
$this->assertTrue(!isset($vocabularies[$this->vocabulary->id()]), 'The vocabulary was deleted.'); $this->assertTrue(!isset($vocabularies[$this->vocabulary->id()]), 'The vocabulary was deleted.');
} }
@ -94,7 +95,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
function testTaxonomyVocabularyLoadMultiple() { function testTaxonomyVocabularyLoadMultiple() {
// Delete any existing vocabularies. // Delete any existing vocabularies.
foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary->delete(); $vocabulary->delete();
} }
@ -121,7 +122,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// Fetch the vocabularies with entity_load_multiple(), specifying IDs. // Fetch the vocabularies with entity_load_multiple(), specifying IDs.
// Ensure they are returned in the same order as the original array. // Ensure they are returned in the same order as the original array.
$vocabularies = entity_load_multiple('taxonomy_vocabulary', array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id())); $vocabularies = Vocabulary::loadMultiple(array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()));
$loaded_order = array_keys($vocabularies); $loaded_order = array_keys($vocabularies);
$expected_order = array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()); $expected_order = array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id());
$this->assertIdentical($loaded_order, $expected_order); $this->assertIdentical($loaded_order, $expected_order);

View File

@ -8,6 +8,8 @@
namespace Drupal\taxonomy\Tests; namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Tests the taxonomy vocabulary interface. * Tests the taxonomy vocabulary interface.
* *
@ -80,7 +82,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
$this->createVocabulary(); $this->createVocabulary();
} }
// Get all vocabularies and change their weights. // Get all vocabularies and change their weights.
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = Vocabulary::loadMultiple();
$edit = array(); $edit = array();
foreach ($vocabularies as $key => $vocabulary) { foreach ($vocabularies as $key => $vocabulary) {
$weight = -$vocabulary->get('weight'); $weight = -$vocabulary->get('weight');
@ -92,7 +94,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
// Load the vocabularies from the database. // Load the vocabularies from the database.
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache(); $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$new_vocabularies = entity_load_multiple('taxonomy_vocabulary'); $new_vocabularies = Vocabulary::loadMultiple();
// Check that the weights are saved in the database correctly. // Check that the weights are saved in the database correctly.
foreach ($vocabularies as $key => $vocabulary) { foreach ($vocabularies as $key => $vocabulary) {
@ -105,12 +107,12 @@ class VocabularyUiTest extends TaxonomyTestBase {
*/ */
function testTaxonomyAdminNoVocabularies() { function testTaxonomyAdminNoVocabularies() {
// Delete all vocabularies. // Delete all vocabularies.
$vocabularies = entity_load_multiple('taxonomy_vocabulary'); $vocabularies = Vocabulary::loadMultiple();
foreach ($vocabularies as $key => $vocabulary) { foreach ($vocabularies as $key => $vocabulary) {
$vocabulary->delete(); $vocabulary->delete();
} }
// Confirm that no vocabularies are found in the database. // Confirm that no vocabularies are found in the database.
$this->assertFalse(entity_load_multiple('taxonomy_vocabulary'), 'No vocabularies found.'); $this->assertFalse(Vocabulary::loadMultiple(), 'No vocabularies found.');
$this->drupalGet('admin/structure/taxonomy'); $this->drupalGet('admin/structure/taxonomy');
// Check the default message for no vocabularies. // Check the default message for no vocabularies.
$this->assertText(t('No vocabularies available.')); $this->assertText(t('No vocabularies available.'));
@ -131,7 +133,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
// Check the created vocabulary. // Check the created vocabulary.
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache(); $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$vocabulary = entity_load('taxonomy_vocabulary', $vid); $vocabulary = Vocabulary::load($vid);
$this->assertTrue($vocabulary, 'Vocabulary found.'); $this->assertTrue($vocabulary, 'Vocabulary found.');
// Delete the vocabulary. // Delete the vocabulary.
@ -144,6 +146,6 @@ class VocabularyUiTest extends TaxonomyTestBase {
$this->drupalPostForm(NULL, NULL, t('Delete')); $this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->label())), 'Vocabulary deleted.'); $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->label())), 'Vocabulary deleted.');
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache(); $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$this->assertFalse(entity_load('taxonomy_vocabulary', $vid), 'Vocabulary not found.'); $this->assertFalse(Vocabulary::load($vid), 'Vocabulary not found.');
} }
} }

View File

@ -12,12 +12,40 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ContentLanguageSettings; use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\taxonomy\VocabularyStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Base form for vocabulary edit forms. * Base form for vocabulary edit forms.
*/ */
class VocabularyForm extends EntityForm { class VocabularyForm extends EntityForm {
/**
* The vocabulary storage.
*
* @var \Drupal\taxonomy\VocabularyStorageInterface.
*/
protected $vocabularyStorage;
/**
* Constructs a new vocabulary form.
*
* @param \Drupal\taxonomy\VocabularyStorageInterface $vocabulary_storage
* The vocabulary storage.
*/
public function __construct(VocabularyStorageInterface $vocabulary_storage) {
$this->vocabularyStorage = $vocabulary_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')->getStorage('taxonomy_vocabulary')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -42,7 +70,7 @@ class VocabularyForm extends EntityForm {
'#default_value' => $vocabulary->id(), '#default_value' => $vocabulary->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => array( '#machine_name' => array(
'exists' => 'taxonomy_vocabulary_load', 'exists' => array($this, 'exists'),
'source' => array('name'), 'source' => array('name'),
), ),
); );
@ -136,4 +164,18 @@ class VocabularyForm extends EntityForm {
$form_state->set('vid', $vocabulary->id()); $form_state->set('vid', $vocabulary->id());
} }
/**
* Determines if the vocabulary already exists.
*
* @param string $id
* The vocabulary ID
*
* @return bool
* TRUE if the vocabulary exists, FALSE otherwise.
*/
public function exists($id) {
$action = $this->vocabularyStorage->load($id);
return !empty($action);
}
} }

View File

@ -7,6 +7,7 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Implements hook_token_info(). * Implements hook_token_info().
@ -127,7 +128,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
break; break;
case 'vocabulary': case 'vocabulary':
$vocabulary = entity_load('taxonomy_vocabulary', $term->bundle()); $vocabulary = Vocabulary::load($term->bundle());
$replacements[$original] = String::checkPlain($vocabulary->label()); $replacements[$original] = String::checkPlain($vocabulary->label());
break; break;
@ -141,7 +142,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
} }
if ($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'vocabulary')) { if ($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'vocabulary')) {
$vocabulary = entity_load('taxonomy_vocabulary', $term->bundle()); $vocabulary = Vocabulary::load($term->bundle());
$replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); $replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options);
} }

View File

@ -11,6 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutable;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\taxonomy\Entity\Vocabulary;
/** /**
* Converts a form element in the add view wizard to be AJAX-enabled. * Converts a form element in the add view wizard to be AJAX-enabled.
@ -231,7 +232,7 @@ function views_ui_taxonomy_autocomplete_validate($element, FormStateInterface $f
$allowed_values = $field_storage->getSetting('allowed_values'); $allowed_values = $field_storage->getSetting('allowed_values');
if (!empty($allowed_values)) { if (!empty($allowed_values)) {
foreach ($allowed_values as $tree) { foreach ($allowed_values as $tree) {
if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { if ($vocabulary = Vocabulary::load($tree['vocabulary'])) {
$vocabularies[$vocabulary->id()] = $tree['vocabulary']; $vocabularies[$vocabulary->id()] = $tree['vocabulary'];
} }
} }