Commit abe83bfb authored by alexpott's avatar alexpott

Issue #2030669 by daffie, Sharique, rpayanm, Mile23, undertext, marcingy,...

Issue #2030669 by daffie, Sharique, rpayanm, Mile23, undertext, marcingy, martin107, filijonka, amitgoyal, msupko: Expand Vocabulary with methods
parent 3d57852d
......@@ -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();
......
......@@ -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');
}
/**
......
......@@ -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);
}
}
......@@ -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(
......
......@@ -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(),
);
}
......
......@@ -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}
*/
......
......@@ -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.'));
......
......@@ -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();
......
......@@ -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()]),
],
];
}
......
......@@ -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();
}
......
......@@ -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',
......
......@@ -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.
......
......@@ -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();
......
......@@ -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));
......
......@@ -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.
......
......@@ -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.');
}
......
......@@ -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;
}
......
......@@ -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();
}
......@@ -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();
}
......
......@@ -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':
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment