diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php index 0898f48cf88acfe324941faf7f459a9585c001d5..bddea8dbf8897bba9e677ee5f06597bdc0a01e9a 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. @@ -170,7 +171,7 @@ public function testConfigEntityReferenceItem() { $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 ead923ab2706dc4cdb19e9bf87b5bcb7d1133fa8..aff0b859aaf740cf3e51c6220bc22ea150128740 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -13,6 +13,7 @@ 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 @@ 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'); @@ -344,7 +345,7 @@ private function doAdminTests($user) { 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 @@ 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->label(), $edit['name'], 'The name was updated'); @@ -369,7 +370,7 @@ function editForumVocabulary() { $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 0995ecfbd2ceb59877c7f425657d525938147c59..8cc59ae5775bffba448110b16e0b9dd31401193e 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->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 895fac6396fd23a3368d0532d231ac7618d7c340..f53eb7d9eb0b6b56fecb0168c44f4891b982f0ce 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/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index c65919446ae208268f7fac6c0a90d6aef51e39d0..35ea40823910a4b2676ebbac7fe8dcb79be9d082 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\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 @@ public function testTaxonomyVocabularyHooks() { )); $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 0ca834a60392223e8039147fc23c71fe63eb394e..7f8be0aa842c8282520ad4f1e67952047989daa9 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 9a6a2689bbdeea4cdb19486311cbba7473b8427c..8fb30a6cd9d62c5500d8bf5ea72c62ad1239e4fe 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. @@ -83,7 +85,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->label(); diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/src/Plugin/Field/FieldWidget/TaxonomyAutocompleteWidget.php index 8b7fa812d6403b3f99acd4ca8705cb22068dba42..8182b440d9c92848d9e30fdce7d8e83a899f6eef 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\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 @@ 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') ); } @@ -138,7 +146,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 58b3034acfaef4e4c08f59d9dded47268d4536bc..5d4469fc84a1339b651f318abd2416c184bfdcdd 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. @@ -64,7 +65,7 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA $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 a8dab7445a2304ea6f5e5f622aab2d8fe2187864..597f8261830f2cfb9812ef167c68df2c76acb7c6 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. @@ -19,11 +21,47 @@ */ 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 a90b5e193054932a04fce252c0dfd1427bcf9600..a1496c2f178683798c4b87c4d21fc21e1ffa20f4 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\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 @@ public static function create(ContainerInterface $container, array $configuratio $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 @@ 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 a5b533c764d70edf54c112bd6eb86cc770fd9983..81fd898744b65116d1d022eb39aee8aefb69a349 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. @@ -22,6 +25,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(). */ @@ -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 1c44562ceb12bff7f36539e47295160eae3f1bb8..c158de437d3e06dbe8e071d3cbbba0ebf3005f7a 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 @@ 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(); @@ -150,7 +150,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 6113057f6a57567ca0afe720abe7e7b5f226f3bc..b6fed8b05937fdd0850a837a05f18fb163407309 100644 --- a/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php +++ b/core/modules/taxonomy/src/Plugin/views/relationship/NodeTermData.php @@ -84,7 +84,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 94557b44bc10c907a50d7458b504ad3c3c3eca08..67b498343855b2a64eec20cdb4ab121550198a85 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->getHierarchy(), '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 37ec181c05d9ed6726ea24a4589f2de39f83f2a8..4e3a9f0e8750e53ffeaf98d0b793d1bf40540e74 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->label(), $original_vocabulary->label(), '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->label(), $vocabulary->label(), '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 5bd84de895648d64bd67e96db12ce343645383df..bc508cc868c059a631c3de883333f8aa0e91567c 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->get('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->label())), '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 e3d0ffe37435fe68e9f0783e9cb4fbdc7b61a442..fa726259287f321a0071f4859c923a515a5e0f72 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -12,12 +12,40 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ContentLanguageSettings; +use Drupal\taxonomy\VocabularyStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base form for vocabulary edit forms. */ 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} */ @@ -42,7 +70,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'), ), ); @@ -136,4 +164,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->vocabularyStorage->load($id); + return !empty($action); + } + } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index 5c9403b06a80f083057cc553b3b0e28a7307a325..08c5c89d2f3e470034f2cd0a36dd32e447927dd6 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->label()); 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 aee3fbb5966539a28752432d08e2bc17ecb392a4..7ee7df4ee98655379884f83e02544e9c76d125cd 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -11,6 +11,7 @@ use Drupal\Core\Url; 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. @@ -231,7 +232,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']; } }