diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php index c7fc90badf6f921fd228f2e62ea4867ad6876379..0898f48cf88acfe324941faf7f459a9585c001d5 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php @@ -161,17 +161,17 @@ public function testConfigEntityReferenceItem() { $this->assertTrue($entity->field_test_taxonomy_vocabulary instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->field_test_taxonomy_vocabulary[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->field_test_taxonomy_vocabulary->target_id, $referenced_entity_id); - $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->name, $this->vocabulary->name); + $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->label(), $this->vocabulary->label()); $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->id(), $referenced_entity_id); $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->uuid(), $this->vocabulary->uuid()); // Change the name of the term via the reference. $new_name = $this->randomMachineName(); - $entity->field_test_taxonomy_vocabulary->entity->name = $new_name; + $entity->field_test_taxonomy_vocabulary->entity->set('name', $new_name); $entity->field_test_taxonomy_vocabulary->entity->save(); // Verify it is the correct name. $vocabulary = entity_load('taxonomy_vocabulary', $referenced_entity_id); - $this->assertEqual($vocabulary->name, $new_name); + $this->assertEqual($vocabulary->label(), $new_name); // Make sure the computed term reflects updates to the term id. $vocabulary2 = entity_create('taxonomy_vocabulary', array( @@ -183,7 +183,7 @@ public function testConfigEntityReferenceItem() { $entity->field_test_taxonomy_vocabulary->target_id = $vocabulary2->id(); $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->id(), $vocabulary2->id()); - $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->name, $vocabulary2->name); + $this->assertEqual($entity->field_test_taxonomy_vocabulary->entity->label(), $vocabulary2->label()); // Delete terms so we have nothing to reference and try again $this->vocabulary->delete(); diff --git a/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php index dbd72b84129e710e68fc77ef2ee4319ec5dfbfbc..aa95fdd214d2ba69f4b5b9bc29313d31a5920236 100644 --- a/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -340,16 +340,16 @@ function editForumVocabulary() { $current_vocabulary = entity_load('taxonomy_vocabulary', $vid); // Make sure we actually edited the vocabulary properly. - $this->assertEqual($current_vocabulary->name, $edit['name'], 'The name was updated'); - $this->assertEqual($current_vocabulary->description, $edit['description'], 'The description was updated'); + $this->assertEqual($current_vocabulary->label(), $edit['name'], 'The name was updated'); + $this->assertEqual($current_vocabulary->getDescription(), $edit['description'], 'The description was updated'); // Restore the original vocabulary's name and description. - $current_vocabulary->set('name', $original_vocabulary->name); - $current_vocabulary->set('description', $original_vocabulary->description); + $current_vocabulary->set('name', $original_vocabulary->label()); + $current_vocabulary->set('description', $original_vocabulary->getDescription()); $current_vocabulary->save(); // Reload vocabulary to make sure changes are saved. $current_vocabulary = entity_load('taxonomy_vocabulary', $vid); - $this->assertEqual($current_vocabulary->name, $original_vocabulary->name, 'The original vocabulary settings were restored'); + $this->assertEqual($current_vocabulary->label(), $original_vocabulary->label(), 'The original vocabulary settings were restored'); } /** diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php index 607d4d789919512a38f94d891d860b213a369bc1..0995ecfbd2ceb59877c7f425657d525938147c59 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php @@ -46,16 +46,16 @@ public function testTaxonomyVocabulary() { $j = $i + 1; $vocabulary = entity_load('taxonomy_vocabulary', "vocabulary_{$j}_i_{$i}_"); $this->assertEqual(array($vocabulary->id()), entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j))); - $this->assertEqual($vocabulary->name, "vocabulary $j (i=$i)"); - $this->assertEqual($vocabulary->description, "description of vocabulary $j (i=$i)"); - $this->assertEqual($vocabulary->hierarchy, $i); - $this->assertEqual($vocabulary->weight, 4 + $i); + $this->assertEqual($vocabulary->label(), "vocabulary $j (i=$i)"); + $this->assertEqual($vocabulary->getDescription(), "description of vocabulary $j (i=$i)"); + $this->assertEqual($vocabulary->getHierarchy(), $i); + $this->assertEqual($vocabulary->get('weight'), 4 + $i); } $vocabulary = entity_load('taxonomy_vocabulary', 'vocabulary_name_much_longer_than'); - $this->assertEqual($vocabulary->name, 'vocabulary name much longer than thirty two characters'); - $this->assertEqual($vocabulary->description, 'description of vocabulary name much longer than thirty two characters'); - $this->assertEqual($vocabulary->hierarchy, 3); - $this->assertEqual($vocabulary->weight, 7); + $this->assertEqual($vocabulary->label(), 'vocabulary name much longer than thirty two characters'); + $this->assertEqual($vocabulary->getDescription(), 'description of vocabulary name much longer than thirty two characters'); + $this->assertEqual($vocabulary->getHierarchy(), 3); + $this->assertEqual($vocabulary->get('weight'), 7); } } diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 3e040a428c0a908cd025b4f4ef9196bbb389db32..c65919446ae208268f7fac6c0a90d6aef51e39d0 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -450,7 +450,7 @@ public function testTaxonomyVocabularyHooks() { )); $GLOBALS['entity_crud_hook_test'] = array(); - $vocabulary->name = 'New name'; + $vocabulary->set('name', 'New name'); $vocabulary->save(); $this->assertHookMessageOrder(array( diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index aeb0cb7739063529c9f5eadb8fbcba14f56babbd..0ca834a60392223e8039147fc23c71fe63eb394e 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -424,8 +424,8 @@ function hook_mail($key, &$message, $params) { '%term_name' => $entity->name, '%term_description' => $entity->description, '%term_id' => $entity->id(), - '%vocabulary_name' => $vocabulary->name, - '%vocabulary_description' => $vocabulary->description, + '%vocabulary_name' => $vocabulary->label(), + '%vocabulary_description' => $vocabulary->getDescription(), '%vocabulary_id' => $vocabulary->id(), ); } diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php index e65055147380eb7f8313b7c649047c9dc66d59b2..6d83fa73838dcb546df881f1b002832c72e49e25 100644 --- a/core/modules/taxonomy/src/Entity/Vocabulary.php +++ b/core/modules/taxonomy/src/Entity/Vocabulary.php @@ -52,21 +52,21 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface { * * @var string */ - public $vid; + protected $vid; /** * Name of the vocabulary. * * @var string */ - public $name; + protected $name; /** * Description of the vocabulary. * * @var string */ - public $description; + protected $description; /** * The type of hierarchy allowed within the vocabulary. @@ -78,14 +78,29 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface { * * @var integer */ - public $hierarchy = TAXONOMY_HIERARCHY_DISABLED; + protected $hierarchy = TAXONOMY_HIERARCHY_DISABLED; /** * The weight of this vocabulary in relation to other vocabularies. * * @var integer */ - public $weight = 0; + protected $weight = 0; + + /** + * {@inheritdoc} + */ + public function getHierarchy() { + return $this->hierarchy; + } + + /** + * {@inheritdoc} + */ + public function setHierarchy($hierarchy) { + $this->hierarchy = $hierarchy; + return $this; + } /** * {@inheritdoc} @@ -94,6 +109,13 @@ public function id() { return $this->vid; } + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->description; + } + /** * {@inheritdoc} */ diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index e4c55048b73528635858657f70cfb20ac9b91e6b..9e7e3910daf8ce13b7c16f8d3ce33e635cf2acb2 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -227,7 +227,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular '#title' => $term->getName(), '#url' => $term->urlInfo(), ); - if ($taxonomy_vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { + if ($taxonomy_vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $parent_fields = TRUE; $form['terms'][$key]['term']['tid'] = array( '#type' => 'hidden', @@ -344,7 +344,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular 'group' => 'term-weight', ); - if ($taxonomy_vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { + if ($taxonomy_vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) { $form['actions'] = array('#type' => 'actions', '#tree' => FALSE); $form['actions']['submit'] = array( '#type' => 'submit', @@ -454,8 +454,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } // Update the vocabulary hierarchy to flat or single hierarchy. - if ($vocabulary->hierarchy != $hierarchy) { - $vocabulary->hierarchy = $hierarchy; + if ($vocabulary->getHierarchy() != $hierarchy) { + $vocabulary->setHierarchy($hierarchy); $vocabulary->save(); } drupal_set_message($this->t('The configuration options have been saved.')); diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php index 75051c9827f3c26b4446812e8221c7c0235e9c01..9a6a2689bbdeea4cdb19486311cbba7473b8427c 100644 --- a/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php @@ -125,7 +125,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $options = array(); foreach ($vocabularies as $vocabulary) { - $options[$vocabulary->id()] = $vocabulary->name; + $options[$vocabulary->id()] = $vocabulary->label(); } $element = array(); diff --git a/core/modules/taxonomy/src/TaxonomyPermissions.php b/core/modules/taxonomy/src/TaxonomyPermissions.php index 817991963c264b74372604747df44c1e15cbab2f..6b7b841fe7ce7dc0648e33811df44b70dbec6373 100644 --- a/core/modules/taxonomy/src/TaxonomyPermissions.php +++ b/core/modules/taxonomy/src/TaxonomyPermissions.php @@ -14,6 +14,8 @@ /** * Provides dynamic permissions of the taxonomy module. + * + * @see taxonomy.permissions.yml */ class TaxonomyPermissions implements ContainerInjectionInterface { @@ -44,21 +46,22 @@ public static function create(ContainerInterface $container) { } /** - * Returns an array of REST permissions. + * Get taxonomy permissions. * * @return array + * Permissions array. */ public function permissions() { $permissions = []; foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) { $permissions += [ 'edit terms in ' . $vocabulary->id() => [ - 'title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->name]), + 'title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->label()]), ], ]; $permissions += [ 'delete terms in ' . $vocabulary->id() => [ - 'title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->name]), + 'title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->label()]), ], ]; } diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 9d3c2cfb2d594a05d7fb092c50284d9fad74a953..daa2868c380820e9e3b2812e1a0178852081ff7d 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -30,7 +30,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['relations'] = array( '#type' => 'details', '#title' => $this->t('Relations'), - '#open' => $vocabulary->hierarchy == TAXONOMY_HIERARCHY_MULTIPLE, + '#open' => $vocabulary->getHierarchy() == TAXONOMY_HIERARCHY_MULTIPLE, '#weight' => 10, ); @@ -154,8 +154,8 @@ public function save(array $form, FormStateInterface $form_state) { } // If we've increased the number of parents and this is a single or flat // hierarchy, update the vocabulary immediately. - elseif ($current_parent_count > $previous_parent_count && $vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE) { - $vocabulary->hierarchy = $current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE; + elseif ($current_parent_count > $previous_parent_count && $vocabulary->getHierarchy() != TAXONOMY_HIERARCHY_MULTIPLE) { + $vocabulary->setHierarchy($current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE); $vocabulary->save(); } diff --git a/core/modules/taxonomy/src/Tests/EfqTest.php b/core/modules/taxonomy/src/Tests/EfqTest.php index ec184b31c481399d6954c87aaea34cb136af1ada..65a66c4e174a4c6e8742da01e2d6999a323fbf50 100644 --- a/core/modules/taxonomy/src/Tests/EfqTest.php +++ b/core/modules/taxonomy/src/Tests/EfqTest.php @@ -55,7 +55,7 @@ function testTaxonomyEfq() { ->condition('vid', $vocabulary2->id()) ->execute(); sort($result); - $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', array('%name' => $vocabulary2->name))); + $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', array('%name' => $vocabulary2->label()))); $tid = reset($result); $ids = (object) array( 'entity_type' => 'taxonomy_term', diff --git a/core/modules/taxonomy/src/Tests/TermFieldTest.php b/core/modules/taxonomy/src/Tests/TermFieldTest.php index 50d23e8e40607afb884a37251439778e6550d3e6..3c14410f5af08670ccf6b0efd3dd9c5b60ba997b 100644 --- a/core/modules/taxonomy/src/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php @@ -166,7 +166,7 @@ function testTaxonomyTermFieldChangeMachineName() { $this->field_storage->save(); // Change the machine name. $new_name = Unicode::strtolower($this->randomMachineName()); - $this->vocabulary->vid = $new_name; + $this->vocabulary->set('vid', $new_name); $this->vocabulary->save(); // Check that the field is still attached to the vocabulary. diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 8fb4b67fb7b009cdcc002a76a9a1f07bd2e1964b..94557b44bc10c907a50d7458b504ad3c3c3eca08 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -72,7 +72,7 @@ function testTaxonomyTermHierarchy() { // Check that hierarchy is flat. $vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id()); - $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.'); + $this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.'); // Edit $term2, setting $term1 as parent. $edit = array(); diff --git a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php index f25591ba825a3567d88d21e58d5de7f8c80d53be..6f9ca29212cbf31b50e58801577962fd30c495eb 100644 --- a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php @@ -88,7 +88,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:url]'] = $term1->url('canonical', array('absolute' => TRUE)); $tests['[term:node-count]'] = 0; $tests['[term:parent:name]'] = '[term:parent:name]'; - $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name); + $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->label()); foreach ($tests as $input => $expected) { $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId())); @@ -105,7 +105,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:parent:name]'] = String::checkPlain($term1->getName()); $tests['[term:parent:url]'] = $term1->url('canonical', array('absolute' => TRUE)); $tests['[term:parent:parent:name]'] = '[term:parent:parent:name]'; - $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name); + $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->label()); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); @@ -119,7 +119,7 @@ function testTaxonomyTokenReplacement() { $tests['[term:name]'] = $term2->getName(); $tests['[term:description]'] = $term2->getDescription(); $tests['[term:parent:name]'] = $term1->getName(); - $tests['[term:vocabulary:name]'] = $this->vocabulary->name; + $tests['[term:vocabulary:name]'] = $this->vocabulary->label(); foreach ($tests as $input => $expected) { $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); @@ -129,8 +129,8 @@ function testTaxonomyTokenReplacement() { // Generate and test sanitized tokens. $tests = array(); $tests['[vocabulary:vid]'] = $this->vocabulary->id(); - $tests['[vocabulary:name]'] = String::checkPlain($this->vocabulary->name); - $tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->description); + $tests['[vocabulary:name]'] = String::checkPlain($this->vocabulary->label()); + $tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->getDescription()); $tests['[vocabulary:node-count]'] = 1; $tests['[vocabulary:term-count]'] = 2; @@ -143,8 +143,8 @@ function testTaxonomyTokenReplacement() { } // Generate and test unsanitized tokens. - $tests['[vocabulary:name]'] = $this->vocabulary->name; - $tests['[vocabulary:description]'] = $this->vocabulary->description; + $tests['[vocabulary:name]'] = $this->vocabulary->label(); + $tests['[vocabulary:description]'] = $this->vocabulary->getDescription(); foreach ($tests as $input => $expected) { $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE)); diff --git a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php index d5aaa5685285e3451a24b191d1b35edcbe471c58..37ec181c05d9ed6726ea24a4589f2de39f83f2a8 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php @@ -70,17 +70,17 @@ function testTaxonomyVocabularyDeleteWithTerms() { function testTaxonomyVocabularyLoadStaticReset() { $original_vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id()); $this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.'); - $this->assertEqual($this->vocabulary->name, $original_vocabulary->name, 'Vocabulary loaded successfully.'); + $this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.'); // Change the name and description. $vocabulary = $original_vocabulary; - $vocabulary->name = $this->randomMachineName(); - $vocabulary->description = $this->randomMachineName(); + $vocabulary->set('name', $this->randomMachineName()); + $vocabulary->set('description', $this->randomMachineName()); $vocabulary->save(); // Load the vocabulary. $new_vocabulary = entity_load('taxonomy_vocabulary', $original_vocabulary->id()); - $this->assertEqual($new_vocabulary->name, $vocabulary->name, 'The vocabulary was loaded.'); + $this->assertEqual($new_vocabulary->label(), $vocabulary->label(), 'The vocabulary was loaded.'); // Delete the vocabulary. $this->vocabulary->delete(); @@ -100,13 +100,13 @@ function testTaxonomyVocabularyLoadMultiple() { // Create some vocabularies and assign weights. $vocabulary1 = $this->createVocabulary(); - $vocabulary1->weight = 0; + $vocabulary1->set('weight', 0); $vocabulary1->save(); $vocabulary2 = $this->createVocabulary(); - $vocabulary2->weight = 1; + $vocabulary2->set('weight', 1); $vocabulary2->save(); $vocabulary3 = $this->createVocabulary(); - $vocabulary3->weight = 2; + $vocabulary3->set('weight', 2); $vocabulary3->save(); // Check if third party settings exist. @@ -129,12 +129,12 @@ function testTaxonomyVocabularyLoadMultiple() { // Test loading vocabularies by their properties. $controller = $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary'); // Fetch vocabulary 1 by name. - $vocabulary = current($controller->loadByProperties(array('name' => $vocabulary1->name))); + $vocabulary = current($controller->loadByProperties(array('name' => $vocabulary1->label()))); $this->assertEqual($vocabulary->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by name.'); // Fetch vocabulary 2 by name and ID. $vocabulary = current($controller->loadByProperties(array( - 'name' => $vocabulary2->name, + 'name' => $vocabulary2->label(), 'vid' => $vocabulary2->id(), ))); $this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.'); @@ -159,7 +159,7 @@ function testTaxonomyVocabularyChangeMachineName() { // Change the machine name. $old_name = $this->vocabulary->id(); $new_name = Unicode::strtolower($this->randomMachineName()); - $this->vocabulary->vid = $new_name; + $this->vocabulary->set('vid', $new_name); $this->vocabulary->save(); // Check that entity bundles are properly updated. diff --git a/core/modules/taxonomy/src/Tests/VocabularyUiTest.php b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php index d9e305ce4993861856fbeb6e75b5acb37089d925..5bd84de895648d64bd67e96db12ce343645383df 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyUiTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php @@ -83,8 +83,8 @@ function testTaxonomyAdminChangingWeights() { $vocabularies = entity_load_multiple('taxonomy_vocabulary'); $edit = array(); foreach ($vocabularies as $key => $vocabulary) { - $weight = -$vocabulary->weight; - $vocabularies[$key]->weight = $weight; + $weight = -$vocabulary->get('weight'); + $vocabularies[$key]->set('weight', $weight); $edit['vocabularies[' . $key . '][weight]'] = $weight; } // Saving the new weights via the interface. @@ -96,7 +96,7 @@ function testTaxonomyAdminChangingWeights() { // Check that the weights are saved in the database correctly. foreach ($vocabularies as $key => $vocabulary) { - $this->assertEqual($new_vocabularies[$key]->weight, $vocabularies[$key]->weight, 'The vocabulary weight was changed.'); + $this->assertEqual($new_vocabularies[$key]->get('weight'), $vocabularies[$key]->get('weight'), 'The vocabulary weight was changed.'); } } @@ -137,12 +137,12 @@ function testTaxonomyAdminDeletingVocabulary() { // Delete the vocabulary. $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id()); $this->clickLink(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->assertRaw(t('Are you sure you want to delete the vocabulary %name?', array('%name' => $vocabulary->label())), '[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.'); // Confirm deletion. $this->drupalPostForm(NULL, NULL, t('Delete')); - $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), 'Vocabulary deleted.'); + $this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->label())), 'Vocabulary deleted.'); $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache(); $this->assertFalse(entity_load('taxonomy_vocabulary', $vid), 'Vocabulary not found.'); } diff --git a/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php index dc8b6b1958bfd10780aa0c26ea0de49c04fba67e..e3d0ffe37435fe68e9f0783e9cb4fbdc7b61a442 100644 --- a/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -33,7 +33,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['name'] = array( '#type' => 'textfield', '#title' => $this->t('Name'), - '#default_value' => $vocabulary->name, + '#default_value' => $vocabulary->label(), '#maxlength' => 255, '#required' => TRUE, ); @@ -49,7 +49,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'textfield', '#title' => $this->t('Description'), - '#default_value' => $vocabulary->description, + '#default_value' => $vocabulary->getDescription(), ); // $form['langcode'] is not wrapped in an @@ -114,20 +114,20 @@ public function save(array $form, FormStateInterface $form_state) { $vocabulary = $this->entity; // Prevent leading and trailing spaces in vocabulary names. - $vocabulary->name = trim($vocabulary->name); + $vocabulary->set('name', trim($vocabulary->label())); $status = $vocabulary->save(); $edit_link = $this->entity->link($this->t('Edit')); switch ($status) { case SAVED_NEW: - drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->label()))); + $this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->label(), 'link' => $edit_link)); $form_state->setRedirectUrl($vocabulary->urlInfo('overview-form')); break; case SAVED_UPDATED: - drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->name))); - $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->name, 'link' => $edit_link)); + drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->label()))); + $this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->label(), 'link' => $edit_link)); $form_state->setRedirect('taxonomy.vocabulary_list'); break; } diff --git a/core/modules/taxonomy/src/VocabularyInterface.php b/core/modules/taxonomy/src/VocabularyInterface.php index 7eabb9c2523a3261cde8f8f23ccd426d4f5bb133..428e84a0db73e62874a53714225bf22389544cf1 100644 --- a/core/modules/taxonomy/src/VocabularyInterface.php +++ b/core/modules/taxonomy/src/VocabularyInterface.php @@ -15,4 +15,33 @@ */ interface VocabularyInterface extends ConfigEntityInterface, ThirdPartySettingsInterface { + /** + * Returns the vocabulary hierarchy. + * + * @return integer + * The vocabulary hierarchy. + */ + public function getHierarchy(); + + /** + * Sets the vocabulary hierarchy. + * + * @param integer $hierarchy + * The hierarchy type of vocabulary. + * Possible values: + * - TAXONOMY_HIERARCHY_DISABLED: No parents. + * - TAXONOMY_HIERARCHY_SINGLE: Single parent. + * - TAXONOMY_HIERARCHY_MULTIPLE: Multiple parents. + * + * @return $this + */ + public function setHierarchy($hierarchy); + + /** + * Returns the vocabulary description. + * + * @return string + * The vocabulary description. + */ + public function getDescription(); } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 4c8ee292d93e8649301c8684a95dfa89da9dc0b3..95f6a6bcc3923d3221ccbc6d4e91b7569a2bbe88 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -83,13 +83,13 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) { case 'entity.taxonomy_vocabulary.overview_form': $vocabulary = $route_match->getParameter('taxonomy_vocabulary'); - switch ($vocabulary->hierarchy) { + switch ($vocabulary->getHierarchy()) { 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' => Unicode::ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '

