Issue #2225431 by mr.baileys, Wim Leers, swentel: Apply formatters and widgets to Taxonomy Term base fields.

8.0.x
catch 2014-03-30 13:24:35 +02:00
parent 63375a5e7b
commit d19928b695
17 changed files with 102 additions and 123 deletions

View File

@ -152,12 +152,17 @@ entity_form_display.field.*:
type: integer type: integer
label: 'Weight' label: 'Weight'
entity_view_display.field.string: entity_form_display.field.string:
type: entity_field_view_display_base type: entity_field_form_display_base
label: 'Plain text display format settings' label: 'Text field display format settings'
mapping: mapping:
settings: settings:
type: sequence type: mapping
label: 'Settings' label: 'Settings'
sequence: mapping:
- type: string size:
type: integer
label: 'Size of textfield'
placeholder:
type: label
label: 'Placeholder'

View File

@ -5,9 +5,15 @@ mode: default
status: true status: true
content: content:
name: name:
type: string
weight: -5 weight: -5
settings:
size: 60
placeholder: ''
description: description:
type: text_textfield
weight: 0 weight: 0
settings: { }
dependencies: dependencies:
entity: entity:
- taxonomy.vocabulary.forums - taxonomy.vocabulary.forums

View File

@ -368,8 +368,8 @@ class ForumTest extends WebTestBase {
$description = $this->randomName(100); $description = $this->randomName(100);
$edit = array( $edit = array(
'name' => $name, 'name[0][value]' => $name,
'description[value]' => $description, 'description[0][value]' => $description,
'parent[0]' => $parent, 'parent[0]' => $parent,
'weight' => '0', 'weight' => '0',
); );

View File

@ -50,12 +50,12 @@ class PathTaxonomyTermTest extends PathTestBase {
$vocabulary = entity_load('taxonomy_vocabulary', 'tags'); $vocabulary = entity_load('taxonomy_vocabulary', 'tags');
$description = $this->randomName(); $description = $this->randomName();
$edit = array( $edit = array(
'name' => $this->randomName(), 'name[0][value]' => $this->randomName(),
'description[value]' => $description, 'description[0][value]' => $description,
'path[alias]' => $this->randomName(), 'path[alias]' => $this->randomName(),
); );
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add', $edit, t('Save')); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add', $edit, t('Save'));
$tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField(); $tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name[0][value]']))->fetchField();
// Confirm that the alias works. // Confirm that the alias works.
$this->drupalGet($edit['path[alias]']); $this->drupalGet($edit['path[alias]']);

View File

@ -8,6 +8,3 @@
.taxonomy-term-divider-bottom { .taxonomy-term-divider-bottom {
border-top: 1px dotted #ccc; border-top: 1px dotted #ccc;
} }
.taxonomy-term-description {
margin: 5px 0 20px;
}

View File

@ -132,12 +132,33 @@ class Term extends ContentEntityBase implements TermInterface {
->setLabel(t('Name')) ->setLabel(t('Name'))
->setDescription(t('The term name.')) ->setDescription(t('The term name.'))
->setRequired(TRUE) ->setRequired(TRUE)
->setSetting('max_length', 255); ->setSetting('max_length', 255)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => -5,
))
->setDisplayConfigurable('form', TRUE);
$fields['description'] = FieldDefinition::create('text_long') $fields['description'] = FieldDefinition::create('text_long')
->setLabel(t('Description')) ->setLabel(t('Description'))
->setDescription(t('A description of the term.')) ->setDescription(t('A description of the term.'))
->setSetting('text_processing', 1); ->setSetting('text_processing', 1)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'text_default',
'weight' => 0,
))
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', array(
'type' => 'text_textfield',
'weight' => 0,
))
->setDisplayConfigurable('form', TRUE);
$fields['weight'] = FieldDefinition::create('integer') $fields['weight'] = FieldDefinition::create('integer')
->setLabel(t('Weight')) ->setLabel(t('Weight'))

View File

