Issue #2016701 by Berdir, ceng, alarcombe, daffie, rhm50: Expand TermInterface to provide methods.

8.0.x
Alex Pott 2014-03-17 10:11:38 +00:00
parent aed35d3a1f
commit a8a8b2cbcc
48 changed files with 338 additions and 257 deletions

View File

@ -154,7 +154,7 @@ class EditAutocompleteTermTest extends WebTestBase {
'form_id' => 'edit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
$this->field_name => implode(', ', array($this->term1->label(), 'new term', $this->term2->label())),
$this->field_name => implode(', ', array($this->term1->getName(), 'new term', $this->term2->getName())),
'op' => t('Save'),
);
@ -163,8 +163,8 @@ class EditAutocompleteTermTest extends WebTestBase {
$this->assertResponse(200);
$ajax_commands = drupal_json_decode($response);
$this->drupalSetContent($ajax_commands[0]['data']);
$this->assertLink($this->term1->label());
$this->assertLink($this->term2->label());
$this->assertLink($this->term1->getName());
$this->assertLink($this->term2->getName());
$this->assertText('new term');
$this->assertNoLink('new term');
@ -179,7 +179,7 @@ class EditAutocompleteTermTest extends WebTestBase {
// taxonomy terms, including the one that has just been newly created and
// which is not yet stored.
$this->drupalSetContent($ajax_commands[0]['data']);
$this->assertFieldByName($this->field_name, implode(', ', array($this->term1->label(), 'new term', $this->term2->label())));
$this->assertFieldByName($this->field_name, implode(', ', array($this->term1->getName(), 'new term', $this->term2->label())));
// Save the entity.
$post = array('nocssjs' => 'true');
@ -189,8 +189,8 @@ class EditAutocompleteTermTest extends WebTestBase {
// The full node display should now link to all entities, with the new
// one created in the database as well.
$this->drupalGet('node/' . $this->node->id());
$this->assertLink($this->term1->label());
$this->assertLink($this->term2->label());
$this->assertLink($this->term1->getName());
$this->assertLink($this->term2->getName());
$this->assertLink('new term');
}
}

View File

@ -90,17 +90,17 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$this->assertTrue($entity->field_test_taxonomy_term instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy_term[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy_term->target_id, $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->name->value, $this->term->name->value);
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName());
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid());
// Change the name of the term via the reference.
$new_name = $this->randomName();
$entity->field_test_taxonomy_term->entity->name = $new_name;
$entity->field_test_taxonomy_term->entity->setName($new_name);
$entity->field_test_taxonomy_term->entity->save();
// Verify it is the correct name.
$term = entity_load('taxonomy_term', $tid);
$this->assertEqual($term->name->value, $new_name);
$this->assertEqual($term->getName(), $new_name);
// Make sure the computed term reflects updates to the term id.
$term2 = entity_create('taxonomy_term', array(
@ -112,7 +112,7 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$entity->field_test_taxonomy_term->target_id = $term2->id();
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $term2->id());
$this->assertEqual($entity->field_test_taxonomy_term->entity->name->value, $term2->name->value);
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $term2->getName());
// Delete terms so we have nothing to reference and try again
$term->delete();
@ -146,8 +146,8 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$entity->field_test_taxonomy_vocabulary->entity->name = $new_name;
$entity->field_test_taxonomy_vocabulary->entity->save();
// Verify it is the correct name.
$term = entity_load('taxonomy_vocabulary', $referenced_entity_id);
$this->assertEqual($term->name, $new_name);
$vocabulary = entity_load('taxonomy_vocabulary', $referenced_entity_id);
$this->assertEqual($vocabulary->name, $new_name);
// Make sure the computed term reflects updates to the term id.
$vocabulary2 = entity_create('taxonomy_vocabulary', array(

View File

@ -237,7 +237,7 @@ function forum_node_validate(EntityInterface $node, $form, &$form_state) {
->count()
->execute();
if ($used && !empty($term->forum_container->value)) {
form_set_error('taxonomy_forums', $form_state, t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->label())));
form_set_error('taxonomy_forums', $form_state, t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->getName())));
}
}
}

View File

@ -145,7 +145,7 @@ class ForumController extends ControllerBase {
);
$build['#attached']['library'][] = 'forum/forum.index';
if (empty($term->forum_container->value)) {
$build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->label());
$build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName());
}
return $build;

View File

