diff --git a/core/modules/config/lib/Drupal/config/ConfigurableInterface.php b/core/modules/config/lib/Drupal/config/ConfigurableInterface.php index bf49b9b..2ac9bb3 100644 --- a/core/modules/config/lib/Drupal/config/ConfigurableInterface.php +++ b/core/modules/config/lib/Drupal/config/ConfigurableInterface.php @@ -7,12 +7,12 @@ namespace Drupal\config; -use Drupal\entity\StorableInterface; +use Drupal\entity\EntityInterface; /** * Defines the interface common for all configurable entities. */ -interface ConfigurableInterface extends StorableInterface { +interface ConfigurableInterface extends EntityInterface { /** * Returns the original ID. diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 30b1e6b..fe915d4 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -220,17 +220,8 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) { function forum_entity_info_alter(&$info) { // Take over URI construction for taxonomy terms that are forums. if ($vid = config('forum.settings')->get('vocabulary')) { - // Within hook_entity_info(), we can't invoke entity_load() as that would - // cause infinite recursion, so we call taxonomy_vocabulary_get_names() - // instead of taxonomy_vocabulary_load(). All we need is the machine name - // of $vid, so retrieving and iterating all the vocabulary names is somewhat - // inefficient, but entity info is cached across page requests, and an - // iteration of all vocabularies once per cache clearing isn't a big deal, - // and is done as part of taxonomy_entity_info() anyway. - foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { - if ($vid == $vocabulary->vid) { - $info['taxonomy_term']['bundles'][$machine_name]['uri callback'] = 'forum_uri'; - } + if (isset($info['taxonomy_term']['bundles'][$vid])) { + $info['taxonomy_term']['bundles'][$vid]['uri callback'] = 'forum_uri'; } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php index 929422c..7ed596f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php @@ -81,16 +81,6 @@ class Term extends Entity { public $parent; /** - * The machine name of the vocabulary the term is assigned to. - * - * If not given, this value will be set automatically by loading the - * vocabulary based on the $entity->vid property. - * - * @var string - */ - public $vocabulary_machine_name; - - /** * Implements Drupal\entity\EntityInterface::id(). */ public function id() { @@ -101,6 +91,6 @@ public function id() { * Implements Drupal\entity\EntityInterface::bundle(). */ public function bundle() { - return $this->vocabulary_machine_name; + return $this->vid; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index dfa1c3f..15cfe9b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -49,11 +49,6 @@ public function form(array $form, array &$form_state, EntityInterface $term) { '#default_value' => $term->langcode, ); - $form['vocabulary_machine_name'] = array( - '#type' => 'value', - '#value' => isset($term->vocabulary_machine_name) ? $term->vocabulary_machine_name : $vocabulary->name, - ); - $form['relations'] = array( '#type' => 'fieldset', '#title' => t('Relations'), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index e90699d..ec791f5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -24,15 +24,6 @@ class TermStorageController extends DatabaseStorageController { */ public function create(array $values) { $entity = parent::create($values); - // Ensure the vocabulary machine name is initialized as it is used as the - // bundle key. Only attempt to do this if a vocabulary ID is available, - // which might not be the case when creating partial entity structures. - // @todo Move to Term::bundle() once field API has been converted - // to make use of it. - if (!isset($entity->vocabulary_machine_name) && isset($entity->vid)) { - $vocabulary = taxonomy_vocabulary_load($entity->vid); - $entity->vocabulary_machine_name = $vocabulary->machine_name; - } // Save new terms with no parents by default. if (!isset($entity->parent)) { $entity->parent = array(0); @@ -47,10 +38,6 @@ protected function buildQuery($ids, $revision_id = FALSE) { $query = parent::buildQuery($ids, $revision_id); $query->addTag('translatable'); $query->addTag('term_access'); - - // Add the machine name field from the {taxonomy_vocabulary} table. - $query->innerJoin('taxonomy_vocabulary', 'v', 'base.vid = v.vid'); - $query->addField('v', 'machine_name', 'vocabulary_machine_name'); return $query; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php index 8fb20d0..a2fba81 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php @@ -58,7 +58,7 @@ function testTaxonomyEfq() { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'taxonomy_term'); - $query->entityCondition('bundle', $vocabulary2->machine_name); + $query->entityCondition('bundle', $vocabulary2->vid); $result = $query->execute(); $result = $result['taxonomy_term']; asort($result); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php index 3dd43b1..81bf412 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php @@ -45,7 +45,7 @@ function testTaxonomyTermHooks() { 'name' => $this->randomName(), 'antonym' => 'Long', ); - $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->vid . '/add', $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name']); $term = reset($terms); $this->assertEqual($term->antonym, $edit['antonym'], 'Antonym was loaded into the term object.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index 79998b6..c07cfbb 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -35,13 +35,13 @@ function setUp() { $this->vocabulary = $this->createVocabulary(); $field = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), @@ -50,7 +50,7 @@ function setUp() { field_create_field($field); $this->instance = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'bundle' => 'article', 'entity_type' => 'node', 'widget' => array( @@ -84,7 +84,7 @@ function testTaxonomyRss() { // Change the format to 'RSS category'. $this->drupalGet("admin/structure/types/manage/article/display/rss"); $edit = array( - "fields[taxonomy_" . $this->vocabulary->machine_name . "][type]" => 'taxonomy_term_reference_rss_category', + "fields[taxonomy_" . $this->vocabulary->vid . "][type]" => 'taxonomy_term_reference_rss_category', ); $this->drupalPost(NULL, $edit, t('Save')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php index 6f4dcb2..40284cc 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php @@ -38,7 +38,7 @@ function createVocabulary() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => $this->randomName(), 'description' => $this->randomName(), - 'machine_name' => drupal_strtolower($this->randomName()), + 'vid' => drupal_strtolower($this->randomName()), 'langcode' => LANGUAGE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('article' => 'article'), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index c8bd41e..a71384f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -48,11 +48,11 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary1->machine_name, + 'vocabulary' => $this->vocabulary1->vid, 'parent' => '0', ), array( - 'vocabulary' => $this->vocabulary2->machine_name, + 'vocabulary' => $this->vocabulary2->vid, 'parent' => '0', ), ), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 34065e1..27fbd6f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -47,7 +47,7 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => '0', ), ), @@ -142,11 +142,11 @@ function testTaxonomyTermFieldChangeMachineName() { // they all get updated. $this->field['settings']['allowed_values'] = array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => '0', ), array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => '0', ), array( @@ -157,7 +157,7 @@ function testTaxonomyTermFieldChangeMachineName() { field_update_field($this->field); // Change the machine name. $new_name = drupal_strtolower($this->randomName()); - $this->vocabulary->machine_name = $new_name; + $this->vocabulary->vid = $new_name; taxonomy_vocabulary_save($this->vocabulary); // Check that the field instance is still attached to the vocabulary. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 31d01c5..7afd15c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -38,7 +38,7 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), @@ -68,7 +68,7 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php index f64cf58..db51cc1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php @@ -50,7 +50,7 @@ function testTermLanguage() { language_save($language); // Add a term. - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->vid . '/add'); // Check that we have the language selector. $this->assertField('edit-langcode', t('The language selector field was found on the page')); // Submit the term. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 1f34e66..4d5701d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -27,13 +27,13 @@ function setUp() { $this->vocabulary = $this->createVocabulary(); $field = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), @@ -42,7 +42,7 @@ function setUp() { field_create_field($field); $this->instance = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'bundle' => 'article', 'entity_type' => 'node', 'widget' => array( @@ -200,13 +200,13 @@ function testNodeTermCreationAndDeletion() { // Test autocomplete on term 3, which contains a comma. // The term will be quoted, and the " will be encoded in unicode (\u0022). $input = substr($term_objects['term3']->name, 0, 3); - $json = $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); + $json = $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->vid . '/' . $input); $this->assertEqual($json, '{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name))); // Test autocomplete on term 4 - it is alphanumeric only, so no extra // quoting. $input = substr($term_objects['term4']->name, 0, 3); - $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); + $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->vid . '/' . $input); $this->assertRaw('{"' . $term_objects['term4']->name . '":"' . $term_objects['term4']->name . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->name))); // Test taxonomy autocomplete with a nonexistent field. @@ -239,7 +239,7 @@ function testTermAutocompletion() { // We should get both term in a json encoded string. $input = '10/'; $path = 'taxonomy/autocomplete/taxonomy_'; - $path .= $this->vocabulary->machine_name . '/' . $input; + $path .= $this->vocabulary->vid . '/' . $input; // The result order is not guaranteed, so check each term separately. $result = $this->drupalGet($path); $data = drupal_json_decode($result); @@ -250,7 +250,7 @@ function testTermAutocompletion() { // We should only get the first term in a json encoded string. $input = '10/16'; $url = 'taxonomy/autocomplete/taxonomy_'; - $url .= $this->vocabulary->machine_name . '/' . $input; + $url .= $this->vocabulary->vid . '/' . $input; $this->drupalGet($url); $target = array($first_term->name => check_plain($first_term->name)); $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns only the expected matching term.'); @@ -258,7 +258,7 @@ function testTermAutocompletion() { // Try to autocomplete a term name with both a comma and a slash. $input = '"term with, comma and / a'; $url = 'taxonomy/autocomplete/taxonomy_'; - $url .= $this->vocabulary->machine_name . '/' . $input; + $url .= $this->vocabulary->vid . '/' . $input; $this->drupalGet($url); $n = $third_term->name; // Term names containing commas or quotes must be wrapped in quotes. @@ -282,14 +282,14 @@ function testTermInterface() { $edit['parent[]'] = array(0); // Create the term to edit. - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save')); $terms = taxonomy_term_load_multiple_by_name($edit['name']); $term = reset($terms); $this->assertNotNull($term, 'Term found in database.'); // Submitting a term takes us to the add page; we need the List page. - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->vid); // Test edit link as accessed from Taxonomy administration pages. // Because Simpletest creates its own database when running tests, we know @@ -308,7 +308,7 @@ function testTermInterface() { $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); // Check that the term is still present at admin UI after edit. - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->vid); $this->assertText($edit['name'], 'The randomly generated term name is present.'); $this->assertLink(t('edit')); @@ -356,7 +356,7 @@ function testTermReorder() { drupal_static_reset('taxonomy_get_treeterms'); list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid); - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->vid); // Each term has four hidden fields, "tid:1:0[tid]", "tid:1:0[parent]", // "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2, @@ -386,7 +386,7 @@ function testTermReorder() { $this->assertEqual($terms[1]->parents, array($term2->tid), 'Term 3 was made a child of term 2.'); $this->assertEqual($terms[2]->tid, $term1->tid, 'Term 1 was moved below term 2.'); - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name, array(), t('Reset to alphabetical')); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->vid, array(), t('Reset to alphabetical')); // Submit confirmation form. $this->drupalPost(NULL, array(), t('Reset to alphabetical')); @@ -414,7 +414,7 @@ function testTermMultipleParentsInterface() { 'parent[]' => array(0, $parent->tid), ); // Save the new term. - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save')); // Check that the term was successfully created. $terms = taxonomy_term_load_multiple_by_name($edit['name']); @@ -472,7 +472,7 @@ function testTaxonomyGetTermByName() { $this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.'); // Load single term when restricted to one vocabulary. - $terms = taxonomy_term_load_multiple_by_name($term->name, $this->vocabulary->machine_name); + $terms = taxonomy_term_load_multiple_by_name($term->name, $this->vocabulary->vid); $this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.'); $this->assertTrue(isset($terms[$term->tid]), 'Term loaded using exact name and vocabulary machine name.'); @@ -481,7 +481,7 @@ function testTaxonomyGetTermByName() { // Try to load a term by name that doesn't exist in this vocabulary but // exists in another vocabulary. - $terms = taxonomy_term_load_multiple_by_name($term2->name, $new_vocabulary->machine_name); + $terms = taxonomy_term_load_multiple_by_name($term2->name, $new_vocabulary->vid); $this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.'); // Try to load terms filtering by a non-existing vocabulary. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index e273c1b..561cd2f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -28,13 +28,13 @@ function setUp() { $this->langcode = LANGUAGE_NOT_SPECIFIED; $field = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), @@ -43,7 +43,7 @@ function setUp() { field_create_field($field); $this->instance = array( - 'field_name' => 'taxonomy_' . $this->vocabulary->machine_name, + 'field_name' => 'taxonomy_' . $this->vocabulary->vid, 'bundle' => 'article', 'entity_type' => 'node', 'widget' => array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php index f4368b7..4b9a3f6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php @@ -51,15 +51,15 @@ function testVocabularyLanguage() { $this->assertField('edit-langcode', t('The language selector field was found on the page')); // Create the vocabulary. - $machine_name = drupal_strtolower($this->randomName()); + $vid = drupal_strtolower($this->randomName()); $edit['name'] = $this->randomName(); $edit['description'] = $this->randomName(); $edit['langcode'] = 'aa'; - $edit['machine_name'] = $machine_name; + $edit['vid'] = $vid; $this->drupalPost(NULL, $edit, t('Save')); // Check the language on the edit page. - $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit'); + $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit'); $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.')); // Change the language and save again. @@ -67,7 +67,7 @@ function testVocabularyLanguage() { $this->drupalPost(NULL, $edit, t('Save')); // Check again the language on the edit page. - $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit'); + $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit'); $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.')); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php index 6197fdb..91e022f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php @@ -37,10 +37,10 @@ function testVocabularyInterface() { // Create a new vocabulary. $this->clickLink(t('Add vocabulary')); $edit = array(); - $machine_name = drupal_strtolower($this->randomName()); + $vid = drupal_strtolower($this->randomName()); $edit['name'] = $this->randomName(); $edit['description'] = $this->randomName(); - $edit['machine_name'] = $machine_name; + $edit['vid'] = $vid; $this->drupalPost(NULL, $edit, t('Save')); $this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.'); @@ -55,12 +55,12 @@ function testVocabularyInterface() { $this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.'); // Try to submit a vocabulary with a duplicate machine name. - $edit['machine_name'] = $machine_name; + $edit['vid'] = $vid; $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); $this->assertText(t('The machine-readable name is already in use. It must be unique.')); // Try to submit an invalid machine name. - $edit['machine_name'] = '!&^%'; + $edit['vid'] = '!&^%'; $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); $this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.')); @@ -68,7 +68,7 @@ function testVocabularyInterface() { $edit = array(); $edit['name'] = 'Don\'t Panic'; $edit['description'] = $this->randomName(); - $edit['machine_name'] = 'don_t_panic'; + $edit['vid'] = 'don_t_panic'; $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); $site_name = config('system.site')->get('name'); @@ -114,10 +114,10 @@ function testTaxonomyAdminNoVocabularies() { taxonomy_vocabulary_delete($key); } // Confirm that no vocabularies are found in the database. - $this->assertFalse(taxonomy_vocabulary_load_multiple(), 'No vocabularies found in the database.'); + $this->assertFalse(taxonomy_vocabulary_load_multiple(), 'No vocabularies found.'); $this->drupalGet('admin/structure/taxonomy'); // Check the default message for no vocabularies. - $this->assertText(t('No vocabularies available.'), 'No vocabularies were found.'); + $this->assertText(t('No vocabularies available.')); } /** @@ -127,7 +127,7 @@ function testTaxonomyAdminDeletingVocabulary() { // Create a vocabulary. $edit = array( 'name' => $this->randomName(), - 'machine_name' => drupal_strtolower($this->randomName()), + 'vid' => drupal_strtolower($this->randomName()), ); $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); $this->assertText(t('Created new vocabulary'), 'New vocabulary was created.'); @@ -137,11 +137,11 @@ function testTaxonomyAdminDeletingVocabulary() { $vid = $vocabularies[count($vocabularies) - 1]->vid; entity_get_controller('taxonomy_vocabulary')->resetCache(); $vocabulary = taxonomy_vocabulary_load($vid); - $this->assertTrue($vocabulary, 'Vocabulary found in database.'); + $this->assertTrue($vocabulary, 'Vocabulary found.'); // Delete the vocabulary. $edit = array(); - $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit', $edit, t('Delete')); + $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->vid . '/edit', $edit, t('Delete')); $this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', array('%name' => $vocabulary->name)), '[confirm deletion] Asks for confirmation.'); $this->assertText(t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), '[confirm deletion] Inform that all terms will be deleted.'); @@ -149,6 +149,6 @@ function testTaxonomyAdminDeletingVocabulary() { $this->drupalPost(NULL, NULL, t('Delete')); $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), 'Vocabulary deleted.'); entity_get_controller('taxonomy_vocabulary')->resetCache(); - $this->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary is not found in the database')); + $this->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary not found.')); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index 9080ef2..bb769d0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -139,7 +139,7 @@ function testTaxonomyVocabularyLoadMultiple() { // Fetch the names for all vocabularies, confirm that they are keyed by // machine name. $names = taxonomy_vocabulary_get_names(); - $this->assertEqual($names[$vocabulary1->machine_name]->name, $vocabulary1->name, 'Vocabulary 1 name found.'); + $this->assertEqual($names[$vocabulary1->vid], $vocabulary1->vid, 'Vocabulary 1 name found.'); // Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(). // Confirm that the vocabularies are ordered by weight. @@ -176,14 +176,14 @@ function testTaxonomyVocabularyChangeMachineName() { $instance = array( 'field_name' => 'field_test', 'entity_type' => 'taxonomy_term', - 'bundle' => $this->vocabulary->machine_name, + 'bundle' => $this->vocabulary->vid, ); field_create_instance($instance); // Change the machine name. - $old_name = $this->vocabulary->machine_name; + $old_name = $this->vocabulary->vid; $new_name = drupal_strtolower($this->randomName()); - $this->vocabulary->machine_name = $new_name; + $this->vocabulary->vid = $new_name; taxonomy_vocabulary_save($this->vocabulary); // Check that entity bundles are properly updated. @@ -207,7 +207,7 @@ function testUninstallReinstall() { $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'taxonomy_term', - 'bundle' => $this->vocabulary->machine_name, + 'bundle' => $this->vocabulary->vid, 'label' => $this->randomName() . '_label', ); field_create_instance($this->instance); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Vocabulary.php index 13f6bbf..f5008b2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Vocabulary.php @@ -7,12 +7,12 @@ namespace Drupal\taxonomy; -use Drupal\entity\Entity; +use Drupal\config\ConfigurableBase; /** * Defines the taxonomy vocabulary entity. */ -class Vocabulary extends Entity { +class Vocabulary extends ConfigurableBase { /** * The taxonomy vocabulary ID. @@ -28,12 +28,7 @@ class Vocabulary extends Entity { */ public $name; - /** - * The vocabulary machine name. - * - * @var string - */ - public $machine_name; + public $uuid; /** * Description of the vocabulary. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index 667041e..26ee82e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -31,12 +31,12 @@ public function form(array $form, array &$form_state, EntityInterface $vocabular '#maxlength' => 255, '#required' => TRUE, ); - $form['machine_name'] = array( + $form['vid'] = array( '#type' => 'machine_name', - '#default_value' => $vocabulary->machine_name, + '#default_value' => $vocabulary->vid, '#maxlength' => 255, '#machine_name' => array( - 'exists' => 'taxonomy_vocabulary_machine_name_load', + 'exists' => 'taxonomy_vocabulary_load', ), ); $form['description'] = array( @@ -57,10 +57,6 @@ public function form(array $form, array &$form_state, EntityInterface $vocabular '#value' => '0', ); - if (isset($vocabulary->vid)) { - $form['vid'] = array('#type' => 'value', '#value' => $vocabulary->vid); - } - return parent::form($form, $form_state, $vocabulary); } @@ -88,13 +84,13 @@ public function validate(array $form, array &$form_state) { // Make sure that the machine name of the vocabulary is not in the // disallowed list (names that conflict with menu items, such as 'list' // and 'add'). - // During the deletion there is no 'machine_name' key. - if (isset($form_state['values']['machine_name'])) { + // During the deletion there is no 'vid' key. + if (isset($form_state['values']['vid'])) { // Do not allow machine names to conflict with taxonomy path arguments. - $machine_name = $form_state['values']['machine_name']; + $vid = $form_state['values']['vid']; $disallowed = array('add', 'list'); - if (in_array($machine_name, $disallowed)) { - form_set_error('machine_name', t('The machine-readable name cannot be "add" or "list".')); + if (in_array($vid, $disallowed)) { + form_set_error('vid', t('The machine-readable name cannot be "add" or "list".')); } } } @@ -128,13 +124,13 @@ public function save(array $form, array &$form_state) { switch (taxonomy_vocabulary_save($vocabulary)) { case SAVED_NEW: drupal_set_message(t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); - watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit')); - $form_state['redirect'] = 'admin/structure/taxonomy/' . $vocabulary->machine_name; + watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/' . $vocabulary->vid . '/edit')); + $form_state['redirect'] = 'admin/structure/taxonomy/' . $vocabulary->vid; break; case SAVED_UPDATED: drupal_set_message(t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); - watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit')); + watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('edit'), 'admin/structure/taxonomy/' . $vocabulary->vid . '/edit')); $form_state['redirect'] = 'admin/structure/taxonomy'; break; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php index 77f5ce7..1bc6cba 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -2,39 +2,29 @@ /** * @file - * Definition of VocabularyStorageController. + * Definition of Drupal\taxonomy\VocabularyStorageController. */ namespace Drupal\taxonomy; +use Drupal\config\ConfigStorageController; use Drupal\entity\StorableInterface; -use Drupal\entity\DatabaseStorageController; /** * Defines a controller class for taxonomy vocabularies. */ -class VocabularyStorageController extends DatabaseStorageController { - - /** - * Overrides Drupal\entity\DatabaseStorageController::buildQuery(). - */ - protected function buildQuery($ids, $revision_id = FALSE) { - $query = parent::buildQuery($ids, $revision_id); - $query->addTag('translatable'); - $query->orderBy('base.weight'); - $query->orderBy('base.name'); - return $query; - } +class VocabularyStorageController extends ConfigStorageController { /** * Overrides Drupal\entity\DatabaseStorageController::postSave(). */ protected function postSave(StorableInterface $entity, $update) { + parent::postSave($entity, $update); if (!$update) { - field_attach_create_bundle('taxonomy_term', $entity->machine_name); + field_attach_create_bundle('taxonomy_term', $entity->vid); } - elseif ($entity->original->machine_name != $entity->machine_name) { - field_attach_rename_bundle('taxonomy_term', $entity->original->machine_name, $entity->machine_name); + elseif ($entity->original->vid != $entity->vid) { + field_attach_rename_bundle('taxonomy_term', $entity->original->vid, $entity->vid); } } @@ -42,6 +32,7 @@ protected function postSave(StorableInterface $entity, $update) { * Overrides Drupal\entity\DatabaseStorageController::preDelete(). */ protected function preDelete($entities) { + parent::preDelete($entities); // Only load terms without a parent, child terms will get deleted too. $tids = db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid IN (:vids) AND th.parent = 0', array(':vids' => array_keys($entities)))->fetchCol(); taxonomy_term_delete_multiple($tids); @@ -51,6 +42,7 @@ protected function preDelete($entities) { * Overrides Drupal\entity\DatabaseStorageController::postDelete(). */ protected function postDelete($entities) { + parent::postDelete($entities); // Load all Taxonomy module fields and delete those which use only this // vocabulary. $taxonomy_fields = field_read_fields(array('module' => 'taxonomy')); @@ -60,7 +52,7 @@ protected function postDelete($entities) { // vocabulary. foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) { foreach ($entities as $vocabulary) { - if ($allowed_value['vocabulary'] == $vocabulary->machine_name) { + if ($allowed_value['vocabulary'] == $vocabulary->vid) { unset($taxonomy_field['settings']['allowed_values'][$key]); $modified_field = TRUE; } diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 163c0e7..e403bc7 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -28,9 +28,9 @@ function taxonomy_overview_vocabularies($form) { '#delta' => 10, '#default_value' => $vocabulary->weight, ); - $form[$vocabulary->vid]['edit'] = array('#type' => 'link', '#title' => t('edit vocabulary'), '#href' => "admin/structure/taxonomy/$vocabulary->machine_name/edit"); - $form[$vocabulary->vid]['list'] = array('#type' => 'link', '#title' => t('list terms'), '#href' => "admin/structure/taxonomy/$vocabulary->machine_name"); - $form[$vocabulary->vid]['add'] = array('#type' => 'link', '#title' => t('add terms'), '#href' => "admin/structure/taxonomy/$vocabulary->machine_name/add"); + $form[$vocabulary->vid]['edit'] = array('#type' => 'link', '#title' => t('edit vocabulary'), '#href' => "admin/structure/taxonomy/$vocabulary->vid/edit"); + $form[$vocabulary->vid]['list'] = array('#type' => 'link', '#title' => t('list terms'), '#href' => "admin/structure/taxonomy/$vocabulary->vid"); + $form[$vocabulary->vid]['add'] = array('#type' => 'link', '#title' => t('add terms'), '#href' => "admin/structure/taxonomy/$vocabulary->vid/add"); } // Only make this form include a submit button and weight if more than one @@ -289,7 +289,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { $form['#page_entries'] = $page_entries; $form['#back_step'] = $back_step; $form['#forward_step'] = $forward_step; - $form['#empty_text'] = t('No terms available. Add term.', array('@link' => url('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add'))); + $form['#empty_text'] = t('No terms available. Add term.', array('@link' => url('admin/structure/taxonomy/' . $vocabulary->vid . '/add'))); if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $form['actions'] = array('#type' => 'actions', '#tree' => FALSE); @@ -522,7 +522,7 @@ function theme_taxonomy_overview_terms($variables) { * Returns a rendered edit form to create a new term associated to the given vocabulary. */ function taxonomy_term_add($vocabulary) { - $term = entity_create('taxonomy_term', array('vid' => $vocabulary->vid, 'vocabulary_machine_name' => $vocabulary->machine_name)); + $term = entity_create('taxonomy_term', array('vid' => $vocabulary->vid)); return entity_get_form($term); } @@ -539,7 +539,7 @@ function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->vid);; $form['type'] = array('#type' => 'value', '#value' => 'term'); $form['name'] = array('#type' => 'value', '#value' => $term->name); - $form['vocabulary_machine_name'] = array('#type' => 'value', '#value' => $term->vocabulary_machine_name); + $form['vid'] = array('#type' => 'value', '#value' => $term->vid); $form['delete'] = array('#type' => 'value', '#value' => TRUE); return confirm_form($form, t('Are you sure you want to delete the term %title?', @@ -618,13 +618,12 @@ function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vi $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); $form['vid'] = array('#type' => 'value', '#value' => $vid); - $form['machine_name'] = array('#type' => 'value', '#value' => $vocabulary->machine_name); $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name); $form['reset_alphabetical'] = array('#type' => 'value', '#value' => TRUE); return confirm_form($form, t('Are you sure you want to reset the vocabulary %title to alphabetical order?', array('%title' => $vocabulary->name)), - 'admin/structure/taxonomy/' . $vocabulary->machine_name, + 'admin/structure/taxonomy/' . $vocabulary->vid, t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'), t('Reset to alphabetical'), t('Cancel')); @@ -642,5 +641,5 @@ function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_sta ->execute(); drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']))); watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - $form_state['redirect'] = 'admin/structure/taxonomy/' . $form_state['values']['machine_name']; + $form_state['redirect'] = 'admin/structure/taxonomy/' . $form_state['values']['vid']; } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 361dc6a..089e6e2 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for the taxonomy module. */ +use Drupal\Component\Uuid\Uuid; + /** * Implements hook_uninstall(). */ @@ -13,9 +15,10 @@ function taxonomy_uninstall() { variable_del('taxonomy_override_selector'); variable_del('taxonomy_terms_per_page_admin'); // Remove taxonomy_term bundles. - $vocabularies = db_query("SELECT machine_name FROM {taxonomy_vocabulary}")->fetchCol(); - foreach ($vocabularies as $vocabulary) { - field_attach_delete_bundle('taxonomy_term', $vocabulary); + $config_names = config_get_storage_names_with_prefix('taxonomy.vocabulary.'); + foreach ($config_names as $config_name) { + $vid = substr($config_name, strlen('taxonomy.vocabulary.')); + field_attach_delete_bundle('taxonomy_term', $vid); } } @@ -39,11 +42,11 @@ function taxonomy_schema() { 'not null' => FALSE, ), 'vid' => array( - 'type' => 'int', - 'unsigned' => TRUE, + 'type' => 'varchar', + 'length' => 255, 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.', + 'default' => '', + 'description' => 'The ID of the vocabulary to which the term is assigned.', ), 'langcode' => array( 'description' => 'The {language}.langcode of this term.', @@ -84,12 +87,6 @@ function taxonomy_schema() { 'unique keys' => array( 'uuid' => array('uuid'), ), - 'foreign keys' => array( - 'vocabulary' => array( - 'table' => 'taxonomy_vocabulary', - 'columns' => array('vid' => 'vid'), - ), - ), 'indexes' => array( 'taxonomy_tree' => array('vid', 'weight', 'name'), 'vid_name' => array('vid', 'name'), @@ -127,68 +124,6 @@ function taxonomy_schema() { 'primary key' => array('tid', 'parent'), ); - $schema['taxonomy_vocabulary'] = array( - 'description' => 'Stores vocabulary information.', - 'fields' => array( - 'vid' => array( - 'type' => 'serial', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'Primary Key: Unique vocabulary ID.', - ), - 'langcode' => array( - 'description' => 'The {language}.langcode of this vocabulary.', - 'type' => 'varchar', - 'length' => 12, - 'not null' => TRUE, - 'default' => '', - ), - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'Name of the vocabulary.', - 'translatable' => TRUE, - ), - 'machine_name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The vocabulary machine name.', - ), - 'description' => array( - 'type' => 'text', - 'not null' => FALSE, - 'size' => 'big', - 'description' => 'Description of the vocabulary.', - 'translatable' => TRUE, - ), - 'hierarchy' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'size' => 'tiny', - 'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)', - ), - 'weight' => array( - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The weight of this vocabulary in relation to other vocabularies.', - ), - ), - 'primary key' => array('vid'), - 'indexes' => array( - 'list' => array('weight', 'name'), - ), - 'unique keys' => array( - 'machine_name' => array('machine_name'), - ), - ); - $schema['taxonomy_index'] = array( 'description' => 'Maintains denormalized information about node/term relationships.', 'fields' => array( @@ -264,21 +199,13 @@ function taxonomy_field_schema($field) { } /** - * Remove the {taxonomy_vocabulary}.module field. - */ -function taxonomy_update_8000() { - db_drop_field('taxonomy_vocabulary', 'module'); -} - -/** - * Adds langcode field to {taxonomy_term_data} and {taxonomy_vocabulary}. + * Adds langcode field to {taxonomy_term_data}. * * @see http://drupal.org/node/1454538 */ function taxonomy_update_8001() { $descriptions = array( 'taxonomy_term_data' => 'The {language}.langcode of this term.', - 'taxonomy_vocabulary' => 'The {language}.langcode of this vocabulary.', ); foreach ($descriptions as $table => $description) { $langcode_field = array( @@ -335,3 +262,50 @@ function taxonomy_update_8002() { db_add_field('taxonomy_term_data', 'uuid', $spec, $keys); } } + +/** + * Convert vocabularies into configuration. + */ +function taxonomy_update_8003() { + $uuid = new Uuid(); + + $result = db_query('SELECT * FROM {taxonomy_vocabulary}'); + foreach ($result as $vocabulary) { + $config = config('taxonomy.vocabulary.' . $vocabulary->machine_name) + ->set('vid', $vocabulary->machine_name) + ->set('name', $vocabulary->name) + ->set('uuid', !empty($vocabulary->uuid) ? $vocabulary->uuid : $uuid->generate()) + ->set('description', $vocabulary->description) + ->set('hierarchy', $vocabulary->hierarchy) + ->set('weight', $vocabulary->weight) + ->save(); + } +} + +/** + * Change {taxonomy_term_data}.vid into a string holding the vocabulary machine name. + */ +function taxonomy_update_8004() { + db_change_field('taxonomy_term_data', 'vid', 'vid', array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The ID of the vocabulary to which the term is assigned.', + )); + $map = db_query('SELECT vid, machine_name FROM {taxonomy_vocabulary}')->fetchAllKeyed(); + foreach ($map as $vid => $machine_name) { + db_update('taxonomy_term_data') + ->condition('vid', $vid) + ->fields(array('vid' => $machine_name)) + ->execute(); + } +} + +/** + * Remove the {taxonomy_vocabulary} database table. + */ +function taxonomy_update_8005() { + db_drop_table('taxonomy_vocabulary'); +} + diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index a772e02..17686c5 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -68,7 +68,7 @@ function taxonomy_help($path, $arg) { $output = '

' . t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '

'; return $output; case 'admin/structure/taxonomy/%': - $vocabulary = taxonomy_vocabulary_machine_name_load($arg[3]); + $vocabulary = taxonomy_vocabulary_load($arg[3]); switch ($vocabulary->hierarchy) { case TAXONOMY_HIERARCHY_DISABLED: return '

' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '

'; @@ -121,12 +121,12 @@ function taxonomy_entity_info() { 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'tid', - 'bundle' => 'vocabulary_machine_name', + 'bundle' => 'vid', 'label' => 'name', 'uuid' => 'uuid', ), 'bundle keys' => array( - 'bundle' => 'machine_name', + 'bundle' => 'vid', ), 'bundles' => array(), 'view modes' => array( @@ -138,12 +138,13 @@ function taxonomy_entity_info() { ), ), ); - foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { - $return['taxonomy_term']['bundles'][$machine_name] = array( - 'label' => $vocabulary->name, + foreach (taxonomy_vocabulary_get_names() as $vid) { + $config = config('taxonomy.vocabulary.' . $vid); + $return['taxonomy_term']['bundles'][$vid] = array( + 'label' => $config->get('name'), 'admin' => array( - 'path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name', - 'real path' => 'admin/structure/taxonomy/' . $machine_name, + 'path' => 'admin/structure/taxonomy/%taxonomy_vocabulary', + 'real path' => 'admin/structure/taxonomy/' . $vid, 'bundle argument' => 3, 'access arguments' => array('administer taxonomy'), ), @@ -156,7 +157,7 @@ function taxonomy_entity_info() { 'form controller class' => array( 'default' => 'Drupal\taxonomy\VocabularyFormController', ), - 'base table' => 'taxonomy_vocabulary', + 'config prefix' => 'taxonomy.vocabulary', 'entity keys' => array( 'id' => 'vid', 'label' => 'name', @@ -360,7 +361,7 @@ function taxonomy_menu() { 'file' => 'taxonomy.pages.inc', ); - $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name'] = array( + $items['admin/structure/taxonomy/%taxonomy_vocabulary'] = array( 'title callback' => 'entity_page_label', 'title arguments' => array(3), 'page callback' => 'drupal_get_form', @@ -368,12 +369,12 @@ function taxonomy_menu() { 'access arguments' => array('administer taxonomy'), 'file' => 'taxonomy.admin.inc', ); - $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list'] = array( + $items['admin/structure/taxonomy/%taxonomy_vocabulary/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); - $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/edit'] = array( + $items['admin/structure/taxonomy/%taxonomy_vocabulary/edit'] = array( 'title' => 'Edit', 'page callback' => 'entity_get_form', 'page arguments' => array(3), @@ -383,7 +384,7 @@ function taxonomy_menu() { 'file' => 'taxonomy.admin.inc', ); - $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add'] = array( + $items['admin/structure/taxonomy/%taxonomy_vocabulary/add'] = array( 'title' => 'Add term', 'page callback' => 'taxonomy_term_add', 'page arguments' => array(3), @@ -469,14 +470,14 @@ function taxonomy_vocabulary_delete_multiple(array $vids) { function taxonomy_taxonomy_vocabulary_update(Vocabulary $vocabulary) { // Reflect machine name changes in the definitions of existing 'taxonomy' // fields. - if (!empty($vocabulary->original->machine_name) && $vocabulary->original->machine_name != $vocabulary->machine_name) { + if (!empty($vocabulary->original->vid) && $vocabulary->original->vid != $vocabulary->vid) { $fields = field_read_fields(); foreach ($fields as $field_name => $field) { $update = FALSE; if ($field['type'] == 'taxonomy_term_reference') { foreach ($field['settings']['allowed_values'] as $key => &$value) { - if ($value['vocabulary'] == $vocabulary->original->machine_name) { - $value['vocabulary'] = $vocabulary->machine_name; + if ($value['vocabulary'] == $vocabulary->original->vid) { + $value['vocabulary'] = $vocabulary->vid; $update = TRUE; } } @@ -650,10 +651,10 @@ function template_preprocess_taxonomy_term(&$variables) { field_attach_preprocess('taxonomy_term', $term, $variables['content'], $variables); // Gather classes, and clean up name so there are no underscores. - $vocabulary_name_css = str_replace('_', '-', $term->vocabulary_machine_name); + $vocabulary_name_css = str_replace('_', '-', $term->vid); $variables['attributes']['class'][] = 'vocabulary-' . $vocabulary_name_css; - $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->vocabulary_machine_name; + $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->vid; $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->tid; } @@ -688,18 +689,19 @@ function taxonomy_vocabulary_static_reset(array $ids = NULL) { /** * Get names for all taxonomy vocabularies. * - * @return - * An associative array of objects keyed by vocabulary machine name with - * information about taxonomy vocabularies. Each object has properties: - * - name: The vocabulary name. - * - machine_name: The machine name. - * - vid: The vocabulary ID. + * @return array + * A list of existing vocabulary IDs. */ function taxonomy_vocabulary_get_names() { $names = &drupal_static(__FUNCTION__); if (!isset($names)) { - $names = db_query('SELECT name, machine_name, vid FROM {taxonomy_vocabulary}')->fetchAllAssoc('machine_name'); + $names = array(); + $config_names = config_get_storage_names_with_prefix('taxonomy.vocabulary.'); + foreach ($config_names as $config_name) { + $vid = substr($config_name, strlen('taxonomy.vocabulary.')); + $names[$vid] = $vid; + } } return $names; @@ -928,7 +930,7 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) { if (isset($vocabulary)) { $vocabularies = taxonomy_vocabulary_get_names(); if (isset($vocabularies[$vocabulary])){ - $values['vid'] = $vocabularies[$vocabulary]->vid; + $values['vid'] = $vocabulary; } else { // Return an empty array when filtering by a non-existing vocabulary. @@ -987,31 +989,12 @@ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { * @return Drupal\taxonomy\Vocabulary|false * The taxonomy vocabulary entity, if exists, FALSE otherwise. Results are * statically cached. - * - * @see taxonomy_vocabulary_machine_name_load() */ function taxonomy_vocabulary_load($vid) { return entity_load('taxonomy_vocabulary', $vid); } /** - * Return the taxonomy vocabulary entity matching a vocabulary machine name. - * - * @param $name - * The vocabulary's machine name. - * - * @return Drupal\taxonomy\Vocabulary|false - * The taxonomy vocabulary entity, if exists, FALSE otherwise. Results are - * statically cached. - * - * @see taxonomy_vocabulary_load() - */ -function taxonomy_vocabulary_machine_name_load($name) { - $result = entity_load_multiple_by_properties('taxonomy_vocabulary', array('machine_name' => $name)); - return reset($result); -} - -/** * Return the taxonomy term entity matching a term ID. * * @param $tid @@ -1156,7 +1139,7 @@ function taxonomy_field_validate($entity_type, $entity, $field, $instance, $lang foreach ($field['settings']['allowed_values'] as $settings) { // If no parent is specified, check if the term is in the vocabulary. if (isset($settings['vocabulary']) && empty($settings['parent'])) { - if ($settings['vocabulary'] == $terms[$item['tid']]->vocabulary_machine_name) { + if ($settings['vocabulary'] == $terms[$item['tid']]->vid) { $validate = TRUE; break; } @@ -1291,7 +1274,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance, function taxonomy_allowed_values($field, $instance, $entity_type, $entity) { $options = array(); foreach ($field['settings']['allowed_values'] as $tree) { - if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) { + if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) { if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE)) { foreach ($terms as $term) { $options[$term->tid] = str_repeat('-', $term->depth) . $term->label(); @@ -1398,7 +1381,7 @@ function taxonomy_autocomplete_validate($element, &$form_state) { $field = field_widget_field($element, $form_state); $vocabularies = array(); foreach ($field['settings']['allowed_values'] as $tree) { - if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) { + if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) { $vocabularies[$vocabulary->vid] = $vocabulary; } } @@ -1417,7 +1400,6 @@ function taxonomy_autocomplete_validate($element, &$form_state) { 'tid' => 'autocreate', 'vid' => $vocabulary->vid, 'name' => $typed_term, - 'vocabulary_machine_name' => $vocabulary->machine_name, ); } $value[] = (array)$term; @@ -1441,7 +1423,7 @@ function taxonomy_field_settings_form($field, $instance, $has_data) { $vocabularies = taxonomy_vocabulary_load_multiple(); $options = array(); foreach ($vocabularies as $vocabulary) { - $options[$vocabulary->machine_name] = $vocabulary->name; + $options[$vocabulary->vid] = $vocabulary->name; } $form['allowed_values'] = array( '#tree' => TRUE, @@ -1666,34 +1648,3 @@ function taxonomy_taxonomy_term_delete(Term $term) { * @} End of "defgroup taxonomy_index". */ -/** - * Implements hook_entity_query_alter(). - * - * Converts EntityFieldQuery instances on taxonomy terms that have an entity - * condition on term bundles (vocabulary machine names). Since the vocabulary - * machine name is not present in the {taxonomy_term_data} table itself, we have - * to convert the bundle condition into a property condition of vocabulary IDs - * to match against {taxonomy_term_data}.vid. - */ -function taxonomy_entity_query_alter($query) { - $conditions = &$query->entityConditions; - - // Alter only taxonomy term queries with bundle conditions. - if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) { - // Convert vocabulary machine names to vocabulary IDs. - $vocabulary_data = taxonomy_vocabulary_get_names(); - $vids = array(); - if (is_array($conditions['bundle']['value'])) { - foreach ($conditions['bundle']['value'] as $vocabulary_machine_name) { - $vids[] = $vocabulary_data[$vocabulary_machine_name]->vid; - } - } - else { - $vocabulary_machine_name = $conditions['bundle']['value']; - $vids = $vocabulary_data[$vocabulary_machine_name]->vid; - } - - $query->propertyCondition('vid', $vids, $conditions['bundle']['operator']); - unset($conditions['bundle']); - } -} diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 597b95d..0bea38d 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -132,9 +132,8 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') { // Part of the criteria for the query come from the field's own settings. $vids = array(); - $vocabularies = taxonomy_vocabulary_get_names(); foreach ($field['settings']['allowed_values'] as $tree) { - $vids[] = $vocabularies[$tree['vocabulary']]->vid; + $vids[] = $tree['vocabulary']; } $query = db_select('taxonomy_term_data', 't');