Commit 9d56386e authored by Digidog's avatar Digidog
Browse files

#335281 by thePanz, jcfiala, stella, Digidog: committed patch by stella...

#335281 by thePanz, jcfiala, stella, Digidog: committed patch by stella #comment-4929778 for title attribute support.
parent 2c743e73
......@@ -173,6 +173,20 @@ function link_field_instance_settings_form($field, $instance) {
'#description' => t('When output, this link will have have this class attribute. Multiple classes should be separated by spaces.'),
'#default_value' => empty($instance['settings']['attributes']['class']) ? '' : $instance['settings']['attributes']['class'],
);
$form['attributes']['configurable_title'] = array(
'#title' => t("Allow the user to enter a link 'title' attribute"),
'#type' => 'checkbox',
'#default_value' => empty($instance['settings']['attributes']['configurable_title']) ? '' : $instance['settings']['attributes']['configurable_title'],
);
$form['attributes']['title'] = array(
'#title' => t("Default link 'title' Attribute"),
'#type' => 'textfield',
'#description' => t('When output, links will use this "title" attribute if the user does not provide one and 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($instance['settings']['attributes']['title']) ? '' : $instance['settings']['attributes']['title'],
'#field_prefix' => 'title = "',
'#field_suffix' => '"',
'#size' => 20,
);
return $form;
}
......@@ -468,6 +482,19 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$node) {
$item['attributes']['rel'] = str_replace('nofollow', '', $item['attributes']);
}
// Handle "title" link attribute.
if (!empty($item['attributes']['title']) && module_exists('token')) {
// Load the node (necessary for nodes in views).
$token_node = isset($node->nid) ? node_load($node->nid) : $node;
$item['attributes']['title'] = filter_xss(token_replace($item['attributes']['title'], array('node' => $token_node)),
array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
}
// Remove title attribute if it's equal to link text.
if ($item['attributes']['title'] == $item['title']) {
unset($item['attributes']['title']);
}
unset($item['attributes']['configurable_title']);
// Remove empty attributes.
$item['attributes'] = array_filter($item['attributes']);
......@@ -541,6 +568,9 @@ function theme_link_field($vars) {
if (!empty($element['attributes']['target'])) {
$output .= '<div class="link-attributes">'. drupal_render($element['attributes']['target']) .'</div>';
}
if (!empty($element['attributes']['title'])) {
$output .= '<div class="link-attributes">'. drupal_render($element['attributes']['title']) .'</div>';
}
return $output;
}
......@@ -609,6 +639,15 @@ function link_field_process($element, $form_state, $complete_form) {
'#default_value' => isset($attributes['target']) ? $attributes['target'] : FALSE,
);
}
if (!empty($settings['attributes']['configurable_title']) && $settings['attributes']['configurable_title'] == 1) {
$element['attributes']['title'] = array(
'#type' => 'textfield',
'#title' => t('Link "title" attribute'),
'#default_value' => isset($attributes['title']) ? $attributes['title'] : '',
'#field_prefix' => 'title = "',
'#field_suffix' => '"',
);
}
return $element;
}
......
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