Commit d19928b6 authored by catch's avatar catch

Issue #2225431 by mr.baileys, Wim Leers, swentel: Apply formatters and widgets...

Issue #2225431 by mr.baileys, Wim Leers, swentel: Apply formatters and widgets to Taxonomy Term base fields.
parent 63375a5e
......@@ -152,12 +152,17 @@ entity_form_display.field.*:
type: integer
label: 'Weight'
entity_view_display.field.string:
type: entity_field_view_display_base
label: 'Plain text display format settings'
entity_form_display.field.string:
type: entity_field_form_display_base
label: 'Text field display format settings'
mapping:
settings:
type: sequence
type: mapping
label: 'Settings'
sequence:
- type: string
mapping:
size:
type: integer
label: 'Size of textfield'
placeholder:
type: label
label: 'Placeholder'
......@@ -5,9 +5,15 @@ mode: default
status: true
content:
name:
type: string
weight: -5
settings:
size: 60
placeholder: ''
description:
type: text_textfield
weight: 0
settings: { }
dependencies:
entity:
- taxonomy.vocabulary.forums
......@@ -368,8 +368,8 @@ function createForum($type, $parent = 0) {
$description = $this->randomName(100);
$edit = array(
'name' => $name,
'description[value]' => $description,
'name[0][value]' => $name,
'description[0][value]' => $description,
'parent[0]' => $parent,
'weight' => '0',
);
......
......@@ -50,12 +50,12 @@ function testTermAlias() {
$vocabulary = entity_load('taxonomy_vocabulary', 'tags');
$description = $this->randomName();
$edit = array(
'name' => $this->randomName(),
'description[value]' => $description,
'name[0][value]' => $this->randomName(),
'description[0][value]' => $description,
'path[alias]' => $this->randomName(),
);
$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.
$this->drupalGet($edit['path[alias]']);
......
......@@ -8,6 +8,3 @@
.taxonomy-term-divider-bottom {
border-top: 1px dotted #ccc;
}
.taxonomy-term-description {
margin: 5px 0 20px;
}
......@@ -132,12 +132,33 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setLabel(t('Name'))
->setDescription(t('The term name.'))
->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')
->setLabel(t('Description'))
->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')
->setLabel(t('Weight'))
......
......@@ -61,22 +61,6 @@ public function form(array $form, array &$form_state) {
$form_state['taxonomy']['parent'] = $parent;
$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;
$form['langcode'] = array(
'#type' => 'language_select',
......
......@@ -16,33 +16,11 @@
*/
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}
*/
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
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(
'route_parameters' => array('taxonomy_term' => $entity->id()),
'metadata' => array('changed' => $entity->getChangedTime()),
......
......@@ -79,10 +79,10 @@ public function testTaxonomyImageAccess() {
// Create a term and upload the image.
$files = $this->drupalGetTestFiles('image');
$image = array_pop($files);
$edit['name'] = $this->randomName();
$edit['name[0][value]'] = $this->randomName();
$edit['files[field_test_0]'] = drupal_realpath($image->uri);
$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);
$this->assertText(t('Created new term @name.', array('@name' => $term->getName())));
......
......@@ -57,11 +57,11 @@ function testTermLanguage() {
$this->assertField('edit-langcode', t('The language selector field was found on the page.'));
// Submit the term.
$edit = array(
'name' => $this->randomName(),
'name[0][value]' => $this->randomName(),
'langcode' => 'aa',
);
$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);
$this->assertEqual($term->language()->id, $edit['langcode'], 'The term contains the correct langcode.');
......
......@@ -296,8 +296,8 @@ function testTermAutocompletion() {
*/
function testTermInterface() {
$edit = array(
'name' => $this->randomName(12),
'description[value]' => $this->randomName(100),
'name[0][value]' => $this->randomName(12),
'description[0][value]' => $this->randomName(100),
);
// Explicitly set the parents field to 'root', to ensure that
// TermFormController::save() handles the invalid term ID correctly.
......@@ -306,7 +306,7 @@ function testTermInterface() {
// Create the term to edit.
$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);
$this->assertNotNull($term, 'Term found in database.');
......@@ -318,12 +318,12 @@ function testTermInterface() {
// the first edit link found on the listing page is to our term.
$this->clickLink(t('edit'));
$this->assertRaw($edit['name'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
$this->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
$edit = array(
'name' => $this->randomName(14),
'description[value]' => $this->randomName(102),
'name[0][value]' => $this->randomName(14),
'description[0][value]' => $this->randomName(102),
);
// Edit the term.
......@@ -331,25 +331,25 @@ function testTermInterface() {
// Check that the term is still present at admin UI after edit.
$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'));
// 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.');
// View the term and check that it is correct.
$this->drupalGet('taxonomy/term/' . $term->id());
$this->assertText($edit['name'], 'The randomly generated term name is present.');
$this->assertText($edit['description[value]'], 'The randomly generated term description is present.');
$this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
// 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.
$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.');
$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.
$value = $this->randomName();
......@@ -437,19 +437,19 @@ function testTermMultipleParentsInterface() {
// Add a new term with multiple parents.
$edit = array(
'name' => $this->randomName(12),
'description[value]' => $this->randomName(100),
'name[0][value]' => $this->randomName(12),
'description[0][value]' => $this->randomName(100),
'parent[]' => array(0, $parent->id()),
);
// Save the new term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
// 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);
$this->assertNotNull($term, 'Term found in database.');
$this->assertEqual($edit['name'], $term->getName(), 'Term name was successfully saved.');
$this->assertEqual($edit['description[value]'], $term->getDescription(), 'Term description was successfully saved.');
$this->assertEqual($edit['name[0][value]'], $term->getName(), 'Term name 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
// not added by taxonomy_term_load_parents().
$parents = taxonomy_term_load_parents($term->id());
......
......@@ -81,6 +81,25 @@ protected function 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().
*/
......
......@@ -75,7 +75,7 @@ function testTaxonomyTokenReplacement() {
// Edit $term2, setting $term1 as parent.
$edit = array();
$edit['name'] = '<blink>Blinking Text</blink>';
$edit['name[0][value]'] = '<blink>Blinking Text</blink>';
$edit['parent[]'] = array($term1->id());
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
......
......@@ -37,34 +37,34 @@ function testVocabularyPermissionsTaxonomyTerm() {
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
$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.
$edit = array();
$edit['name'] = $this->randomName();
$edit['name[0][value]'] = $this->randomName();
$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);
// Edit the term.
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
$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->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.
$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.
$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.
$user = $this->drupalCreateUser(array("edit terms in {$vocabulary->id()}"));
......@@ -82,9 +82,9 @@ function testVocabularyPermissionsTaxonomyTerm() {
$this->assertResponse(200);
$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->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.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
......
......@@ -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.
*
......@@ -349,7 +317,8 @@ function template_preprocess_taxonomy_term(&$variables) {
$variables['url'] = $term->url();
// 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);
// Helpful $content variable for templates.
......
......@@ -19,7 +19,7 @@
* field_types = {
* "text",
* "text_long",
* "text_with_summary"
* "text_with_summary",
* },
* edit = {
* "editor" = "plain_text"
......
......@@ -4,7 +4,7 @@ bundle: article
mode: default
content:
title:
type: text_textfield
type: string
weight: 0
settings:
size: 60
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment