Commit f48d8972 authored by John Fiala's avatar John Fiala
Browse files

Issue #1836632 by jcfiala:Removed double-encoding of titles when url not specified in link field.

parent 44256e4a
......@@ -435,6 +435,9 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
if (empty($item['url']) && empty($item['title'])) {
return;
}
if (empty($item['html'])) {
$item['html'] = FALSE;
}
// Replace URL tokens.
$entity_type = $instance['entity_type'];
......@@ -923,14 +926,13 @@ function theme_link_formatter_link_default($vars) {
if (isset($link_options['attributes']['class'])) {
$link_options['attributes']['class'] = array($link_options['attributes']['class']);
}
// Display a normal link if both title and URL are available.
if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], $link_options);
}
// If only a title, display the title.
elseif (!empty($vars['element']['title'])) {
return check_plain($vars['element']['title']);
return $link_options['html'] ? $vars['element']['title'] : check_plain($vars['element']['title']);
}
elseif (!empty($vars['element']['url'])) {
return l($vars['element']['title'], $vars['element']['url'], $link_options);
......
......@@ -44,7 +44,6 @@ class LinkContentCrudTest extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save and add fields'));
$this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
//$field = $this->createField(array('type' => 'link', 'widget_type' => 'link'), 0);
// Now add a singleton field.
$single_field_name_friendly = $this->randomName(20);
$single_field_name_machine = strtolower($this->randomName(10));
......@@ -69,14 +68,5 @@ class LinkContentCrudTest extends DrupalWebTestCase {
menu_rebuild();
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
/*$table_schema = drupal_get_schema();
$this->assertEqual(1, 1, print_r(array_keys($table_schema), TRUE));
// Check the schema - the values should be in the per-type table.
$this->assertSchemaMatchesTables(array(
'per_type' => array(
$this->content_types[0]->type => array($field['field_name'] => array('url', 'title', 'attributes')),
),
));*/
}
}
......@@ -224,6 +224,56 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertRaw(l('<strong>'. $name .'</strong>', $input['href'], array('html' => TRUE)));
}
/**
* Testing that if you have the title but no url, the title is not sanitized twice.
*/
function testCRUDTitleOnlyTitleNoLink() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$field_name = 'field_'. $name;
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][url]' => 1,
), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => '',
);
$edit = array(
'title' => $name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
}
/**
* If we're creating a new field and just hit 'save' on the default options, we want to make
* sure they are set to the expected results.
......@@ -248,25 +298,19 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
//_content_type_info(TRUE);
//$fields = content_fields();
//$field = $fields['field_'. $name];
//$field = field_info_field('field_'. $name);
_field_info_collate_fields(TRUE);
$instances = field_info_instances('node', 'page');
//$this->debug($instances);
//$this->assert('debug', '<pre>'. print_r($instances, TRUE) .'</pre>', 'Debug');
$instance = $instances['field_'. $name];
//$this->assertTrue(1 === $instance['validate_url'], 'Make sure validation is on.');
$this->assertFalse($instance['required'], 'Make sure field is not required.');
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be off by default.');
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
//$this->fail('<pre>'. print_r($fields['field_'. $name], TRUE) .'</pre>');
}
}
......@@ -374,4 +374,56 @@ class LinkTokenTest extends LinkBaseTestClass {
$this->assertRaw(l($input['label'], $input['href'] .'/'. $this->web_user->uid));
}
/**
* Test that if you have a title and no url on a field which does not have tokens enabled,
* that the title is sanitized once.
*/
function testCRUDTitleOnlyTitleNoLink2() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$field_name = 'field_'. $name;
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$this->drupalPost(NULL, array(
'instance[settings][url]' => 1,
'instance[settings][enable_tokens]' => 0,
), t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
// create page form
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => '',
);
$edit = array(
'title' => $name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This &amp; That');
}
}
Supports Markdown
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