@ -61,22 +61,6 @@ class TermFormController extends ContentEntityFormController {
$form_state['taxonomy']['parent'] = $parent; $form_state['taxonomy']['parent'] = $parent;
$form_state['taxonomy']['vocabulary'] = $vocabulary; $form_state['taxonomy']['vocabulary'] = $vocabulary;
$form['name'] = array(
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#default_value' => $term->getName(),
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -5,
);
$form['description'] = array(
'#type' => 'text_format',
'#title' => $this->t('Description'),
'#default_value' => $term->getDescription(),
'#format' => $term->getFormat(),
'#weight' => 0,
);
$language_configuration = $this->moduleHandler->moduleExists('language') ? language_get_default_configuration('taxonomy_term', $vocabulary->id()) : FALSE; $language_configuration = $this->moduleHandler->moduleExists('language') ? language_get_default_configuration('taxonomy_term', $vocabulary->id()) : FALSE;
$form['langcode'] = array( $form['langcode'] = array(
'#type' => 'language_select', '#type' => 'language_select',

View File

@ -16,33 +16,11 @@ use Drupal\Core\Entity\EntityViewBuilder;
*/ */
class TermViewBuilder extends EntityViewBuilder { class TermViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
parent::buildContent($entities, $displays, $view_mode, $langcode);
foreach ($entities as $entity) {
// Add the description if enabled.
// @todo Remove this when base fields are able to use formatters.
// https://drupal.org/node/2144919
$display = $displays[$entity->bundle()];
if ($entity->getDescription() && $display->getComponent('description')) {
$entity->content['description'] = array(
'#markup' => $entity->description->processed,
'#prefix' => '<div class="taxonomy-term-description">',
'#suffix' => '</div>',
);
}
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) { protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
parent::alterBuild($build, $entity, $display, $view_mode, $langcode); parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
$build['#attached']['css'][] = drupal_get_path('module', 'taxonomy') . '/css/taxonomy.module.css';
$build['#contextual_links']['taxonomy_term'] = array( $build['#contextual_links']['taxonomy_term'] = array(
'route_parameters' => array('taxonomy_term' => $entity->id()), 'route_parameters' => array('taxonomy_term' => $entity->id()),
'metadata' => array('changed' => $entity->getChangedTime()), 'metadata' => array('changed' => $entity->getChangedTime()),

View File

@ -79,10 +79,10 @@ class TaxonomyImageTest extends TaxonomyTestBase {
// Create a term and upload the image. // Create a term and upload the image.
$files = $this->drupalGetTestFiles('image'); $files = $this->drupalGetTestFiles('image');
$image = array_pop($files); $image = array_pop($files);
$edit['name'] = $this->randomName(); $edit['name[0][value]'] = $this->randomName();
$edit['files[field_test_0]'] = drupal_realpath($image->uri); $edit['files[field_test_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); $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'])); $terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]']));
$term = reset($terms); $term = reset($terms);
$this->assertText(t('Created new term @name.', array('@name' => $term->getName()))); $this->assertText(t('Created new term @name.', array('@name' => $term->getName())));

View File

@ -57,11 +57,11 @@ class TermLanguageTest extends TaxonomyTestBase {
$this->assertField('edit-langcode', t('The language selector field was found on the page.')); $this->assertField('edit-langcode', t('The language selector field was found on the page.'));
// Submit the term. // Submit the term.
$edit = array( $edit = array(
'name' => $this->randomName(), 'name[0][value]' => $this->randomName(),
'langcode' => 'aa', 'langcode' => 'aa',
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name']); $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms); $term = reset($terms);
$this->assertEqual($term->language()->id, $edit['langcode'], 'The term contains the correct langcode.'); $this->assertEqual($term->language()->id, $edit['langcode'], 'The term contains the correct langcode.');

View File

@ -296,8 +296,8 @@ class TermTest extends TaxonomyTestBase {
*/ */
function testTermInterface() { function testTermInterface() {
$edit = array( $edit = array(
'name' => $this->randomName(12), 'name[0][value]' => $this->randomName(12),
'description[value]' => $this->randomName(100), 'description[0][value]' => $this->randomName(100),
); );
// Explicitly set the parents field to 'root', to ensure that // Explicitly set the parents field to 'root', to ensure that
// TermFormController::save() handles the invalid term ID correctly. // TermFormController::save() handles the invalid term ID correctly.
@ -306,7 +306,7 @@ class TermTest extends TaxonomyTestBase {
// Create the term to edit. // Create the term to edit.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name']); $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms); $term = reset($terms);
$this->assertNotNull($term, 'Term found in database.'); $this->assertNotNull($term, 'Term found in database.');
@ -318,12 +318,12 @@ class TermTest extends TaxonomyTestBase {
// the first edit link found on the listing page is to our term. // the first edit link found on the listing page is to our term.
$this->clickLink(t('edit')); $this->clickLink(t('edit'));
$this->assertRaw($edit['name'], 'The randomly generated term name is present.'); $this->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.'); $this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
$edit = array( $edit = array(
'name' => $this->randomName(14), 'name[0][value]' => $this->randomName(14),
'description[value]' => $this->randomName(102), 'description[0][value]' => $this->randomName(102),
); );
// Edit the term. // Edit the term.
@ -331,25 +331,25 @@ class TermTest extends TaxonomyTestBase {
// Check that the term is still present at admin UI after edit. // Check that the term is still present at admin UI after edit.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview'); $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertText($edit['name'], 'The randomly generated term name is present.'); $this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertLink(t('edit')); $this->assertLink(t('edit'));
// Check the term link can be clicked through to the term page. // Check the term link can be clicked through to the term page.
$this->clickLink($edit['name']); $this->clickLink($edit['name[0][value]']);
$this->assertResponse(200, 'Term page can be accessed via the listing link.'); $this->assertResponse(200, 'Term page can be accessed via the listing link.');
// View the term and check that it is correct. // View the term and check that it is correct.
$this->drupalGet('taxonomy/term/' . $term->id()); $this->drupalGet('taxonomy/term/' . $term->id());
$this->assertText($edit['name'], 'The randomly generated term name is present.'); $this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.'); $this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
// Did this page request display a 'term-listing-heading'? // Did this page request display a 'term-listing-heading'?
$this->assertPattern('|class="taxonomy-term-description"|', 'Term page displayed the term description element.'); $this->assertTrue($this->xpath('//div[contains(@class, "field-taxonomy-term--description")]'), 'Term page displayed the term description element.');
// Check that it does NOT show a description when description is blank. // Check that it does NOT show a description when description is blank.
$term->setDescription(NULL); $term->setDescription(NULL);
$term->save(); $term->save();
$this->drupalGet('taxonomy/term/' . $term->id()); $this->drupalGet('taxonomy/term/' . $term->id());
$this->assertNoPattern('|class="taxonomy-term-description"|', 'Term page did not display the term description when description was blank.'); $this->assertFalse($this->xpath('//div[contains(@class, "field-taxonomy-term--description")]'), 'Term page did not display the term description when description was blank.');
// Check that the description value is processed. // Check that the description value is processed.
$value = $this->randomName(); $value = $this->randomName();
@ -437,19 +437,19 @@ class TermTest extends TaxonomyTestBase {
// Add a new term with multiple parents. // Add a new term with multiple parents.
$edit = array( $edit = array(
'name' => $this->randomName(12), 'name[0][value]' => $this->randomName(12),
'description[value]' => $this->randomName(100), 'description[0][value]' => $this->randomName(100),
'parent[]' => array(0, $parent->id()), 'parent[]' => array(0, $parent->id()),
); );
// Save the new term. // Save the new term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save')); $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
// Check that the term was successfully created. // Check that the term was successfully created.
$terms = taxonomy_term_load_multiple_by_name($edit['name']); $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms); $term = reset($terms);
$this->assertNotNull($term, 'Term found in database.'); $this->assertNotNull($term, 'Term found in database.');
$this->assertEqual($edit['name'], $term->getName(), 'Term name was successfully saved.'); $this->assertEqual($edit['name[0][value]'], $term->getName(), 'Term name was successfully saved.');
$this->assertEqual($edit['description[value]'], $term->getDescription(), 'Term description was successfully saved.'); $this->assertEqual($edit['description[0][value]'], $term->getDescription(), 'Term description was successfully saved.');
// Check that the parent tid is still there. The other parent (<root>) is // Check that the parent tid is still there. The other parent (<root>) is
// not added by taxonomy_term_load_parents(). // not added by taxonomy_term_load_parents().
$parents = taxonomy_term_load_parents($term->id()); $parents = taxonomy_term_load_parents($term->id());

View File

@ -81,6 +81,25 @@ class TermTranslationUITest extends ContentTranslationUITest {
return array('name' => $this->name) + parent::getNewEntityValues($langcode); return array('name' => $this->name) + parent::getNewEntityValues($langcode);
} }
/**
* Returns an edit array containing the values to be posted.
*/
protected function getEditValues($values, $langcode, $new = FALSE) {
$edit = parent::getEditValues($values, $langcode, $new);
// To be able to post values for the configurable base fields (name,
// description) have to be suffixed with [0][value].
foreach ($edit as $property => $value) {
foreach (array('name', 'description') as $key) {
if ($property == $key) {
$edit[$key . '[0][value]'] = $value;
unset($edit[$property]);
}
}
}
return $edit;
}
/** /**
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::testTranslationUI(). * Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::testTranslationUI().
*/ */

View File

@ -75,7 +75,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
// Edit $term2, setting $term1 as parent. // Edit $term2, setting $term1 as parent.
$edit = array(); $edit = array();
$edit['name'] = '<blink>Blinking Text</blink>'; $edit['name[0][value]'] = '<blink>Blinking Text</blink>';
$edit['parent[]'] = array($term1->id()); $edit['parent[]'] = array($term1->id());
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save')); $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));

View File

@ -37,34 +37,34 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
// Visit the main taxonomy administration page. // Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertField('edit-name', 'Add taxonomy term form opened successfully.'); $this->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.');
// Submit the term. // Submit the term.
$edit = array(); $edit = array();
$edit['name'] = $this->randomName(); $edit['name[0][value]'] = $this->randomName();
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Created new term %name.', array('%name' => $edit['name'])), 'Term created successfully.'); $this->assertRaw(t('Created new term %name.', array('%name' => $edit['name[0][value]'])), 'Term created successfully.');
$terms = taxonomy_term_load_multiple_by_name($edit['name']); $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms); $term = reset($terms);
// Edit the term. // Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit'); $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText($edit['name'], 'Edit taxonomy term form opened successfully.'); $this->assertText($edit['name[0][value]'], 'Edit taxonomy term form opened successfully.');
$edit['name'] = $this->randomName(); $edit['name[0][value]'] = $this->randomName();
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Updated term %name.', array('%name' => $edit['name'])), 'Term updated successfully.'); $this->assertRaw(t('Updated term %name.', array('%name' => $edit['name[0][value]'])), 'Term updated successfully.');
// Delete the vocabulary. // Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the term %name?', array('%name' => $edit['name'])), 'Delete taxonomy term form opened successfully.'); $this->assertRaw(t('Are you sure you want to delete the term %name?', array('%name' => $edit['name[0][value]'])), 'Delete taxonomy term form opened successfully.');
// Confirm deletion. // Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete')); $this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', array('%name' => $edit['name'])), 'Term deleted.'); $this->assertRaw(t('Deleted term %name.', array('%name' => $edit['name[0][value]'])), 'Term deleted.');
// Test as user with "edit" permissions. // Test as user with "edit" permissions.
$user = $this->drupalCreateUser(array("edit terms in {$vocabulary->id()}")); $user = $this->drupalCreateUser(array("edit terms in {$vocabulary->id()}"));
@ -82,9 +82,9 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.'); $this->assertText($term->getName(), 'Edit taxonomy term form opened successfully.');
$edit['name'] = $this->randomName(); $edit['name[0][value]'] = $this->randomName();
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Updated term %name.', array('%name' => $edit['name'])), 'Term updated successfully.'); $this->assertRaw(t('Updated term %name.', array('%name' => $edit['name[0][value]'])), 'Term updated successfully.');
// Delete the vocabulary. // Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete'); $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');

View File

@ -132,38 +132,6 @@ function taxonomy_term_uri($term) {
)); ));
} }
/**
* Implements hook_entity_extra_field_info().
*/
function taxonomy_entity_extra_field_info() {
$return = array();
foreach (entity_get_bundles('taxonomy_term') as $bundle => $bundle_info) {
$return['taxonomy_term'][$bundle] = array(
'form' => array(
'name' => array(
'label' => t('Name'),
'description' => t('Term name textfield'),
'weight' => -5,
),
'description' => array(
'label' => t('Description'),
'description' => t('Term description textarea'),
'weight' => 0,
),
),
'display' => array(
'description' => array(
'label' => t('Description'),
'description' => t('Term description'),
'weight' => 0,
),
),
);
}
return $return;
}
/** /**
* Return nodes attached to a term across all field instances. * Return nodes attached to a term across all field instances.
* *
@ -349,7 +317,8 @@ function template_preprocess_taxonomy_term(&$variables) {
$variables['url'] = $term->url(); $variables['url'] = $term->url();
// We use name here because that is what appears in the UI. // We use name here because that is what appears in the UI.
$variables['name'] = String::checkPlain($term->getName()); $variables['name'] = $variables['elements']['name'];
unset($variables['elements']['name']);
$variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term); $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
// Helpful $content variable for templates. // Helpful $content variable for templates.

View File

@ -19,7 +19,7 @@ use Drupal\Core\Field\FieldItemListInterface;
* field_types = { * field_types = {
* "text", * "text",
* "text_long", * "text_long",
* "text_with_summary" * "text_with_summary",
* }, * },
* edit = { * edit = {
* "editor" = "plain_text" * "editor" = "plain_text"

View File

@ -4,7 +4,7 @@ bundle: article
mode: default mode: default
content: content:
title: title:
type: text_textfield type: string
weight: 0 weight: 0
settings: settings:
size: 60 size: 60