@ -81,14 +81,14 @@ class ForumFormController extends TermFormController {
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->label(), '@type' => $this->forumFormType)));
watchdog('forum', 'Created new @type %term.', array('%term' => $term->label(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
drupal_set_message($this->t('Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
watchdog('forum', 'Created new @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
$form_state['values']['tid'] = $term->id();
break;
case SAVED_UPDATED:
drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->label(), '@type' => $this->forumFormType)));
watchdog('taxonomy', 'Updated @type %term.', array('%term' => $term->label(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
drupal_set_message($this->t('The @type %term has been updated.', array('%term' => $term->getName(), '@type' => $this->forumFormType)));
watchdog('taxonomy', 'Updated @type %term.', array('%term' => $term->getName(), '@type' => $this->forumFormType), WATCHDOG_NOTICE, l($this->t('edit'), 'admin/structure/forum/edit/' . $this->urlStub . '/' . $term->id()));
// Clear the page and block caches to avoid stale data.
Cache::invalidateTags(array('content' => TRUE));
break;
@ -149,7 +149,7 @@ class ForumFormController extends TermFormController {
if ($tree) {
foreach ($tree as $term) {
if (!in_array($term->id(), $exclude)) {
$options[$term->id()] = str_repeat(' -- ', $term->depth) . $term->label();
$options[$term->id()] = str_repeat(' -- ', $term->depth) . $term->getName();
}
}
}

View File

@ -118,7 +118,7 @@ class PagePreviewTest extends NodeTestBase {
$edit = array();
$edit[$title_key] = $this->randomName(8);
$edit[$body_key] = $this->randomName(16);
$edit[$term_key] = $this->term->label();
$edit[$term_key] = $this->term->getName();
$this->drupalPostForm('node/add/page', $edit, t('Preview'));
// Check that the preview is displaying the title, body and term.
@ -150,12 +150,12 @@ class PagePreviewTest extends NodeTestBase {
$edit = array();
$newterm1 = $this->randomName(8);
$newterm2 = $this->randomName(8);
$edit[$term_key] = $this->term->label() . ', ' . $newterm1 . ', ' . $newterm2;
$edit[$term_key] = $this->term->getName() . ', ' . $newterm1 . ', ' . $newterm2;
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
$this->assertRaw('>' . $newterm1 . '<', 'First new term displayed.');
$this->assertRaw('>' . $newterm2 . '<', 'Second new term displayed.');
// The first term should be displayed as link, the others not.
$this->assertLink($this->term->label());
$this->assertLink($this->term->getName());
$this->assertNoLink($newterm1);
$this->assertNoLink($newterm2);
@ -170,7 +170,7 @@ class PagePreviewTest extends NodeTestBase {
$this->assertRaw('>' . $newterm1 . '<', 'First existing term displayed.');
$this->assertRaw('>' . $newterm2 . '<', 'Second existing term displayed.');
$this->assertRaw('>' . $newterm3 . '<', 'Third new term displayed.');
$this->assertNoText($this->term->label());
$this->assertNoText($this->term->getName());
$this->assertLink($newterm1);
$this->assertLink($newterm2);
$this->assertNoLink($newterm3);

View File

@ -103,7 +103,7 @@ class TaxonomyTermReferenceRdfaTest extends FieldRdfaTestBase {
* Tests the plain formatter.
*/
public function testPlainFormatter() {
$this->assertFormatterRdfa('taxonomy_term_reference_plain', 'http://schema.org/about', $this->term->label(), 'literal');
$this->assertFormatterRdfa('taxonomy_term_reference_plain', 'http://schema.org/about', $this->term->getName(), 'literal');
}
/**

View File

@ -327,7 +327,7 @@ class StandardProfileTest extends WebTestBase {
// Term name.
$expected_value = array(
'type' => 'literal',
'value' => $this->term->get('name')->value,
'value' => $this->term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($this->termUri, 'http://schema.org/name', $expected_value), "Term name was found (schema:name) on term page.");
@ -414,7 +414,7 @@ class StandardProfileTest extends WebTestBase {
// Tag name.
$expected_value = array(
'type' => 'literal',
'value' => $this->term->get('name')->value,
'value' => $this->term->getName(),
'lang' => 'en',
);
// @todo enable with https://drupal.org/node/2072791

View File

@ -66,14 +66,14 @@ class TaxonomyAttributesTest extends TaxonomyTestBase {
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->label(),
'value' => $term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->label(),
'value' => $term->getName(),
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');

View File

@ -128,7 +128,7 @@ class TaxonomyTermFieldAttributesTest extends TaxonomyTestBase {
//$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).');
$expected_value = array(
'type' => 'literal',
'value' => $term1->label(),
'value' => $term1->getName(),
);
//$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).');
// Term 2.
@ -139,7 +139,7 @@ class TaxonomyTermFieldAttributesTest extends TaxonomyTestBase {
//$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).');
$expected_value = array(
'type' => 'literal',
'value' => $term2->label(),
'value' => $term2->getName(),
);
//$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).');
}

View File

@ -536,7 +536,7 @@ function rdf_preprocess_taxonomy_term(&$variables) {
'about' => url('taxonomy/term/' . $term->id()),
'typeof' => $bundle_mapping['types'],
'property' => $name_field_mapping['properties'],
'content' => $term->label(),
'content' => $term->getName(),
),
);
drupal_add_html_head($term_label_meta, 'rdf_term_label');

View File

@ -385,7 +385,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
));
$_SESSION['entity_crud_hook_test'] = array();
$term->name = 'New name';
$term->setName('New name');
$term->save();
$this->assertHookMessageOrder(array(

View File

@ -270,7 +270,7 @@ class BreadcrumbTest extends MenuTestBase {
$tree += array(
$link['link_path'] => $link['link_title'],
);
$this->assertBreadcrumb($link['link_path'], $trail, $term->label(), $tree);
$this->assertBreadcrumb($link['link_path'], $trail, $term->getName(), $tree);
$this->assertRaw(check_plain($parent->getTitle()), 'Tagged node found.');
// Additionally make sure that this link appears only once; i.e., the
@ -286,7 +286,7 @@ class BreadcrumbTest extends MenuTestBase {
// Next iteration should expect this tag as parent link.
// Note: Term name, not link name, due to taxonomy_term_page().
$trail += array(
$link['link_path'] => $term->label(),
$link['link_path'] => $term->getName(),
);
}

View File

@ -67,7 +67,7 @@ class TaxonomyController extends ControllerBase {
* The term label.
*/
public function termTitle(TermInterface $taxonomy_term) {
return Xss::filter($taxonomy_term->label());
return Xss::filter($taxonomy_term->getName());
}
/**

View File

@ -196,8 +196,8 @@ class TermAutocompleteController implements ContainerInjectionInterface {
$terms = $this->termStorage->loadMultiple(array_keys($tids));
foreach ($terms as $term) {
// Term names containing commas or quotes must be wrapped in quotes.
$name = Tags::encode($term->label());
$matches[] = array('value' => $prefix . $name, 'label' => String::checkPlain($term->label()));
$name = Tags::encode($term->getName());
$matches[] = array('value' => $prefix . $name, 'label' => String::checkPlain($term->getName()));
}
return $matches;
}

View File

@ -55,93 +55,12 @@ use Drupal\taxonomy\TermInterface;
class Term extends ContentEntityBase implements TermInterface {
/**
* The taxonomy term ID.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $tid;
/**
* The term UUID.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $uuid;
/**
* The taxonomy vocabulary ID this term belongs to.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $vid;
/**
* Name of the term.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $name;
/**
* Description of the term.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $description;
/**
* The text format name for the term's description.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $format;
/**
* The weight of this term.
*
* This property stores the weight of this term in relation to other terms of
* the same vocabulary.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $weight;
/**
* The parent term(s) for this term.
*
* This property is not loaded, but may be used to modify the term parents via
* Term::save().
*
* The property can be set to an array of term IDs. An entry of 0 means this
* term does not have any parents. When omitting this variable during an
* update, the existing hierarchy for the term remains unchanged.
*
* @var \Drupal\Core\Field\FieldItemListInterface
*/
public $parent;
/**
* Implements Drupal\Core\Entity\EntityInterface::id().
* {@inheritdoc}
*/
public function id() {
return $this->get('tid')->value;
}
/**
* {@inheritdoc}
*/
protected function init() {
parent::init();
unset($this->tid);
unset($this->uuid);
unset($this->vid);
unset($this->name);
unset($this->weight);
unset($this->format);
unset($this->description);
unset($this->parent);
}
/**
* {@inheritdoc}
*/
@ -244,7 +163,74 @@ class Term extends ContentEntityBase implements TermInterface {
* {@inheritdoc}
*/
public function getChangedTime() {
return $this->changed->value;
return $this->get('changed')->value;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->get('description')->value;
}
/**
* {@inheritdoc}
*/
public function setDescription($description) {
$this->set('description', $description);
return $this;
}
/**
* {@inheritdoc}
*/
public function getFormat() {
return $this->get('description')->format;
}
/**
* {@inheritdoc}
*/
public function setFormat($format) {
$this->get('description')->format = $format;
return $this;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->label();
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->get('weight')->value;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->set('weight', $weight);
return $this;
}
/**
* {@inheritdoc}
*/
public function getVocabularyId() {
return $this->get('vid')->target_id;
}
}

View File

@ -212,7 +212,7 @@ class OverviewTerms extends FormBase {
$form['terms'][$key]['term'] = array(
'#prefix' => !empty($indentation) ? drupal_render($indentation) : '',
'#type' => 'link',
'#title' => $term->label(),
'#title' => $term->getName(),
'#route_name' => $uri['route_name'],
'#route_parameters' => $uri['route_parameters'],
);
@ -249,7 +249,7 @@ class OverviewTerms extends FormBase {
'#delta' => $delta,
'#title' => $this->t('Weight for added term'),
'#title_display' => 'invisible',
'#default_value' => $term->weight->value,
'#default_value' => $term->getWeight(),
'#attributes' => array(
'class' => array('term-weight'),
),
@ -387,8 +387,8 @@ class OverviewTerms extends FormBase {
$weight = 0;
$term = $tree[0];
while ($term->id() != $form['#first_tid']) {
if ($term->parents[0] == 0 && $term->weight->value != $weight) {
$term->weight->value = $weight;
if ($term->parents[0] == 0 && $term->getWeight() != $weight) {
$term->setWeight($weight);
$changed_terms[$term->id()] = $term;
}
$weight++;
@ -402,15 +402,15 @@ class OverviewTerms extends FormBase {
if (isset($form['terms'][$tid]['#term'])) {
$term = $form['terms'][$tid]['#term'];
// Give terms at the root level a weight in sequence with terms on previous pages.
if ($values['term']['parent'] == 0 && $term->weight->value != $weight) {
$term->weight->value = $weight;
if ($values['term']['parent'] == 0 && $term->getWeight() != $weight) {
$term->setWeight($weight);
$changed_terms[$term->id()] = $term;
}
// Terms not at the root level can safely start from 0 because they're all on this page.
elseif ($values['term']['parent'] > 0) {
$level_weights[$values['term']['parent']] = isset($level_weights[$values['term']['parent']]) ? $level_weights[$values['term']['parent']] + 1 : 0;
if ($level_weights[$values['term']['parent']] != $term->weight->value) {
$term->weight->value = $level_weights[$values['term']['parent']];
if ($level_weights[$values['term']['parent']] != $term->getWeight()) {
$term->setWeight($level_weights[$values['term']['parent']]);
$changed_terms[$term->id()] = $term;
}
}
@ -427,9 +427,9 @@ class OverviewTerms extends FormBase {
// Build a list of all terms that need to be updated on following pages.
for ($weight; $weight < count($tree); $weight++) {
$term = $tree[$weight];
if ($term->parents[0] == 0 && $term->weight->value != $weight) {
if ($term->parents[0] == 0 && $term->getWeight() != $weight) {
$term->parent->value = $term->parents[0];
$term->weight->value = $weight;
$term->setWeight($weight);
$changed_terms[$term->id()] = $term;
}
$hierarchy = $term->parents[0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;

View File

@ -28,7 +28,7 @@ class TermDeleteForm extends ContentEntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the term %title?', array('%title' => $this->entity->label()));
return $this->t('Are you sure you want to delete the term %title?', array('%title' => $this->entity->getName()));
}
/**
@ -65,8 +65,8 @@ class TermDeleteForm extends ContentEntityConfirmFormBase {
// @todo Move to storage controller http://drupal.org/node/1988712
taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $this->entity->id()));
drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->label())));
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE);
drupal_set_message($this->t('Deleted term %name.', array('%name' => $this->entity->getName())));
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->entity->getName()), WATCHDOG_NOTICE);
$form_state['redirect_route']['route_name'] = 'taxonomy.vocabulary_list';
Cache::invalidateTags(array('content' => TRUE));
}

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Component\Utility\String;
/**
* Plugin implementation of the 'taxonomy_term_reference_link' formatter.
@ -27,13 +28,12 @@ class LinkFormatter extends TaxonomyFormatterBase {
*/
public function viewElements(FieldItemListInterface $items) {
$elements = array();
// Terms without target_id do not exist yet, theme such terms as just their
// name.
foreach ($items as $delta => $item) {
if (!$item->target_id) {
$elements[$delta] = array(
'#markup' => check_plain($item->entity->label()),
'#markup' => String::checkPlain($item->entity->label()),
);
}
else {
@ -42,7 +42,7 @@ class LinkFormatter extends TaxonomyFormatterBase {
$uri = $term->urlInfo();
$elements[$delta] = array(
'#type' => 'link',
'#title' => $term->label(),
'#title' => $term->getName(),
'#route_name' => $uri['route_name'],
'#route_parameters' => $uri['route_parameters'],
'#options' => $uri['options'],

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Component\Utility\String;
/**
* Plugin implementation of the 'taxonomy_term_reference_plain' formatter.
@ -30,7 +31,7 @@ class PlainFormatter extends TaxonomyFormatterBase {
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#markup' => check_plain($item->entity->label()),
'#markup' => String::checkPlain($item->entity->label()),
);
}

View File

@ -77,7 +77,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements AllowedVa
if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) {
if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) {
foreach ($terms as $term) {
$options[$term->id()] = str_repeat('-', $term->depth) . $term->label();
$options[$term->id()] = str_repeat('-', $term->depth) . $term->getName();
}
}
}

View File

@ -66,7 +66,7 @@ class TermSelection extends SelectionBase {
if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) {
if ($terms = taxonomy_get_tree($vocabulary->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) {
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->label());
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . String::checkPlain($term->getName());
}
}
}

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\ManyToOne;
use Drupal\Component\Utility\String;
/**
* Allow taxonomy term ID(s) as argument.
@ -24,8 +25,8 @@ class IndexTid extends ManyToOne {
->fields('td', array('name'))
->condition('td.tid', $this->value)
->execute();
foreach ($result as $term) {
$titles[] = check_plain($term->name);
foreach ($result as $term_record) {
$titles[] = String::checkPlain($term_record->name);
}
return $titles;
}

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\Component\Utility\String;
/**
* Argument handler for taxonomy terms with depth.
@ -121,7 +122,7 @@ class IndexTidDepth extends ArgumentPluginBase {
function title() {
$term = entity_load('taxonomy_term', $this->argument);
if (!empty($term)) {
return check_plain($term->label());
return String::checkPlain($term->getName());
}
// TODO review text
return t('No name');

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\Numeric;
use Drupal\Component\Utility\String;
/**
* Argument handler for basic taxonomy tid.
@ -26,7 +27,7 @@ class Taxonomy extends Numeric {
if ($this->argument) {
$term = entity_load('taxonomy_term', $this->argument);
if (!empty($term)) {
return check_plain($term->label());
return String::checkPlain($term->getName());
}
}
// TODO review text

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\Numeric;
use Drupal\Component\Utility\String;
/**
* Argument handler to accept a vocabulary id.
@ -24,7 +25,7 @@ class VocabularyVid extends Numeric {
function title() {
$vocabulary = entity_load('taxonomy_vocabulary', $this->argument);
if ($vocabulary) {
return check_plain($vocabulary->label());
return String::checkPlain($vocabulary->label());
}
return t('No vocabulary');

View File

@ -10,6 +10,7 @@ namespace Drupal\taxonomy\Plugin\views\field;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\PrerenderList;
use Drupal\Component\Utility\String;
/**
* Field handler to display all taxonomy terms of a node.
@ -115,15 +116,15 @@ class TaxonomyIndexTid extends PrerenderList {
}
$result = $query->execute();
foreach ($result as $term) {
$this->items[$term->node_nid][$term->tid]['name'] = check_plain($term->name);
$this->items[$term->node_nid][$term->tid]['tid'] = $term->tid;
$this->items[$term->node_nid][$term->tid]['vocabulary_vid'] = $term->vid;
$this->items[$term->node_nid][$term->tid]['vocabulary'] = check_plain($vocabularies[$term->vid]->label());
foreach ($result as $term_record) {
$this->items[$term_record->node_nid][$term_record->tid]['name'] = String::checkPlain($term_record->name);
$this->items[$term_record->node_nid][$term_record->tid]['tid'] = $term_record->tid;
$this->items[$term_record->node_nid][$term_record->tid]['vocabulary_vid'] = $term_record->vid;
$this->items[$term_record->node_nid][$term_record->tid]['vocabulary'] = String::checkPlain($vocabularies[$term_record->vid]->label());
if (!empty($this->options['link_to_taxonomy'])) {
$this->items[$term->node_nid][$term->tid]['make_link'] = TRUE;
$this->items[$term->node_nid][$term->tid]['path'] = 'taxonomy/term/' . $term->tid;
$this->items[$term_record->node_nid][$term_record->tid]['make_link'] = TRUE;
$this->items[$term_record->node_nid][$term_record->tid]['path'] = 'taxonomy/term/' . $term_record->tid;
}
}
}

View File

@ -111,11 +111,11 @@ class TaxonomyIndexTid extends ManyToOne {
->fields('td')
->condition('td.tid', $this->value)
->execute();
foreach ($result as $term) {
foreach ($result as $term_record) {
if ($default) {
$default .= ', ';
}
$default .= $term->name;
$default .= $term_record->name;
}
}
@ -136,9 +136,9 @@ class TaxonomyIndexTid extends ManyToOne {
$options = array();
if ($tree) {
foreach ($tree as $term) {
foreach ($tree as $term_record) {
$choice = new \stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$choice->option = array($term_record->tid => str_repeat('-', $term_record->depth) . $term_record->name);
$options[] = $choice;
}
}
@ -155,8 +155,8 @@ class TaxonomyIndexTid extends ManyToOne {
$query->condition('td.vid', $vocabulary->id());
}
$result = $query->execute();
foreach ($result as $term) {
$options[$term->tid] = $term->name;
foreach ($result as $term_record) {
$options[$term_record->tid] = $term_record->name;
}
}
@ -316,9 +316,9 @@ class TaxonomyIndexTid extends ManyToOne {
$query->condition('td.vid', $this->options['vid']);
$query->addTag('term_access');
$result = $query->execute();
foreach ($result as $term) {
unset($missing[strtolower($term->name)]);
$tids[] = $term->tid;
foreach ($result as $term_record) {
unset($missing[strtolower($term_record->name)]);
$tids[] = $term_record->tid;
}
if ($missing && !empty($this->options['error_message'])) {
@ -357,8 +357,8 @@ class TaxonomyIndexTid extends ManyToOne {
->fields('td')
->condition('td.tid', $this->value)
->execute();
foreach ($result as $term) {
$this->value_options[$term->tid] = $term->name;
foreach ($result as $term_record) {
$this->value_options[$term_record->tid] = $term_record->name;
}
}
return parent::adminSummary();

View File

@ -35,7 +35,7 @@ class TermBreadcrumbBuilder extends BreadcrumbBuilderBase {
$breadcrumb = array();
while ($parents = taxonomy_term_load_parents($term->id())) {
$term = array_shift($parents);
$breadcrumb[] = $this->l($term->label(), 'taxonomy.term_page', array('taxonomy_term' => $term->id()));
$breadcrumb[] = $this->l($term->getName(), 'taxonomy.term_page', array('taxonomy_term' => $term->id()));
}
$breadcrumb[] = $this->l($this->t('Home'), '<front>');
$breadcrumb = array_reverse($breadcrumb);

View File

@ -64,7 +64,7 @@ class TermFormController extends ContentEntityFormController {
$form['name'] = array(
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#default_value' => $term->name->value,
'#default_value' => $term->getName(),
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -5,
@ -73,8 +73,8 @@ class TermFormController extends ContentEntityFormController {
$form['description'] = array(
'#type' => 'text_format',
'#title' => $this->t('Description'),
'#default_value' => $term->description->value,
'#format' => $term->description->format,
'#default_value' => $term->getDescription(),
'#format' => $term->getFormat(),
'#weight' => 0,
);
$language_configuration = $this->moduleHandler->moduleExists('language') ? language_get_default_configuration('taxonomy_term', $vocabulary->id()) : FALSE;
@ -112,6 +112,7 @@ class TermFormController extends ContentEntityFormController {
if (empty($parent)) {
$parent = array(0);
}
foreach ($tree as $item) {
if (!in_array($item->tid, $exclude)) {
$options[$item->tid] = str_repeat('-', $item->depth) . $item->name;
@ -131,7 +132,7 @@ class TermFormController extends ContentEntityFormController {
'#type' => 'textfield',
'#title' => $this->t('Weight'),
'#size' => 6,
'#default_value' => $term->weight->value,
'#default_value' => $term->getWeight(),
'#description' => $this->t('Terms are displayed in ascending order by weight.'),
'#required' => TRUE,
);
@ -172,13 +173,7 @@ class TermFormController extends ContentEntityFormController {
$term = parent::buildEntity($form, $form_state);
// Prevent leading and trailing spaces in term names.
$term->name->value = trim($term->name->value);
// Convert text_format field into values expected by
// \Drupal\Core\Entity\Entity::save() method.
$description = $form_state['values']['description'];
$term->description->value = $description['value'];
$term->description->format = $description['format'];
$term->setName(trim($term->getName()));
// Assign parents with proper delta values starting from 0.
$term->parent = array_keys($form_state['values']['parent']);
@ -194,12 +189,12 @@ class TermFormController extends ContentEntityFormController {
switch ($term->save()) {
case SAVED_NEW:
drupal_set_message($this->t('Created new term %term.', array('%term' => $term->label())));
watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l($this->t('edit'), 'taxonomy/term/' . $term->id() . '/edit'));
drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName())));
watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->getName()), WATCHDOG_NOTICE, l($this->t('edit'), 'taxonomy/term/' . $term->id() . '/edit'));
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated term %term.', array('%term' => $term->label())));
watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l($this->t('edit'), 'taxonomy/term/' . $term->id() . '/edit'));
drupal_set_message($this->t('Updated term %term.', array('%term' => $term->getName())));
watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->getName()), WATCHDOG_NOTICE, l($this->t('edit'), 'taxonomy/term/' . $term->id() . '/edit'));
// Clear the page and block caches to avoid stale data.
Cache::invalidateTags(array('content' => TRUE));
break;

View File

@ -15,4 +15,84 @@ use Drupal\Core\Entity\EntityChangedInterface;
*/
interface TermInterface extends ContentEntityInterface, EntityChangedInterface {
/**
* Gets the term's description.
*
* @return string
* The term description.
*/
public function getDescription();
/**
* Sets the term's description.
*
* @param string $description
* The term's description.
*
* @return $this
*/
public function setDescription($description);
/**
* Gets the text format name for the term's description.
*
* @return string
* The text format name.
*/
public function getFormat();
/**
* Sets the text format name for the term's description.
*
* @param string $format
* The term's decription text format.
*
* @return $this
*/
public function setFormat($format);
/**
* Gets the name of the term.
*
* @return string
* The name of the term.
*/
public function getName();
/**
* Sets the name of the term.
*
* @param int $name
* The term's name.
*
* @return $this
*/
public function setName($name);
/**
* Gets the weight of this term.
*
* @return int
* The weight of the term.
*/
public function getWeight();
/**
* Gets the weight of this term.
*
* @param int $weight
* The term's weight.
*
* @return $this
*/
public function setWeight($weight);
/**
* Get the taxonomy vocabulary id this term belongs to.
*
* @return int
* The id of the vocabulary.
*/
public function getVocabularyId();
}

View File

@ -27,7 +27,7 @@ class TermViewBuilder extends EntityViewBuilder {
// @todo Remove this when base fields are able to use formatters.
// https://drupal.org/node/2144919
$display = $displays[$entity->bundle()];
if (!empty($entity->description->value) && $display->getComponent('description')) {
if ($entity->getDescription() && $display->getComponent('description')) {
$entity->content['description'] = array(
'#markup' => $entity->description->processed,
'#prefix' => '<div class="taxonomy-term-description">',

View File

@ -63,7 +63,7 @@ class LoadMultipleTest extends TaxonomyTestBase {
// Create a single term and load it by name.
$term = $this->createTerm($vocabulary);
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->name->value));
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->getName()));
$this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
$loaded_term = reset($loaded_terms);
$this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');

View File

@ -102,7 +102,7 @@ class RssTest extends TaxonomyTestBase {
$this->drupalGet('rss.xml');
$test_element = array(
'key' => 'category',
'value' => $term1->name->value,
'value' => $term1->getName(),
'attributes' => array(
'domain' => url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE)),
),

View File

@ -84,7 +84,7 @@ class TaxonomyImageTest extends TaxonomyTestBase {
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name']));
$term = reset($terms);
$this->assertText(t('Created new term @name.', array('@name' => $term->label())));
$this->assertText(t('Created new term @name.', array('@name' => $term->getName())));
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(array('access content'));

View File

@ -25,6 +25,13 @@ class TaxonomyTermReferenceItemTest extends FieldUnitTestBase {
*/
public static $modules = array('taxonomy', 'options', 'text', 'filter');
/**
* The term entity.
*
* @var \Drupal\taxonomy\TermInterface
*/
protected $term;
public static function getInfo() {
return array(
'name' => 'Taxonomy reference field item',
@ -87,29 +94,29 @@ class TaxonomyTermReferenceItemTest extends FieldUnitTestBase {
$this->assertTrue($entity->field_test_taxonomy instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy->target_id, $this->term->id(), 'Field item contains the expected TID.');
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $this->term->name->value, 'Field item entity contains the expected name.');
$this->assertEqual($entity->field_test_taxonomy->entity->getName(), $this->term->getName(), 'Field item entity contains the expected name.');
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $tid, 'Field item entity contains the expected ID.');
$this->assertEqual($entity->field_test_taxonomy->entity->uuid(), $this->term->uuid(), 'Field item entity contains the expected UUID.');
// Change the name of the term via the reference.
$new_name = $this->randomName();
$entity->field_test_taxonomy->entity->name = $new_name;
$entity->field_test_taxonomy->entity->setName($new_name);
$entity->field_test_taxonomy->entity->save();
// Verify it is the correct name.
$term = entity_load('taxonomy_term', $tid);
$this->assertEqual($term->name->value, $new_name, 'The name of the term was changed.');
$this->assertEqual($term->getName(), $new_name, 'The name of the term was changed.');
// Make sure the computed term reflects updates to the term id.
$term2 = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $this->term->bundle(),
'vid' => $this->term->getVocabularyId(),
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$term2->save();
$entity->field_test_taxonomy->target_id = $term2->id();
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id(), 'Field item entity contains the new TID.');
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $term2->name->value, 'Field item entity contains the new name.');
$this->assertEqual($entity->field_test_taxonomy->entity->getName(), $term2->getName(), 'Field item entity contains the new name.');
}
}

View File

@ -105,8 +105,8 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase {
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->drupalSetContent(drupal_render($content));
$this->assertText($term1->label(), 'Term 1 name is displayed.');
$this->assertText($term2->label(), 'Term 2 name is displayed.');
$this->assertText($term1->getName(), 'Term 1 name is displayed.');
$this->assertText($term2->getName(), 'Term 2 name is displayed.');
// Delete vocabulary 2.
$this->vocabulary2->delete();
@ -118,8 +118,8 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase {
$this->drupalSetContent(drupal_render($content));
// Term 1 should still be displayed; term 2 should not be.
$this->assertText($term1->label(), 'Term 1 name is displayed.');
$this->assertNoText($term2->label(), 'Term 2 name is not displayed.');
$this->assertText($term1->getName(), 'Term 1 name is displayed.');
$this->assertNoText($term2->getName(), 'Term 2 name is not displayed.');
// Verify that field and instance settings are correct.
$field = field_info_field('entity_test', $this->field_name);

View File

@ -120,7 +120,7 @@ class TermFieldTest extends TaxonomyTestBase {
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->drupalSetContent(drupal_render($content));
$this->assertText($term->label(), 'Term label is displayed.');
$this->assertText($term->getName(), 'Term label is displayed.');
// Delete the vocabulary and verify that the widget is gone.
$this->vocabulary->delete();

View File

@ -215,6 +215,6 @@ class TermIndexTest extends TaxonomyTestBase {
// Verify that the page breadcrumbs include a link to the parent term.
$this->drupalGet('taxonomy/term/' . $term1->id());
$this->assertRaw(l($term2->label(), 'taxonomy/term/' . $term2->id()), 'Parent term link is displayed when viewing the node.');
$this->assertRaw(l($term2->getName(), 'taxonomy/term/' . $term2->id()), 'Parent term link is displayed when viewing the node.');
}
}

View File

@ -10,6 +10,7 @@ namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Component\Utility\String;
/**
* Tests for taxonomy term functions.
@ -122,25 +123,25 @@ class TermTest extends TaxonomyTestBase {
// Check that the term is displayed when the node is viewed.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->drupalGet('node/' . $node->id());
$this->assertText($term1->label(), 'Term is displayed when viewing the node.');
$this->assertText($term1->getName(), 'Term is displayed when viewing the node.');
$this->clickLink(t('Edit'));
$this->assertText($term1->label(), 'Term is displayed when editing the node.');
$this->assertText($term1->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, array(), t('Save'));
$this->assertText($term1->label(), 'Term is displayed after saving the node with no changes.');
$this->assertText($term1->getName(), 'Term is displayed after saving the node with no changes.');
// Edit the node with a different term.
$edit[$this->instance->getName() . '[]'] = $term2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->drupalGet('node/' . $node->id());
$this->assertText($term2->label(), 'Term is displayed when viewing the node.');
$this->assertText($term2->getName(), 'Term is displayed when viewing the node.');
// Preview the node.
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
$this->assertNoUniqueText($term2->label(), 'Term is displayed when previewing the node.');
$this->assertNoUniqueText($term2->getName(), 'Term is displayed when previewing the node.');
$this->drupalPostForm(NULL, NULL, t('Preview'));
$this->assertNoUniqueText($term2->label(), 'Term is displayed when previewing the node again.');
$this->assertNoUniqueText($term2->getName(), 'Term is displayed when previewing the node again.');
}
/**
@ -206,29 +207,29 @@ class TermTest extends TaxonomyTestBase {
// Delete term 2 from the term delete page.
$this->drupalPostForm('taxonomy/term/' . $term_objects['term2']->id() . '/delete', array(), t('Delete'));
$term_names = array($term_objects['term3']->label(), $term_objects['term4']->label());
$term_names = array($term_objects['term3']->getName(), $term_objects['term4']->getName());
// Get the node.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->drupalGet('node/' . $node->id());
foreach ($term_names as $term_name) {
$this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', array('%name' => $term_name, '%deleted1' => $term_objects['term1']->label(), '%deleted2' => $term_objects['term2']->label())));
$this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', array('%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName())));
}
$this->assertNoText($term_objects['term1']->label(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term1']->label())));
$this->assertNoText($term_objects['term2']->label(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term2']->label())));
$this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term1']->getName())));
$this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term2']->getName())));
// Test autocomplete on term 3, which contains a comma.
// The term will be quoted, and the " will be encoded in unicode (\u0022).
$input = substr($term_objects['term3']->label(), 0, 3);
$input = substr($term_objects['term3']->getName(), 0, 3);
$json = $this->drupalGet('taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input)));
$this->assertEqual($json, '[{"value":"\u0022' . $term_objects['term3']->label() . '\u0022","label":"' . $term_objects['term3']->label() . '"}]', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->label())));
$this->assertEqual($json, '[{"value":"\u0022' . $term_objects['term3']->getName() . '\u0022","label":"' . $term_objects['term3']->getName() . '"}]', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->getName())));
// Test autocomplete on term 4 - it is alphanumeric only, so no extra
// quoting.
$input = substr($term_objects['term4']->label(), 0, 3);
$input = substr($term_objects['term4']->getName(), 0, 3);
$this->drupalGet('taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input)));
$this->assertRaw('[{"value":"' . $term_objects['term4']->label() . '","label":"' . $term_objects['term4']->label() . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->label())));
$this->assertRaw('[{"value":"' . $term_objects['term4']->getName() . '","label":"' . $term_objects['term4']->getName() . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->getName())));
// Test taxonomy autocomplete with a nonexistent field.
$field_name = $this->randomName();
@ -245,15 +246,15 @@ class TermTest extends TaxonomyTestBase {
function testTermAutocompletion() {
// Add a term with a slash in the name.
$first_term = $this->createTerm($this->vocabulary);
$first_term->name = '10/16/2011';
$first_term->setName('10/16/2011');
$first_term->save();
// Add another term that differs after the slash character.
$second_term = $this->createTerm($this->vocabulary);
$second_term->name = '10/17/2011';
$second_term->setName('10/17/2011');
$second_term->save();
// Add another term that has both a comma and a slash character.
$third_term = $this->createTerm($this->vocabulary);
$third_term->name = 'term with, a comma and / a slash';
$third_term->setName('term with, a comma and / a slash');
$third_term->save();
// Try to autocomplete a term name that matches both terms.
@ -263,8 +264,8 @@ class TermTest extends TaxonomyTestBase {
// The result order is not guaranteed, so check each term separately.
$result = $this->drupalGet($path, array('query' => array('q' => $input)));
$data = drupal_json_decode($result);
$this->assertEqual($data[0]['label'], check_plain($first_term->label()), 'Autocomplete returned the first matching term');
$this->assertEqual($data[1]['label'], check_plain($second_term->label()), 'Autocomplete returned the second matching term');
$this->assertEqual($data[0]['label'], String::checkPlain($first_term->getName()), 'Autocomplete returned the first matching term');
$this->assertEqual($data[1]['label'], String::checkPlain($second_term->getName()), 'Autocomplete returned the second matching term');
// Try to autocomplete a term name that matches first term.
// We should only get the first term in a json encoded string.
@ -272,8 +273,8 @@ class TermTest extends TaxonomyTestBase {
$path = 'taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id();
$this->drupalGet($path, array('query' => array('q' => $input)));
$target = array(array(
'value' => check_plain($first_term->label()),
'label' => $first_term->label(),
'value' => String::checkPlain($first_term->getName()),
'label' => $first_term->getName(),
));
$this->assertRaw(Json::encode($target), 'Autocomplete returns only the expected matching term.');
@ -282,10 +283,10 @@ class TermTest extends TaxonomyTestBase {
$path = 'taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id();
$this->drupalGet($path, array('query' => array('q' => $input)));
// Term names containing commas or quotes must be wrapped in quotes.
$n = Tags::encode($third_term->label());
$n = Tags::encode($third_term->getName());
$target = array(array(
'value' => $n,
'label' => check_plain($third_term->label()),
'label' => String::checkPlain($third_term->getName()),
));
$this->assertRaw(Json::encode($target), 'Autocomplete returns a term containing a comma and a slash.');
}
@ -345,13 +346,14 @@ class TermTest extends TaxonomyTestBase {
// Did this page request display a 'term-listing-heading'?
$this->assertPattern('|class="taxonomy-term-description"|', 'Term page displayed the term description element.');
// Check that it does NOT show a description when description is blank.
$term->description->value = NULL;
$term->setDescription(NULL);
$term->save();
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.');
// Check that the description value is processed.
$term->description->value = $value = $this->randomName();
$value = $this->randomName();
$term->setDescription($value);
$term->save();
$this->assertEqual($term->description->processed, "<p>$value</p>\n");
@ -446,8 +448,8 @@ class TermTest extends TaxonomyTestBase {
$terms = taxonomy_term_load_multiple_by_name($edit['name']);
$term = reset($terms);
$this->assertNotNull($term, 'Term found in database.');
$this->assertEqual($edit['name'], $term->label(), 'Term name was successfully saved.');
$this->assertEqual($edit['description[value]'], $term->description->value, 'Term description was successfully saved.');
$this->assertEqual($edit['name'], $term->getName(), 'Term name was successfully saved.');
$this->assertEqual($edit['description[value]'], $term->getDescription(), 'Term description was successfully saved.');
// Check that the parent tid is still there. The other parent (<root>) is
// not added by taxonomy_term_load_parents().
$parents = taxonomy_term_load_parents($term->id());
@ -462,19 +464,19 @@ class TermTest extends TaxonomyTestBase {
$term = $this->createTerm($this->vocabulary);
// Load the term with the exact name.
$terms = taxonomy_term_load_multiple_by_name($term->label());
$terms = taxonomy_term_load_multiple_by_name($term->getName());
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name.');
// Load the term with space concatenated.
$terms = taxonomy_term_load_multiple_by_name(' ' . $term->label() . ' ');
$terms = taxonomy_term_load_multiple_by_name(' ' . $term->getName() . ' ');
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with extra whitespace.');
// Load the term with name uppercased.
$terms = taxonomy_term_load_multiple_by_name(strtoupper($term->label()));
$terms = taxonomy_term_load_multiple_by_name(strtoupper($term->getName()));
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with uppercased name.');
// Load the term with name lowercased.
$terms = taxonomy_term_load_multiple_by_name(strtolower($term->label()));
$terms = taxonomy_term_load_multiple_by_name(strtolower($term->getName()));
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded with lowercased name.');
// Try to load an invalid term name.
@ -482,23 +484,23 @@ class TermTest extends TaxonomyTestBase {
$this->assertFalse($terms, 'No term loaded with an invalid name.');
// Try to load the term using a substring of the name.
$terms = taxonomy_term_load_multiple_by_name(drupal_substr($term->label(), 2), 'No term loaded with a substring of the name.');
$terms = taxonomy_term_load_multiple_by_name(drupal_substr($term->getName(), 2), 'No term loaded with a substring of the name.');
$this->assertFalse($terms);
// Create a new term in a different vocabulary with the same name.
$new_vocabulary = $this->createVocabulary();
$new_term = entity_create('taxonomy_term', array(
'name' => $term->label(),
'name' => $term->getName(),
'vid' => $new_vocabulary->id(),
));
$new_term->save();
// Load multiple terms with the same name.
$terms = taxonomy_term_load_multiple_by_name($term->label());
$terms = taxonomy_term_load_multiple_by_name($term->getName());
$this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.');
// Load single term when restricted to one vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term->label(), $this->vocabulary->id());
$terms = taxonomy_term_load_multiple_by_name($term->getName(), $this->vocabulary->id());
$this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.');
$this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name and vocabulary machine name.');
@ -507,11 +509,11 @@ class TermTest extends TaxonomyTestBase {
// Try to load a term by name that doesn't exist in this vocabulary but
// exists in another vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term2->label(), $new_vocabulary->id());
$terms = taxonomy_term_load_multiple_by_name($term2->getName(), $new_vocabulary->id());
$this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.');
// Try to load terms filtering by a non-existing vocabulary.
$terms = taxonomy_term_load_multiple_by_name($term2->label(), 'non_existing_vocabulary');
$terms = taxonomy_term_load_multiple_by_name($term2->getName(), 'non_existing_vocabulary');
$this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
}
@ -532,15 +534,15 @@ class TermTest extends TaxonomyTestBase {
$edit = array();
$edit['title[0][value]'] = $this->randomName(8);
$edit['body[0][value]'] = $this->randomName(16);
$edit[$this->instance->getName()] = $term->label();
$edit[$this->instance->getName()] = $term->getName();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
// Check that the term is displayed when editing and saving the node with no
// changes.
$this->clickLink(t('Edit'));
$this->assertRaw($term->label(), 'Term is displayed when editing the node.');
$this->assertRaw($term->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, array(), t('Save'));
$this->assertRaw($term->label(), 'Term is displayed after saving the node with no changes.');
$this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.');
}
}

View File

@ -9,6 +9,7 @@ namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\Language;
use Drupal\Component\Utility\String;
/**
* Test taxonomy token replacement in strings.
@ -87,12 +88,12 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Generate and test sanitized tokens for term1.
$tests = array();
$tests['[term:tid]'] = $term1->id();
$tests['[term:name]'] = check_plain($term1->name->value);
$tests['[term:name]'] = String::checkPlain($term1->getName());
$tests['[term:description]'] = $term1->description->processed;
$tests['[term:url]'] = url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE));
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
$tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name);
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->id));
@ -102,14 +103,14 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Generate and test sanitized tokens for term2.
$tests = array();
$tests['[term:tid]'] = $term2->id();
$tests['[term:name]'] = check_plain($term2->name->value);
$tests['[term:name]'] = String::checkPlain($term2->getName());
$tests['[term:description]'] = $term2->description->processed;
$tests['[term:url]'] = url('taxonomy/term/' . $term2->id(), array('absolute' => TRUE));
$tests['[term:node-count]'] = 1;
$tests['[term:parent:name]'] = check_plain($term1->name->value);
$tests['[term:parent:name]'] = String::checkPlain($term1->getName());
$tests['[term:parent:url]'] = url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE));
$tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
$tests['[term:vocabulary:name]'] = check_plain($this->vocabulary->name);
$tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name);
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
@ -120,9 +121,9 @@ class TokenReplaceTest extends TaxonomyTestBase {
}
// Generate and test unsanitized tokens.
$tests['[term:name]'] = $term2->name->value;
$tests['[term:description]'] = $term2->description->value;
$tests['[term:parent:name]'] = $term1->name->value;
$tests['[term:name]'] = $term2->getName();
$tests['[term:description]'] = $term2->getDescription();
$tests['[term:parent:name]'] = $term1->getName();
$tests['[term:vocabulary:name]'] = $this->vocabulary->name;
foreach ($tests as $input => $expected) {
@ -133,7 +134,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Generate and test sanitized tokens.
$tests = array();
$tests['[vocabulary:vid]'] = $this->vocabulary->id();
$tests['[vocabulary:name]'] = check_plain($this->vocabulary->name);
$tests['[vocabulary:name]'] = String::checkPlain($this->vocabulary->name);
$tests['[vocabulary:description]'] = filter_xss($this->vocabulary->description);
$tests['[vocabulary:node-count]'] = 1;
$tests['[vocabulary:term-count]'] = 2;
@ -156,3 +157,4 @@ class TokenReplaceTest extends TaxonomyTestBase {
}
}
}

View File

@ -89,7 +89,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
$attributes = $option->attributes();
$tid = (string) $attributes->value;
$this->assertEqual($prefix . $terms[$i][$j]->label(), (string) $option);
$this->assertEqual($prefix . $terms[$i][$j]->getName(), (string) $option);
$this->assertEqual($terms[$i][$j]->id(), $tid);
}
}

View File

@ -80,7 +80,7 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(200);
$this->assertText($term->name->value, 'Edit taxonomy term form opened successfully.');
$this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.');
$edit['name'] = $this->randomName();
$this->drupalPostForm(NULL, $edit, t('Save'));
@ -107,11 +107,11 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the term %name?', array('%name' => $term->label())), 'Delete taxonomy term form opened successfully.');
$this->assertRaw(t('Are you sure you want to delete the term %name?', array('%name' => $term->getName())), 'Delete taxonomy term form opened successfully.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', array('%name' => $term->label())), 'Term deleted.');
$this->assertRaw(t('Deleted term %name.', array('%name' => $term->getName())), 'Term deleted.');
// Test as user without proper permissions.
$user = $this->drupalCreateUser();

View File

@ -13,6 +13,7 @@ use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\VocabularyInterface;
use Drupal\Component\Utility\String;
/**
* Denotes that no term in the vocabulary has a parent.
@ -377,7 +378,7 @@ function template_preprocess_taxonomy_term(&$variables) {
$variables['url'] = $term->url();
// We use name here because that is what appears in the UI.
$variables['name'] = check_plain($term->label());
$variables['name'] = String::checkPlain($term->getName());
$variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
// Helpful $content variable for templates.
@ -782,7 +783,7 @@ function taxonomy_field_widget_info_alter(&$info) {
* The term name to be used as the page title.
*/
function taxonomy_term_title(Term $term) {
return $term->label();
return $term->getName();
}
/**

View File

@ -17,7 +17,7 @@ use Drupal\taxonomy\Entity\Term;
* Use \Drupal\taxonomy\Controller\TaxonomyController::termPage().
*/
function taxonomy_term_page(Term $term) {
$build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->label());
$build['#attached']['drupal_add_feed'][] = array('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->getName());
foreach ($term->uriRelationships() as $rel) {
// Set the term path as the canonical URL to prevent duplicate content.
@ -71,7 +71,7 @@ function taxonomy_term_page(Term $term) {
*/
function taxonomy_term_feed(Term $term) {
$channel['link'] = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE));
$channel['title'] = \Drupal::config('system.site')->get('name') . ' - ' . $term->label();
$channel['title'] = \Drupal::config('system.site')->get('name') . ' - ' . $term->getName();
// Only display the description if we have a single term, to avoid clutter and confusion.
// HTML will be removed from feed description.
$channel['description'] = $term->description->processed;

View File

@ -5,6 +5,8 @@
* Builds placeholder replacement tokens for taxonomy terms and vocabularies.
*/
use Drupal\Component\Utility\String;
/**
* Implements hook_token_info().
*/
@ -104,11 +106,11 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'name':
$replacements[$original] = $sanitize ? check_plain($term->name->value) : $term->name->value;
$replacements[$original] = $sanitize ? String::checkPlain($term->getName()) : $term->getName();
break;
case 'description':
$replacements[$original] = $sanitize ? $term->description->processed : $term->description->value;
$replacements[$original] = $sanitize ? $term->description->processed : $term->getDescription();
break;
case 'url':
@ -125,13 +127,13 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
case 'vocabulary':
$vocabulary = entity_load('taxonomy_vocabulary', $term->bundle());
$replacements[$original] = check_plain($vocabulary->name);
$replacements[$original] = String::checkPlain($vocabulary->name);
break;
case 'parent':
if ($parents = taxonomy_term_load_parents($term->id())) {
$parent = array_pop($parents);
$replacements[$original] = check_plain($parent->name->value);
$replacements[$original] = String::checkPlain($parent->getName());
}
break;
}
@ -158,7 +160,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
break;
case 'name':
$replacements[$original] = $sanitize ? check_plain($vocabulary->name) : $vocabulary->name;
$replacements[$original] = $sanitize ? String::checkPlain($vocabulary->name) : $vocabulary->name;
break;
case 'description':

View File

@ -70,7 +70,7 @@ class RowEntityTest extends ViewUnitTestBase {
$this->content = $view->preview();
$this->content = drupal_render($this->content);
$this->assertText($term->label(), 'The rendered entity appears as row in the view.');
$this->assertText($term->getName(), 'The rendered entity appears as row in the view.');
// Tests the available view mode options.
$form = array();

View File

@ -80,7 +80,7 @@ class ViewsTaxonomyAutocompleteTest extends ViewTestBase {
$this->assertIdentical(array(), $this->drupalGetJSON($base_autocomplete_path));
// Test a with whole name term.
$label = $this->term1->label();
$label = $this->term1->getName();
$expected = array(array(
'value' => $label,
'label' => String::checkPlain($label),