summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-01-05 13:18:58 +0000
committerAlex Pott2015-01-05 13:18:58 +0000
commitabe83bfb19bfa11c82a8728139f9a5467fe60f0b (patch)
treeb32fcaeef4d410d3d8ab42cba00e127940dd8a04
parent3d57852da0c7218a5b04759f1552d8f57ee2b222 (diff)
Issue #2030669 by daffie, Sharique, rpayanm, Mile23, undertext, marcingy, martin107, filijonka, amitgoyal, msupko: Expand Vocabulary with methods
-rw-r--r--core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php8
-rw-r--r--core/modules/forum/src/Tests/ForumTest.php10
-rw-r--r--core/modules/migrate_drupal/src/Tests/d6/MigrateTaxonomyVocabularyTest.php16
-rw-r--r--core/modules/system/src/Tests/Entity/EntityCrudHookTest.php2
-rw-r--r--core/modules/system/system.api.php4
-rw-r--r--core/modules/taxonomy/src/Entity/Vocabulary.php32
-rw-r--r--core/modules/taxonomy/src/Form/OverviewTerms.php8
-rw-r--r--core/modules/taxonomy/src/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php2
-rw-r--r--core/modules/taxonomy/src/TaxonomyPermissions.php9
-rw-r--r--core/modules/taxonomy/src/TermForm.php6
-rw-r--r--core/modules/taxonomy/src/Tests/EfqTest.php2
-rw-r--r--core/modules/taxonomy/src/Tests/TermFieldTest.php2
-rw-r--r--core/modules/taxonomy/src/Tests/TermTest.php2
-rw-r--r--core/modules/taxonomy/src/Tests/TokenReplaceTest.php14
-rw-r--r--core/modules/taxonomy/src/Tests/VocabularyCrudTest.php20
-rw-r--r--core/modules/taxonomy/src/Tests/VocabularyUiTest.php10
-rw-r--r--core/modules/taxonomy/src/VocabularyForm.php14
-rw-r--r--core/modules/taxonomy/src/VocabularyInterface.php29
-rw-r--r--core/modules/taxonomy/taxonomy.module12
-rw-r--r--core/modules/taxonomy/taxonomy.tokens.inc6
-rw-r--r--core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php2
21 files changed, 132 insertions, 78 deletions
diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php
index c7fc90b..0898f48 100644
--- a/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php
+++ b/core/modules/entity_reference/src/Tests/EntityReferenceItemTest.php
@@ -161,17 +161,17 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$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 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$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 dbd72b8..aa95fdd 100644
--- a/core/modules/forum/src/Tests/ForumTest.php
+++ b/core/modules/forum/src/Tests/ForumTest.php
@@ -340,16 +340,16 @@ class ForumTest extends WebTestBase {
$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 607d4d7..0995ecf 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 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupalTestBase {
$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 3e040a4..c659194 100644
--- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php
@@ -450,7 +450,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
));
$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 aeb0cb7..0ca834a 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 e650551..6d83fa7 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}
@@ -97,6 +112,13 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
/**
* {@inheritdoc}
*/
+ public function getDescription() {
+ return $this->description;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php
index e4c5504..9e7e391 100644
--- a/core/modules/taxonomy/src/Form/OverviewTerms.php
+++ b/core/modules/taxonomy/src/Form/OverviewTerms.php
@@ -227,7 +227,7 @@ class OverviewTerms extends FormBase {
'#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 @@ class OverviewTerms extends FormBase {
'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 @@ class OverviewTerms extends FormBase {
}
// 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 75051c9..9a6a268 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 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements OptionsPr
$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 8179919..6b7b841 100644
--- a/core/modules/taxonomy/src/TaxonomyPermissions.php
+++ b/core/modules/taxonomy/src/TaxonomyPermissions.php
@@ -14,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides dynamic permissions of the taxonomy module.
+ *
+ * @see taxonomy.permissions.yml
*/
class TaxonomyPermissions implements ContainerInjectionInterface {
@@ -44,21 +46,22 @@ class TaxonomyPermissions implements ContainerInjectionInterface {
}
/**
- * 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 9d3c2cf..daa2868 100644
--- a/core/modules/taxonomy/src/TermForm.php
+++ b/core/modules/taxonomy/src/TermForm.php
@@ -30,7 +30,7 @@ class TermForm extends ContentEntityForm {
$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 @@ class TermForm extends ContentEntityForm {
}
// 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 ec184b3..65a66c4 100644
--- a/core/modules/taxonomy/src/Tests/EfqTest.php
+++ b/core/modules/taxonomy/src/Tests/EfqTest.php
@@ -55,7 +55,7 @@ class EfqTest extends TaxonomyTestBase {
->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 50d23e8..3c14410 100644
--- a/core/modules/taxonomy/src/Tests/TermFieldTest.php
+++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php
@@ -166,7 +166,7 @@ class TermFieldTest extends TaxonomyTestBase {
$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 8fb4b67..94557b4 100644
--- a/core/modules/taxonomy/src/Tests/TermTest.php
+++ b/core/modules/taxonomy/src/Tests/TermTest.php
@@ -72,7 +72,7 @@ class TermTest extends TaxonomyTestBase {
// 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 f25591b..6f9ca29 100644
--- a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php
+++ b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php
@@ -88,7 +88,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
$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 @@ class TokenReplaceTest extends TaxonomyTestBase {
$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 @@ class TokenReplaceTest extends TaxonomyTestBase {
$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 @@ class TokenReplaceTest extends TaxonomyTestBase {
// 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 @@ class TokenReplaceTest extends TaxonomyTestBase {
}
// 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 d5aaa56..37ec181 100644
--- a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php
+++ b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php
@@ -70,17 +70,17 @@ class VocabularyCrudTest extends TaxonomyTestBase {
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 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// 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 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// 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 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// 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 d9e305c..5bd84de 100644
--- a/core/modules/taxonomy/src/Tests/VocabularyUiTest.php
+++ b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php
@@ -83,8 +83,8 @@ class VocabularyUiTest extends TaxonomyTestBase {
$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 @@ class VocabularyUiTest extends TaxonomyTestBase {
// 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 @@ class VocabularyUiTest extends TaxonomyTestBase {
// 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 dc8b6b1..e3d0ffe 100644
--- a/core/modules/taxonomy/src/VocabularyForm.php
+++ b/core/modules/taxonomy/src/VocabularyForm.php
@@ -33,7 +33,7 @@ class VocabularyForm extends EntityForm {
$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 @@ class VocabularyForm extends EntityForm {
$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 @@ class VocabularyForm extends EntityForm {
$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 7eabb9c..428e84a 100644
--- a/core/modules/taxonomy/src/VocabularyInterface.php
+++ b/core/modules/taxonomy/src/VocabularyInterface.php
@@ -15,4 +15,33 @@ use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
*/
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 4c8ee29..95f6a6b 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 '<p>' . 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)) . '</p>';
+ return '<p>' . 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())) . '</p>';
case TAXONOMY_HIERARCHY_SINGLE:
- return '<p>' . 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)) . '</p>';
+ return '<p>' . 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())) . '</p>';
case TAXONOMY_HIERARCHY_MULTIPLE:
- return '<p>' . 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))) . '</p>';
+ return '<p>' . 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()))) . '</p>';
}
}
}
@@ -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 aa1505c..5c9403b 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 270da71..675aa82 100644
--- a/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php
+++ b/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php
@@ -67,7 +67,7 @@ class ViewsTaxonomyAutocompleteTest extends ViewTestBase {
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));