summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--link.module13
-rw-r--r--tests/link.attribute.test111
2 files changed, 118 insertions, 6 deletions
diff --git a/link.module b/link.module
index 536e49e..15596d6 100644
--- a/link.module
+++ b/link.module
@@ -144,7 +144,7 @@ function link_field_settings($op, $field) {
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
- '#description' => t('When output, this link will have have this class attribute. Multiple classes should be separated by spaces.'),
+ '#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces.'),
'#default_value' => empty($field['attributes']['class']) ? '' : $field['attributes']['class'],
);
$form['attributes']['title'] = array(
@@ -152,7 +152,7 @@ function link_field_settings($op, $field) {
'#type' => 'textfield',
'#field_prefix' => 'title = "',
'#field_suffix' => '"',
- '#description' => t('When output, links will have this "title" attribute. Read <a href="http://www.w3.org/TR/WCAG10-HTML-TECHS/#links">WCAG Guidelines</a> for links comformances. Tokens values will be evaluated.'),
+ '#description' => t('When output, links will use this "title" attribute (when different from the link text). Read <a href="http://www.w3.org/TR/WCAG10-HTML-TECHS/#links">WCAG 1.0 Guidelines</a> for links comformances. Tokens values will be evaluated.'),
'#default_value' => empty($field['attributes']['title']) ? '' : $field['attributes']['title'],
);
return $form;
@@ -410,12 +410,17 @@ function _link_sanitize(&$item, $delta, &$field, &$node) {
$item['attributes']['rel'] = str_replace('nofollow', '', $item['attributes']);
}
- // Handle "title" link attribute
+ // Handle "title" link attribute.
if (!empty($attributes['title']) && module_exists('token')) {
- // Load the node (necessary for nodes in views)
+ // Load the node (necessary for nodes in views).
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$item['attributes']['title'] = token_replace($attributes['title'], 'node', $token_node);
}
+ // Remove title attribute if it's equal to link text.
+ if ($item['attributes']['title'] == $item['display_title']) {
+ unset($item['attributes']['title']);
+ }
+
// Remove empty attributes.
$item['attributes'] = array_filter($item['attributes']);
diff --git a/tests/link.attribute.test b/tests/link.attribute.test
index 02027a8..e570b99 100644
--- a/tests/link.attribute.test
+++ b/tests/link.attribute.test
@@ -236,8 +236,7 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
$url_type = str_replace('_', '-', $this->content_types[0]->type);
$edit = array('attributes[title]' => 'test_data');
- //$this->drupalGet('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name']);
- //$this->pass($this->content);
+
$this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
$edit, t('Save field settings'));
$this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
@@ -251,6 +250,8 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
$edit = array();
$edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
+ $title = 'title_'. $this->randomName(20);
+ $edit[$field['field_name'] .'[0][title]'] = $title;
$this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
@@ -261,6 +262,112 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
'@type' => $this->content_types[0]->name)));
$this->drupalGet('node/'. $node->nid);
+ $this->assertText($title, 'Make sure the link title/text shows');
$this->assertRaw(' title="test_data"', "Do we show the title?");
}
+
+ /**
+ * When the title attribute matches the link title, we need to suppress
+ * the title attribute.
+ */
+ function test_Link_With_Title_Attribute_Not_Shown_form() {
+ $this->acquireContentTypes(1);
+ $field_settings = array(
+ 'type' => 'link',
+ 'widget_type' => 'link',
+ 'type_name' => $this->content_types[0]->name,
+ 'attributes' => array(
+ 'class' => '',
+ 'target' => 'default',
+ 'rel' => 'nofollow',
+ 'title' => '',
+ ),
+ );
+
+ $common_title = 'title_'. $this->randomName(20);
+
+ $field = $this->createField($field_settings, 0);
+ $field_db_info = content_database_info($field);
+ $url_type = str_replace('_', '-', $this->content_types[0]->type);
+
+ $edit = array('attributes[title]' => $common_title);
+
+ $this->drupalPost('admin/content/node-type/'. $url_type .'/fields/'. $field['field_name'],
+ $edit, t('Save field settings'));
+ $this->assertText(t('Saved field @field_name', array('@field_name' => $field['field_name'])));
+
+ // So, having saved this field_name, let's see if it works...
+ $this->acquireNodes(1);
+
+ $node = node_load($this->nodes[0]->nid);
+
+ $this->drupalGet('node/'. $this->nodes[0]->nid);
+
+ $edit = array();
+ $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
+ $edit[$field['field_name'] .'[0][title]'] = $common_title;
+
+ $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
+
+ // Make sure we get a new version!
+ $node = node_load($this->nodes[0]->nid, NULL, TRUE);
+ $this->assertText(t('@type @title has been updated.',
+ array('@title' => $node->title,
+ '@type' => $this->content_types[0]->name)));
+
+ $this->drupalGet('node/'. $node->nid);
+ $this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows');
+ $this->assertNoRaw(' title="'. $common_title .'"',
+ "Do we hide the title, since it matches the link title?");
+ $this->pass($this->content);
+ }
+
+ /**
+ * When the title attribute matches the link title, we need to suppress
+ * the title attribute.
+ */
+ function test_Link_without_title_attribute() {
+ $this->acquireContentTypes(1);
+ $field_settings = array(
+ 'type' => 'link',
+ 'widget_type' => 'link',
+ 'type_name' => $this->content_types[0]->name,
+ 'attributes' => array(
+ 'class' => '',
+ 'target' => 'default',
+ 'rel' => 'nofollow',
+ 'title' => '',
+ ),
+ );
+
+ $common_title = 'title_'. $this->randomName(20);
+
+ $field = $this->createField($field_settings, 0);
+ $field_db_info = content_database_info($field);
+ $url_type = str_replace('_', '-', $this->content_types[0]->type);
+
+ // So, having saved this field_name, let's see if it works...
+ $this->acquireNodes(1);
+
+ $node = node_load($this->nodes[0]->nid);
+
+ $this->drupalGet('node/'. $this->nodes[0]->nid);
+
+ $edit = array();
+ $edit[$field['field_name'] .'[0][url]'] = 'http://www.example.com/test';
+ $edit[$field['field_name'] .'[0][title]'] = $common_title;
+
+ $this->drupalPost('node/'. $this->nodes[0]->nid .'/edit', $edit, t('Save'));
+
+ // Make sure we get a new version!
+ $node = node_load($this->nodes[0]->nid, NULL, TRUE);
+ $this->assertText(t('@type @title has been updated.',
+ array('@title' => $node->title,
+ '@type' => $this->content_types[0]->name)));
+
+ $this->drupalGet('node/'. $node->nid);
+ $this->assertRaw('>'. $common_title .'<', 'Make sure the link title/text shows');
+ $this->assertNoRaw(' title=""',
+ "Do we hide the title, since it is empty?");
+ }
} \ No newline at end of file