Révision 7fe061e8
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/ds/ds.api.php | ||
---|---|---|
202 | 202 |
'block' => 'user|menu', |
203 | 203 |
|
204 | 204 |
// block_render: block render type, only for block fields. |
205 |
// - DS_BLOCK_CONTENT : render through block template file.
|
|
205 |
// - DS_BLOCK_TEMPLATE : render through block template file.
|
|
206 | 206 |
// - DS_BLOCK_TITLE_CONTENT : render only title and content. |
207 | 207 |
// - DS_BLOCK_CONTENT : render only content. |
208 | 208 |
'block_render' => DS_BLOCK_CONTENT, |
drupal7/sites/all/modules/ds/ds.ds_fields_info.inc | ||
---|---|---|
24 | 24 |
'properties' => $field->properties, |
25 | 25 |
); |
26 | 26 |
if (!empty($field->ui_limit)) { |
27 |
$fields[$entity_type][$key]['ui_limit'] = explode("\n", $field->ui_limit); |
|
28 |
// Ensure that all strings are trimmed, eg. don't have |
|
29 |
// extra spaces, \r chars etc. |
|
30 |
foreach ($fields[$entity_type][$key]['ui_limit'] as $k => $v) { |
|
31 |
$fields[$entity_type][$key]['ui_limit'][$k] = trim($v); |
|
32 |
} |
|
27 |
$lines = explode("\n", $field->ui_limit); |
|
28 |
$fields[$entity_type][$key]['ui_limit'] = $lines; |
|
33 | 29 |
} |
34 | 30 |
} |
35 | 31 |
} |
... | ... | |
79 | 75 |
'properties' => array( |
80 | 76 |
'settings' => array( |
81 | 77 |
'link text' => array('type' => 'textfield'), |
78 |
'link class' => array('type' => 'textfield', 'description' => t('Put a class on the link. Eg: btn btn-default')), |
|
82 | 79 |
'wrapper' => array('type' => 'textfield', 'description' => t('Eg: h1, h2, p')), |
83 | 80 |
'class' => array('type' => 'textfield', 'description' => t('Put a class on the wrapper. Eg: block-title')), |
84 | 81 |
), |
85 |
'default' => array('link text' => 'Read more', 'wrapper' => '', 'class' => '', 'link' => 1), |
|
82 |
'default' => array('link text' => 'Read more', 'link class' => '', 'wrapper' => '', 'class' => '', 'link' => 1),
|
|
86 | 83 |
) |
87 | 84 |
); |
88 | 85 |
|
drupal7/sites/all/modules/ds/ds.info | ||
---|---|---|
13 | 13 |
files[] = tests/ds.forms.test |
14 | 14 |
configure = admin/structure/ds |
15 | 15 |
|
16 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
17 |
version = "7.x-2.11"
|
|
16 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
17 |
version = "7.x-2.12"
|
|
18 | 18 |
core = "7.x" |
19 | 19 |
project = "ds" |
20 |
datestamp = "1437725041"
|
|
20 |
datestamp = "1452953681"
|
|
21 | 21 |
|
drupal7/sites/all/modules/ds/ds.module | ||
---|---|---|
613 | 613 |
if ($vars['elements']['#entity_type'] == 'taxonomy_term') { |
614 | 614 |
$object = 'term'; |
615 | 615 |
} |
616 |
|
|
617 |
// Get entity id and bundle |
|
618 |
list($id,, $bundle) = entity_extract_ids($vars['elements']['#entity_type'], $vars[$object]); |
|
619 |
|
|
616 | 620 |
if (isset($vars[$object]->preprocess_fields)) { |
617 | 621 |
foreach ($vars[$object]->preprocess_fields as $field) { |
618 | 622 |
|
... | ... | |
657 | 661 |
$layout['layout'] = $layout['panels']['theme']; |
658 | 662 |
} |
659 | 663 |
|
660 |
$bundle = strtr($vars['elements']['#bundle'], '-', '_');
|
|
664 |
$bundle = strtr($bundle, '-', '_');
|
|
661 | 665 |
$vars['theme_hook_suggestions'][] = $layout['layout']; |
662 | 666 |
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type']; |
663 | 667 |
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '_' . $vars['elements']['#view_mode']; |
664 | 668 |
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '_' . $bundle; |
665 | 669 |
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '_' . $bundle . '_' . $vars['elements']['#view_mode']; |
670 |
$vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '__' . $id; |
|
666 | 671 |
} |
667 | 672 |
|
668 | 673 |
// If the layout has wrapper class lets add it. |
... | ... | |
766 | 771 |
} |
767 | 772 |
} |
768 | 773 |
|
774 |
// Set field weights for all fields, including pre-process. |
|
775 |
foreach($layout_render_array as $region => &$fields) { |
|
776 |
foreach ($fields as $field_key => &$field) { |
|
777 |
$field['#weight'] = $field_key; |
|
778 |
} |
|
779 |
} |
|
780 |
|
|
769 | 781 |
// Let other modules alter the ds array before creating the region variables. |
770 | 782 |
$context = array('entity' => isset($vars[$object]) ? $vars[$object] : (isset($vars['elements']['#' . $object]) ? $vars['elements']['#' . $object] : ''), 'entity_type' => $vars['elements']['#entity_type'], 'bundle' => $vars['elements']['#bundle'], 'view_mode' => $vars['elements']['#view_mode']); |
771 | 783 |
drupal_alter('ds_pre_render', $layout_render_array, $context, $vars); |
... | ... | |
1031 | 1043 |
else { |
1032 | 1044 |
$uri_info = entity_uri($field['entity_type'], $field['entity']); |
1033 | 1045 |
} |
1046 |
if (isset($settings['link class'])) { |
|
1047 |
$uri_info['options']['attributes']['class'][] = $settings['link class']; |
|
1048 |
} |
|
1034 | 1049 |
$output = l($output, $uri_info['path'], $uri_info['options']); |
1035 | 1050 |
if ($title_field) { |
1036 | 1051 |
$output = ds_edit_support('title', $output, $field); |
drupal7/sites/all/modules/ds/includes/ds.field_ui.inc | ||
---|---|---|
774 | 774 |
if (isset($form_state['values']['additional_settings']['preview']['info']['settings']['disable_css'])) { |
775 | 775 |
$record->settings['layout_disable_css'] = $form_state['values']['additional_settings']['preview']['info']['settings']['disable_css']; |
776 | 776 |
} |
777 |
else { |
|
778 |
$record->settings['layout_disable_css'] = FALSE; |
|
779 |
} |
|
777 | 780 |
|
778 | 781 |
$record->settings = $record->settings; |
779 | 782 |
|
... | ... | |
1759 | 1762 |
if ($classes_access) { |
1760 | 1763 |
$form['additional_settings']['ds_classes']['info'] = array('#markup' => l(t('Manage region and field CSS classes'), 'admin/structure/ds/classes', array('query' => drupal_get_destination()))); |
1761 | 1764 |
} |
1765 |
elseif (user_access('admin_classes')) { |
|
1766 |
$form['additional_settings']['ds_classes']['info'] = array('#markup' => l(t('To manage region and field CSS classes, the Display Suite UI module should be enabled.'), 'admin/modules', array('query' => drupal_get_destination(), 'fragment' => 'edit-modules-display-suite'))); |
|
1767 |
} |
|
1762 | 1768 |
} |
1763 | 1769 |
else { |
1764 | 1770 |
if ($classes_access) { |
... | ... | |
1894 | 1900 |
|
1895 | 1901 |
$suggestions_array[0] = $layout_string . '--' . $entity_type; |
1896 | 1902 |
$suggestions_array[2] = $layout_string . '--' . $entity_type . '-' . $bundle; |
1903 |
$suggestions_array[4] = $layout_string . '--' . $entity_type . '--{id}'; |
|
1897 | 1904 |
if (!isset($form_state['no_view_mode_suggestions']) && $view_mode != 'default') { |
1898 | 1905 |
$suggestions_array[1] = $layout_string . '--' . $entity_type . '-' . $view_mode; |
1899 | 1906 |
$suggestions_array[3] = $layout_string . '--' . $entity_type . '-' . $bundle . '-' . $view_mode; |
... | ... | |
1936 | 1943 |
if (isset($layout->settings['layout_disable_css'])) { |
1937 | 1944 |
$disable_css = $layout->settings['layout_disable_css']; |
1938 | 1945 |
} |
1939 |
if (isset($form_state['values']) && $disable_css !== $form_state['values']['additional_settings']['ds_layouts']['preview']['info']['settings']['disable_css']) { |
|
1940 |
$disable_css = $form_state['values']['additional_settings']['ds_layouts']['preview']['info']['settings']['disable_css']; |
|
1941 |
} |
|
1942 | 1946 |
|
1943 | 1947 |
$form['additional_settings']['ds_layouts']['preview']['info']['settings']['disable_css'] = array( |
1944 | 1948 |
'#type' => 'checkbox', |
drupal7/sites/all/modules/ds/modules/ds_devel/ds_devel.info | ||
---|---|---|
5 | 5 |
dependencies[] = ds |
6 | 6 |
dependencies[] = devel |
7 | 7 |
|
8 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
9 |
version = "7.x-2.11"
|
|
8 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
9 |
version = "7.x-2.12"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "ds" |
12 |
datestamp = "1437725041"
|
|
12 |
datestamp = "1452953681"
|
|
13 | 13 |
|
drupal7/sites/all/modules/ds/modules/ds_extras/ds_extras.info | ||
---|---|---|
5 | 5 |
dependencies[] = ds |
6 | 6 |
configure = admin/structure/ds/list/extras |
7 | 7 |
|
8 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
9 |
version = "7.x-2.11"
|
|
8 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
9 |
version = "7.x-2.12"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "ds" |
12 |
datestamp = "1437725041"
|
|
12 |
datestamp = "1452953681"
|
|
13 | 13 |
|
drupal7/sites/all/modules/ds/modules/ds_extras/ds_extras.module | ||
---|---|---|
236 | 236 |
} |
237 | 237 |
|
238 | 238 |
/** |
239 |
* Utility funtion to return the view mode for the current entity. |
|
239 |
* Utility function to return the view mode for the current entity.
|
|
240 | 240 |
* |
241 | 241 |
* The drupal_static is called in ds_extras_node_show to set |
242 | 242 |
* the current view mode. Through this technique, the hide page |
drupal7/sites/all/modules/ds/modules/ds_format/ds_format.info | ||
---|---|---|
5 | 5 |
dependencies[] = ds |
6 | 6 |
configure = admin/structure/ds/list/extras |
7 | 7 |
|
8 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
9 |
version = "7.x-2.11"
|
|
8 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
9 |
version = "7.x-2.12"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "ds" |
12 |
datestamp = "1437725041"
|
|
12 |
datestamp = "1452953681"
|
|
13 | 13 |
|
drupal7/sites/all/modules/ds/modules/ds_forms/ds_forms.info | ||
---|---|---|
4 | 4 |
package = "Display Suite" |
5 | 5 |
dependencies[] = ds |
6 | 6 |
|
7 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
8 |
version = "7.x-2.11"
|
|
7 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
8 |
version = "7.x-2.12"
|
|
9 | 9 |
core = "7.x" |
10 | 10 |
project = "ds" |
11 |
datestamp = "1437725041"
|
|
11 |
datestamp = "1452953681"
|
|
12 | 12 |
|
drupal7/sites/all/modules/ds/modules/ds_search/ds_search.info | ||
---|---|---|
5 | 5 |
dependencies[] = ds |
6 | 6 |
configure = admin/structure/ds/list/search |
7 | 7 |
|
8 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
9 |
version = "7.x-2.11"
|
|
8 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
9 |
version = "7.x-2.12"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "ds" |
12 |
datestamp = "1437725041"
|
|
12 |
datestamp = "1452953681"
|
|
13 | 13 |
|
drupal7/sites/all/modules/ds/modules/ds_ui/ds_ui.info | ||
---|---|---|
4 | 4 |
package = "Display Suite" |
5 | 5 |
dependencies[] = ds |
6 | 6 |
|
7 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
8 |
version = "7.x-2.11"
|
|
7 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
8 |
version = "7.x-2.12"
|
|
9 | 9 |
core = "7.x" |
10 | 10 |
project = "ds" |
11 |
datestamp = "1437725041"
|
|
11 |
datestamp = "1452953681"
|
|
12 | 12 |
|
drupal7/sites/all/modules/ds/modules/ds_ui/includes/ds.classes.inc | ||
---|---|---|
32 | 32 |
); |
33 | 33 |
} |
34 | 34 |
|
35 |
$form['ds_classes_fields'] = array( |
|
36 |
'#type' => 'textarea', |
|
37 |
'#title' => t('CSS classes for fields'), |
|
38 |
'#default_value' => variable_get('ds_classes_fields', ''), |
|
39 |
'#description' => t('Configure CSS classes which you can add to fields on the "manage display" screens. Add multiple CSS classes line by line.<br />If you want to have a friendly name, separate class and friendly name by |, but this is not required. eg:<br /><em>class_name_1<br />class_name_2|Friendly name<br />class_name_3</em>') |
|
40 |
); |
|
35 |
// Only show field classes if DS extras module is enabled |
|
36 |
if (module_exists('ds_extras')) { |
|
37 |
$form['ds_classes_fields'] = array( |
|
38 |
'#type' => 'textarea', |
|
39 |
'#title' => t('CSS classes for fields'), |
|
40 |
'#default_value' => variable_get('ds_classes_fields', ''), |
|
41 |
'#description' => t('Configure CSS classes which you can add to fields on the "manage display" screens. Add multiple CSS classes line by line.<br />If you want to have a friendly name, separate class and friendly name by |, but this is not required. eg:<br /><em>class_name_1<br />class_name_2|Friendly name<br />class_name_3</em>') |
|
42 |
); |
|
43 |
} |
|
41 | 44 |
|
42 | 45 |
return system_settings_form($form); |
43 | 46 |
} |
drupal7/sites/all/modules/ds/modules/ds_ui/includes/ds.fields.inc | ||
---|---|---|
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
/** |
117 |
* Shared form for all all fields.
|
|
117 |
* Shared form for all fields. |
|
118 | 118 |
*/ |
119 | 119 |
function ds_shared_form(&$form, $field) { |
120 | 120 |
ctools_include('export'); |
... | ... | |
176 | 176 |
'#description' => t('Limit this field on field UI per bundles and/or view modes. The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'. You may use * to select all, e.g article|*, *|full or *|*. Enter one value per line.'), |
177 | 177 |
'#type' => 'textarea', |
178 | 178 |
'#default_value' => $field->ui_limit, |
179 |
'#element_validate' => array('ds_ui_limit_validate'), |
|
179 | 180 |
); |
180 | 181 |
|
181 | 182 |
$form['submit'] = array( |
... | ... | |
191 | 192 |
return $field; |
192 | 193 |
} |
193 | 194 |
|
195 |
/** |
|
196 |
* Element validation function for ui limit field. |
|
197 |
*/ |
|
198 |
function ds_ui_limit_validate($element, &$form_state, $form) { |
|
199 |
// Get all enabled entity types. |
|
200 |
$entity_types = array_filter($form_state['values']['entities']); |
|
201 |
|
|
202 |
if (!empty($element['#value'])) { |
|
203 |
$ui_limit = $element['#value']; |
|
204 |
|
|
205 |
$lines = explode("\n", str_replace("\r", "\n", $ui_limit)); |
|
206 |
// Ensure that all strings are trimmed and filter out empty lines. |
|
207 |
$lines = array_filter(array_map('trim', $lines)); |
|
208 |
|
|
209 |
$error = FALSE; |
|
210 |
foreach ($lines as $line) { |
|
211 |
// Each line should hold a pipe character to seperate bundle and view_mode. |
|
212 |
if (strpos($line, '|') === FALSE) { |
|
213 |
$error = TRUE; |
|
214 |
continue; |
|
215 |
} |
|
216 |
|
|
217 |
list($bundle, $view_mode) = explode('|', $line); |
|
218 |
|
|
219 |
if (empty($bundle) || empty($view_mode) || !_ds_check_existing_ui_limit($entity_types, $bundle, $view_mode)) { |
|
220 |
$error = TRUE; |
|
221 |
} |
|
222 |
} |
|
223 |
if ($error) { |
|
224 |
form_error($element, t('The values are in the form of $bundle|$view_mode, where $view_mode may be either a view mode set to use custom settings, or \'default\'.')); |
|
225 |
} |
|
226 |
|
|
227 |
// Set trimmed and validated entry back as value. |
|
228 |
form_set_value($element, implode("\n", $lines), $form_state); |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
/** |
|
233 |
* Helper function to check if bundle + view_mode combination exists. |
|
234 |
*/ |
|
235 |
function _ds_check_existing_ui_limit($entity_types, $bundle, $view_mode) { |
|
236 |
$exists = FALSE; |
|
237 |
foreach ($entity_types as $entity_type) { |
|
238 |
$info = entity_get_info($entity_type); |
|
239 |
|
|
240 |
// Combine allowed bundles and entity specific ones. |
|
241 |
$bundle_allowed = array('*'); |
|
242 |
$bundles = array_merge($bundle_allowed, array_keys($info['bundles'])); |
|
243 |
|
|
244 |
// Combine allowed view_modes and entity specific ones. |
|
245 |
$view_mode_allowed = array('*', 'default'); |
|
246 |
$view_modes = array_merge($view_mode_allowed, array_keys($info['view modes'])); |
|
247 |
|
|
248 |
if (in_array($bundle, $bundles) && |
|
249 |
in_array($view_mode, $view_modes)) { |
|
250 |
|
|
251 |
$exists = TRUE; |
|
252 |
break; |
|
253 |
} |
|
254 |
} |
|
255 |
if (!$exists) { |
|
256 |
drupal_set_message(t('Incorrect field limit combination: @bundle|@view_mode', array('@bundle' => $bundle, '@view_mode' => $view_mode)), 'error'); |
|
257 |
} |
|
258 |
|
|
259 |
return $exists; |
|
260 |
} |
|
261 |
|
|
194 | 262 |
/** |
195 | 263 |
* Return whether a field machine name is unique. |
196 | 264 |
*/ |
... | ... | |
209 | 277 |
$field->properties = array(); |
210 | 278 |
$field->field = $form_state['values']['field']; |
211 | 279 |
$field->label = $form_state['values']['name']; |
212 |
$field->ui_limit = str_replace("\r", '', $form_state['values']['ui_limit']);
|
|
280 |
$field->ui_limit = $form_state['values']['ui_limit'];
|
|
213 | 281 |
|
214 | 282 |
$entities = $form_state['values']['entities']; |
215 | 283 |
foreach ($entities as $key => $value) { |
drupal7/sites/all/modules/ds/tests/ds_exportables_test/ds_exportables_test.info | ||
---|---|---|
4 | 4 |
core = 7.x |
5 | 5 |
hidden = TRUE |
6 | 6 |
|
7 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
8 |
version = "7.x-2.11"
|
|
7 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
8 |
version = "7.x-2.12"
|
|
9 | 9 |
core = "7.x" |
10 | 10 |
project = "ds" |
11 |
datestamp = "1437725041"
|
|
11 |
datestamp = "1452953681"
|
|
12 | 12 |
|
drupal7/sites/all/modules/ds/tests/ds_test.info | ||
---|---|---|
5 | 5 |
dependencies[] = ds_extras |
6 | 6 |
hidden = TRUE |
7 | 7 |
|
8 |
; Information added by Drupal.org packaging script on 2015-07-24
|
|
9 |
version = "7.x-2.11"
|
|
8 |
; Information added by Drupal.org packaging script on 2016-01-16
|
|
9 |
version = "7.x-2.12"
|
|
10 | 10 |
core = "7.x" |
11 | 11 |
project = "ds" |
12 |
datestamp = "1437725041"
|
|
12 |
datestamp = "1452953681"
|
|
13 | 13 |
|
drupal7/sites/all/modules/link/README.txt | ||
---|---|---|
1 |
Module description |
|
2 |
------------------ |
|
3 |
The link module can be count to the top 50 modules in Drupal installations and provides a standard custom content field for links. With this module links can be added easily to any content types and profiles and include advanced validating and different ways of storing internal or external links and URLs. It also supports additional link text title, site wide tokens for titles and title attributes, target attributes, css class attribution, static repeating values, input conversion, and many more. |
|
4 |
|
|
5 |
Requirements / Dependencies |
|
6 |
--------------------------- |
|
7 |
1. Drupal 6: Custom content module (CCK) |
|
8 |
2. Drupal 7: Fields API is provided already by core [no dependencies]. |
|
9 |
3. Drupal 8: Link module is in core now. No module installation needed. Yay! Don't forget to activate it. It's deactivated by default. |
|
10 |
|
|
11 |
INFO Since some misleading user reports we need to clarify here - Link module is NOT about to add links to any menus or the navigation nor primary/secondary menu. This can be done with default menu module (part of Drupal core). The Link module provides an additional custom field for storing and validating links to be added with any content type, which means another input block additional to your text-body, title, image and any other input you can make on new content creation. |
|
12 |
|
|
13 |
Installation |
|
14 |
------------ |
|
15 |
1. Drop the entire link module directory into your 'sites/all/modules' folder |
|
16 |
2. Enable the module from the Administration area modules page (admin/build/modules) |
|
17 |
3. Create or Edit a content-type and add a new field of type link (admin/content/types in D6, admin/structure/types in D7) |
|
18 |
|
|
19 |
Configuration |
|
20 |
------------- |
|
21 |
Configuration is only slightly more complicated than a text field. Link text titles for URLs can be made required, set as instead of URL, optional (default), or left out entirely. If no link text title is provided, the trimmed version of the complete URL will be displayed. The target attribute should be set to "_blank", "top", or left out completely (checkboxes provide info). The rel=nofollow attribute prevents the link from being followed by certain search engines. More info at Wikipedia (http://en.wikipedia.org/wiki/Spam_in_blogs#rel.3D.22nofollow.22). |
|
22 |
|
|
23 |
Example |
|
24 |
------- |
|
25 |
If you were to create a field named 'My New Link', the default display of the link would be: <em><div class="field_my_new_link" target="[target_value]"><a href="[URL]">[Title]</a></div></em> where items between [] characters would be customized based on the user input. |
|
26 |
|
|
27 |
The link module supports both, internal and external URLs. URLs are validated on input. Here are some examples of data input and the default view of a link: http://drupal.org results in http://drupal.org, but drupal.org results in http://drupal.org, while <front> will convert into http://drupal.org and node/74971 into http://drupal.org/project/link |
|
28 |
|
|
29 |
Anchors and query strings may also be used in any of these cases, including: node/74971/edit?destination=node/74972<front>#pager |
|
30 |
|
|
31 |
Theming and Output |
|
32 |
------------------ |
|
33 |
Since link module is mainly a data storage field in a modular framework, the theming and output is up to the site builder and other additional modules. There are many modules in the Drupal repository, which control the output of fields perfectly and can handle rules, user actions, markup dependencies, and can vary the output under many different conditions, with much more efficience and flexibility for different scenarios. Please check out modules like views, display suite, panels, etc for such needs. |
drupal7/sites/all/modules/link/link.info | ||
---|---|---|
12 | 12 |
files[] = tests/link.crud.test |
13 | 13 |
files[] = tests/link.crud_browser.test |
14 | 14 |
files[] = tests/link.token.test |
15 |
files[] = tests/link.entity_token.test |
|
15 | 16 |
files[] = tests/link.validate.test |
16 | 17 |
|
17 | 18 |
; Views Handlers |
18 | 19 |
files[] = views/link_views_handler_argument_target.inc |
19 | 20 |
files[] = views/link_views_handler_filter_protocol.inc |
20 | 21 |
|
21 |
; Information added by Drupal.org packaging script on 2014-10-21
|
|
22 |
version = "7.x-1.3"
|
|
22 |
; Information added by Drupal.org packaging script on 2016-01-15
|
|
23 |
version = "7.x-1.4"
|
|
23 | 24 |
core = "7.x" |
24 | 25 |
project = "link" |
25 |
datestamp = "1413924830"
|
|
26 |
datestamp = "1452830642"
|
|
26 | 27 |
|
drupal7/sites/all/modules/link/link.module | ||
---|---|---|
207 | 207 |
$form['attributes']['class'] = array( |
208 | 208 |
'#type' => 'textfield', |
209 | 209 |
'#title' => t('Additional CSS Class'), |
210 |
'#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces.'), |
|
210 |
'#description' => t('When output, this link will have this class attribute. Multiple classes should be separated by spaces. Only alphanumeric characters and hyphens are allowed'),
|
|
211 | 211 |
'#default_value' => empty($instance['settings']['attributes']['class']) ? '' : $instance['settings']['attributes']['class'], |
212 | 212 |
); |
213 | 213 |
$form['attributes']['configurable_title'] = array( |
... | ... | |
291 | 291 |
*/ |
292 | 292 |
function link_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { |
293 | 293 |
foreach ($items as $delta => $value) { |
294 |
_link_process($items[$delta], $delta, $field, $entity); |
|
294 |
_link_process($items[$delta], $delta, $field, $entity, $instance);
|
|
295 | 295 |
} |
296 | 296 |
} |
297 | 297 |
|
... | ... | |
300 | 300 |
*/ |
301 | 301 |
function link_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { |
302 | 302 |
foreach ($items as $delta => $value) { |
303 |
_link_process($items[$delta], $delta, $field, $entity); |
|
303 |
_link_process($items[$delta], $delta, $field, $entity, $instance);
|
|
304 | 304 |
} |
305 | 305 |
} |
306 | 306 |
|
... | ... | |
371 | 371 |
|
372 | 372 |
/** |
373 | 373 |
* Prepares the item attributes and url for storage. |
374 |
* |
|
375 |
* @param $item |
|
376 |
* Link field values. |
|
377 |
* |
|
378 |
* @param $delta |
|
379 |
* The sequence number for current values. |
|
380 |
* |
|
381 |
* @param $field |
|
382 |
* The field structure array. |
|
383 |
* |
|
384 |
* @param $entity |
|
385 |
* Entity object. |
|
386 |
* |
|
387 |
* @param $instance |
|
388 |
* The instance structure for $field on $entity's bundle. |
|
389 |
* |
|
374 | 390 |
*/ |
375 |
function _link_process(&$item, $delta, $field, $entity) { |
|
391 |
function _link_process(&$item, $delta, $field, $entity, $instance) {
|
|
376 | 392 |
// Trim whitespace from URL. |
377 | 393 |
if (!empty($item['url'])) { |
378 | 394 |
$item['url'] = trim($item['url']); |
... | ... | |
391 | 407 |
|
392 | 408 |
// Don't save an invalid default value (e.g. 'http://'). |
393 | 409 |
if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url']) && is_object($entity)) { |
394 |
if (!link_validate_url($item['url'])) { |
|
410 |
$langcode = !empty($entity) ? field_language($instance['entity_type'], $entity, $instance['field_name']) : LANGUAGE_NONE; |
|
411 |
if (!link_validate_url($item['url'], $langcode)) { |
|
395 | 412 |
unset($item['url']); |
396 | 413 |
} |
397 | 414 |
} |
... | ... | |
403 | 420 |
function _link_validate(&$item, $delta, $field, $entity, $instance, $langcode, &$optional_field_found, &$errors) { |
404 | 421 |
if ($item['url'] && !(isset($instance['default_value'][$delta]['url']) && $item['url'] === $instance['default_value'][$delta]['url'] && !$instance['required'])) { |
405 | 422 |
// Validate the link. |
406 |
if (link_validate_url(trim($item['url'])) == FALSE) {
|
|
423 |
if (!link_validate_url(trim($item['url']), $langcode)) {
|
|
407 | 424 |
$errors[$field['field_name']][$langcode][$delta][] = array( |
408 | 425 |
'error' => 'link_required', |
409 | 426 |
'message' => t('The value %value provided for %field is not a valid URL.', array( |
... | ... | |
474 | 491 |
$entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type |
475 | 492 |
); |
476 | 493 |
if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) { |
477 |
global $user; |
|
478 |
// Load the entity if necessary for entities in views. |
|
479 |
if (isset($entity->{$property_id})) { |
|
480 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
481 |
$entity_loaded = array_pop($entity_loaded); |
|
482 |
} |
|
483 |
else { |
|
484 |
$entity_loaded = $entity; |
|
494 |
$text_tokens = token_scan($item['url']); |
|
495 |
if (!empty($text_tokens)) { |
|
496 |
// Load the entity if necessary for entities in views. |
|
497 |
if (isset($entity->{$property_id})) { |
|
498 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
499 |
$entity_loaded = array_pop($entity_loaded); |
|
500 |
} |
|
501 |
else { |
|
502 |
$entity_loaded = $entity; |
|
503 |
} |
|
504 |
$item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded)); |
|
485 | 505 |
} |
486 |
$item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded)); |
|
487 | 506 |
} |
488 | 507 |
|
489 |
$type = link_validate_url($item['url']);
|
|
508 |
$type = link_url_type($item['url']);
|
|
490 | 509 |
// If the type of the URL cannot be determined and URL validation is disabled, |
491 | 510 |
// then assume LINK_EXTERNAL for later processing. |
492 | 511 |
if ($type == FALSE && $instance['settings']['validate_url'] === 0) { |
... | ... | |
496 | 515 |
$url_parts = _link_parse_url($url); |
497 | 516 |
|
498 | 517 |
if (!empty($url_parts['url'])) { |
499 |
$item['url'] = $url_parts['url']; |
|
500 |
$item += array( |
|
501 |
'query' => isset($url_parts['query']) ? $url_parts['query'] : NULL, |
|
518 |
$item['url'] = url($url_parts['url'], |
|
519 |
array('query' => isset($url_parts['query']) ? $url_parts['query'] : NULL, |
|
502 | 520 |
'fragment' => isset($url_parts['fragment']) ? $url_parts['fragment'] : NULL, |
503 | 521 |
'absolute' => !empty($instance['settings']['absolute_url']), |
504 | 522 |
'html' => TRUE, |
523 |
) |
|
505 | 524 |
); |
506 | 525 |
} |
507 | 526 |
|
... | ... | |
541 | 560 |
|
542 | 561 |
// Replace title tokens. |
543 | 562 |
if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) { |
544 |
// Load the entity if necessary for entities in views. |
|
545 |
if (isset($entity->{$property_id})) { |
|
546 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
547 |
$entity_loaded = array_pop($entity_loaded); |
|
548 |
} |
|
549 |
else { |
|
550 |
$entity_loaded = $entity; |
|
563 |
$text_tokens = token_scan($title); |
|
564 |
if (!empty($text_tokens)) { |
|
565 |
// Load the entity if necessary for entities in views. |
|
566 |
if (isset($entity->{$property_id})) { |
|
567 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
568 |
$entity_loaded = array_pop($entity_loaded); |
|
569 |
} |
|
570 |
else { |
|
571 |
$entity_loaded = $entity; |
|
572 |
} |
|
573 |
$title = token_replace($title, array($entity_token_type => $entity_loaded)); |
|
551 | 574 |
} |
552 |
$title = token_replace($title, array($entity_token_type => $entity_loaded)); |
|
553 | 575 |
$title = filter_xss($title, array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); |
554 | 576 |
$item['html'] = TRUE; |
555 | 577 |
} |
... | ... | |
599 | 621 |
|
600 | 622 |
// Handle "title" link attribute. |
601 | 623 |
if (!empty($item['attributes']['title']) && module_exists('token')) { |
602 |
// Load the entity (necessary for entities in views). |
|
603 |
if (isset($entity->{$property_id})) { |
|
604 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
605 |
$entity_loaded = array_pop($entity_loaded); |
|
606 |
} |
|
607 |
else { |
|
608 |
$entity_loaded = $entity; |
|
624 |
$text_tokens = token_scan($item['attributes']['title']); |
|
625 |
if (!empty($text_tokens)) { |
|
626 |
// Load the entity (necessary for entities in views). |
|
627 |
if (isset($entity->{$property_id})) { |
|
628 |
$entity_loaded = entity_load($entity_type, array($entity->{$property_id})); |
|
629 |
$entity_loaded = array_pop($entity_loaded); |
|
630 |
} |
|
631 |
else { |
|
632 |
$entity_loaded = $entity; |
|
633 |
} |
|
634 |
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded)); |
|
609 | 635 |
} |
610 |
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded)); |
|
611 | 636 |
$item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u')); |
612 | 637 |
} |
613 | 638 |
// Handle attribute classes. |
614 | 639 |
if (!empty($item['attributes']['class'])) { |
615 | 640 |
$classes = explode(' ', $item['attributes']['class']); |
616 | 641 |
foreach ($classes as &$class) { |
617 |
$class = drupal_html_class($class);
|
|
642 |
$class = drupal_clean_css_identifier($class);
|
|
618 | 643 |
} |
619 | 644 |
$item['attributes']['class'] = implode(' ', $classes); |
620 | 645 |
} |
... | ... | |
660 | 685 |
* Replaces the PHP parse_str() function. |
661 | 686 |
* |
662 | 687 |
* Because parse_str replaces the following characters in query parameters name |
663 |
* in order to maintain compability with deprecated register_globals directive: |
|
688 |
* in order to maintain compatibility with deprecated register_globals directive:
|
|
664 | 689 |
* |
665 | 690 |
* - chr(32) ( ) (space) |
666 | 691 |
* - chr(46) (.) (dot) |
... | ... | |
700 | 725 |
'link_formatter_link_plain' => array( |
701 | 726 |
'variables' => array('element' => NULL, 'field' => NULL), |
702 | 727 |
), |
728 |
'link_formatter_link_host' => array( |
|
729 |
'variables' => array('element' => NULL), |
|
730 |
), |
|
703 | 731 |
'link_formatter_link_absolute' => array( |
704 | 732 |
'variables' => array('element' => NULL, 'field' => NULL), |
705 | 733 |
), |
... | ... | |
859 | 887 |
); |
860 | 888 |
} |
861 | 889 |
|
862 |
// If the title field is avaliable or there are field accepts multiple values
|
|
890 |
// If the title field is available or there are field accepts multiple values
|
|
863 | 891 |
// then allow the individual field items display the required asterisk if needed. |
864 | 892 |
if (isset($element['title']) || isset($element['_weight'])) { |
865 | 893 |
// To prevent an extra required indicator, disable the required flag on the |
... | ... | |
885 | 913 |
'field types' => array('link_field'), |
886 | 914 |
'multiple values' => FIELD_BEHAVIOR_DEFAULT, |
887 | 915 |
), |
916 |
'link_host' => array( |
|
917 |
'label' => t('Host, as plain text'), |
|
918 |
'field types' => array('link_field'), |
|
919 |
'multiple values' => FIELD_BEHAVIOR_DEFAULT, |
|
920 |
), |
|
888 | 921 |
'link_url' => array( |
889 | 922 |
'label' => t('URL, as link'), |
890 | 923 |
'field types' => array('link_field'), |
... | ... | |
1015 | 1048 |
return empty($vars['element']['url']) ? check_plain($vars['element']['title']) : url($vars['element']['url'], $link_options); |
1016 | 1049 |
} |
1017 | 1050 |
|
1051 |
/** |
|
1052 |
* Theme function for 'host' text field formatter. |
|
1053 |
*/ |
|
1054 |
function theme_link_formatter_link_host($vars) { |
|
1055 |
$host = @parse_url($vars['element']['url']); |
|
1056 |
return isset($host['host']) ? check_plain($host['host']) : ''; |
|
1057 |
} |
|
1058 |
|
|
1018 | 1059 |
/** |
1019 | 1060 |
* Formats a link as an absolute URL. |
1020 | 1061 |
*/ |
... | ... | |
1142 | 1183 |
|
1143 | 1184 |
/** |
1144 | 1185 |
* Forms a valid URL if possible from an entered address. |
1145 |
*
|
|
1186 |
* |
|
1146 | 1187 |
* Trims whitespace and automatically adds an http:// to addresses without a |
1147 | 1188 |
* protocol specified |
1148 | 1189 |
* |
... | ... | |
1153 | 1194 |
*/ |
1154 | 1195 |
function link_cleanup_url($url, $protocol = 'http') { |
1155 | 1196 |
$url = trim($url); |
1156 |
$type = link_validate_url($url);
|
|
1197 |
$type = link_url_type($url);
|
|
1157 | 1198 |
|
1158 | 1199 |
if ($type === LINK_EXTERNAL) { |
1159 | 1200 |
// Check if there is no protocol specified. |
... | ... | |
1173 | 1214 |
|
1174 | 1215 |
/** |
1175 | 1216 |
* Validates a URL. |
1176 |
* |
|
1217 |
* |
|
1218 |
* @param $text |
|
1219 |
* Url to be validated. |
|
1220 |
* |
|
1221 |
* @param $langcode |
|
1222 |
* An optional language code to look up the path in. |
|
1223 |
* |
|
1224 |
* @return boolean |
|
1225 |
* True if a valid link, FALSE otherwise. |
|
1226 |
*/ |
|
1227 |
function link_validate_url($text, $langcode = NULL) { |
|
1228 |
$text = link_cleanup_url($text); |
|
1229 |
$type = link_url_type($text); |
|
1230 |
|
|
1231 |
if ($type && ($type == LINK_INTERNAL || $type == LINK_EXTERNAL)) { |
|
1232 |
$flag = valid_url($text, TRUE); |
|
1233 |
if (!$flag) { |
|
1234 |
$normal_path = drupal_get_normal_path($text, $langcode); |
|
1235 |
$parsed_link = parse_url($normal_path, PHP_URL_PATH); |
|
1236 |
if ($normal_path != $parsed_link) { |
|
1237 |
$normal_path = $parsed_link; |
|
1238 |
} |
|
1239 |
$flag = drupal_valid_path($normal_path); |
|
1240 |
} |
|
1241 |
if (!$flag) { |
|
1242 |
$flag = file_exists($normal_path); |
|
1243 |
} |
|
1244 |
if (!$flag) { |
|
1245 |
$uri = file_build_uri($normal_path); |
|
1246 |
$flag = file_exists($uri); |
|
1247 |
} |
|
1248 |
} |
|
1249 |
else { |
|
1250 |
$flag = (bool) $type; |
|
1251 |
} |
|
1252 |
|
|
1253 |
return $flag; |
|
1254 |
} |
|
1255 |
|
|
1256 |
/** |
|
1257 |
* Type check a URL. |
|
1258 |
* |
|
1177 | 1259 |
* Accepts all URLs following RFC 1738 standard for URL formation and all e-mail |
1178 | 1260 |
* addresses following the RFC 2368 standard for mailto address formation. |
1179 | 1261 |
* |
1180 | 1262 |
* @param string $text |
1181 |
* Url to be validated.
|
|
1263 |
* Url to be checked.
|
|
1182 | 1264 |
* |
1183 | 1265 |
* @return mixed |
1184 | 1266 |
* Returns boolean FALSE if the URL is not valid. On success, returns one of |
1185 | 1267 |
* the LINK_(linktype) constants. |
1186 | 1268 |
*/ |
1187 |
function link_validate_url($text) {
|
|
1269 |
function link_url_type($text) {
|
|
1188 | 1270 |
// @TODO Complete letters. |
1189 | 1271 |
$LINK_ICHARS_DOMAIN = (string) html_entity_decode(implode("", array( |
1190 | 1272 |
"æ", // æ |
drupal7/sites/all/modules/link/tests/link.attribute.test | ||
---|---|---|
254 | 254 |
} |
255 | 255 |
} |
256 | 256 |
|
257 |
function testFormatterHost() { |
|
258 |
$content_type_friendly = $this->randomName(20); |
|
259 |
$content_type_machine = strtolower($this->randomName(10)); |
|
260 |
|
|
261 |
$this->drupalCreateContentType(array( |
|
262 |
'type' => $content_type_machine, |
|
263 |
'name' => $content_type_friendly, |
|
264 |
)); |
|
265 |
|
|
266 |
|
|
267 |
// Now add a singleton field. |
|
268 |
$single_field_name_friendly = $this->randomName(20); |
|
269 |
$single_field_name_machine = strtolower($this->randomName(10)); |
|
270 |
//$single_field_name = 'field_'. $single_field_name_machine; |
|
271 |
$this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine); |
|
272 |
|
|
273 |
// Okay, now we want to make sure this display is changed: |
|
274 |
$this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display'); |
|
275 |
$edit = array( |
|
276 |
'fields[field_'. $single_field_name_machine .'][label]' => 'above', |
|
277 |
'fields[field_'. $single_field_name_machine .'][type]' => 'link_host', |
|
278 |
); |
|
279 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
280 |
|
|
281 |
$this->createNodeTypeUser($content_type_machine); |
|
282 |
|
|
283 |
$link_text = 'Display'; |
|
284 |
$link_url = 'http://www.example.com/'; |
|
285 |
$this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url); |
|
286 |
|
|
287 |
$this->assertText('www.example.com'); |
|
288 |
$this->assertNoText($link_text); |
|
289 |
$this->assertNoLinkByHref($link_url); |
|
290 |
} |
|
291 |
|
|
257 | 292 |
function testFormatterURL() { |
258 | 293 |
$content_type_friendly = $this->randomName(20); |
259 | 294 |
$content_type_machine = strtolower($this->randomName(10)); |
drupal7/sites/all/modules/link/tests/link.crud_browser.test | ||
---|---|---|
312 | 312 |
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.'); |
313 | 313 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
314 | 314 |
} |
315 |
|
|
316 |
/** |
|
317 |
* If we're creating a new field and just hit 'save' on the default options, we want to make |
|
318 |
* sure they are set to the expected results. |
|
319 |
*/ |
|
320 |
function testCRUDCreateFieldWithClass() { |
|
321 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
322 |
$this->drupalLogin($this->web_user); |
|
323 |
|
|
324 |
// create field |
|
325 |
$name = strtolower($this->randomName()); |
|
326 |
$edit = array( |
|
327 |
'fields[_add_new_field][label]' => $name, |
|
328 |
'fields[_add_new_field][field_name]' => $name, |
|
329 |
'fields[_add_new_field][type]' => 'link_field', |
|
330 |
'fields[_add_new_field][widget_type]' => 'link_field', |
|
331 |
); |
|
332 |
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save')); |
|
333 |
|
|
334 |
$this->drupalPost(NULL, array(), t('Save field settings')); |
|
335 |
$link_class_name = 'basic-link-' . strtolower($this->randomName()); |
|
336 |
$edit = array( |
|
337 |
'instance[settings][attributes][class]' => $link_class_name, |
|
338 |
); |
|
339 |
$this->drupalPost(NULL, $edit, t('Save settings')); |
|
340 |
|
|
341 |
// Is field created? |
|
342 |
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); |
|
343 |
node_types_rebuild(); |
|
344 |
menu_rebuild(); |
|
345 |
|
|
346 |
_field_info_collate_fields(TRUE); |
|
347 |
$instances = field_info_instances('node', 'page'); |
|
348 |
|
|
349 |
$instance = $instances['field_' . $name]; |
|
350 |
$this->assertFalse($instance['required'], 'Make sure field is not required.'); |
|
351 |
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.'); |
|
352 |
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.'); |
|
353 |
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.'); |
|
354 |
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.'); |
|
355 |
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"'); |
|
356 |
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); |
|
357 |
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.'); |
|
358 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
|
359 |
|
|
360 |
// Now, let's create a node with this field and make sure the link shows up: |
|
361 |
// create page form |
|
362 |
$field_name = 'field_' . $name; |
|
363 |
$this->drupalGet('node/add/page'); |
|
364 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
|
365 |
|
|
366 |
$input = array( |
|
367 |
'title' => 'This & That', |
|
368 |
'href' => 'http://www.example.com/', |
|
369 |
); |
|
370 |
|
|
371 |
$edit = array( |
|
372 |
'title' => $field_name, |
|
373 |
$field_name . '[und][0][title]' => $input['title'], |
|
374 |
$field_name . '[und][0][url]' => $input['href'], |
|
375 |
); |
|
376 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
377 |
|
|
378 |
$url = $this->getUrl(); |
|
379 |
|
|
380 |
// change to anonymous user |
|
381 |
$this->drupalLogout(); |
|
382 |
$this->drupalGet($url); |
|
383 |
|
|
384 |
$this->assertRaw('This & That'); |
|
385 |
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page."); |
|
386 |
} |
|
387 |
|
|
388 |
/** |
|
389 |
* If we're creating a new field and just hit 'save' on the default options, we want to make |
|
390 |
* sure they are set to the expected results. |
|
391 |
*/ |
|
392 |
function testCRUDCreateFieldWithTwoClasses() { |
|
393 |
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); |
|
394 |
$this->drupalLogin($this->web_user); |
|
395 |
|
|
396 |
// create field |
|
397 |
$name = strtolower($this->randomName()); |
|
398 |
$edit = array( |
|
399 |
'fields[_add_new_field][label]' => $name, |
|
400 |
'fields[_add_new_field][field_name]' => $name, |
|
401 |
'fields[_add_new_field][type]' => 'link_field', |
|
402 |
'fields[_add_new_field][widget_type]' => 'link_field', |
|
403 |
); |
|
404 |
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save')); |
|
405 |
|
|
406 |
$this->drupalPost(NULL, array(), t('Save field settings')); |
|
407 |
$link_class_name = 'basic-link ' . strtoupper($this->randomName()); |
|
408 |
$edit = array( |
|
409 |
'instance[settings][attributes][class]' => $link_class_name, |
|
410 |
); |
|
411 |
$this->drupalPost(NULL, $edit, t('Save settings')); |
|
412 |
|
|
413 |
// Is field created? |
|
414 |
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added'); |
|
415 |
node_types_rebuild(); |
|
416 |
menu_rebuild(); |
|
417 |
|
|
418 |
_field_info_collate_fields(TRUE); |
|
419 |
$instances = field_info_instances('node', 'page'); |
|
420 |
|
|
421 |
$instance = $instances['field_' . $name]; |
|
422 |
$this->assertFalse($instance['required'], 'Make sure field is not required.'); |
|
423 |
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.'); |
|
424 |
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.'); |
|
425 |
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.'); |
|
426 |
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.'); |
|
427 |
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"'); |
|
428 |
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.'); |
|
429 |
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.'); |
|
430 |
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.'); |
|
431 |
|
|
432 |
// Now, let's create a node with this field and make sure the link shows up: |
|
433 |
// create page form |
|
434 |
$field_name = 'field_' . $name; |
|
435 |
$this->drupalGet('node/add/page'); |
|
436 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
|
437 |
|
|
438 |
$input = array( |
|
439 |
'title' => 'This & That', |
|
440 |
'href' => 'http://www.example.com/', |
|
441 |
); |
|
442 |
|
|
443 |
$edit = array( |
|
444 |
'title' => $field_name, |
|
445 |
$field_name . '[und][0][title]' => $input['title'], |
|
446 |
$field_name . '[und][0][url]' => $input['href'], |
|
447 |
); |
|
448 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
449 |
|
|
450 |
$url = $this->getUrl(); |
|
451 |
|
|
452 |
// change to anonymous user |
|
453 |
$this->drupalLogout(); |
|
454 |
$this->drupalGet($url); |
|
455 |
|
|
456 |
$this->assertRaw('This & That'); |
|
457 |
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page."); |
|
458 |
} |
|
315 | 459 |
} |
drupal7/sites/all/modules/link/tests/link.entity_token.test | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Contains simpletests making sure entity_token integration works. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Testing that tokens can be used in link titles |
|
10 |
*/ |
|
11 |
class LinkEntityTokenTest extends LinkBaseTestClass { |
|
12 |
|
|
13 |
public static function getInfo() { |
|
14 |
return array( |
|
15 |
'name' => 'Link entity tokens test', |
|
16 |
'description' => 'Tests that a link field appears properly in entity tokens', |
|
17 |
'group' => 'Link', |
|
18 |
'dependencies' => array('token', 'entity', 'entity_token'), |
|
19 |
); |
|
20 |
} |
|
21 |
|
|
22 |
function setUp($modules = array()) { |
|
23 |
parent::setUp(array('token', 'entity', 'entity_token')); |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Creates a link field, fills it, then uses a loaded node to test tokens. |
|
28 |
*/ |
|
29 |
function testFieldTokenNodeLoaded() { |
|
30 |
// create field |
|
31 |
$settings = array( |
|
32 |
'instance[settings][enable_tokens]' => 0, |
|
33 |
); |
|
34 |
$field_name = $this->createLinkField('page', |
|
35 |
$settings); |
|
36 |
|
|
37 |
// create page form |
|
38 |
$this->drupalGet('node/add/page'); |
|
39 |
//$field_name = 'field_' . $name; |
|
40 |
$this->assertField($field_name . '[und][0][title]', 'Title found'); |
|
41 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
|
42 |
|
|
43 |
$token_url_tests = array( |
|
44 |
1 => array( |
|
45 |
'href' => 'http://example.com/' . $this->randomName(), |
|
46 |
'label' => $this->randomName(), |
|
47 |
), |
|
48 |
2 => array( |
|
49 |
'href' => 'http://example.com/' . $this->randomName() . '?property=value', |
|
50 |
'label' => $this->randomName(), |
|
51 |
), |
|
52 |
3 => array( |
|
53 |
'href' => 'http://example.com/' . $this->randomName() . '#position', |
|
54 |
'label' => $this->randomName(), |
|
55 |
), |
|
56 |
4 => array( |
|
57 |
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2', |
|
58 |
'label' => $this->randomName(), |
|
59 |
), |
|
60 |
); |
|
61 |
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>'); |
|
62 |
|
|
63 |
foreach ($token_url_tests as &$input) { |
|
64 |
$this->drupalGet('node/add/page'); |
|
65 |
|
|
66 |
$edit = array( |
|
67 |
'title' => $input['label'], |
|
68 |
$field_name . '[und][0][title]' => $input['label'], |
|
69 |
$field_name . '[und][0][url]' => $input['href'], |
|
70 |
); |
|
71 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
72 |
$url = $this->getUrl(); |
|
73 |
$input['url'] = $url; |
|
74 |
} |
|
75 |
|
|
76 |
// change to anonymous user |
|
77 |
$this->drupalLogout(); |
|
78 |
|
|
79 |
foreach ($token_url_tests as $index => $input2) { |
|
80 |
$node = node_load($index); |
|
81 |
$this->assertNotEqual(NULL, $node, "Do we have a node?"); |
|
82 |
$this->assertEqual($node->nid, $index, "Test that we have a node."); |
|
83 |
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; |
|
84 |
$assert_data = token_replace($token_name, |
|
85 |
array('node' => $node)); |
|
86 |
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Creates a link field, fills it, then uses a loaded and node_view'd node to test tokens. |
|
92 |
*/ |
|
93 |
function testFieldTokenNodeViewed() { |
|
94 |
// create field |
|
95 |
$settings = array( |
|
96 |
'instance[settings][enable_tokens]' => 0, |
|
97 |
); |
|
98 |
$field_name = $this->createLinkField('page', |
|
99 |
$settings); |
|
100 |
|
|
101 |
// create page form |
|
102 |
$this->drupalGet('node/add/page'); |
|
103 |
//$field_name = 'field_' . $name; |
|
104 |
$this->assertField($field_name . '[und][0][title]', 'Title found'); |
|
105 |
$this->assertField($field_name . '[und][0][url]', 'URL found'); |
|
106 |
|
|
107 |
$token_url_tests = array( |
|
108 |
1 => array( |
|
109 |
'href' => 'http://example.com/' . $this->randomName(), |
|
110 |
'label' => $this->randomName(), |
|
111 |
), |
|
112 |
2 => array( |
|
113 |
'href' => 'http://example.com/' . $this->randomName() . '?property=value', |
|
114 |
'label' => $this->randomName(), |
|
115 |
), |
|
116 |
3 => array( |
|
117 |
'href' => 'http://example.com/' . $this->randomName() . '#position', |
|
118 |
'label' => $this->randomName(), |
|
119 |
), |
|
120 |
4 => array( |
|
121 |
'href' => 'http://example.com/' . $this->randomName() . '#lower?property=value2', |
|
122 |
'label' => $this->randomName(), |
|
123 |
), |
|
124 |
); |
|
125 |
//$this->assert('pass', '<pre>' . print_r($token_url_tests, TRUE) . '<pre>'); |
|
126 |
|
|
127 |
foreach ($token_url_tests as &$input) { |
|
128 |
$this->drupalGet('node/add/page'); |
|
129 |
|
|
130 |
$edit = array( |
|
131 |
'title' => $input['label'], |
|
132 |
$field_name . '[und][0][title]' => $input['label'], |
|
133 |
$field_name . '[und][0][url]' => $input['href'], |
|
134 |
); |
|
135 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
136 |
$url = $this->getUrl(); |
|
137 |
$input['url'] = $url; |
|
138 |
} |
|
139 |
|
|
140 |
// change to anonymous user |
|
141 |
$this->drupalLogout(); |
|
142 |
|
|
143 |
foreach ($token_url_tests as $index => $input2) { |
|
144 |
$node = node_load($index); |
|
145 |
$node_array = node_view($node, 'full'); |
|
146 |
$this->assertNotEqual(NULL, $node, "Do we have a node?"); |
|
147 |
$this->assertEqual($node->nid, $index, "Test that we have a node."); |
|
148 |
$token_name = '[node:' . str_replace('_', '-', $field_name) . ':url]'; |
|
149 |
$assert_data = token_replace($token_name, |
|
150 |
array('node' => $node)); |
|
151 |
$this->assertEqual($input2['href'], $assert_data, "Test that the url token has been set to " . $input2['href'] . ' - ' . $assert_data); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
} |
drupal7/sites/all/modules/link/tests/link.token.test | ||
---|---|---|
426 | 426 |
|
427 | 427 |
$this->assertRaw('This & That'); |
428 | 428 |
} |
429 |
|
|
430 |
|
|
429 | 431 |
} |
drupal7/sites/all/modules/link/tests/link.validate.test | ||
---|---|---|
22 | 22 |
|
23 | 23 |
$field_name = $this->createLinkField(); |
24 | 24 |
|
25 |
$permission = 'create page content'; |
|
26 |
$this->checkPermissions(array($permission), TRUE); |
|
27 |
|
|
28 |
$this->drupalGet('node/add/page'); |
|
29 |
|
|
30 | 25 |
$label = $this->randomName(); |
31 |
$edit = array(
|
|
26 |
$settings = array(
|
|
32 | 27 |
'title' => $label, |
33 |
$field_name . '[und][0][title]' => $label, |
|
34 |
$field_name . '[und][0][url]' => $url, |
|
28 |
$field_name => array( |
|
29 |
LANGUAGE_NONE=> array( |
|
30 |
array( |
|
31 |
'title' => $label, |
|
32 |
'url' => $url, |
|
33 |
) |
|
34 |
), |
|
35 |
), |
|
35 | 36 |
); |
36 |
$this->drupalPost(NULL, $edit, t('Save')); |
|
37 |
$this->assertRaw(' has been created.', 'Node created'); |
|
38 | 37 |
|
39 |
$nid = 1; //$matches[1];
|
|
38 |
$node = $this->drupalCreateNode($settings);
|
|
40 | 39 |
|
41 |
$node = node_load($nid);
|
|
40 |
$this->assertNotNull($node, ' has been created.', 'Node created');
|
|
42 | 41 |
|
43 |
$this->assertEqual($url, $node->{$field_name}['und'][0]['url']);
|
|
42 |
$this->assertEqual($url, $node->{$field_name}[LANGUAGE_NONE][0]['url']);
|
|
44 | 43 |
} |
45 | 44 |
} |
46 | 45 |
|
... | ... | |
269 | 268 |
|
270 | 269 |
// Validate that an internal url would be accepted. |
271 | 270 |
function test_link_internal_url() { |
272 |
$this->link_test_validate_url('node/32'); |
|
271 |
// Create the content first. |
|
272 |
$node = $this->drupalCreateNode(); |
|
273 |
|
|
274 |
$link = 'node/' . $node->nid; |
|
275 |
$this->link_test_validate_url($link); |
|
276 |
$type = link_url_type($link); |
|
277 |
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); |
|
273 | 278 |
} |
274 | 279 |
|
275 | 280 |
// Validate a simple mailto. |
... | ... | |
340 | 345 |
/** |
341 | 346 |
* Here, we're testing that a very long url is stored properly in the db. |
342 | 347 |
* |
343 |
* Basicly, trying to test http://drupal.org/node/376818 |
|
348 |
* Basically, trying to test http://drupal.org/node/376818
|
|
344 | 349 |
*/ |
345 | 350 |
function testLinkURLFieldIsBig() { |
346 | 351 |
$long_url = 'http://th.wikipedia.org/wiki/%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%9A%E0%B8%8D%E0%B8%88%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%B9%E0%B8%97%E0%B8%B4%E0%B8%A8_%E0%B8%99%E0%B8%84%E0%B8%A3%E0%B8%A8%E0%B8%A3%E0%B8%B5%E0%B8%98%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%A3%E0%B8%B2%E0%B8%8A'; |
... | ... | |
363 | 368 |
'group' => 'Link', |
364 | 369 |
); |
365 | 370 |
} |
371 |
|
|
372 |
function setUp() { |
|
373 |
parent::setUp('link'); |
|
374 |
} |
|
366 | 375 |
|
367 | 376 |
/** |
368 | 377 |
* Translates the LINK type constants to english for display and debugging of tests |
... | ... | |
386 | 395 |
} |
387 | 396 |
} |
388 | 397 |
|
389 |
// Make sure that a link labelled <front> works.
|
|
398 |
// Make sure that a link labeled <front> works. |
|
390 | 399 |
function testValidateFrontLink() { |
391 | 400 |
$valid = link_validate_url('<front>'); |
392 |
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verfied and identified'); |
|
401 |
$this->assertEqual(LINK_FRONT, $valid, 'Make sure that front link is verified and identified');
|
|
393 | 402 |
} |
394 | 403 |
|
395 | 404 |
function testValidateEmailLink() { |
... | ... | |
409 | 418 |
|
410 | 419 |
function testValidateNewsArticleLink() { |
411 | 420 |
$valid = link_validate_url('news:hj0db8$vrm$1@news.eternal-september.org'); |
412 |
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article valiates as news.'); |
|
421 |
$this->assertEqual(LINK_NEWS, $valid, 'Make sure link to specific article validates as news.');
|
|
413 | 422 |
} |
414 | 423 |
|
415 | 424 |
function testValidateBadNewsgroupLink() { |
... | ... | |
418 | 427 |
} |
419 | 428 |
|
420 | 429 |
function testValidateInternalLinks() { |
430 |
$tempfile = drupal_tempnam('public://files', 'test'); |
|
421 | 431 |
$links = array( |
422 |
'node/5', |
|
423 | 432 |
'rss.xml', |
424 |
'files/test.jpg',
|
|
425 |
'/var/www/test',
|
|
433 |
file_uri_target($tempfile),
|
|
434 |
drupal_realpath($tempfile),
|
|
426 | 435 |
); |
427 | 436 |
|
428 | 437 |
foreach ($links as $link) { |
438 |
$type = link_url_type($link); |
|
439 |
$this->assertEqual(LINK_INTERNAL, $type, 'Test ' . $link . ' is an internal link.'); |
|
429 | 440 |
$valid = link_validate_url($link); |
430 |
$this->assertEqual(LINK_INTERNAL, $valid, 'Test ' . $link . ' internal link.');
|
|
441 |
$this->assertTrue($valid, 'Test ' . $link . ' is valid internal link.');
|
|
431 | 442 |
} |
432 | 443 |
} |
433 | 444 |
|
... | ... | |
446 | 457 |
'http://255.255.255.255:4823/', |
447 | 458 |
'www.test-site.com', |
448 | 459 |
'http://example.com/index.php?q=node/123', |
449 |
'http://example.com/index.php?page=this\that', |
|
450 | 460 |
'http://example.com/?first_name=Joe Bob&last_name=Smith', |
451 | 461 |
// Anchors |
452 | 462 |
'http://www.example.com/index.php#test', |
... | ... | |
464 | 474 |
} |
465 | 475 |
} |
466 | 476 |
foreach ($links as $link) { |
477 |
$type = link_url_type($link); |
|
478 |
$this->assertEqual(LINK_EXTERNAL, $type, 'Testing that ' . $link . ' is an external link.'); |
|
467 | 479 |
$valid = link_validate_url($link); |
468 |
$this->assertEqual(LINK_EXTERNAL, $valid, 'Testing that ' . $link . ' is a valid external link.');
|
|
480 |
$this->assertTrue($valid, 'Test ' . $link . ' is valid external link.');
|
|
469 | 481 |
// The following two lines are commented out and only used for comparisons. |
470 | 482 |
//$valid2 = valid_url($link, TRUE); |
471 | 483 |
//$this->assertEqual(TRUE, $valid2, "Using valid_url() on $link."); |
... | ... | |
485 | 497 |
'http://www.testß.com/', // ß not allowed in domain names! |
486 | 498 |
'http://www.example.frog/', // Bad TLD |
487 | 499 |
//'http://www.-fudge.com/', // domains can't have sections starting with a dash. |
500 |
'http://example.com/index.php?page=this\that', |
|
501 |
'example@example.com', |
|
488 | 502 |
); |
489 | 503 |
foreach ($links as $link) { |
490 | 504 |
$valid = link_validate_url($link); |
Formats disponibles : Unified diff
Weekly update of contrib modules