diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php index db91b59..7d170c3 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\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. @@ -147,7 +148,7 @@ public function testConfigEntityReferenceItem() { $entity->field_test_taxonomy_vocabulary->entity->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->name, $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 8ebdb81..18cca75 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; use Drupal\simpletest\WebTestBase; +use Drupal\taxonomy\Entity\Vocabulary; /** * Create, view, edit, delete, and change forum entries and verify its @@ -198,7 +199,7 @@ function testForum() { // 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'); @@ -319,7 +320,7 @@ private function doAdminTests($user) { function editForumVocabulary() { // Backup forum taxonomy. $vid = \Drupal::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( @@ -333,7 +334,7 @@ function editForumVocabulary() { $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->name, $edit['name'], 'The name was updated'); @@ -344,7 +345,7 @@ function editForumVocabulary() { $current_vocabulary->set('description', $original_vocabulary->description); $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->name, $original_vocabulary->name, '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 607d4d7..1b16835 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 @@ 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 @@ protected function setUp() { 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->name, "vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->description, "description of vocabulary $j (i=$i)"); $this->assertEqual($vocabulary->hierarchy, $i); $this->assertEqual($vocabulary->weight, 4 + $i); } - $vocabulary = entity_load('taxonomy_vocabulary', 'vocabulary_name_much_longer_than'); + $vocabulary = Vocabulary::load('vocabulary_name_much_longer_than'); $this->assertEqual($vocabulary->name, 'vocabulary name much longer than thirty two characters'); $this->assertEqual($vocabulary->description, 'description of vocabulary name much longer than thirty two characters'); $this->assertEqual($vocabulary->hierarchy, 3); diff --git a/core/modules/path/src/Tests/PathTaxonomyTermTest.php b/core/modules/path/src/Tests/PathTaxonomyTermTest.php index 895fac6..f53eb7d 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 @@ protected function setUp() { */ 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/system.api.php b/core/modules/system/system.api.php index 4e98a64..ccea4cd 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 @@ -456,7 +457,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 83d9780..fa4d5eb 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\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. @@ -82,7 +84,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { 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 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) * {@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->name; diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php index dd85ed7..c6a129e 100644 --- a/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php @@ -13,7 +13,7 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\VocabularyStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -36,12 +36,18 @@ class TaxonomyAutocompleteWidget extends WidgetBase implements ContainerFactoryP protected $termStorage; /** + * @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_interface) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings); $this->termStorage = $term_storage; + $this->vocabularyStorage = $vocabulary_interface; } /** @@ -54,7 +60,8 @@ public static function create(ContainerInterface $container, array $configuratio $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') ); } @@ -137,7 +144,7 @@ public function massageFormValues(array $values, array $form, FormStateInterface // 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 50f3bc1..cd4141a 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\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. @@ -63,7 +64,7 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA $bundle_names = !empty($this->instance['settings']['handler_settings']['target_bundles']) ? $this->instance['settings']['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 a8dab74..58c9f14 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 @@ 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. @@ -20,10 +22,46 @@ 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 interface. + */ + 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 2cd7a13..025bfe9 100644 --- a/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/src/Plugin/views/argument_default/Tid.php @@ -16,6 +16,8 @@ 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. @@ -28,6 +30,42 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface { /** + * The vocabulary 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. + * @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\Plugin\views\PluginBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -81,7 +119,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ); $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 a5b533c..81fd898 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\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. @@ -23,6 +26,42 @@ 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(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -64,7 +103,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ); $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 @@ public function query() { } 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 071b2f8..716a2d2 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -14,6 +14,9 @@ use Drupal\views\Plugin\views\filter\ManyToOne; use Drupal\Component\Utility\String; use Drupal\Component\Utility\Tags; +use Drupal\taxonomy\Entity\Vocabulary; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\taxonomy\VocabularyStorageInterface; /** * Filter by term id. @@ -28,6 +31,42 @@ class TaxonomyIndexTid extends ManyToOne { var $validated_exposed_input = NULL; /** + * 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\filter\ManyToOne::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -55,7 +94,7 @@ protected function defineOptions() { } 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(); @@ -99,7 +138,7 @@ public function buildExtraOptionsForm(&$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']) { $form['markup'] = array( '#markup' => '
' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '
', diff --git a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php index c0629c9..b37a06a 100644 --- a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php +++ b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php @@ -11,6 +11,9 @@ use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\relationship\RelationshipPluginBase; +use Drupal\taxonomy\Entity\Vocabulary; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\taxonomy\VocabularyStorageInterface; /** * Relationship handler to return the taxonomy terms of nodes. @@ -22,6 +25,42 @@ class NodeTermData extends RelationshipPluginBase { /** + * 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\relationship\RelationshipPluginBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -46,7 +85,7 @@ protected function defineOptions() { } public function buildOptionsForm(&$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(); diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 0900dce..f327048 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -14,6 +14,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldStorageConfig; use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\Entity\Vocabulary; /** * Tests load, save and delete for taxonomy terms. @@ -71,7 +72,7 @@ function testTaxonomyTermHierarchy() { $term2 = $this->createTerm($this->vocabulary); // Check that hierarchy is flat. - $vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id()); + $vocabulary = Vocabulary::load($this->vocabulary->id()); $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.'); // Edit $term2, setting $term1 as parent. diff --git a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php index b167840..aff04e7 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\field\Entity\FieldConfig; +use Drupal\taxonomy\Entity\Vocabulary; /** * Tests loading, saving and deleting vocabularies. @@ -37,7 +38,7 @@ protected function setUp() { */ function testTaxonomyVocabularyDeleteWithTerms() { // Delete any existing vocabularies. - foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { + foreach (Vocabulary::loadMultiple() as $vocabulary) { $vocabulary->delete(); } @@ -68,7 +69,7 @@ function testTaxonomyVocabularyDeleteWithTerms() { * Ensure that the vocabulary static reset works correctly. */ 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->assertEqual($this->vocabulary->name, $original_vocabulary->name, 'Vocabulary loaded successfully.'); @@ -79,12 +80,12 @@ function testTaxonomyVocabularyLoadStaticReset() { $vocabulary->save(); // Load the vocabulary. - $new_vocabulary = entity_load('taxonomy_vocabulary', $original_vocabulary->id()); + $new_vocabulary = Vocabulary::load($original_vocabulary->id()); $this->assertEqual($new_vocabulary->name, $vocabulary->name, 'The vocabulary was loaded.'); // Delete the vocabulary. $this->vocabulary->delete(); - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = Vocabulary::loadMultiple(); $this->assertTrue(!isset($vocabularies[$this->vocabulary->id()]), 'The vocabulary was deleted.'); } @@ -94,7 +95,7 @@ function testTaxonomyVocabularyLoadStaticReset() { function testTaxonomyVocabularyLoadMultiple() { // Delete any existing vocabularies. - foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { + foreach (Vocabulary::loadMultiple() as $vocabulary) { $vocabulary->delete(); } @@ -121,7 +122,7 @@ function testTaxonomyVocabularyLoadMultiple() { // Fetch the vocabularies with entity_load_multiple(), specifying IDs. // 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); $expected_order = array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()); $this->assertIdentical($loaded_order, $expected_order); diff --git a/core/modules/taxonomy/src/Tests/VocabularyUiTest.php b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php index 134bb36..d4932a2 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyUiTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php @@ -8,6 +8,8 @@ namespace Drupal\taxonomy\Tests; use Drupal\Component\Utility\Unicode; +use Drupal\taxonomy\Entity\Vocabulary; + /** * Tests the taxonomy vocabulary interface. * @@ -80,7 +82,7 @@ function testTaxonomyAdminChangingWeights() { $this->createVocabulary(); } // Get all vocabularies and change their weights. - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = Vocabulary::loadMultiple(); $edit = array(); foreach ($vocabularies as $key => $vocabulary) { $weight = -$vocabulary->weight; @@ -92,7 +94,7 @@ function testTaxonomyAdminChangingWeights() { // Load the vocabularies from the database. $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. foreach ($vocabularies as $key => $vocabulary) { @@ -105,12 +107,12 @@ function testTaxonomyAdminChangingWeights() { */ function testTaxonomyAdminNoVocabularies() { // Delete all vocabularies. - $vocabularies = entity_load_multiple('taxonomy_vocabulary'); + $vocabularies = Vocabulary::loadMultiple(); foreach ($vocabularies as $key => $vocabulary) { $vocabulary->delete(); } // 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'); // Check the default message for no vocabularies. $this->assertText(t('No vocabularies available.')); @@ -131,7 +133,7 @@ function testTaxonomyAdminDeletingVocabulary() { // Check the created vocabulary. $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache(); - $vocabulary = entity_load('taxonomy_vocabulary', $vid); + $vocabulary = Vocabulary::load($vid); $this->assertTrue($vocabulary, 'Vocabulary found.'); // Delete the vocabulary. @@ -144,6 +146,6 @@ function testTaxonomyAdminDeletingVocabulary() { $this->drupalPostForm(NULL, NULL, t('Delete')); $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), 'Vocabulary deleted.'); $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.'); } } diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index 34dc3ed..c96925b 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -11,6 +11,8 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\taxonomy\VocabularyStorageInterface; /** * Base form for vocabulary edit forms. @@ -18,6 +20,32 @@ class VocabularyForm extends EntityForm { /** + * The vocabulary storage. + * + * @var \Drupal\taxonomy\VocabularyStorageInterface. + */ + protected $storage; + + /** + * Constructs a new vocabulary form. + * + * @param \Drupal\taxonomy\VocabularyStorageInterface $storage + * The vocabulary storage. + */ + public function __construct(VocabularyStorageInterface $storage) { + $this->storage = $storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager')->getStorage('taxonomy_vocabulary') + ); + } + + /** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { @@ -41,7 +69,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array( - 'exists' => 'taxonomy_vocabulary_load', + 'exists' => array($this, 'exists'), 'source' => array('name'), ), ); @@ -157,4 +185,18 @@ public function save(array $form, FormStateInterface $form_state) { $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->storage->load($id); + return !empty($action); + } + } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index aa1505c..da36818 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Xss; +use Drupal\taxonomy\Entity\Vocabulary; /** * Implements hook_token_info(). @@ -127,7 +128,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'vocabulary': - $vocabulary = entity_load('taxonomy_vocabulary', $term->bundle()); + $vocabulary = Vocabulary::load($term->bundle()); $replacements[$original] = String::checkPlain($vocabulary->name); break; @@ -141,7 +142,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = } 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); } diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index 61bd9a8..3564afe 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\ViewExecutable; use Drupal\views\Views; +use Drupal\taxonomy\Entity\Vocabulary; /** * Converts a form element in the add view wizard to be AJAX-enabled. @@ -230,7 +231,7 @@ function views_ui_taxonomy_autocomplete_validate($element, FormStateInterface $f $allowed_values = $field_storage->getSetting('allowed_values'); if (!empty($allowed_values)) { foreach ($allowed_values as $tree) { - if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { + if ($vocabulary = Vocabulary::load($tree['vocabulary'])) { $vocabularies[$vocabulary->id()] = $tree['vocabulary']; } }