Commit 7dc306cf authored by ceanu's avatar ceanu
Browse files

Issue #97766 by tanepiper, heddn, timbrandin, droath, alanburke, Digidog:...

Issue #97766 by tanepiper, heddn, timbrandin, droath, alanburke, Digidog: Class attribute field option for each dataset in link widget.
parent 334b6e32
...@@ -191,6 +191,11 @@ function link_field_instance_settings_form($field, $instance) { ...@@ -191,6 +191,11 @@ function link_field_instance_settings_form($field, $instance) {
'#description' => t('Turn on/off if rel attribute should be removed automatically, if user given link is internal/external'), '#description' => t('Turn on/off if rel attribute should be removed automatically, if user given link is internal/external'),
'#options' => $rel_remove_options, '#options' => $rel_remove_options,
); );
$form['attributes']['configurable_class'] = array(
'#title' => t("Allow the user to enter a custom link class per link"),
'#type' => 'checkbox',
'#default_value' => empty($instance['settings']['attributes']['configurable_class']) ? '' : $instance['settings']['attributes']['configurable_class'],
);
$form['attributes']['class'] = array( $form['attributes']['class'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Additional CSS Class'), '#title' => t('Additional CSS Class'),
...@@ -592,6 +597,16 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) { ...@@ -592,6 +597,16 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded)); $item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
$item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); $item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
} }
// Handle classes
if (!empty($item['attributes']['class'])){
$classes = explode(' ', $item['attributes']['class']);
foreach ($classes as &$class) {
$class = drupal_html_class($class);
}
$item['attributes']['class'] = implode(' ', $classes);
}
unset($item['attributes']['configurable_class']);
// Remove title attribute if it's equal to link text. // Remove title attribute if it's equal to link text.
if (isset($item['attributes']['title']) && $item['attributes']['title'] == $item['title']) { if (isset($item['attributes']['title']) && $item['attributes']['title'] == $item['title']) {
unset($item['attributes']['title']); unset($item['attributes']['title']);
...@@ -723,6 +738,9 @@ function theme_link_field($vars) { ...@@ -723,6 +738,9 @@ function theme_link_field($vars) {
if (!empty($element['attributes']['title'])) { if (!empty($element['attributes']['title'])) {
$output .= '<div class="link-attributes">' . drupal_render($element['attributes']['title']) . '</div>'; $output .= '<div class="link-attributes">' . drupal_render($element['attributes']['title']) . '</div>';
} }
if (!empty($element['attributes']['class'])) {
$output .= '<div class="link-attributes">'. drupal_render($element['attributes']['class']) .'</div>';
}
$output .= drupal_render_children($element); $output .= drupal_render_children($element);
return $output; return $output;
} }
...@@ -816,6 +834,15 @@ function link_field_process($element, $form_state, $complete_form) { ...@@ -816,6 +834,15 @@ function link_field_process($element, $form_state, $complete_form) {
'#field_suffix' => '"', '#field_suffix' => '"',
); );
} }
if (!empty($settings['attributes']['configurable_class']) && $settings['attributes']['configurable_class'] == 1) {
$element['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Custom link class'),
'#default_value' => isset($attributes['class']) ? $attributes['class'] : '',
'#field_prefix' => 'class = "',
'#field_suffix' => '"',
);
}
// If the title field is avaliable or there are field accepts multiple values // If the title field is avaliable or there are field accepts multiple values
// then allow the individual field items display the required asterisk if needed. // then allow the individual field items display the required asterisk if needed.
......
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