diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index e95460704d026f33786cdb5945306ab24e7d8852..33812a8884be451947e2e4cc0d94f7d82027b4a7 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php @@ -154,7 +154,7 @@ public function testAutocompleteEdit() { '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 @@ public function testAutocompleteEdit() { $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 @@ public function testAutocompleteEdit() { // 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 @@ public function testAutocompleteEdit() { // 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'); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php index e95650aaba3d5593c7afd6dd2e1193c0d8bb0325..8c33d47d9361fe09d49f7a6a9e8ac7272d9c30f5 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php @@ -90,17 +90,17 @@ public function testContentEntityReferenceItem() { $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 @@ public function testContentEntityReferenceItem() { $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 @@ public function testConfigEntityReferenceItem() { $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( diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index c728ad1fe37583fb41da7e7d5d844db75118ac2f..959a700e16f6f73008c25f6a574a1223094d8629 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -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()))); } } } diff --git a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php index c70d794b1a1ea030053c0d1bc9fac2e4dff0eb21..01a2566d3f8a3ccc212e6f1871ca9a6349a3e6b9 100644 --- a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php +++ b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php @@ -145,7 +145,7 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren ); $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; diff --git a/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php b/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php index ae16f9071d45cec33e4b915c81ba9d214de04892..fe0d5a2a906b5bc7fa26923b568849702f07b81b 100644 --- a/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php +++ b/core/modules/forum/lib/Drupal/forum/Form/ForumFormController.php @@ -81,14 +81,14 @@ public function save(array $form, array &$form_state) { 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 @@ protected function forumParentSelect($tid, $title) { 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(); } } } diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index 2b8dab03f83293843d58f8a5610e54dedb49e917..48a8ea60885a567e4044358c3c1f1cde13b7ffb8 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -118,7 +118,7 @@ function testPagePreview() { $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 @@ function testPagePreview() { $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 @@ function testPagePreview() { $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); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php index 09b2c87986ec159d53cd09e11c828f81e9d10c2d..4e4f7a10e0e7be9d39eb3861aecc47eacf890eea 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php @@ -103,7 +103,7 @@ public function setUp() { * 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'); } /** diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php index 2d4ed43df14b5285787a22b6d0a3617dd3c0b994..5919d54300edc9b8b7fafbd784f4fefe1eaa763b 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/StandardProfileTest.php @@ -327,7 +327,7 @@ protected function doTermRdfaTests() { // 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 @@ protected function assertRdfaArticleProperties($graph, $message_prefix) { // 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 diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php index 268a24769ae96aabff5c976d00fd6d9d081bf2f0..1172fbc091e9560b002437eb56eaa480dd2df83e 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyAttributesTest.php @@ -66,14 +66,14 @@ function testTaxonomyTermRdfaAttributes() { // 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).'); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php index 2cea8b895287a76b05a1136e44dbb67772f6d5fc..82b8516ff64adbf31164e75abb8b3d135037208e 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php @@ -128,7 +128,7 @@ function testNodeTeaser() { //$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 @@ function testNodeTeaser() { //$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).'); } diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index f925304538ef100891f1c47381db6e284fadb3f4..a6d8270a0aa85afcbf813d7d96f08e3a673ff3e1 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -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'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index b7dd9addd1bec8308101011852ceadd7a6e9df66..aa6f6ecfe4fba17a64815033927d7335f51187ed 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -385,7 +385,7 @@ public function testTaxonomyTermHooks() { )); $_SESSION['entity_crud_hook_test'] = array(); - $term->name = 'New name'; + $term->setName('New name'); $term->save(); $this->assertHookMessageOrder(array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index d7e51c4c06ffaf80126623bc5321e7f40a59bded..ab9b883dd3e503af3e97417420faa7e5dc8a0978 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -270,7 +270,7 @@ function testBreadCrumbs() { $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 @@ function testBreadCrumbs() { // 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(), ); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php index 9ade6c980d3cfaf922e7701ec7b5a2cb9c9276aa..fb06df847f8c3873f66d19ae51b3786f1324f172 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php @@ -67,7 +67,7 @@ public function vocabularyTitle(VocabularyInterface $taxonomy_vocabulary) { * The term label. */ public function termTitle(TermInterface $taxonomy_term) { - return Xss::filter($taxonomy_term->label()); + return Xss::filter($taxonomy_term->getName()); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php index b360883b051fecf486ff7185cbf046673af189db..dce3472cd83bd94d02068e8b7ac320e74182d490 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php @@ -196,8 +196,8 @@ protected function getMatchingTerms($tags_typed, array $vids, $tag_last) { $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; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php index 33d4c88aa6c579687dcf5b9634a2f29c95831fb9..38c84e1baa0c26c5b9467814d2782a67c694522b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Term.php @@ -55,93 +55,12 @@ 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 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { * {@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; } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php index 29868ab9b74cb4f06913874c2eaa96bb236e231a..13c8d2e43ec51c57005f42eb7c69178af03f44b8 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/OverviewTerms.php @@ -212,7 +212,7 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ $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 @@ public function buildForm(array $form, array &$form_state, VocabularyInterface $ '#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 @@ public function submitForm(array &$form, array &$form_state) { $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 @@ public function submitForm(array &$form, array &$form_state) { 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 @@ public function submitForm(array &$form, array &$form_state) { // 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; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php index b9d810d913d3eed5236caca5aa94ee1a7e4b2f46..07b6af1bb3afda31a7ccd60ccf75bfcf11ab69c9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php @@ -28,7 +28,7 @@ public function getFormId() { * {@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 @@ public function submit(array $form, array &$form_state) { // @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)); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php index f7d0325ec004f199050f42c78eb4c0e599a7afd9..6848c775ab80e9e4459c577d0d57d5737980b13f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -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 @@ public function viewElements(FieldItemListInterface $items) { $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'], diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/PlainFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/PlainFormatter.php index 826db273bf8f2a5dffb8ff772fd9b7816781cc2e..1bf4ab4790c40fdce7b8d34af4d64c950870c225 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/PlainFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldFormatter/PlainFormatter.php @@ -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 @@ public function viewElements(FieldItemListInterface $items) { foreach ($items as $delta => $item) { $elements[$delta] = array( - '#markup' => check_plain($item->entity->label()), + '#markup' => String::checkPlain($item->entity->label()), ); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php index c7e679b3a22eb3cdcb40ee418303eccfea38af04..d044f9609dc8defaf781ab53c8e0d2fb9afeecc6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php @@ -77,7 +77,7 @@ public function getSettableOptions(AccountInterface $account = NULL) { 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(); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php index 43648452274520c055597a078041d8ee476b173c..50f3bc14babc09ad316362d84c83ef8e5451594d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php @@ -66,7 +66,7 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA 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()); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTid.php index abe16ead1e30e4cdf3bc75165a89bd7ed2d94372..b9c8f951140168e79b02cdc338db592647649008 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTid.php @@ -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 @@ public function titleQuery() { ->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; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTidDepth.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTidDepth.php index 84c9415e76abc73e089a9fcc50c2fbab8efdf219..86a3391061b871ca5df717f498b00396b001db25 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTidDepth.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTidDepth.php @@ -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 @@ public function query($group_by = FALSE) { 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'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/Taxonomy.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/Taxonomy.php index d1f75c6c33f5892ef4312f5a32e28b608df507af..c2b54fab3d168ebd857fa868d8a1430f53751d84 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/Taxonomy.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/Taxonomy.php @@ -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 @@ function title() { 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 diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php index aa9a5825474ca37e6a795c57e0a2292a408ad283..8eb7bf6d75e5b82f3cda17691ce84dbaf78eec3e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/VocabularyVid.php @@ -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'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php index bb6d43bc7071e72fde7a630e2583d62c5c0c2005..141037645c5a8abd18908c97a5985cf0048a6ce0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/field/TaxonomyIndexTid.php @@ -10,6 +10,7 @@ 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 @@ public function preRender(&$values) { } $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; } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php index ec4b127dd570d51458a0566ad2df897d31112e90..6fee2e2c210ed54d81f3951c495f90c4697d8611 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php @@ -111,11 +111,11 @@ protected function valueForm(&$form, &$form_state) { ->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 @@ protected function valueForm(&$form, &$form_state) { $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 @@ protected function valueForm(&$form, &$form_state) { $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 @@ function validate_term_strings(&$form, $values) { $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 @@ public function adminSummary() { ->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(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php index e886357d59769cac0c834f6d56379798a8971900..6625d55e88d061c5930463c6853a4f344aaa054c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php @@ -35,7 +35,7 @@ public function build(array $attributes) { $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'), ''); $breadcrumb = array_reverse($breadcrumb); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index 52ef2a86cde9de23cf3a2d58e1bef2c2994ecfe7..f06c47907b20d1bae49d00e7a3a7de1c9b6d5f6d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -64,7 +64,7 @@ public function form(array $form, array &$form_state) { $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 @@ public function form(array $form, array &$form_state) { $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 @@ public function form(array $form, array &$form_state) { 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 @@ public function form(array $form, array &$form_state) { '#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 @@ public function buildEntity(array $form, array &$form_state) { $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 @@ public function save(array $form, array &$form_state) { 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; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php index 03770bd90d32be71c778f9acbe024b6d4775a830..433f4873e92c6c21c2bfc80daf7e7020e6796545 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php @@ -15,4 +15,84 @@ */ 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(); + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php index 1eb21f0797c1b570f5bfcf2b033823154938994e..a8e26707e37cfcb99eab0b9f5c804659a0ba7a07 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php @@ -27,7 +27,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang // @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' => '
', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php index b0bb675c9c1a3a26162c024f9bef16fad32dfd6c..2c538fea951b2ecefc52344c9c56f43ed1afac50 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LoadMultipleTest.php @@ -63,7 +63,7 @@ function testTaxonomyTermMultipleLoad() { // 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.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index 7e20e61a0a1d5c9c808bc6ac2c5437dbb36640bb..709d0fa8bcbe76f02a0289bef5733cab0ed7825a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -102,7 +102,7 @@ function testTaxonomyRss() { $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)), ), diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php index c12c9bfbcbb8b4c1e98ec0d1deba4f78a94ddd9c..52becaa6317ee5b9e9a910521d98f3616a35a6d4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php @@ -84,7 +84,7 @@ public function testTaxonomyImageAccess() { $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')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php index 63b6fd12d35f184024d7e3d2efdea77bb445b068..0a67140961df820b221011aabc905cf1a614f056 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -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 @@ public function testTaxonomyTermReferenceItem() { $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.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 65ef16b3e719780b4059ac02bec9958ebe269359..afac0db0ed005d8a27a99d5bde74c2b4d655d8b0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -105,8 +105,8 @@ function testTaxonomyTermFieldMultipleVocabularies() { $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 @@ function testTaxonomyTermFieldMultipleVocabularies() { $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); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index be0ad94152cd17fa7aba5e2b82c8f4701f1005ea..237f9db4dae626f4fc3addb2add4eba035c00ef9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -120,7 +120,7 @@ function testTaxonomyTermFieldWidgets() { $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(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 31838d1498874fd9734e0b1ab43ba28d69565ea8..e79d159a6389431abf4f17d90402233aed3df9df 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -215,6 +215,6 @@ function testTaxonomyTermHierarchyBreadcrumbs() { // 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.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 5a535675908c18419eff897d8a393b18e7deefff..ca6283619eecb053023455633c38e8a65dd15af3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -10,6 +10,7 @@ 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 @@ function testTaxonomyNode() { // 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 @@ function testNodeTermCreationAndDeletion() { // 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 @@ function testNodeTermCreationAndDeletion() { 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 @@ function testTermAutocompletion() { // 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 @@ function testTermAutocompletion() { $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 @@ function testTermAutocompletion() { $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 @@ function testTermInterface() { // 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, "

$value

\n"); @@ -446,8 +448,8 @@ function testTermMultipleParentsInterface() { $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 () is // not added by taxonomy_term_load_parents(). $parents = taxonomy_term_load_parents($term->id()); @@ -462,19 +464,19 @@ function testTaxonomyGetTermByName() { $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 @@ function testTaxonomyGetTermByName() { $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 @@ function testTaxonomyGetTermByName() { // Try to load a term by name that doesn't exist in this vocabulary but // exists in another vocabulary. - $terms = taxonomy_term_load_multiple_by_name($term2->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 @@ function testReSavingTags() { $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.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index eac5f8496b9e061ed06ec8bb78267b64f26950b0..d3a938b54017afa19cfc9f971caed101658a0e4e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -9,6 +9,7 @@ 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 @@ function testTaxonomyTokenReplacement() { // 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 @@ function testTaxonomyTokenReplacement() { // 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 @@ function testTaxonomyTokenReplacement() { } // 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 @@ function testTaxonomyTokenReplacement() { // 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 @@ function testTaxonomyTokenReplacement() { } } } + diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyIndexTidUiTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyIndexTidUiTest.php index 2de652247c676e4e84356fef3266fd14ceb25bcc..d2b2fb3590d6deb92f9de528cdd593cd18ccbcc6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyIndexTidUiTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyIndexTidUiTest.php @@ -89,7 +89,7 @@ public function testFilterUI() { $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); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php index 9b4611d87d985cd98b49c4ba878399344686a89c..b97a092ef03671d6d149f78b7b625268a98991e0 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyPermissionsTest.php @@ -80,7 +80,7 @@ function testVocabularyPermissionsTaxonomyTerm() { // 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 @@ function testVocabularyPermissionsTaxonomyTerm() { // 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(); diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index d9147c0a174c9f1999f505e57dc0a9ee8cf2d86b..5ee5dd8e24f70706880ce5bc6c647fee99add16a 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -13,6 +13,7 @@ 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(); } /** diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 99e406d8ce4f9159ad32959a34e855fb35b20112..294dabba7d13db5281d40905f0dcd5728d68841e 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -17,7 +17,7 @@ * 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; diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index eec9d73fda03bbdbcd7f8f8048811756dbe4a0e4..f89f0a6a0658ba1de64429f5f51d25be08d6c07d 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -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': diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php index 177fdeaa169f3d312d33d5993a165199f63ad156..bb479044b62b08dd64dac8a73732c40145c448ff 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/RowEntityTest.php @@ -70,7 +70,7 @@ public function testEntityRow() { $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(); diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php index 8b3db49b47f83aae733647201b29e6abb2bcdbc2..766ae49ee9106b39466082f9b2564ced3d88c2f3 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php @@ -80,7 +80,7 @@ public function testTaxonomyAutocomplete() { $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),