diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php index 0898f48cf88..bddea8dbf88 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\field\Tests\FieldUnitTestBase; use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\Entity\Vocabulary; /** * 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->save(); // 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); // Make sure the computed term reflects updates to the term id. diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index ead923ab270..aff0b859aaf 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; use Drupal\simpletest\WebTestBase; use Drupal\Core\Url; +use Drupal\taxonomy\Entity\Vocabulary; /** * 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. $this->drupalGet('forum'); $this->assertTitle(t('Forums | Drupal')); - $vocabulary = entity_load('taxonomy_vocabulary', $this->forum['vid']); + $vocabulary = Vocabulary::load($this->forum['vid']); $vocabulary->set('name', 'Discussions'); $vocabulary->save(); $this->drupalGet('forum'); @@ -344,7 +345,7 @@ class ForumTest extends WebTestBase { function editForumVocabulary() { // Backup forum taxonomy. $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. $edit = array( @@ -358,7 +359,7 @@ class ForumTest extends WebTestBase { $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited'); // 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. $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->save(); // 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'); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php index 0995ecfbd2c..8cc59ae5775 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php @@ -9,6 +9,7 @@ namespace Drupal\migrate_drupal\Tests\d6; use Drupal\migrate\MigrateExecutable; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; +use Drupal\taxonomy\Entity\Vocabulary; /** * Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml. @@ -44,14 +45,14 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupalTestBase { public function testTaxonomyVocabulary() { for ($i = 0; $i < 3; $i++) { $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($vocabulary->label(), "vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->getDescription(), "description of vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->getHierarchy(), $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->getDescription(), 'description of vocabulary name much longer than thirty two characters'); $this->assertEqual($vocabulary->getHierarchy(), 3); diff --git a/core/modules/path/src/Tests/PathTaxonomyTermTest.php b/core/modules/path/src/Tests/PathTaxonomyTermTest.php index 895fac6396f..f53eb7d9eb0 100644 --- a/core/modules/path/src/Tests/PathTaxonomyTermTest.php +++ b/core/modules/path/src/Tests/PathTaxonomyTermTest.php @@ -7,6 +7,8 @@ namespace Drupal\path\Tests; +use Drupal\taxonomy\Entity\Vocabulary; + /** * Tests URL aliases for taxonomy terms. * @@ -41,7 +43,7 @@ class PathTaxonomyTermTest extends PathTestBase { */ function testTermAlias() { // Create a term in the default 'Tags' vocabulary with URL alias. - $vocabulary = entity_load('taxonomy_vocabulary', 'tags'); + $vocabulary = Vocabulary::load('tags'); $description = $this->randomMachineName(); $edit = array( 'name[0][value]' => $this->randomMachineName(), diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index c65919446ae..35ea4082391 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -14,6 +14,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\block\Entity\Block; use Drupal\taxonomy\Entity\Term; use Drupal\node\Entity\Node; +use Drupal\taxonomy\Entity\Vocabulary; /** * 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(); - $vocabulary = entity_load('taxonomy_vocabulary', $vocabulary->id()); + $vocabulary = Vocabulary::load($vocabulary->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type taxonomy_vocabulary', diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 0ca834a6039..7f8be0aa842 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -8,6 +8,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Mail\MailFormatHelper; use Drupal\Core\Url; +use Drupal\taxonomy\Entity\Vocabulary; /** * @addtogroup hooks @@ -419,7 +420,7 @@ function hook_mail($key, &$message, $params) { ); if ($context['hook'] == 'taxonomy') { $entity = $params['entity']; - $vocabulary = entity_load('taxonomy_vocabulary', $entity->id()); + $vocabulary = Vocabulary::load($entity->id()); $variables += array( '%term_name' => $entity->name, '%term_description' => $entity->description, diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php index 9a6a2689bbd..8fb30a6cd9d 100644 --- a/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php @@ -13,6 +13,8 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\OptGroup; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\OptionsProviderInterface; +use Drupal\Core\TypedData\AllowedValuesInterface; +use Drupal\taxonomy\Entity\Vocabulary; /** * Plugin implementation of the 'term_reference' field type. @@ -83,7 +85,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements OptionsPr else { $options = array(); 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)) { foreach ($terms as $term) { $options[$term->id()] = str_repeat('-', $term->depth) . $term->getName(); @@ -122,7 +124,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements OptionsPr * {@inheritdoc} */ public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = Vocabulary::loadMultiple(); $options = array(); foreach ($vocabularies as $vocabulary) { $options[$vocabulary->id()] = $vocabulary->label(); diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php index 8b7fa812d64..8182b440d9c 100644 --- a/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php @@ -13,8 +13,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\taxonomy\Entity\Term; -use Drupal\taxonomy\Plugin\Field\FieldType\TaxonomyTermReferenceItem; +use Drupal\taxonomy\VocabularyStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -36,13 +35,21 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP */ protected $termStorage; + /** + * The vocabulary storage. + * + * @var VocabularyStorageInterface + */ + protected $vocabularyStorage; + /** * {@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); $this->termStorage = $term_storage; + $this->vocabularyStorage = $vocabulary_storage; } /** @@ -55,7 +62,8 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP $configuration['field_definition'], $configuration['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. 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; } } diff --git a/core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php b/core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php index 58b3034acfa..5d4469fc84a 100644 --- a/core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php +++ b/core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase; +use Drupal\taxonomy\Entity\Vocabulary; /** * 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); 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)) { foreach ($terms as $term) { $options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->getName()); diff --git a/core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php b/core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php index a8dab7445a2..597f8261830 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php +++ b/core/modules/taxonomy/src/Plugin/views/argument/VocabularyVid.php @@ -9,6 +9,8 @@ namespace Drupal\taxonomy\Plugin\views\argument; use Drupal\views\Plugin\views\argument\Numeric; use Drupal\Component\Utility\String; +use Drupal\taxonomy\VocabularyStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Argument handler to accept a vocabulary id. @@ -19,11 +21,47 @@ use Drupal\Component\Utility\String; */ 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. */ function title() { - $vocabulary = entity_load('taxonomy_vocabulary', $this->argument); + $vocabulary = $this->vocabularyStorage->load($this->argument); if ($vocabulary) { return String::checkPlain($vocabulary->label()); } diff --git a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php index a90b5e19305..a1496c2f178 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php @@ -17,6 +17,8 @@ use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase; use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Drupal\taxonomy\Entity\Vocabulary; +use Drupal\taxonomy\VocabularyStorageInterface; /** * Taxonomy tid default argument. @@ -37,21 +39,31 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface /** * Constructs a new Date instance. + * The vocary storage. + * + * @var \Drupal\taxonomy\VocabularyStorageInterface. + */ + protected $vocabularyStorage; + + /** + * Constructs a Tid 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. - * + * The plugin implementation definition. * * @param \Drupal\Core\Routing\RouteMatchInterface $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); $this->routeMatch = $route_match; + $this->vocabularyStorage = $vocabulary_storage; } /** @@ -62,7 +74,8 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface $configuration, $plugin_id, $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(); - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = $this->vocabularyStorage->loadMultiple(); foreach ($vocabularies as $voc) { $options[$voc->id()] = $voc->label(); } diff --git a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php index a5b533c764d..81fd898744b 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/field/TaxonomyIndexTid.php @@ -12,6 +12,9 @@ use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\PrerenderList; 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. @@ -22,6 +25,42 @@ use Drupal\Component\Utility\String; */ 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(). */ @@ -64,7 +103,7 @@ class TaxonomyIndexTid extends PrerenderList { ); $options = array(); - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = $this->vocabularyStorage->loadMultiple(); foreach ($vocabularies as $voc) { $options[$voc->id()] = $voc->label(); } @@ -93,7 +132,7 @@ class TaxonomyIndexTid extends PrerenderList { } public function preRender(&$values) { - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = $this->vocabularyStorage->loadMultiple(); $this->field_alias = $this->aliases['nid']; $nids = array(); foreach ($values as $result) { diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index 1c44562ceb1..c158de437d3 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -106,7 +106,7 @@ class TaxonomyIndexTid extends ManyToOne { } public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) { - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = $this->vocabularyStorage->loadMultiple(); $options = array(); foreach ($vocabularies as $voc) { $options[$voc->id()] = $voc->label(); @@ -150,7 +150,7 @@ class TaxonomyIndexTid extends ManyToOne { } 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']) { $form['markup'] = array( '#markup' => '