1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Theme functions for the link module. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * Theme the settings form for the link field. |
---|
10 | */ |
---|
11 | function theme_link_field_settings($form) { |
---|
12 | $title_value = drupal_render($form['title_value']); |
---|
13 | $title_checkbox = drupal_render($form['title']['value']); |
---|
14 | |
---|
15 | // Set Static Title radio option to include the title_value textfield. |
---|
16 | $form['title']['value'] = array('#value' => '<div class="container-inline">'. $title_checkbox . $title_value .'</div>'); |
---|
17 | |
---|
18 | // Reprint the title radio options with the included textfield. |
---|
19 | return drupal_render($form); |
---|
20 | } |
---|
21 | |
---|
22 | /** |
---|
23 | * FAPI theme for an individual text elements. |
---|
24 | */ |
---|
25 | function theme_link($element) { |
---|
26 | drupal_add_css(drupal_get_path('module', 'link') .'/link.css'); |
---|
27 | |
---|
28 | // Prefix single value link fields with the name of the field. |
---|
29 | if (empty($element['#field']['multiple'])) { |
---|
30 | if (isset($element['url']) && isset($element['title'])) { |
---|
31 | $element['url']['#title'] = $element['#title'] .' '. $element['url']['#title']; |
---|
32 | $element['title']['#title'] = $element['#title'] .' '. $element['title']['#title']; |
---|
33 | } |
---|
34 | elseif ($element['url']) { |
---|
35 | $element['url']['#title'] = $element['#title']; |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | $output = ''; |
---|
40 | $output .= '<div class="link-field-subrow clear-block">'; |
---|
41 | if (isset($element['title'])) { |
---|
42 | $output .= '<div class="link-field-title link-field-column">'. theme('textfield', $element['title']) .'</div>'; |
---|
43 | } |
---|
44 | $output .= '<div class="link-field-url'. (isset($element['title']) ? ' link-field-column' : '') .'">'. theme('textfield', $element['url']) .'</div>'; |
---|
45 | $output .= '</div>'; |
---|
46 | if (!empty($element['attributes']['target'])) { |
---|
47 | $output .= '<div class="link-attributes">'. theme('checkbox', $element['attributes']['target']) .'</div>'; |
---|
48 | } |
---|
49 | return $output; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Theme function for 'default' text field formatter. |
---|
54 | */ |
---|
55 | function theme_link_formatter_default($element) { |
---|
56 | // Display a normal link if both title and URL are available. |
---|
57 | if (!empty($element['#item']['display_title']) && !empty($element['#item']['url'])) { |
---|
58 | return l($element['#item']['display_title'], $element['#item']['url'], $element['#item']); |
---|
59 | } |
---|
60 | |
---|
61 | // If no title, no url, display nothing. |
---|
62 | elseif (empty($element['#item']['title']) && empty($element['#item']['url'])) { |
---|
63 | return ; |
---|
64 | } |
---|
65 | // If only a title, display the title. |
---|
66 | elseif (!empty($element['#item']['display_title'])) { |
---|
67 | return check_plain($element['#item']['display_title']); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Theme function for 'plain' text field formatter. |
---|
73 | */ |
---|
74 | function theme_link_formatter_plain($element) { |
---|
75 | return empty($element['#item']['url']) ? check_plain($element['#item']['title']) : url($element['#item']['url'], $element['#item']); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Theme function for 'absolute' link field formatter. |
---|
80 | */ |
---|
81 | function theme_link_formatter_absolute($element) { |
---|
82 | $absolute = array('absolute' => TRUE); |
---|
83 | return empty($element['#item']['url']) ? '' : url($element['#item']['url'], $absolute + $element['#item']); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Theme function for 'title_plain' text field formatter. |
---|
88 | */ |
---|
89 | function theme_link_formatter_title_plain($element) { |
---|
90 | return empty($element['#item']['title']) ? '' : check_plain($element['#item']['title']); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Theme function for 'url' text field formatter. |
---|
95 | */ |
---|
96 | function theme_link_formatter_url($element) { |
---|
97 | return $element['#item']['url'] ? l($element['#item']['display_url'], $element['#item']['url'], $element['#item']) : ''; |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Theme function for 'short' text field formatter. |
---|
102 | */ |
---|
103 | function theme_link_formatter_short($element) { |
---|
104 | return $element['#item']['url'] ? l(t('Link'), $element['#item']['url'], $element['#item']) : ''; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Theme function for 'label' text field formatter. |
---|
109 | */ |
---|
110 | function theme_link_formatter_label($element) { |
---|
111 | return $element['#item']['url'] ? l($element['#item']['label'], $element['#item']['url'], $element['#item']) : ''; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * Theme function for 'separate' text field formatter. |
---|
116 | */ |
---|
117 | function theme_link_formatter_separate($element) { |
---|
118 | $class = empty($element['#item']['attributes']['class']) ? '' : ' '. $element['#item']['attributes']['class']; |
---|
119 | unset($element['#item']['attributes']['class']); |
---|
120 | $title = empty($element['#item']['title']) ? '' : check_plain($element['#item']['title']); |
---|
121 | |
---|
122 | $output = ''; |
---|
123 | $output .= '<div class="link-item '. $class .'">'; |
---|
124 | if (!empty($title)) { |
---|
125 | $output .= '<div class="link-title">'. $title .'</div>'; |
---|
126 | } |
---|
127 | $output .= '<div class="link-url">'. l($element['#item']['display_url'], $element['#item']['url'], $element['#item']) .'</div>'; |
---|
128 | $output .= '</div>'; |
---|
129 | return $output; |
---|
130 | } |
---|