diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index 4aa0dd6..fac3f13 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -34,19 +34,19 @@ class ManageFieldsTest extends FieldUiTestBase { // Create a vocabulary named "Tags". $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Tags', - 'machine_name' => 'tags', + 'vid' => 'tags', 'langcode' => LANGUAGE_NOT_SPECIFIED, )); taxonomy_vocabulary_save($vocabulary); $field = array( - 'field_name' => 'field_' . $vocabulary->machine_name, + 'field_name' => 'field_' . $vocabulary->vid, 'type' => 'taxonomy_term_reference', ); field_create_field($field); $instance = array( - 'field_name' => 'field_' . $vocabulary->machine_name, + 'field_name' => 'field_' . $vocabulary->vid, 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article', @@ -109,8 +109,8 @@ class ManageFieldsTest extends FieldUiTestBase { // Assert the field appears in the "re-use existing field" section for // different entity types; e.g. if a field was added in a node entity, it // should also appear in the 'taxonomy term' entity. - $vocabulary = taxonomy_vocabulary_load(1); - $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/fields'); + $vocabulary = taxonomy_vocabulary_load('tags'); + $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->vid . '/fields'); $this->assertTrue($this->xpath('//select[@name="fields[_add_existing_field][field_name]"]//option[@value="' . $this->field_name . '"]'), t('Existing field was found in account settings.')); } diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 8e6fddf..d3d4423 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -40,12 +40,12 @@ function forum_enable() { if (!$vocabulary) { // If the module was installed and uninstalled previously, the vocabulary // with machine name 'forums' might still exist. - $vocabulary = taxonomy_vocabulary_machine_name_load('forums'); + $vocabulary = taxonomy_vocabulary_load('forums'); if (!$vocabulary) { // Otherwise, installing from scratch; create the vocabulary. $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => t('Forums'), - 'machine_name' => 'forums', + 'vid' => 'forums', 'langcode' => language_default()->langcode, 'description' => t('Forum navigation vocabulary'), 'hierarchy' => 1, @@ -65,7 +65,7 @@ function forum_enable() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $vocabulary->machine_name, + 'vocabulary' => $vocabulary->vid, 'parent' => 0, ), ), diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 65f76c5..6923012 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'; } } } @@ -595,7 +586,8 @@ function forum_field_storage_pre_update($entity_type, $entity, &$skip_fields) { */ function forum_form_taxonomy_vocabulary_form_alter(&$form, &$form_state, $form_id) { $vid = config('forum.settings')->get('vocabulary'); - if (isset($form['vid']['#value']) && $form['vid']['#value'] == $vid) { + $vocabulary = $form_state['controller']->getEntity($form_state); + if (!$vocabulary->isNew() && $vid == $vocabulary->vid) { $form['help_forum_vocab'] = array( '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'), '#weight' => -1, @@ -606,6 +598,8 @@ function forum_form_taxonomy_vocabulary_form_alter(&$form, &$form_state, $form_i $form['hierarchy']['#value'] = TAXONOMY_HIERARCHY_SINGLE; // Do not allow to delete forum's vocabulary. $form['actions']['delete']['#access'] = FALSE; + // Do not allow to change a vid of forum's vocabulary. + $form['vid']['#disabled'] = TRUE; } } diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index a09ce92..e44b659 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -315,7 +315,7 @@ class ForumTest extends WebTestBase { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Tags', 'description' => $description, - 'machine_name' => 'tags', + 'vid' => 'tags', 'langcode' => language_default()->langcode, 'help' => $help, )); @@ -343,15 +343,16 @@ class ForumTest extends WebTestBase { // Generate a random name/description. $title = $this->randomName(10); $description = $this->randomName(100); + // @todo check that no vid field availiable. + $new_vid = drupal_strtolower(drupal_substr($this->randomName(), 3, 9)); $edit = array( 'name' => $title, 'description' => $description, - 'machine_name' => drupal_strtolower(drupal_substr($this->randomName(), 3, 9)), ); // Edit the vocabulary. - $this->drupalPost('admin/structure/taxonomy/' . $original_settings->machine_name . '/edit', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $original_settings->vid . '/edit', $edit, t('Save')); $this->assertResponse(200); $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), t('Vocabulary was edited')); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php index 421870d..2149dcc 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php @@ -33,7 +33,7 @@ class PathTaxonomyTermTest extends PathTestBase { // Create a Tags vocabulary for the Article node type. $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => t('Tags'), - 'machine_name' => 'tags', + 'vid' => 'tags', )); $vocabulary->save(); @@ -47,13 +47,14 @@ class PathTaxonomyTermTest extends PathTestBase { */ function testTermAlias() { // Create a term in the default 'Tags' vocabulary with URL alias. - $vocabulary = taxonomy_vocabulary_load(1); + $vocabulary = taxonomy_vocabulary_load('tags'); $description = $this->randomName();; - $edit = array(); - $edit['name'] = $this->randomName(); - $edit['description[value]'] = $description; - $edit['path[alias]'] = $this->randomName(); - $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add', $edit, t('Save')); + $edit = array( + 'name' => $this->randomName(), + 'description[value]' => $description, + 'path[alias]' => $this->randomName(), + ); + $this->drupalPost('admin/structure/taxonomy/' . $vocabulary->vid . '/add', $edit, t('Save')); // Confirm that the alias works. $this->drupalGet($edit['path[alias]']); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 4afb574..992d0c7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -314,7 +314,7 @@ class EntityCrudHookTest extends WebTestBase { public function testTaxonomyVocabularyHooks() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Test vocabulary', - 'machine_name' => 'test', + 'vid' => 'test', 'langcode' => LANGUAGE_NOT_SPECIFIED, 'description' => NULL, 'module' => 'entity_crud_hook_test', diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php index 7e0c5e9..a5f8b94 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php @@ -138,7 +138,7 @@ class DependencyTest extends ModuleTestBase { // - taxonomy depends on options // - poll depends on php (via module_test) // The correct enable order is: - $expected_order = array('comment', 'options', 'taxonomy', 'php', 'poll', 'forum'); + $expected_order = array('comment', 'config', 'options', 'taxonomy', 'php', 'poll', 'forum'); // Enable the modules through the UI, verifying that the dependency chain // is correct. @@ -146,14 +146,15 @@ class DependencyTest extends ModuleTestBase { $edit['modules[Core][forum][enable]'] = 'forum'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); $this->assertModules(array('forum'), FALSE); - $this->assertText(t('You must enable the Taxonomy, Options, Comment, Poll, PHP Filter modules to install Forum.')); + $this->assertText(t('You must enable the Taxonomy, Configuration manager, Options, Comment, Poll, PHP Filter modules to install Forum.')); $edit['modules[Core][options][enable]'] = 'options'; + $edit['modules[Core][config][enable]'] = 'config'; $edit['modules[Core][taxonomy][enable]'] = 'taxonomy'; $edit['modules[Core][comment][enable]'] = 'comment'; $edit['modules[Core][poll][enable]'] = 'poll'; $edit['modules[Core][php][enable]'] = 'php'; $this->drupalPost('admin/modules', $edit, t('Save configuration')); - $this->assertModules(array('forum', 'poll', 'php', 'comment', 'taxonomy', 'options'), TRUE); + $this->assertModules(array('forum', 'poll', 'php', 'comment', 'taxonomy', 'config', 'options'), TRUE); // Check the actual order which is saved by module_test_modules_enabled(). $this->assertIdentical(variable_get('test_module_enable_order', array()), $expected_order); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php index 42ad4c5..35ddc97 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Term.php @@ -82,16 +82,6 @@ class Term extends Entity implements ContentEntityInterface { 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\Core\Entity\EntityInterface::id(). */ public function id() { @@ -102,6 +92,6 @@ class Term extends Entity implements ContentEntityInterface { * Implements Drupal\Core\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 c7ee415..8a4f0f8 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -49,11 +49,6 @@ class TermFormController extends EntityFormController { '#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 c77cad5..e9db16d 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 @@ class TermStorageController extends DatabaseStorageController { $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 7726dbf..6f1f9d1 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 @@ class EfqTest extends TaxonomyTestBase { $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 e9bb9f6..fa7df9a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php @@ -50,7 +50,7 @@ class HooksTest extends TaxonomyTestBase { '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 @@ class RssTest extends TaxonomyTestBase { $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 @@ class RssTest extends TaxonomyTestBase { 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 @@ class RssTest extends TaxonomyTestBase { // 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 @@ abstract class TaxonomyTestBase extends WebTestBase { $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 37cbf4e..422c3e7 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 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase { '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 @@ class TermFieldTest extends TaxonomyTestBase { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => '0', ), ), @@ -142,11 +142,11 @@ class TermFieldTest extends TaxonomyTestBase { // 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 @@ class TermFieldTest extends TaxonomyTestBase { 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 @@ class TermIndexTest extends TaxonomyTestBase { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->vid, 'parent' => 0, ), ), @@ -68,7 +68,7 @@ class TermIndexTest extends TaxonomyTestBase { '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 @@ class TermLanguageTest extends TaxonomyTestBase { 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 b2603d6..07d6397 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 @@ class TermTest extends TaxonomyTestBase { $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 @@ class TermTest extends TaxonomyTestBase { 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( @@ -205,13 +205,13 @@ class TermTest extends TaxonomyTestBase { // 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. @@ -244,7 +244,7 @@ class TermTest extends TaxonomyTestBase { // 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); @@ -255,7 +255,7 @@ class TermTest extends TaxonomyTestBase { // 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.'); @@ -263,7 +263,7 @@ class TermTest extends TaxonomyTestBase { // 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. @@ -287,14 +287,14 @@ class TermTest extends TaxonomyTestBase { $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 @@ -313,7 +313,7 @@ class TermTest extends TaxonomyTestBase { $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')); @@ -361,7 +361,7 @@ class TermTest extends TaxonomyTestBase { 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, @@ -391,7 +391,7 @@ class TermTest extends TaxonomyTestBase { $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')); @@ -419,7 +419,7 @@ class TermTest extends TaxonomyTestBase { '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']); @@ -477,7 +477,7 @@ class TermTest extends TaxonomyTestBase { $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.'); @@ -486,7 +486,7 @@ class TermTest extends TaxonomyTestBase { // 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/ThemeTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php index b226970..930e447 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php @@ -42,7 +42,7 @@ class ThemeTest extends TaxonomyTestBase { // Adding a term to a vocabulary is considered an administrative action and // should use the administrative theme. $vocabulary = $this->createVocabulary(); - $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add'); + $this->drupalGet('admin/structure/taxonomy/' . $vocabulary->vid . '/add'); $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page for adding a taxonomy term.")); // Viewing a taxonomy term should use the default theme. 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 @@ class TokenReplaceTest extends TaxonomyTestBase { $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 @@ class TokenReplaceTest extends TaxonomyTestBase { 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 @@ class VocabularyLanguageTest extends TaxonomyTestBase { $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 @@ class VocabularyLanguageTest extends TaxonomyTestBase { $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..7eeb339 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 @@ class VocabularyTest extends TaxonomyTestBase { // 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 @@ class VocabularyTest extends TaxonomyTestBase { $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 @@ class VocabularyTest extends TaxonomyTestBase { $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 @@ class VocabularyTest extends TaxonomyTestBase { 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.')); } /** @@ -125,23 +125,22 @@ class VocabularyTest extends TaxonomyTestBase { */ function testTaxonomyAdminDeletingVocabulary() { // Create a vocabulary. + $vid = drupal_strtolower($this->randomName()); $edit = array( 'name' => $this->randomName(), - 'machine_name' => drupal_strtolower($this->randomName()), + 'vid' => $vid, ); $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); $this->assertText(t('Created new vocabulary'), 'New vocabulary was created.'); // Check the created vocabulary. - $vocabularies = taxonomy_vocabulary_load_multiple(); - $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 +148,6 @@ class VocabularyTest extends TaxonomyTestBase { $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..b0b5bc9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -39,7 +39,7 @@ class VocabularyUnitTest extends TaxonomyTestBase { * Ensure that when an invalid vocabulary vid is loaded, it is possible * to load the same vid successfully if it subsequently becomes valid. */ - function testTaxonomyVocabularyLoadReturnFalse() { + /*function testTaxonomyVocabularyLoadReturnFalse() { // Load a vocabulary that doesn't exist. $vocabularies = taxonomy_vocabulary_load_multiple(); $vid = count($vocabularies) + 1; @@ -54,7 +54,7 @@ class VocabularyUnitTest extends TaxonomyTestBase { $vocabulary = taxonomy_vocabulary_load($vid); $this->assertTrue(!empty($vocabulary) && is_object($vocabulary), 'Vocabulary is an object.'); $this->assertEqual($vocabulary->vid, $vid, 'Valid vocabulary vid is the same as our previously invalid one.'); - } + }*/ /** * Test deleting a taxonomy that contains terms. @@ -139,7 +139,7 @@ class VocabularyUnitTest extends TaxonomyTestBase { // 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. @@ -156,8 +156,9 @@ class VocabularyUnitTest extends TaxonomyTestBase { $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by ID.'); // Fetch vocabulary 1 by name. - $vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name))); - $this->assertEqual($vocabulary->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name.'); + // @todo Uncomment after implementing EntityStorageControllerInterface::loadByProperties() + //$vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name))); + //$this->assertEqual($vocabulary->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name.'); // Fetch vocabulary 1 by name and ID. $this->assertEqual(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name)))->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name and ID.'); @@ -176,18 +177,20 @@ class VocabularyUnitTest extends TaxonomyTestBase { $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. $info = entity_get_info('taxonomy_term'); + debug($info); + debug($this->vocabulary); $this->assertFalse(isset($info['bundles'][$old_name]), 'The old bundle name does not appear in entity_get_info().'); $this->assertTrue(isset($info['bundles'][$new_name]), 'The new bundle name appears in entity_get_info().'); @@ -207,7 +210,7 @@ class VocabularyUnitTest extends TaxonomyTestBase { $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 e32f285..5f9de33 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\Core\Entity\Entity; +use Drupal\config\ConfigEntityBase; /** * Defines the taxonomy vocabulary entity. */ -class Vocabulary extends Entity { +class Vocabulary extends ConfigEntityBase { /** * The taxonomy vocabulary ID. @@ -29,13 +29,6 @@ class Vocabulary extends Entity { public $name; /** - * The vocabulary machine name. - * - * @var string - */ - public $machine_name; - - /** * Description of the vocabulary. * * @var string diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index bdeea4c..c6ef82d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -31,13 +31,14 @@ class VocabularyFormController extends EntityFormController { '#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', ), + '#disabled' => !$vocabulary->isNew(), ); $form['description'] = array( '#type' => 'textfield', @@ -57,10 +58,6 @@ class VocabularyFormController extends EntityFormController { '#value' => '0', ); - if (isset($vocabulary->vid)) { - $form['vid'] = array('#type' => 'value', '#value' => $vocabulary->vid); - } - return parent::form($form, $form_state, $vocabulary); } @@ -88,13 +85,13 @@ class VocabularyFormController extends EntityFormController { // 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 +125,13 @@ class VocabularyFormController extends EntityFormController { 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 dd5b478..6f73945 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -2,55 +2,65 @@ /** * @file - * Definition of VocabularyStorageController. + * Definition of Drupal\taxonomy\VocabularyStorageController. */ namespace Drupal\taxonomy; +use Drupal\config\ConfigStorageController; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\DatabaseStorageController; /** * Defines a controller class for taxonomy vocabularies. */ -class VocabularyStorageController extends DatabaseStorageController { +class VocabularyStorageController extends ConfigStorageController { /** - * Overrides Drupal\Core\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; - } - - /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::postSave(). + * Overrides Drupal\config\ConfigStorageController::postSave(). */ protected function postSave(EntityInterface $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->getOriginalID() != $entity->vid) { + // Reflect machine name changes in the definitions of existing 'taxonomy' + // fields. + $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'] == $entity->getOriginalID()) { + $value['vocabulary'] = $entity->vid; + $update = TRUE; + } + } + if ($update) { + field_update_field($field); + } + } + } + // Update bundles. + field_attach_rename_bundle('taxonomy_term', $entity->getOriginalID(), $entity->vid); } + parent::postSave($entity, $update); } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::preDelete(). + * Overrides Drupal\config\ConfigStorageController::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); } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::postDelete(). + * Overrides Drupal\config\ConfigStorageController::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 +70,7 @@ class VocabularyStorageController extends DatabaseStorageController { // 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; } @@ -79,7 +89,7 @@ class VocabularyStorageController extends DatabaseStorageController { } /** - * Overrides Drupal\Core\Entity\DrupalDatabaseStorageController::resetCache(). + * Overrides Drupal\config\ConfigStorageController::resetCache(). */ public function resetCache(array $ids = NULL) { drupal_static_reset('taxonomy_vocabulary_get_names'); diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index ecef0b5..7740346 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 @@ -52,7 +52,7 @@ function taxonomy_overview_vocabularies($form) { */ function taxonomy_overview_vocabularies_submit($form, &$form_state) { foreach ($form_state['values'] as $vid => $vocabulary) { - if (is_numeric($vid) && $form[$vid]['#vocabulary']->weight != $form_state['values'][$vid]['weight']) { + if (isset($form[$vid]['#vocabulary']) && $form[$vid]['#vocabulary']->weight != $form_state['values'][$vid]['weight']) { $form[$vid]['#vocabulary']->weight = $form_state['values'][$vid]['weight']; taxonomy_vocabulary_save($form[$vid]['#vocabulary']); } @@ -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); @@ -521,7 +521,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); } @@ -538,7 +538,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?', @@ -617,13 +617,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')); @@ -641,5 +640,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.info b/core/modules/taxonomy/taxonomy.info index 837b556..9b32326 100644 --- a/core/modules/taxonomy/taxonomy.info +++ b/core/modules/taxonomy/taxonomy.info @@ -3,5 +3,6 @@ description = Enables the categorization of content. package = Core version = VERSION core = 8.x +dependencies[] = config dependencies[] = options configure = admin/structure/taxonomy 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 c28cc7b..08f20c8 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -69,7 +69,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)) . '

'; @@ -122,12 +122,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( @@ -139,12 +139,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'), ), @@ -157,7 +158,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', @@ -361,7 +362,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', @@ -369,12 +370,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), @@ -384,7 +385,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), @@ -465,31 +466,6 @@ function taxonomy_vocabulary_delete_multiple(array $vids) { } /** - * Implements hook_taxonomy_vocabulary_update(). - */ -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) { - $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; - $update = TRUE; - } - } - if ($update) { - field_update_field($field); - } - } - } - } -} - -/** * Checks and updates the hierarchy flag of a vocabulary. * * Checks the current parents of all terms in a vocabulary and updates the @@ -734,10 +710,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; } @@ -772,18 +748,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; @@ -1012,7 +989,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. @@ -1059,7 +1036,11 @@ function taxonomy_term_load_multiple(array $tids = NULL) { * An array of vocabulary objects, indexed by vid. */ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { - return entity_load_multiple('taxonomy_vocabulary', $vids); + $vocabularies = entity_load_multiple('taxonomy_vocabulary', $vids); + if (!isset($vids)) { + uasort($vocabularies, 'Drupal\config\ConfigEntityBase::sort'); + } + return $vocabularies; } /** @@ -1071,31 +1052,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 @@ -1240,7 +1202,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; } @@ -1375,7 +1337,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(); @@ -1482,7 +1444,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; } } @@ -1501,7 +1463,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; @@ -1525,7 +1486,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, @@ -1751,38 +1712,6 @@ function taxonomy_taxonomy_term_delete(Term $term) { */ /** - * 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']); - } -} - -/** * Implements hook_library_info(). */ function taxonomy_library_info() { diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 7c77716..154025e 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -135,9 +135,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'); diff --git a/core/profiles/standard/standard.info b/core/profiles/standard/standard.info index 8b8a33b..c5240dd 100644 --- a/core/profiles/standard/standard.info +++ b/core/profiles/standard/standard.info @@ -6,6 +6,7 @@ dependencies[] = node dependencies[] = block dependencies[] = color dependencies[] = comment +dependencies[] = config dependencies[] = contextual dependencies[] = help dependencies[] = image diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 5b74b51..6eb4a23 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -259,21 +259,21 @@ function standard_install() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => st('Tags'), 'description' => $description, - 'machine_name' => 'tags', + 'vid' => 'tags', 'langcode' => language_default()->langcode, 'help' => $help, )); taxonomy_vocabulary_save($vocabulary); $field = array( - 'field_name' => 'field_' . $vocabulary->machine_name, + 'field_name' => 'field_' . $vocabulary->vid, 'type' => 'taxonomy_term_reference', // Set cardinality to unlimited for tagging. 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $vocabulary->machine_name, + 'vocabulary' => $vocabulary->vid, 'parent' => 0, ), ), @@ -282,7 +282,7 @@ function standard_install() { field_create_field($field); $instance = array( - 'field_name' => 'field_' . $vocabulary->machine_name, + 'field_name' => 'field_' . $vocabulary->vid, 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article',