'; + 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' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '

'; case TAXONOMY_HIERARCHY_SINGLE: - return '

' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', array('%capital_name' => Unicode::ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '

'; + return '

' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '

'; case TAXONOMY_HIERARCHY_MULTIPLE: - return '

' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->name))) . '

'; + return '

' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()))) . '

'; } } } @@ -238,8 +238,8 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c $hierarchy = TAXONOMY_HIERARCHY_SINGLE; } } - if ($hierarchy != $vocabulary->hierarchy) { - $vocabulary->hierarchy = $hierarchy; + if ($hierarchy != $vocabulary->getHierarchy()) { + $vocabulary->setHierarchy($hierarchy); $vocabulary->save(); } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index aa1505c59b2d5ddd8768d3a63fdb0ad561b40904..5c9403b06a80f083057cc553b3b0e28a7307a325 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -128,7 +128,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = case 'vocabulary': $vocabulary = entity_load('taxonomy_vocabulary', $term->bundle()); - $replacements[$original] = String::checkPlain($vocabulary->name); + $replacements[$original] = String::checkPlain($vocabulary->label()); break; case 'parent': @@ -161,11 +161,11 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = break; case 'name': - $replacements[$original] = $sanitize ? String::checkPlain($vocabulary->name) : $vocabulary->name; + $replacements[$original] = $sanitize ? String::checkPlain($vocabulary->label()) : $vocabulary->label(); break; case 'description': - $replacements[$original] = $sanitize ? Xss::filter($vocabulary->description) : $vocabulary->description; + $replacements[$original] = $sanitize ? Xss::filter($vocabulary->getDescription()) : $vocabulary->getDescription(); break; case 'term-count': diff --git a/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php b/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php index 270da718bddd1ca4f497d30022743c9320e4be68..675aa82d68ea6f85d5a683d11999544d0d2d0e18 100644 --- a/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php +++ b/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php @@ -67,7 +67,7 @@ protected function setUp() { public function testTaxonomyAutocomplete() { $this->user = $this->drupalCreateUser(array('access content')); $this->drupalLogin($this->user); - $base_autocomplete_path = 'taxonomy/autocomplete_vid/' . $this->vocabulary->vid; + $base_autocomplete_path = 'taxonomy/autocomplete_vid/' . $this->vocabulary->id(); // Test that no terms returns an empty array. $this->assertIdentical(array(), $this->drupalGetJSON($base_autocomplete_path));