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 17d4bd7..5c9e776 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 @@ function setUp() { // 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->id(), 'type' => 'taxonomy_term_reference', ); field_create_field($field); $instance = array( - 'field_name' => 'field_' . $vocabulary->machine_name, + 'field_name' => 'field_' . $vocabulary->id(), 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article', @@ -109,8 +109,8 @@ function createField() { // 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->id() . '/fields'); $this->assertTrue($this->xpath('//select[@name="fields[_add_existing_field][field_name]"]//option[@value="' . $this->field_name . '"]'), 'Existing field was found in account settings.'); } diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 56f8402..728172e 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -37,12 +37,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, @@ -51,7 +51,7 @@ function forum_enable() { )); taxonomy_vocabulary_save($vocabulary); } - $config->set('vocabulary', $vocabulary->vid)->save(); + $config->set('vocabulary', $vocabulary->id())->save(); } // Create the 'taxonomy_forums' field if it doesn't already exist. @@ -62,7 +62,7 @@ function forum_enable() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $vocabulary->machine_name, + 'vocabulary' => $vocabulary->id(), 'parent' => 0, ), ), @@ -76,7 +76,7 @@ function forum_enable() { 'langcode' => language_default()->langcode, 'description' => '', 'parent' => array(0), - 'vid' => $vocabulary->vid, + 'vid' => $vocabulary->id(), )); taxonomy_term_save($term); diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 459cbeb..10cec8c 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_alter(), 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'; } } } @@ -596,7 +587,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->id()) { $form['help_forum_vocab'] = array( '#markup' => t('This is the designated forum vocabulary. Some of the normal vocabulary options have been removed.'), '#weight' => -1, @@ -607,6 +599,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 f56cfbb..b674f59 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -300,7 +300,7 @@ private function doAdminTests($user) { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Tags', 'description' => $description, - 'machine_name' => 'tags', + 'vid' => 'tags', 'langcode' => language_default()->langcode, 'help' => $help, )); @@ -332,11 +332,10 @@ function editForumTaxonomy() { $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->id() . '/edit', $edit, t('Save')); $this->assertResponse(200); $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), 'Vocabulary was edited'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index bf8f845..0667e1b 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -88,7 +88,7 @@ public function testForumPager() { 'type' => 'forum', 'taxonomy_forums' => array( LANGUAGE_NOT_SPECIFIED => array( - array('tid' => $tid, 'vid' => $vid, 'vocabulary_machine_name' => 'forums'), + array('tid' => $tid, 'vid' => $vid), ), ), )); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php b/core/modules/path/lib/Drupal/path/Tests/PathTaxonomyTermTest.php index 421870d..2122b9a 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 @@ function setUp() { // 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 @@ function setUp() { */ 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->id() . '/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..e045d20 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -254,7 +254,7 @@ public function testNodeHooks() { public function testTaxonomyTermHooks() { $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', @@ -314,7 +314,7 @@ public function testTaxonomyTermHooks() { 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/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 73f563b..7c9b9a5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -89,7 +89,7 @@ public function testLanguageUpgrade() { // A langcode property was added to vocabularies and terms. Check that // existing vocabularies and terms got assigned the site default language. - $vocabulary = db_query('SELECT * FROM {taxonomy_vocabulary} WHERE vid = :vid', array(':vid' => 1))->fetchObject(); + $vocabulary = taxonomy_vocabulary_load('tags'); $this->assertEqual($vocabulary->langcode, 'ca'); $term = db_query('SELECT * FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => 1))->fetchObject(); $this->assertEqual($term->langcode, 'ca'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php index 51468af..6b438ba 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php @@ -30,12 +30,12 @@ * fieldable = TRUE, * entity_keys = { * "id" = "tid", - * "bundle" = "vocabulary_machine_name", + * "bundle" = "vid", * "label" = "name", * "uuid" = "uuid" * }, * bundle_keys = { - * "bundle" = "machine_name" + * "bundle" = "vid" * }, * view_modes = { * "full" = { @@ -115,16 +115,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() { @@ -135,6 +125,6 @@ public function id() { * 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/Plugin/Core/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php index 0ecbae8..69b5d89 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php @@ -7,7 +7,7 @@ namespace Drupal\taxonomy\Plugin\Core\Entity; -use Drupal\Core\Entity\Entity; +use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -22,7 +22,7 @@ * form_controller_class = { * "default" = "Drupal\taxonomy\VocabularyFormController" * }, - * base_table = "taxonomy_vocabulary", + * config_prefix = "taxonomy.vocabulary", * entity_keys = { * "id" = "vid", * "label" = "name" @@ -35,7 +35,7 @@ * } * ) */ -class Vocabulary extends Entity { +class Vocabulary extends ConfigEntityBase { /** * The taxonomy vocabulary ID. @@ -52,13 +52,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/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php index 3f4d510..87a73d2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php @@ -63,8 +63,8 @@ public function massageFormValues(array $values, array $form, array &$form_state // Collect candidate vocabularies. foreach ($field['settings']['allowed_values'] as $tree) { - if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) { - $vocabularies[$vocabulary->vid] = $vocabulary; + if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { + $vocabularies[$vocabulary->id()] = $vocabulary; } } @@ -79,9 +79,8 @@ public function massageFormValues(array $values, array $form, array &$form_state $vocabulary = reset($vocabularies); $term = array( 'tid' => 'autocreate', - 'vid' => $vocabulary->vid, + 'vid' => $vocabulary->id(), 'name' => $value, - 'vocabulary_machine_name' => $vocabulary->machine_name, ); } $terms[] = (array)$term; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyMachineName.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyMachineName.php deleted file mode 100644 index c36e406..0000000 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyMachineName.php +++ /dev/null @@ -1,41 +0,0 @@ -addField('v', 'name'); - $query->condition('v.machine_name', $this->argument); - $title = $query->execute()->fetchField(); - - if (empty($title)) { - return t('No vocabulary'); - } - - return check_plain($title); - } - -} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php index f479f66..9ee2920 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php @@ -26,15 +26,12 @@ class VocabularyVid extends Numeric { * Override the behavior of title(). Get the name of the vocabulary. */ function title() { - $query = db_select('taxonomy_vocabulary', 'v'); - $query->addField('v', 'name'); - $query->condition('v.vid', $this->argument); - $title = $query->execute()->fetchField(); - if (empty($title)) { - return t('No vocabulary'); + $vocabulary = entity_load('taxonomy_vocabulary', $this->argument); + if ($vocabulary) { + return check_plain($vocabulary->label()); } - return check_plain($title); + return t('No vocabulary'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php index e657ea6..19a7691 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_default/Tid.php @@ -25,16 +25,6 @@ class Tid extends ArgumentDefaultPluginBase { public function init(ViewExecutable $view, &$argument, $options) { parent::init($view, $argument, $options); - - // Convert legacy vids option to machine name vocabularies. - if (!empty($this->options['vids'])) { - $vocabularies = taxonomy_vocabulary_get_names(); - foreach ($this->options['vids'] as $vid) { - if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) { - $this->options['vocabularies'][$vocabularies[$vid]->machine_name] = $vocabularies[$vid]->machine_name; - } - } - } } protected function defineOptions() { @@ -44,7 +34,7 @@ protected function defineOptions() { $options['node'] = array('default' => FALSE, 'bool' => TRUE); $options['anyall'] = array('default' => ','); $options['limit'] = array('default' => FALSE, 'bool' => TRUE); - $options['vocabularies'] = array('default' => array()); + $options['vids'] = array('default' => array()); return $options; } @@ -73,16 +63,16 @@ public function buildOptionsForm(&$form, &$form_state) { ); $options = array(); - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); foreach ($vocabularies as $voc) { - $options[$voc->machine_name] = check_plain($voc->name); + $options[$voc->id()] = $voc->label(); } - $form['vocabularies'] = array( + $form['vids'] = array( '#type' => 'checkboxes', '#title' => t('Vocabularies'), '#options' => $options, - '#default_value' => $this->options['vocabularies'], + '#default_value' => $this->options['vids'], '#states' => array( 'visible' => array( ':input[name="options[argument_default][taxonomy_tid][limit]"]' => array('checked' => TRUE), @@ -109,7 +99,7 @@ public function buildOptionsForm(&$form, &$form_state) { public function submitOptionsForm(&$form, &$form_state, &$options = array()) { // Filter unselected items so we don't unnecessarily store giant arrays. - $options['vocabularies'] = array_filter($options['vocabularies']); + $options['vids'] = array_filter($options['vids']); } function get_argument() { @@ -146,7 +136,7 @@ function get_argument() { $tids = array(); // filter by vocabulary foreach ($taxonomy as $tid => $vocab) { - if (!empty($this->options['vocabularies'][$vocab])) { + if (!empty($this->options['vids'][$vocab])) { $tids[] = $tid; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_validator/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_validator/Term.php index 955be61..78c04a9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_validator/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument_validator/Term.php @@ -25,21 +25,11 @@ class Term extends ArgumentValidatorPluginBase { public function init(ViewExecutable $view, &$argument, $options) { parent::init($view, $argument, $options); - - // Convert legacy vids option to machine name vocabularies. - if (!empty($this->options['vids'])) { - $vocabularies = taxonomy_vocabulary_get_names(); - foreach ($this->options['vids'] as $vid) { - if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) { - $this->options['vocabularies'][$vocabularies[$vid]->machine_name] = $vocabularies[$vid]->machine_name; - } - } - } } protected function defineOptions() { $options = parent::defineOptions(); - $options['vocabularies'] = array('default' => array()); + $options['vids'] = array('default' => array()); $options['type'] = array('default' => 'tid'); $options['transform'] = array('default' => FALSE, 'bool' => TRUE); @@ -47,19 +37,19 @@ protected function defineOptions() { } public function buildOptionsForm(&$form, &$form_state) { - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $options = array(); foreach ($vocabularies as $voc) { - $options[$voc->machine_name] = check_plain($voc->name); + $options[$voc->id()] = $voc->label(); } - $form['vocabularies'] = array( + $form['vids'] = array( '#type' => 'checkboxes', '#prefix' => '
', '#suffix' => '
', '#title' => t('Vocabularies'), '#options' => $options, - '#default_value' => $this->options['vocabularies'], + '#default_value' => $this->options['vids'], '#description' => t('If you wish to validate for specific vocabularies, check them; if none are checked, all terms will pass.'), ); @@ -85,11 +75,11 @@ public function buildOptionsForm(&$form, &$form_state) { public function submitOptionsForm(&$form, &$form_state, &$options = array()) { // Filter unselected items so we don't unnecessarily store giant arrays. - $options['vocabularies'] = array_filter($options['vocabularies']); + $options['vids'] = array_filter($options['vids']); } function validate_argument($argument) { - $vocabularies = array_filter($this->options['vocabularies']); + $vocabularies = array_filter($this->options['vids']); $type = $this->options['type']; $transform = $this->options['transform']; @@ -105,7 +95,7 @@ function validate_argument($argument) { return FALSE; } $this->argument->validated_title = check_plain($term->name); - return empty($vocabularies) || !empty($vocabularies[$term->vocabulary_machine_name]); + return empty($vocabularies) || !empty($vocabularies[$term->vid]); case 'tids': // An empty argument is not a term so doesn't pass. @@ -141,7 +131,7 @@ function validate_argument($argument) { if (count($test)) { $result = entity_load_multiple('taxonomy_term', $test); foreach ($result as $term) { - if ($vocabularies && empty($vocabularies[$term->vocabulary_machine_name])) { + if ($vocabularies && empty($vocabularies[$term->vid])) { $validated_cache[$term->id()] = FALSE; return FALSE; } @@ -166,7 +156,7 @@ function validate_argument($argument) { $term->name = str_replace(' ', '-', $term->name); } - if ($term && (empty($vocabularies) || !empty($vocabularies[$term->vocabulary_machine_name]))) { + if ($term && (empty($vocabularies) || !empty($vocabularies[$term->vid]))) { if ($type == 'convert') { $this->argument->argument = $term->id(); } @@ -180,7 +170,6 @@ function validate_argument($argument) { function process_summary_arguments(&$args) { $type = $this->options['type']; $transform = $this->options['transform']; - $vocabularies = array_filter($this->options['vocabularies']); if ($type == 'convert') { $arg_keys = array_flip($args); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/LinkEdit.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/LinkEdit.php index fcdd258..8af32b3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/LinkEdit.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/LinkEdit.php @@ -31,10 +31,6 @@ public function init(ViewExecutable $view, &$options) { $this->additional_fields['tid'] = 'tid'; $this->additional_fields['vid'] = 'vid'; - $this->additional_fields['vocabulary_machine_name'] = array( - 'table' => 'taxonomy_vocabulary', - 'field' => 'machine_name', - ); } protected function defineOptions() { @@ -67,7 +63,6 @@ function render($values) { // access checks. See http://drupal.org/node/995156 $term = entity_create('taxonomy_term', array( 'vid' => $values->{$this->aliases['vid']}, - 'vocabulary_machine_name' => $values->{$this->aliases['vocabulary_machine_name']}, )); if (taxonomy_term_access('edit', $term)) { $text = !empty($this->options['text']) ? $this->options['text'] : t('edit'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php index ec56116..a098bfd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/Taxonomy.php @@ -37,10 +37,6 @@ public function init(ViewExecutable $view, &$options) { $this->additional_fields['vid'] = 'vid'; $this->additional_fields['tid'] = 'tid'; - $this->additional_fields['vocabulary_machine_name'] = array( - 'table' => 'taxonomy_vocabulary', - 'field' => 'machine_name', - ); } protected function defineOptions() { @@ -80,7 +76,6 @@ function render_link($data, $values) { $term = entity_create('taxonomy_term', array( 'tid' => $tid, 'vid' => $this->get_value($values, 'vid'), - 'vocabulary_machine_name' => $values->{$this->aliases['vocabulary_machine_name']}, )); $this->options['alter']['make_link'] = TRUE; $uri = $term->uri(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php index 9c75368..4353fdd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php @@ -32,16 +32,6 @@ public function init(ViewExecutable $view, &$options) { else { $this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid'); } - - // Convert legacy vids option to machine name vocabularies. - if (!empty($this->options['vids'])) { - $vocabularies = taxonomy_vocabulary_get_names(); - foreach ($this->options['vids'] as $vid) { - if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) { - $this->options['vocabularies'][$vocabularies[$vid]->machine_name] = $vocabularies[$vid]->machine_name; - } - } - } } protected function defineOptions() { @@ -49,7 +39,7 @@ protected function defineOptions() { $options['link_to_taxonomy'] = array('default' => TRUE, 'bool' => TRUE); $options['limit'] = array('default' => FALSE, 'bool' => TRUE); - $options['vocabularies'] = array('default' => array()); + $options['vids'] = array('default' => array()); return $options; } @@ -71,16 +61,16 @@ public function buildOptionsForm(&$form, &$form_state) { ); $options = array(); - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); foreach ($vocabularies as $voc) { - $options[$voc->machine_name] = check_plain($voc->name); + $options[$voc->id()] = $voc->label(); } - $form['vocabularies'] = array( + $form['vids'] = array( '#type' => 'checkboxes', '#title' => t('Vocabularies'), '#options' => $options, - '#default_value' => $this->options['vocabularies'], + '#default_value' => $this->options['vids'], '#states' => array( 'visible' => array( ':input[name="options[limit]"]' => array('checked' => TRUE), @@ -100,6 +90,7 @@ public function query() { } function pre_render(&$values) { + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $this->field_alias = $this->aliases['nid']; $nids = array(); foreach ($values as $result) { @@ -111,26 +102,23 @@ function pre_render(&$values) { if ($nids) { $query = db_select('taxonomy_term_data', 'td'); $query->innerJoin('taxonomy_index', 'tn', 'td.tid = tn.tid'); - $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); $query->fields('td'); $query->addField('tn', 'nid', 'node_nid'); - $query->addField('tv', 'name', 'vocabulary'); - $query->addField('tv', 'machine_name', 'vocabulary_machine_name'); $query->orderby('td.weight'); $query->orderby('td.name'); $query->condition('tn.nid', $nids); $query->addTag('term_access'); - $vocabs = array_filter($this->options['vocabularies']); + $vocabs = array_filter($this->options['vids']); if (!empty($this->options['limit']) && !empty($vocabs)) { - $query->condition('tv.machine_name', $vocabs); + $query->condition('td.vid', $vocabs); } $result = $query->execute(); foreach ($result as $term) { $this->items[$term->node_nid][$term->tid]['name'] = check_plain($term->name); $this->items[$term->node_nid][$term->tid]['tid'] = $term->tid; - $this->items[$term->node_nid][$term->tid]['vocabulary_machine_name'] = check_plain($term->vocabulary_machine_name); - $this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($term->vocabulary); + $this->items[$term->node_nid][$term->tid]['vocabulary_vid'] = $term->vid; + $this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($vocabularies[$term->vid]->label()); if (!empty($this->options['link_to_taxonomy'])) { $this->items[$term->node_nid][$term->tid]['make_link'] = TRUE; @@ -147,13 +135,13 @@ function render_item($count, $item) { function document_self_tokens(&$tokens) { $tokens['[' . $this->options['id'] . '-tid' . ']'] = t('The taxonomy term ID for the term.'); $tokens['[' . $this->options['id'] . '-name' . ']'] = t('The taxonomy term name for the term.'); - $tokens['[' . $this->options['id'] . '-vocabulary-machine-name' . ']'] = t('The machine name for the vocabulary the term belongs to.'); + $tokens['[' . $this->options['id'] . '-vocabulary-vid' . ']'] = t('The machine name for the vocabulary the term belongs to.'); $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = t('The name for the vocabulary the term belongs to.'); } function add_self_tokens(&$tokens, $item) { - foreach (array('tid', 'name', 'vocabulary_machine_name', 'vocabulary') as $token) { - // Replace _ with - for the vocabulary machine name. + foreach (array('tid', 'name', 'vocabulary_vid', 'vocabulary') as $token) { + // Replace _ with - for the vocabulary vid. $tokens['[' . $this->options['id'] . '-' . str_replace('_', '-', $token) . ']'] = isset($item[$token]) ? $item[$token] : ''; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php index fa8f3de..74a3ef4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php @@ -29,16 +29,7 @@ class TaxonomyIndexTid extends ManyToOne { public function init(ViewExecutable $view, &$options) { parent::init($view, $options); if (!empty($this->definition['vocabulary'])) { - $this->options['vocabulary'] = $this->definition['vocabulary']; - } - - // Convert legacy vid option to machine name vocabulary. - if (isset($this->options['vid']) && !empty($this->options['vid']) & empty($this->options['vocabulary'])) { - $vocabularies = taxonomy_vocabulary_get_names(); - $vid = $this->options['vid']; - if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) { - $this->options['vocabulary'] = $vocabularies[$vid]->machine_name; - } + $this->options['vid'] = $this->definition['vocabulary']; } } @@ -51,7 +42,7 @@ protected function defineOptions() { $options['type'] = array('default' => 'textfield'); $options['limit'] = array('default' => TRUE, 'bool' => TRUE); - $options['vocabulary'] = array('default' => 0); + $options['vid'] = array('default' => ''); $options['hierarchy'] = array('default' => 0); $options['error_message'] = array('default' => TRUE, 'bool' => TRUE); @@ -59,26 +50,26 @@ protected function defineOptions() { } public function buildExtraOptionsForm(&$form, &$form_state) { - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $options = array(); foreach ($vocabularies as $voc) { - $options[$voc->machine_name] = check_plain($voc->name); + $options[$voc->id()] = $voc->label(); } if ($this->options['limit']) { // We only do this when the form is displayed. - if (empty($this->options['vocabulary'])) { + if (empty($this->options['vid'])) { $first_vocabulary = reset($vocabularies); - $this->options['vocabulary'] = $first_vocabulary->machine_name; + $this->options['vid'] = $first_vocabulary->id(); } if (empty($this->definition['vocabulary'])) { - $form['vocabulary'] = array( + $form['vid'] = array( '#type' => 'radios', '#title' => t('Vocabulary'), '#options' => $options, '#description' => t('Select which vocabulary to show terms for in the regular options.'), - '#default_value' => $this->options['vocabulary'], + '#default_value' => $this->options['vid'], ); } } @@ -103,7 +94,7 @@ public function buildExtraOptionsForm(&$form, &$form_state) { } function value_form(&$form, &$form_state) { - $vocabulary = taxonomy_vocabulary_machine_name_load($this->options['vocabulary']); + $vocabulary = entity_load('taxonomy_vocabulary', $this->options['vid']); if (empty($vocabulary) && $this->options['limit']) { $form['markup'] = array( '#markup' => '
' . t('An invalid vocabulary is selected. Please change it in the options.') . '
', @@ -127,18 +118,18 @@ function value_form(&$form, &$form_state) { } $form['value'] = array( - '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->name)) : t('Select terms'), + '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->label())) : t('Select terms'), '#type' => 'textfield', '#default_value' => $default, ); if ($this->options['limit']) { - $form['value']['#autocomplete_path'] = 'admin/views/ajax/autocomplete/taxonomy/' . $vocabulary->vid; + $form['value']['#autocomplete_path'] = 'admin/views/ajax/autocomplete/taxonomy/' . $vocabulary->id(); } } else { if (!empty($this->options['hierarchy']) && $this->options['limit']) { - $tree = taxonomy_get_tree($vocabulary->vid); + $tree = taxonomy_get_tree($vocabulary->id()); $options = array(); if ($tree) { @@ -152,15 +143,13 @@ function value_form(&$form, &$form_state) { else { $options = array(); $query = db_select('taxonomy_term_data', 'td'); - $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); $query->fields('td'); - $query->orderby('tv.weight'); - $query->orderby('tv.name'); + // @todo Sorting on vocabulary properties http://drupal.org/node/1821274 $query->orderby('td.weight'); $query->orderby('td.name'); $query->addTag('term_access'); if ($this->options['limit']) { - $query->condition('tv.machine_name', $vocabulary->machine_name); + $query->condition('td.vid', $vocabulary->id()); } $result = $query->execute(); foreach ($result as $term) { @@ -202,7 +191,7 @@ function value_form(&$form, &$form_state) { } $form['value'] = array( '#type' => 'select', - '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->name)) : t('Select terms'), + '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->label())) : t('Select terms'), '#multiple' => TRUE, '#options' => $options, '#size' => min(9, count($options)), @@ -319,10 +308,9 @@ function validate_term_strings(&$form, $values) { } $query = db_select('taxonomy_term_data', 'td'); - $query->innerJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); $query->fields('td'); $query->condition('td.name', $names); - $query->condition('tv.machine_name', $this->options['vocabulary']); + $query->condition('td.vid', $this->options['vid']); $query->addTag('term_access'); $result = $query->execute(); foreach ($result as $term) { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyMachineName.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyMachineName.php deleted file mode 100644 index 8be71e6..0000000 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyMachineName.php +++ /dev/null @@ -1,37 +0,0 @@ -value_options)) { - return; - } - - $this->value_options = array(); - $vocabularies = taxonomy_vocabulary_get_names(); - foreach ($vocabularies as $voc) { - $this->value_options[$voc->machine_name] = $voc->name; - } - } - -} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php index 1264319..bfa55a2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/VocabularyVid.php @@ -28,9 +28,9 @@ function get_value_options() { } $this->value_options = array(); - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); foreach ($vocabularies as $voc) { - $this->value_options[$voc->vid] = $voc->name; + $this->value_options[$voc->id()] = $voc->label(); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/relationship/NodeTermData.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/relationship/NodeTermData.php index ab2021a..6b06783 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/relationship/NodeTermData.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/relationship/NodeTermData.php @@ -25,32 +25,22 @@ class NodeTermData extends RelationshipPluginBase { public function init(ViewExecutable $view, &$options) { parent::init($view, $options); - - // Convert legacy vids option to machine name vocabularies. - if (!empty($this->options['vids'])) { - $vocabularies = taxonomy_vocabulary_get_names(); - foreach ($this->options['vids'] as $vid) { - if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) { - $this->options['vocabularies'][$vocabularies[$vid]->machine_name] = $vocabularies[$vid]->machine_name; - } - } - } } protected function defineOptions() { $options = parent::defineOptions(); - $options['vocabularies'] = array('default' => array()); + $options['vids'] = array('default' => array()); return $options; } public function buildOptionsForm(&$form, &$form_state) { - $vocabularies = taxonomy_vocabulary_get_names(); + $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $options = array(); foreach ($vocabularies as $voc) { - $options[$voc->machine_name] = check_plain($voc->name); + $options[$voc->id()] = $voc->label(); } - $form['vocabularies'] = array( + $form['vids'] = array( '#type' => 'checkboxes', '#title' => t('Vocabularies'), '#options' => $options, @@ -69,7 +59,7 @@ public function query() { $def = $this->definition; $def['table'] = 'taxonomy_term_data'; - if (!array_filter($this->options['vocabularies'])) { + if (!array_filter($this->options['vids'])) { $taxonomy_index = $this->query->add_table('taxonomy_index', $this->relationship); $def['left_table'] = $taxonomy_index; $def['left_field'] = 'tid'; @@ -85,9 +75,8 @@ public function query() { $def['adjusted'] = TRUE; $query = db_select('taxonomy_term_data', 'td'); - $query->addJoin($def['type'], 'taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); $query->addJoin($def['type'], 'taxonomy_index', 'tn', 'tn.tid = td.tid'); - $query->condition('tv.machine_name', array_filter($this->options['vocabularies'])); + $query->condition('td.vid', array_filter($this->options['vids'])); $query->addTag('term_access'); $query->fields('td'); $query->fields('tn', array('nid')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index f81b9e5..cb5e2e1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -19,7 +19,7 @@ class TermFormController extends EntityFormController { * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $term) { - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = taxonomy_vocabulary_load($term->bundle()); $parent = array_keys(taxonomy_term_load_parents($term->tid)); $form_state['taxonomy']['parent'] = $parent; @@ -41,7 +41,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { '#format' => $term->format, '#weight' => 0, ); - $language_configuration = module_invoke('language', 'get_default_configuration', 'taxonomy_term', $vocabulary->machine_name); + $language_configuration = module_invoke('language', 'get_default_configuration', 'taxonomy_term', $vocabulary->id()); $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Language'), @@ -50,11 +50,6 @@ public function form(array $form, array &$form_state, EntityInterface $term) { '#access' => !is_null($language_configuration['language_hidden']) && !$language_configuration['language_hidden'], ); - $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'), @@ -69,7 +64,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { // hook_form_alter to provide scalable alternatives. if (!variable_get('taxonomy_override_selector', FALSE)) { $parent = array_keys(taxonomy_term_load_parents($term->tid)); - $children = taxonomy_get_tree($vocabulary->vid, $term->tid); + $children = taxonomy_get_tree($vocabulary->id(), $term->tid); // A term can't be the child of itself, nor of its children. foreach ($children as $child) { @@ -77,7 +72,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { } $exclude[] = $term->tid; - $tree = taxonomy_get_tree($vocabulary->vid); + $tree = taxonomy_get_tree($vocabulary->id()); $options = array('<' . t('root') . '>'); if (empty($parent)) { $parent = array(0); @@ -108,7 +103,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { $form['vid'] = array( '#type' => 'value', - '#value' => $vocabulary->vid, + '#value' => $vocabulary->id(), ); $form['tid'] = array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php index 64b7a06..18acd7e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php @@ -25,15 +25,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); @@ -48,10 +39,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 d8a3ca5..d843acc 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php @@ -44,7 +44,7 @@ function testTaxonomyEfq() { $ids = (object) array( 'entity_type' => 'taxonomy_term', 'entity_id' => $tid, - 'bundle' => $this->vocabulary->machine_name, + 'bundle' => $this->vocabulary->id(), ); $term = _field_create_entity_from_ids($ids); $this->assertEqual($term->tid, $tid, 'Taxonomy term can be created based on the IDs'); @@ -66,7 +66,7 @@ function testTaxonomyEfq() { $ids = (object) array( 'entity_type' => 'taxonomy_term', 'entity_id' => $tid, - 'bundle' => $vocabulary2->machine_name, + 'bundle' => $vocabulary2->id(), ); $term = _field_create_entity_from_ids($ids); $this->assertEqual($term->tid, $tid, 'Taxonomy term can be created based on the IDs'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/HooksTest.php index e9bb9f6..edddd1a 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 @@ 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->id() . '/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/LoadMultipleTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php index 657e9b4..d05f033 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php @@ -41,7 +41,7 @@ function testTaxonomyTermMultipleLoad() { $this->createTerm($vocabulary); } // Load the terms from the vocabulary. - $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid)); + $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id())); $count = count($terms); $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count))); @@ -57,7 +57,7 @@ function testTaxonomyTermMultipleLoad() { $this->assertFalse($deleted_term); // Load terms from the vocabulary by vid. - $terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid)); + $terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id())); $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.'); $this->assertFalse(isset($terms3[$deleted->tid])); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index e87d931..505f850 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->id(), 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), '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->id(), '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->id() . "][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..0317ad6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php @@ -38,13 +38,12 @@ 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'), 'weight' => mt_rand(0, 10), )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); return $vocabulary; } @@ -57,7 +56,7 @@ function createTerm($vocabulary) { 'description' => $this->randomName(), // Use the first available text format. 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(), - 'vid' => $vocabulary->vid, + 'vid' => $vocabulary->id(), 'langcode' => LANGUAGE_NOT_SPECIFIED, )); taxonomy_term_save($term); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 37cbf4e..565bb98 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->id(), 'parent' => '0', ), array( - 'vocabulary' => $this->vocabulary2->machine_name, + 'vocabulary' => $this->vocabulary2->id(), 'parent' => '0', ), ), @@ -105,7 +105,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->assertText($term2->name, 'Term 2 name is displayed.'); // Delete vocabulary 2. - taxonomy_vocabulary_delete($this->vocabulary2->vid); + taxonomy_vocabulary_delete($this->vocabulary2->id()); // Re-render the content. $entity = field_test_entity_test_load($id); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 34065e1..a82a1fa 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->id(), 'parent' => '0', ), ), @@ -129,7 +129,7 @@ function testTaxonomyTermFieldWidgets() { $this->assertText($term->label(), 'Term label is displayed.'); // Delete the vocabulary and verify that the widget is gone. - taxonomy_vocabulary_delete($this->vocabulary->vid); + taxonomy_vocabulary_delete($this->vocabulary->id()); $this->drupalGet('test-entity/add/test_bundle'); $this->assertNoFieldByName("{$this->field_name}[$langcode]", '', 'Widget is not displayed'); } @@ -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->id(), 'parent' => '0', ), array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), '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..fe91863 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->id(), 'parent' => 0, ), ), @@ -68,7 +68,7 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), '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 b609dfe..df08a97 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermLanguageTest.php @@ -49,10 +49,10 @@ function testTermLanguage() { $edit = array( 'default_language[language_hidden]' => FALSE, ); - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id() . '/edit', $edit, t('Save')); // Add a term. - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->id() . '/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. @@ -85,8 +85,8 @@ function testDefaultTermLanguage() { 'default_language[langcode]' => 'bb', 'default_language[language_hidden]' => FALSE, ); - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, t('Save')); - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id() . '/edit', $edit, t('Save')); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'bb'); // Make the default language of the terms to be the current interface. @@ -94,10 +94,10 @@ function testDefaultTermLanguage() { 'default_language[langcode]' => 'current_interface', 'default_language[language_hidden]' => FALSE, ); - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, t('Save')); - $this->drupalGet('aa/admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id() . '/edit', $edit, t('Save')); + $this->drupalGet('aa/admin/structure/taxonomy/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'aa'); - $this->drupalGet('bb/admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalGet('bb/admin/structure/taxonomy/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'bb'); // Change the default language of the site and check if the default terms @@ -112,8 +112,8 @@ function testDefaultTermLanguage() { 'default_language[langcode]' => 'site_default', 'default_language[language_hidden]' => FALSE, ); - $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/edit', $edit, t('Save')); - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add'); + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->id() . '/edit', $edit, t('Save')); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->id() . '/add'); $this->assertOptionSelected('edit-langcode', 'cc'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index b2603d6..083b214 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->id(), 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), '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->id(), 'bundle' => 'article', 'entity_type' => 'node', 'widget' => array( @@ -66,7 +66,7 @@ function testTaxonomyTermHierarchy() { $term2 = $this->createTerm($this->vocabulary); // Check that hierarchy is flat. - $vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid); + $vocabulary = taxonomy_vocabulary_load($this->vocabulary->id()); $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.'); // Edit $term2, setting $term1 as parent. @@ -164,7 +164,7 @@ function testNodeTermCreationAndDeletion() { foreach ($terms as $term) { $this->assertText($term, 'The term appears on the node preview'); } - $tree = taxonomy_get_tree($this->vocabulary->vid); + $tree = taxonomy_get_tree($this->vocabulary->id()); $this->assertTrue(empty($tree), 'The terms are not created on preview.'); // taxonomy.module does not maintain its static caches. @@ -205,13 +205,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->id() . '/' . $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->id() . '/' . $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 @@ 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->id() . '/' . $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 @@ 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->id() . '/' . $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 @@ 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->id() . '/' . $input; $this->drupalGet($url); $n = $third_term->name; // Term names containing commas or quotes must be wrapped in quotes. @@ -287,14 +287,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->id() . '/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->id()); // Test edit link as accessed from Taxonomy administration pages. // Because Simpletest creates its own database when running tests, we know @@ -313,7 +313,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->id()); $this->assertText($edit['name'], 'The randomly generated term name is present.'); $this->assertLink(t('edit')); @@ -359,9 +359,9 @@ function testTermReorder() { drupal_static_reset('taxonomy_get_tree'); drupal_static_reset('taxonomy_get_treeparent'); drupal_static_reset('taxonomy_get_treeterms'); - list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid); + list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->id()); - $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name); + $this->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->id()); // 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,19 +386,19 @@ function testTermReorder() { drupal_static_reset('taxonomy_get_tree'); drupal_static_reset('taxonomy_get_treeparent'); drupal_static_reset('taxonomy_get_treeterms'); - $terms = taxonomy_get_tree($this->vocabulary->vid); + $terms = taxonomy_get_tree($this->vocabulary->id()); $this->assertEqual($terms[0]->tid, $term2->tid, 'Term 2 was moved above term 1.'); $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->id(), array(), t('Reset to alphabetical')); // Submit confirmation form. $this->drupalPost(NULL, array(), t('Reset to alphabetical')); drupal_static_reset('taxonomy_get_tree'); drupal_static_reset('taxonomy_get_treeparent'); drupal_static_reset('taxonomy_get_treeterms'); - $terms = taxonomy_get_tree($this->vocabulary->vid); + $terms = taxonomy_get_tree($this->vocabulary->id()); $this->assertEqual($terms[0]->tid, $term1->tid, 'Term 1 was moved to back above term 2.'); $this->assertEqual($terms[1]->tid, $term2->tid, 'Term 2 was moved to back below term 1.'); $this->assertEqual($terms[2]->tid, $term3->tid, 'Term 3 is still below term 2.'); @@ -419,7 +419,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->id() . '/add', $edit, t('Save')); // Check that the term was successfully created. $terms = taxonomy_term_load_multiple_by_name($edit['name']); @@ -468,7 +468,7 @@ function testTaxonomyGetTermByName() { $new_vocabulary = $this->createVocabulary(); $new_term = entity_create('taxonomy_term', array( 'name' => $term->name, - 'vid' => $new_vocabulary->vid, + 'vid' => $new_vocabulary->id(), )); taxonomy_term_save($new_term); @@ -477,7 +477,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->id()); $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 @@ 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->id()); $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/TermTranslationUITest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php index 90982f4..c650c75 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php @@ -54,12 +54,12 @@ protected function setupBundle() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => $this->bundle, 'description' => $this->randomName(), - 'machine_name' => $this->bundle, + 'vid' => $this->bundle, 'langcode' => LANGUAGE_NOT_SPECIFIED, 'help' => '', 'weight' => mt_rand(0, 10), )); - taxonomy_vocabulary_save($vocabulary); + $vocabulary->save(); } /** @@ -73,7 +73,7 @@ function getTranslatorPermissions() { * Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::createEntity(). */ protected function createEntity($values, $langcode) { - $vocabulary = taxonomy_vocabulary_machine_name_load($this->bundle); + $vocabulary = entity_load('taxonomy_vocabulary', $this->bundle); $values['vid'] = $vocabulary->id(); return parent::createEntity($values, $langcode); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php index 22f9dcb..8656505 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermUnitTest.php @@ -25,7 +25,7 @@ function testTermDelete() { $valid_term = $this->createTerm($vocabulary); // Delete a valid term. taxonomy_term_delete($valid_term->tid); - $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->vid)); + $terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id())); $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion'); // Delete an invalid term. Should not throw any notices. @@ -65,11 +65,11 @@ function testTaxonomyVocabularyTree() { * ------ term[3] | depth: 3 */ // Count $term[1] parents with $max_depth = 1. - $tree = taxonomy_get_tree($vocabulary->vid, $term[1]->tid, 1); + $tree = taxonomy_get_tree($vocabulary->id(), $term[1]->tid, 1); $this->assertEqual(1, count($tree), 'We have one parent with depth 1.'); // Count all vocabulary tree elements. - $tree = taxonomy_get_tree($vocabulary->vid); + $tree = taxonomy_get_tree($vocabulary->id()); $this->assertEqual(8, count($tree), 'We have all vocabulary tree elements.'); // Count elements in every tree depth. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/ThemeTest.php index b226970..6d5836c 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 @@ function testTaxonomyTermThemes() { // 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->id() . '/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..6a28ca3 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->id(), 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), '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->id(), 'bundle' => 'article', 'entity_type' => 'node', 'widget' => array( @@ -128,7 +128,7 @@ function testTaxonomyTokenReplacement() { // Generate and test sanitized tokens. $tests = array(); - $tests['[vocabulary:vid]'] = $this->vocabulary->vid; + $tests['[vocabulary:vid]'] = $this->vocabulary->id(); $tests['[vocabulary:name]'] = check_plain($this->vocabulary->name); $tests['[vocabulary:description]'] = filter_xss($this->vocabulary->description); $tests['[vocabulary:node-count]'] = 1; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php index 65f756f..e08e534 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php @@ -52,27 +52,28 @@ function testVocabularyLanguage() { $this->drupalGet('admin/structure/taxonomy/add'); // Check that we have the language selector available. - $this->assertField('edit-langcode', t('The language selector field was found on the page')); + $this->assertField('edit-langcode', '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->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.')); + $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit'); + $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.'); // Change the language and save again. $edit['langcode'] = 'bb'; + unset($edit['vid']); $this->drupalPost(NULL, $edit, t('Save')); // Check again the language on the edit page. - $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit'); - $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.')); + $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit'); + $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.'); } /** @@ -83,19 +84,19 @@ function testVocabularyDefaultLanguageForTerms() { // the terms are saved. $edit = array( 'name' => $this->randomName(), - 'machine_name' => drupal_strtolower($this->randomName()), + 'vid' => drupal_strtolower($this->randomName()), 'default_language[langcode]' => 'bb', 'default_language[language_hidden]' => FALSE, ); - $machine_name = $edit['machine_name']; + $vid = $edit['vid']; $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); // Check that the vocabulary was actually created. - $this->drupalGet('admin/structure/taxonomy/' . $edit['machine_name'] . '/edit'); + $this->drupalGet('admin/structure/taxonomy/' . $edit['vid'] . '/edit'); $this->assertResponse(200, 'The vocabulary has been created.'); // Check that the language settings were saved. - $language_settings = language_get_default_configuration('taxonomy_term', $edit['machine_name']); + $language_settings = language_get_default_configuration('taxonomy_term', $edit['vid']); $this->assertEqual($language_settings['langcode'], 'bb'); $this->assertEqual($language_settings['language_hidden'], FALSE); @@ -108,32 +109,27 @@ function testVocabularyDefaultLanguageForTerms() { 'default_language[langcode]' => 'aa', 'default_language[language_hidden]' => TRUE, ); - $this->drupalPost('admin/structure/taxonomy/' . $machine_name . '/edit', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $vid . '/edit', $edit, t('Save')); // And check again the settings and also the interface. - $language_settings = language_get_default_configuration('taxonomy_term', $machine_name); + $language_settings = language_get_default_configuration('taxonomy_term', $vid); $this->assertEqual($language_settings['langcode'], 'aa'); $this->assertEqual($language_settings['language_hidden'], TRUE); - $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit'); + $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit'); $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.'); $this->assertFieldChecked('edit-default-language-language-hidden', 'Hide language selection option is not checked.'); - // Check that, if the machine name of the vocabulary is changed, then the - // settings are applied on the new machine name. - $edit = array( - 'machine_name' => $machine_name . '_new', + // Check that language settings are changed after editing vocabulary. + $edit = array( + 'name' => $this->randomName(), 'default_language[langcode]' => 'authors_default', 'default_language[language_hidden]' => TRUE, ); - $new_machine_name = $edit['machine_name']; - $this->drupalPost('admin/structure/taxonomy/' . $machine_name . '/edit', $edit, t('Save')); + $this->drupalPost('admin/structure/taxonomy/' . $vid . '/edit', $edit, t('Save')); - // Check that the old settings are empty. - $old_settings = config('language.settings')->get(language_get_default_configuration_settings_key('vocabulary', $machine_name)); - $this->assertNull($old_settings, 'The old vocabulary settings were deleted.'); // Check that we have the new settings. - $new_settings = language_get_default_configuration('taxonomy_term', $new_machine_name); + $new_settings = language_get_default_configuration('taxonomy_term', $vid); $this->assertEqual($new_settings['langcode'], 'authors_default'); $this->assertEqual($new_settings['language_hidden'], TRUE); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php index 6197fdb..0f7d328 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'); @@ -88,15 +88,17 @@ function testTaxonomyAdminChangingWeights() { $vocabularies = taxonomy_vocabulary_load_multiple(); $edit = array(); foreach ($vocabularies as $key => $vocabulary) { - $vocabulary->weight = -$vocabulary->weight; - $vocabularies[$key]->weight = $vocabulary->weight; - $edit[$key . '[weight]'] = $vocabulary->weight; + $weight = -$vocabulary->weight; + $vocabularies[$key]->weight = $weight; + $edit[$key . '[weight]'] = $weight; } // Saving the new weights via the interface. $this->drupalPost('admin/structure/taxonomy', $edit, t('Save')); // Load the vocabularies from the database. + entity_get_controller('taxonomy_vocabulary')->resetCache(); $new_vocabularies = taxonomy_vocabulary_load_multiple(); + taxonomy_vocabulary_sort($new_vocabularies); // Check that the weights are saved in the database correctly. foreach ($vocabularies as $key => $vocabulary) { @@ -114,10 +116,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.')); } /** @@ -125,23 +127,22 @@ function testTaxonomyAdminNoVocabularies() { */ 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->id() . '/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 +150,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..b66da01 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -36,33 +36,12 @@ function setUp() { } /** - * 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() { - // Load a vocabulary that doesn't exist. - $vocabularies = taxonomy_vocabulary_load_multiple(); - $vid = count($vocabularies) + 1; - $vocabulary = taxonomy_vocabulary_load($vid); - // This should not return an object because no such vocabulary exists. - $this->assertTrue(empty($vocabulary), 'No object loaded.'); - - // Create a new vocabulary. - $this->createVocabulary(); - // Load the vocabulary with the same $vid from earlier. - // This should return a vocabulary object since it now matches a real vid. - $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. */ function testTaxonomyVocabularyDeleteWithTerms() { // Delete any existing vocabularies. foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); + taxonomy_vocabulary_delete($vocabulary->id()); } // Assert that there are no terms left. @@ -84,7 +63,7 @@ function testTaxonomyVocabularyDeleteWithTerms() { // Assert that there are now 5 terms. $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); - taxonomy_vocabulary_delete($vocabulary->vid); + taxonomy_vocabulary_delete($vocabulary->id()); // Assert that there are no terms left. $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); @@ -94,7 +73,7 @@ function testTaxonomyVocabularyDeleteWithTerms() { * Ensure that the vocabulary static reset works correctly. */ function testTaxonomyVocabularyLoadStaticReset() { - $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid); + $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->id()); $this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.'); $this->assertEqual($this->vocabulary->name, $original_vocabulary->name, 'Vocabulary loaded successfully.'); @@ -105,14 +84,14 @@ function testTaxonomyVocabularyLoadStaticReset() { taxonomy_vocabulary_save($vocabulary); // Load the vocabulary. - $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->vid); + $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->id()); $this->assertEqual($new_vocabulary->name, $vocabulary->name); $this->assertEqual($new_vocabulary->name, $vocabulary->name); // Delete the vocabulary. - taxonomy_vocabulary_delete($this->vocabulary->vid); + taxonomy_vocabulary_delete($this->vocabulary->id()); $vocabularies = taxonomy_vocabulary_load_multiple(); - $this->assertTrue(!isset($vocabularies[$this->vocabulary->vid]), 'The vocabulary was deleted.'); + $this->assertTrue(!isset($vocabularies[$this->vocabulary->id()]), 'The vocabulary was deleted.'); } /** @@ -122,7 +101,7 @@ function testTaxonomyVocabularyLoadMultiple() { // Delete any existing vocabularies. foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { - taxonomy_vocabulary_delete($vocabulary->vid); + taxonomy_vocabulary_delete($vocabulary->id()); } // Create some vocabularies and assign weights. @@ -139,28 +118,31 @@ 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->id()], $vocabulary1->id(), 'Vocabulary 1 name found.'); // Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(). // Confirm that the vocabularies are ordered by weight. $vocabularies = taxonomy_vocabulary_load_multiple(); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary was found in the vocabularies array.'); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary was found in the vocabularies array.'); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary was found in the vocabularies array.'); + taxonomy_vocabulary_sort($vocabularies); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary1->id(), 'Vocabulary was found in the vocabularies array.'); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary2->id(), 'Vocabulary was found in the vocabularies array.'); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary3->id(), 'Vocabulary was found in the vocabularies array.'); // Fetch the vocabularies with taxonomy_vocabulary_load_multiple(), specifying IDs. // Ensure they are returned in the same order as the original array. - $vocabularies = taxonomy_vocabulary_load_multiple(array($vocabulary3->vid, $vocabulary2->vid, $vocabulary1->vid)); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary loaded successfully by ID.'); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary loaded successfully by ID.'); - $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by ID.'); + $vocabularies = taxonomy_vocabulary_load_multiple(array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id())); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary3->id(), 'Vocabulary loaded successfully by ID.'); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by ID.'); + $this->assertEqual(array_shift($vocabularies)->id(), $vocabulary1->id(), '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 Commented for EntityStorageControllerInterface::loadByProperties() + //$vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name))); + //$this->assertEqual($vocabulary->id(), $vocabulary1->id(), '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.'); + // @todo Commented for EntityStorageControllerInterface::loadByProperties() + //$this->assertEqual(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->id()), array('name' => $vocabulary1->name)))->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by name and ID.'); } /** @@ -176,14 +158,14 @@ function testTaxonomyVocabularyChangeMachineName() { $instance = array( 'field_name' => 'field_test', 'entity_type' => 'taxonomy_term', - 'bundle' => $this->vocabulary->machine_name, + 'bundle' => $this->vocabulary->id(), ); field_create_instance($instance); // Change the machine name. - $old_name = $this->vocabulary->machine_name; + $old_name = $this->vocabulary->id(); $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 +189,7 @@ function testUninstallReinstall() { $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'taxonomy_term', - 'bundle' => $this->vocabulary->machine_name, + 'bundle' => $this->vocabulary->id(), 'label' => $this->randomName() . '_label', ); field_create_instance($this->instance); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index c26251e..44b60fd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -31,14 +31,15 @@ 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->id(), '#maxlength' => 255, '#machine_name' => array( - 'exists' => 'taxonomy_vocabulary_machine_name_load', + 'exists' => 'taxonomy_vocabulary_load', 'source' => array('name'), ), + '#disabled' => !$vocabulary->isNew(), ); $form['description'] = array( '#type' => 'textfield', @@ -65,9 +66,9 @@ public function form(array $form, array &$form_state, EntityInterface $vocabular '#type' => 'language_configuration', '#entity_information' => array( 'entity_type' => 'taxonomy_term', - 'bundle' => $vocabulary->machine_name, + 'bundle' => $vocabulary->id(), ), - '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->machine_name), + '#default_value' => language_get_default_configuration('taxonomy_term', $vocabulary->id()), ); } // Set the hierarchy to "multiple parents" by default. This simplifies the @@ -77,10 +78,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); } @@ -120,13 +117,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".')); } } } @@ -138,13 +135,13 @@ public function languageConfigurationSubmit(array &$form, array &$form_state) { $vocabulary = $this->getEntity($form_state); // Delete the old language settings for the vocabulary, if the machine name // is changed. - if ($vocabulary && isset($vocabulary->machine_name) && $vocabulary->machine_name != $form_state['values']['machine_name']) { - language_clear_default_configuration('taxonomy_term', $vocabulary->machine_name); + if ($vocabulary && $vocabulary->id() && $vocabulary->id() != $form_state['values']['vid']) { + language_clear_default_configuration('taxonomy_term', $vocabulary->id()); } // Since the machine name is not known yet, and it can be changed anytime, // we have to also update the bundle property for the default language // configuration in order to have the correct bundle value. - $form_state['language']['default_language']['bundle'] = $form_state['values']['machine_name']; + $form_state['language']['default_language']['bundle'] = $form_state['values']['vid']; } /** @@ -176,18 +173,18 @@ 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->id() . '/edit')); + $form_state['redirect'] = 'admin/structure/taxonomy/' . $vocabulary->id(); 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->id() . '/edit')); $form_state['redirect'] = 'admin/structure/taxonomy'; break; } - $form_state['values']['vid'] = $vocabulary->vid; - $form_state['vid'] = $vocabulary->vid; + $form_state['values']['vid'] = $vocabulary->id(); + $form_state['vid'] = $vocabulary->id(); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php index dd5b478..2ff20cf 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -2,55 +2,71 @@ /** * @file - * Definition of VocabularyStorageController. + * Definition of Drupal\taxonomy\VocabularyStorageController. */ namespace Drupal\taxonomy; +use Drupal\Core\Config\Entity\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->id()); } - 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->id()) { + // Reflect machine name changes in the definitions of existing 'taxonomy' + // fields. + $fields = field_read_fields(); + foreach ($fields as $field_name => $field) { + $update_field = FALSE; + if ($field['type'] == 'taxonomy_term_reference') { + foreach ($field['settings']['allowed_values'] as $key => &$value) { + if ($value['vocabulary'] == $entity->getOriginalID()) { + $value['vocabulary'] = $entity->id(); + $update_field = TRUE; + } + } + if ($update_field) { + field_update_field($field); + } + } + } + // Update bundles. + field_attach_rename_bundle('taxonomy_term', $entity->getOriginalID(), $entity->id()); } + parent::postSave($entity, $update); + $this->resetCache($update ? array($entity->getOriginalID()) : array()); } /** - * 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); + + $vocabularies = array(); + foreach ($entities as $vocabulary) { + $vocabularies[$vocabulary->id()] = $vocabulary->id(); + } // Load all Taxonomy module fields and delete those which use only this // vocabulary. $taxonomy_fields = field_read_fields(array('module' => 'taxonomy')); @@ -59,11 +75,9 @@ protected function postDelete($entities) { // Term reference fields may reference terms from more than one // vocabulary. foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) { - foreach ($entities as $vocabulary) { - if ($allowed_value['vocabulary'] == $vocabulary->machine_name) { - unset($taxonomy_field['settings']['allowed_values'][$key]); - $modified_field = TRUE; - } + if (isset($vocabularies[$allowed_value['vocabulary']])) { + unset($taxonomy_field['settings']['allowed_values'][$key]); + $modified_field = TRUE; } } if ($modified_field) { @@ -76,14 +90,17 @@ protected function postDelete($entities) { } } } + // Reset caches. + $this->resetCache(array_keys($vocabularies)); } /** - * Overrides Drupal\Core\Entity\DrupalDatabaseStorageController::resetCache(). + * Overrides Drupal\config\ConfigStorageController::resetCache(). */ public function resetCache(array $ids = NULL) { drupal_static_reset('taxonomy_vocabulary_get_names'); parent::resetCache($ids); - cache_invalidate(array('content' => TRUE)); + cache_invalidate(array('content' => TRUE, 'entity_info' => TRUE)); + drupal_static_reset('entity_get_info'); } } diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 1a177ed..5ff70db 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -17,11 +17,12 @@ */ function taxonomy_overview_vocabularies($form) { $vocabularies = taxonomy_vocabulary_load_multiple(); + taxonomy_vocabulary_sort($vocabularies); $form['#tree'] = TRUE; foreach ($vocabularies as $vocabulary) { - $form[$vocabulary->vid]['#vocabulary'] = $vocabulary; - $form[$vocabulary->vid]['name'] = array('#markup' => check_plain($vocabulary->name)); - $form[$vocabulary->vid]['weight'] = array( + $form[$vocabulary->id()]['#vocabulary'] = $vocabulary; + $form[$vocabulary->id()]['name'] = array('#markup' => check_plain($vocabulary->name)); + $form[$vocabulary->id()]['weight'] = array( '#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $vocabulary->name)), '#title_display' => 'invisible', @@ -31,17 +32,17 @@ function taxonomy_overview_vocabularies($form) { $links = array(); $links['edit'] = array( 'title' => t('edit vocabulary'), - 'href' => "admin/structure/taxonomy/$vocabulary->machine_name/edit", + 'href' => "admin/structure/taxonomy/{$vocabulary->id()}/edit", ); $links['list'] = array( 'title' => t('list terms'), - 'href' => "admin/structure/taxonomy/$vocabulary->machine_name", + 'href' => "admin/structure/taxonomy/{$vocabulary->id()}", ); $links['add'] = array( 'title' => t('add terms'), - 'href' => "admin/structure/taxonomy/$vocabulary->machine_name/add", + 'href' => "admin/structure/taxonomy/{$vocabulary->id()}/add", ); - $form[$vocabulary->vid]['operations'] = array( + $form[$vocabulary->id()]['operations'] = array( '#type' => 'operations', '#links' => $links, ); @@ -54,7 +55,7 @@ function taxonomy_overview_vocabularies($form) { $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save')); } elseif (isset($vocabulary)) { - unset($form[$vocabulary->vid]['weight']); + unset($form[$vocabulary->id()]['weight']); } return $form; } @@ -66,7 +67,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']); } @@ -143,7 +144,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { // Check for confirmation forms. if (isset($form_state['confirm_reset_alphabetical'])) { - return taxonomy_vocabulary_confirm_reset_alphabetical($form, $form_state, $vocabulary->vid); + return taxonomy_vocabulary_confirm_reset_alphabetical($form, $form_state, $vocabulary->id()); } $form_state['taxonomy']['vocabulary'] = $vocabulary; @@ -168,7 +169,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) { $delta = 0; $term_deltas = array(); - $tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE); + $tree = taxonomy_get_tree($vocabulary->id(), 0, NULL, TRUE); $term = current($tree); do { // In case this tree is completely empty. @@ -299,7 +300,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->id() . '/add'))); if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $form['actions'] = array('#type' => 'actions', '#tree' => FALSE); @@ -352,7 +353,7 @@ function taxonomy_overview_terms_submit($form, &$form_state) { $hierarchy = TAXONOMY_HIERARCHY_DISABLED; $changed_terms = array(); - $tree = taxonomy_get_tree($vocabulary->vid); + $tree = taxonomy_get_tree($vocabulary->id()); if (empty($tree)) { return; @@ -531,9 +532,9 @@ 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->id())); if (module_exists('language')) { - $term->langcode = language_get_default_langcode('taxonomy_term', $vocabulary->machine_name); + $term->langcode = language_get_default_langcode('taxonomy_term', $vocabulary->id()); } return entity_get_form($term); } @@ -548,14 +549,14 @@ function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { // Always provide entity id in the same form key as in the entity edit form. $form['tid'] = array('#type' => 'value', '#value' => $term->tid); - $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->vid);; + $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->bundle());; $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->bundle()); $form['delete'] = array('#type' => 'value', '#value' => TRUE); return confirm_form($form, t('Are you sure you want to delete the term %title?', - array('%title' => $term->label())), + array('%title' => $term->label())), 'admin/structure/taxonomy', t('Deleting a term will delete all its children if there are any. This action cannot be undone.'), t('Delete'), @@ -598,7 +599,7 @@ function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) { $form['#submit'] = array('taxonomy_vocabulary_confirm_delete_submit'); return confirm_form($form, t('Are you sure you want to delete the vocabulary %title?', - array('%title' => $vocabulary->name)), + array('%title' => $vocabulary->label())), 'admin/structure/taxonomy', t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), t('Delete'), @@ -630,16 +631,15 @@ 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, - t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'), - t('Reset to alphabetical'), - t('Cancel')); + t('Are you sure you want to reset the vocabulary %title to alphabetical order?', + array('%title' => $vocabulary->label())), + 'admin/structure/taxonomy/' . $vocabulary->id(), + t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'), + t('Reset to alphabetical'), + t('Cancel')); } /** @@ -654,5 +654,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.api.php b/core/modules/taxonomy/taxonomy.api.php index 1eb6bf2..99ee4ec 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -23,7 +23,7 @@ */ function hook_taxonomy_vocabulary_load(array $vocabularies) { foreach ($vocabularies as $vocabulary) { - $vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE); + $vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE); } } @@ -52,7 +52,7 @@ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Voc */ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE); + variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', TRUE); } } @@ -67,7 +67,7 @@ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Voca function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { $status = $vocabulary->synonyms ? TRUE : FALSE; if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status); + variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', $status); } } @@ -85,8 +85,8 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Voca * @see taxonomy_vocabulary_delete() */ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { - variable_del('taxonomy_' . $vocabulary->vid . '_synonyms'); + if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { + variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); } } @@ -104,8 +104,8 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\V * @see taxonomy_vocabulary_delete() */ function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) { - variable_del('taxonomy_' . $vocabulary->vid . '_synonyms'); + if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { + variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); } } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 25d2c06..2a418dd 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); } } @@ -23,68 +26,6 @@ function taxonomy_uninstall() { * Implements hook_schema(). */ function taxonomy_schema() { - $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_term_data'] = array( 'description' => 'Stores term information.', 'fields' => array( @@ -101,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.', @@ -146,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'), @@ -264,14 +199,7 @@ 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 */ @@ -349,3 +277,50 @@ function taxonomy_update_8003(&$sandbox) { $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); } + +/** + * Convert vocabularies into configuration. + */ +function taxonomy_update_8004() { + $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) + ->set('langcode', $vocabulary->langcode) + ->save(); + } +} + +/** + * Change {taxonomy_term_data}.vid into a string holding the vocabulary machine name. + */ +function taxonomy_update_8005() { + 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_8006() { + db_drop_table('taxonomy_vocabulary'); +} diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 8da637f..822f762 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)) . '

'; @@ -92,12 +92,12 @@ function taxonomy_permission() { ); foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) { $permissions += array( - 'edit terms in ' . $vocabulary->vid => array( + 'edit terms in ' . $vocabulary->id() => array( 'title' => t('Edit terms in %vocabulary', array('%vocabulary' => $vocabulary->name)), ), ); $permissions += array( - 'delete terms in ' . $vocabulary->vid => array( + 'delete terms in ' . $vocabulary->id() => array( 'title' => t('Delete terms from %vocabulary', array('%vocabulary' => $vocabulary->name)), ), ); @@ -109,12 +109,13 @@ function taxonomy_permission() { * Implements hook_entity_info_alter(). */ function taxonomy_entity_info_alter(&$info) { - foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) { - $info['taxonomy_term']['bundles'][$machine_name] = array( - 'label' => $vocabulary->name, + foreach (taxonomy_vocabulary_get_names() as $id) { + $config = config('taxonomy.vocabulary.' . $id); + $info['taxonomy_term']['bundles'][$id] = 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/' . $id, 'bundle argument' => 3, 'access arguments' => array('administer taxonomy'), ), @@ -315,7 +316,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', @@ -323,12 +324,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), @@ -338,7 +339,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), @@ -386,7 +387,7 @@ function taxonomy_term_access($op, $term) { return FALSE; } - return user_access("$op terms in $term->vid") || user_access('administer taxonomy'); + return user_access("$op terms in {$term->bundle()}") || user_access('administer taxonomy'); } /** @@ -421,31 +422,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 @@ -465,7 +441,7 @@ function taxonomy_taxonomy_vocabulary_update(Vocabulary $vocabulary) { * An integer that represents the level of the vocabulary's hierarchy. */ function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_term) { - $tree = taxonomy_get_tree($vocabulary->vid); + $tree = taxonomy_get_tree($vocabulary->id()); $hierarchy = TAXONOMY_HIERARCHY_DISABLED; foreach ($tree as $term) { // Update the changed term with the new parent value before comparison. @@ -493,7 +469,7 @@ function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_te /** * Saves a term object to the database. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * The taxonomy term entity to be saved. * * @return @@ -528,7 +504,7 @@ function taxonomy_term_delete_multiple(array $tids) { /** * Generates an array which displays a term detail page. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * A taxonomy term object. * @param string $view_mode * View mode, e.g. 'full', 'teaser'... @@ -587,17 +563,17 @@ 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->bundle()); $variables['attributes']['class'][] = 'vocabulary-' . $vocabulary_name_css; - $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->vocabulary_machine_name; + $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->bundle(); $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->tid; } /** * Returns whether the current page is the page of the passed-in term. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * A taxonomy term entity. */ function taxonomy_term_is_page(Term $term) { @@ -625,18 +601,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) { + $id = substr($config_name, strlen('taxonomy.vocabulary.')); + $names[$id] = $id; + } } return $names; @@ -700,14 +677,14 @@ function taxonomy_term_load_parents_all($tid) { * * @param $tid * A taxonomy term ID. - * @param $vid + * @param $bundle * An optional vocabulary ID to restrict the child search. * * @return * An array of term objects that are the children of the term $tid, or an * empty array when no children exist. */ -function taxonomy_term_load_children($tid, $vid = 0) { +function taxonomy_term_load_children($tid, $bundle = 0) { $children = &drupal_static(__FUNCTION__, array()); if ($tid && !isset($children[$tid])) { @@ -715,8 +692,8 @@ function taxonomy_term_load_children($tid, $vid = 0) { $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid'); $query->addField('t', 'tid'); $query->condition('h.parent', $tid); - if ($vid) { - $query->condition('t.vid', $vid); + if ($bundle) { + $query->condition('t.vid', $bundle); } $query->addTag('term_access'); $query->orderBy('t.weight'); @@ -731,7 +708,7 @@ function taxonomy_term_load_children($tid, $vid = 0) { /** * Create a hierarchical representation of a vocabulary. * - * @param $vid + * @param $bundle * Which vocabulary to generate the tree for. * @param $parent * The term ID under which to generate the tree. If 0, generate the tree @@ -750,17 +727,17 @@ function taxonomy_term_load_children($tid, $vid = 0) { * Results are statically cached. Term objects will be partial or complete * depending on the $load_entities parameter. */ -function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities = FALSE) { +function taxonomy_get_tree($bundle, $parent = 0, $max_depth = NULL, $load_entities = FALSE) { $children = &drupal_static(__FUNCTION__, array()); $parents = &drupal_static(__FUNCTION__ . ':parents', array()); $terms = &drupal_static(__FUNCTION__ . ':terms', array()); // We cache trees, so it's not CPU-intensive to call taxonomy_get_tree() on a // term and its children, too. - if (!isset($children[$vid])) { - $children[$vid] = array(); - $parents[$vid] = array(); - $terms[$vid] = array(); + if (!isset($children[$bundle])) { + $children[$bundle] = array(); + $parents[$bundle] = array(); + $terms[$bundle] = array(); $query = db_select('taxonomy_term_data', 't'); $query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid'); @@ -769,25 +746,25 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities ->addTag('term_access') ->fields('t') ->fields('h', array('parent')) - ->condition('t.vid', $vid) + ->condition('t.vid', $bundle) ->orderBy('t.weight') ->orderBy('t.name') ->execute(); foreach ($result as $term) { - $children[$vid][$term->parent][] = $term->tid; - $parents[$vid][$term->tid][] = $term->parent; - $terms[$vid][$term->tid] = $term; + $children[$bundle][$term->parent][] = $term->tid; + $parents[$bundle][$term->tid][] = $term->parent; + $terms[$bundle][$term->tid] = $term; } } // Load full entities, if necessary. The entity controller statically // caches the results. if ($load_entities) { - $term_entities = taxonomy_term_load_multiple(array_keys($terms[$vid])); + $term_entities = taxonomy_term_load_multiple(array_keys($terms[$bundle])); } - $max_depth = (!isset($max_depth)) ? count($children[$vid]) : $max_depth; + $max_depth = (!isset($max_depth)) ? count($children[$bundle]) : $max_depth; $tree = array(); // Keeps track of the parents we have to process, the last entry is used @@ -801,24 +778,24 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities $parent = array_pop($process_parents); // The number of parents determines the current depth. $depth = count($process_parents); - if ($max_depth > $depth && !empty($children[$vid][$parent])) { + if ($max_depth > $depth && !empty($children[$bundle][$parent])) { $has_children = FALSE; - $child = current($children[$vid][$parent]); + $child = current($children[$bundle][$parent]); do { if (empty($child)) { break; } - $term = $load_entities ? $term_entities[$child] : $terms[$vid][$child]; - if (isset($parents[$vid][$term->tid])) { + $term = $load_entities ? $term_entities[$child] : $terms[$bundle][$child]; + if (isset($parents[$bundle][$term->tid])) { // Clone the term so that the depth attribute remains correct // in the event of multiple parents. $term = clone $term; } $term->depth = $depth; unset($term->parent); - $term->parents = $parents[$vid][$term->tid]; + $term->parents = $parents[$bundle][$term->tid]; $tree[] = $term; - if (!empty($children[$vid][$term->tid])) { + if (!empty($children[$bundle][$term->tid])) { $has_children = TRUE; // We have to continue with this parent later. @@ -828,17 +805,17 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities // Reset pointers for child lists because we step in there more often // with multi parents. - reset($children[$vid][$term->tid]); + reset($children[$bundle][$term->tid]); // Move pointer so that we get the correct term the next time. - next($children[$vid][$parent]); + next($children[$bundle][$parent]); break; } - } while ($child = next($children[$vid][$parent])); + } while ($child = next($children[$bundle][$parent])); if (!$has_children) { // We processed all terms in this hierarchy-level, reset pointer // so that this function works the next time it gets called. - reset($children[$vid][$parent]); + reset($children[$bundle][$parent]); } } } @@ -865,7 +842,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. @@ -916,36 +893,29 @@ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { } /** - * Return the taxonomy vocabulary entity matching a vocabulary ID. + * Sorts vocabularies by its weight and label. * - * @param int $vid - * The vocabulary's ID. - * - * @return Drupal\taxonomy\Plugin\Core\Entity\Vocabulary|false - * The taxonomy vocabulary entity, if exists, FALSE otherwise. Results are - * statically cached. - * - * @see taxonomy_vocabulary_machine_name_load() + * @param array $vocabularies + * An array of \Drupal\taxonomy\Plugin\Core\Entity\Vocabulary objects. */ -function taxonomy_vocabulary_load($vid) { - return entity_load('taxonomy_vocabulary', $vid); +function taxonomy_vocabulary_sort(array &$vocabularies = array()) { + // @todo Investigate the cause of Warning: uasort() [function.uasort]: Array + // was modified by the user comparison function + @uasort($vocabularies, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); } /** - * Return the taxonomy vocabulary entity matching a vocabulary machine name. + * Return the taxonomy vocabulary entity matching a vocabulary ID. * - * @param $name - * The vocabulary's machine name. + * @param int $vid + * The vocabulary's ID. * * @return Drupal\taxonomy\Plugin\Core\Entity\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); +function taxonomy_vocabulary_load($vid) { + return entity_load('taxonomy_vocabulary', $vid); } /** @@ -954,7 +924,7 @@ function taxonomy_vocabulary_machine_name_load($name) { * @param $tid * A term's ID * - * @return Drupal\taxonomy\Term|false + * @return Drupal\taxonomy\Plugin\Core\Entity\Term|false * A taxonomy term entity, or FALSE if the term was not found. Results are * statically cached. */ @@ -977,11 +947,11 @@ function _taxonomy_get_tid_from_term(Term $term) { * * @see drupal_explode_tags() */ -function taxonomy_implode_tags($tags, $vid = NULL) { +function taxonomy_implode_tags($tags, $bundle = NULL) { $typed_tags = array(); foreach ($tags as $tag) { // Extract terms belonging to the vocabulary in question. - if (!isset($vid) || $tag->vid == $vid) { + if (!isset($bundle) || $tag->vid == $bundle) { // Make sure we have a completed loaded taxonomy term. if ($tag instanceof EntityInterface && $label = $tag->label()) { // Commas and quotes in tag names are special cases, so encode 'em. @@ -1074,7 +1044,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']]->bundle()) { $validate = TRUE; break; } @@ -1209,8 +1179,8 @@ 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 ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE)) { + if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) { + if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) { foreach ($terms as $term) { $options[$term->tid] = str_repeat('-', $term->depth) . $term->label(); } @@ -1273,7 +1243,7 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field, /** * Title callback for term pages. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * A taxonomy term entity. * * @return @@ -1304,7 +1274,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->id()] = $vocabulary->name; } $form['allowed_values'] = array( '#tree' => TRUE, @@ -1423,7 +1393,7 @@ function taxonomy_node_insert(Node $node) { * The index lists all terms that are related to a given node entity, and is * therefore maintained at the entity level. * - * @param Drupal\node\Node $node + * @param Drupal\node\Plugin\Core\Entity\Node $node * The node entity. */ function taxonomy_build_node_index($node) { @@ -1506,7 +1476,7 @@ function taxonomy_node_predelete(Node $node) { /** * Deletes taxonomy index entries for a given node. * - * @param Drupal\node\Node $node + * @param Drupal\node\Plugin\Core\Entity\Node $node * The node entity. */ function taxonomy_delete_node_index(Node $node) { diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 042263c..48ebdbe 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -12,7 +12,7 @@ /** * Menu callback; displays all nodes associated with a term. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * The taxonomy term entity. */ function taxonomy_term_page(Term $term) { @@ -67,7 +67,7 @@ function taxonomy_term_page(Term $term) { /** * Generate the content feed for a taxonomy term. * - * @param Drupal\taxonomy\Term $term + * @param Drupal\taxonomy\Plugin\Core\Entity\Term $term * The taxonomy term entity. */ function taxonomy_term_feed(Term $term) { @@ -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/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index c7847b3..34099ce 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -123,7 +123,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'vocabulary': - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = taxonomy_vocabulary_load($term->bundle()); $replacements[$original] = check_plain($vocabulary->name); break; @@ -137,7 +137,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = } if ($vocabulary_tokens = token_find_with_prefix($tokens, 'vocabulary')) { - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = taxonomy_vocabulary_load($term->bundle()); $replacements += token_generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options); } @@ -153,7 +153,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = foreach ($tokens as $name => $original) { switch ($name) { case 'vid': - $replacements[$original] = $vocabulary->vid; + $replacements[$original] = $vocabulary->id(); break; case 'name': @@ -166,7 +166,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = case 'term-count': $query = db_select('taxonomy_term_data'); - $query->condition('vid', $vocabulary->vid); + $query->condition('vid', $vocabulary->id()); $query->addTag('vocabulary_term_count'); $count = $query->countQuery()->execute()->fetchField(); $replacements[$original] = $count; @@ -176,7 +176,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $query = db_select('taxonomy_index', 'ti'); $query->addExpression('COUNT(DISTINCT ti.nid)'); $query->leftJoin('taxonomy_term_data', 'td', 'ti.tid = td.tid'); - $query->condition('td.vid', $vocabulary->vid); + $query->condition('td.vid', $vocabulary->id()); $query->addTag('vocabulary_node_count'); $count = $query->execute()->fetchField(); $replacements[$original] = $count; diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index 57ef50c..fc11763 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -13,88 +13,6 @@ function taxonomy_views_data() { $data = array(); - // taxonomy_vocabulary table - - $data['taxonomy_vocabulary']['table']['group'] = t('Taxonomy vocabulary'); - - $data['taxonomy_vocabulary']['table']['join'] = array( - // vocabulary links to taxonomy_term_data directly via vid. - 'taxonomy_term_data' => array( - 'left_field' => 'vid', - 'field' => 'vid', - ), - ); - - // vocabulary name - $data['taxonomy_vocabulary']['name'] = array( - 'title' => t('Name'), // The item it appears as on the UI, - 'field' => array( - 'help' => t('Name of the vocabulary a term is a member of. This will be the vocabulary that whichever term the "Taxonomy: Term" field is; and can similarly cause duplicates.'), - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'sort' => array( - 'id' => 'standard', - 'help' => t('The taxonomy vocabulary name'), - ), - ); - $data['taxonomy_vocabulary']['machine_name'] = array( - 'title' => t('Machine name'), // The item it appears as on the UI, - 'field' => array( - 'help' => t('Machine-Name of the vocabulary a term is a member of. This will be the vocabulary that whichever term the "Taxonomy: Term" field is; and can similarly cause duplicates.'), - 'id' => 'standard', - 'click sortable' => TRUE, - ), - 'filter' => array( - 'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'), - 'id' => 'vocabulary_machine_name', - ), - 'argument' => array( - 'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'), - 'id' => 'vocabulary_machine_name', - ), - ); - $data['taxonomy_vocabulary']['vid'] = array( - 'title' => t('Vocabulary ID'), // The item it appears as on the UI, - 'help' => t('The taxonomy vocabulary ID'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'vocabulary_vid', - 'name field' => 'name', - ), - 'sort' => array( - 'id' => 'standard', - ), - ); - $data['taxonomy_vocabulary']['description'] = array( - 'title' => t('Description'), // The item it appears as on the UI, - 'help' => t('The taxonomy vocabulary description'), - 'field' => array( - 'id' => 'standard', - ), - ); - $data['taxonomy_vocabulary']['weight'] = array( - 'title' => t('Weight'), - 'help' => t('The taxonomy vocabulary weight'), - 'field' => array( - 'id' => 'numeric', - 'click sortable' => TRUE, - ), - 'argument' => array( - 'id' => 'numeric', - 'name field' => 'weight', - ), - 'sort' => array( - 'id' => 'standard', - ), - 'filter' => array( - 'id' => 'numeric', - ), - ); - // taxonomy_term_data table $data['taxonomy_term_data']['table']['group'] = t('Taxonomy term'); @@ -108,10 +26,6 @@ function taxonomy_views_data() { // The term data table $data['taxonomy_term_data']['table']['join'] = array( - 'taxonomy_vocabulary' => array( - 'field' => 'vid', - 'left_field' => 'vid', - ), // This is provided for many_to_one argument 'taxonomy_index' => array( 'field' => 'tid', diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index 7e37452..201fdae 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -47,13 +47,13 @@ protected function setUp() { $this->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('page' => 'page'), 'weight' => mt_rand(0, 10), )); - taxonomy_vocabulary_save($this->vocabulary); + $this->vocabulary->save(); // Setup a field and instance. $this->field_name = drupal_strtolower($this->randomName()); @@ -63,7 +63,7 @@ protected function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), 'parent' => '0', ), ), @@ -154,7 +154,7 @@ function createTerm($vocabulary) { 'description' => $this->randomName(), // Use the first available text format. 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(), - 'vid' => $vocabulary->vid, + 'vid' => $vocabulary->id(), 'langcode' => LANGUAGE_NOT_SPECIFIED, )); taxonomy_term_save($term); diff --git a/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php b/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php index 9c2835a..8485f3e 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/Taxonomy/TaxonomyTestBase.php @@ -74,18 +74,18 @@ protected function mockStandardInstall() { // Create the vocabulary for the tag field. $this->vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Views testing tags', - 'machine_name' => 'views_testing_tags', + 'vid' => 'views_testing_tags', )); $this->vocabulary->save(); $field = array( - 'field_name' => 'field_' . $this->vocabulary->machine_name, + 'field_name' => 'field_' . $this->vocabulary->id(), 'type' => 'taxonomy_term_reference', // Set cardinality to unlimited for tagging. 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->vocabulary->machine_name, + 'vocabulary' => $this->vocabulary->id(), 'parent' => 0, ), ), @@ -93,7 +93,7 @@ protected function mockStandardInstall() { ); field_create_field($field); $instance = array( - 'field_name' => 'field_' . $this->vocabulary->machine_name, + 'field_name' => 'field_' . $this->vocabulary->id(), 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article', @@ -127,7 +127,7 @@ protected function createTerm() { 'description' => $this->randomName(), // Use the first available text format. 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(), - 'vid' => $this->vocabulary->vid, + 'vid' => $this->vocabulary->id(), 'langcode' => LANGUAGE_NOT_SPECIFIED, )); $term->save(); diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index cf3d19e..291cd64 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -48,7 +48,7 @@ function setUp() { // Create the vocabulary for the tag field. $this->tag_vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Views testing tags', - 'machine_name' => 'views_testing_tags', + 'vid' => 'views_testing_tags', )); $this->tag_vocabulary->save(); @@ -60,7 +60,7 @@ function setUp() { 'settings' => array( 'allowed_values' => array( array( - 'vocabulary' => $this->tag_vocabulary->machine_name, + 'vocabulary' => $this->tag_vocabulary->id(), 'parent' => 0, ), ), diff --git a/core/modules/views/views_ui/admin.inc b/core/modules/views/views_ui/admin.inc index 5b0ae41..47e7e53 100644 --- a/core/modules/views/views_ui/admin.inc +++ b/core/modules/views/views_ui/admin.inc @@ -251,8 +251,8 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { $vocabularies = array(); if (!empty($field['settings']['allowed_values'])) { foreach ($field['settings']['allowed_values'] as $tree) { - if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) { - $vocabularies[$vocabulary->vid] = $tree['vocabulary']; + if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { + $vocabularies[$vocabulary->id()] = $tree['vocabulary']; } } } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index b4dc761..6c90c33 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->id(), '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->id(), '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->id(), 'entity_type' => 'node', 'label' => 'Tags', 'bundle' => 'article',