-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkit-language-profile-fix.patch
67 lines (64 loc) · 3.18 KB
/
linkit-language-profile-fix.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
diff --git a/linkit.module b/linkit.module
index 78f7704..3203411 100644
--- a/linkit.module
+++ b/linkit.module
@@ -21,6 +21,11 @@ define('LINKIT_URL_METHOD_RAW_SLASH', 2);
define('LINKIT_URL_METHOD_ALIAS', 3);
/**
+ * Define special aliased paths for use with fields.
+ */
+define('LINKIT_URL_METHOD_ALIAS_FOR_FIELDS', 4);
+
+/**
* Define which query string key Better autocomplete will just.
*/
define('LINKIT_BAC_QUERY_KEY', 's');
@@ -1154,6 +1159,23 @@ function linkit_get_insert_plugin_processed_path(LinkitProfile $profile, $uri, $
case LINKIT_URL_METHOD_ALIAS:
$path = url($uri, $options);
break;
+ // Technically, the best insert method to use with fields is
+ // LINKIT_URL_METHOD_RAW. However, for usability reasons, the user
+ // may want to see the aliased link in the edit form, too.
+ // This, of course, it's not what LINKIT_URL_METHOD_RAW provides.
+ // The following insert method is a "hacked" version of the one above.
+ // Since a path saved in a Link field will again go through url() when
+ // rendered, the leading slash must be removed from the alias; and
+ // in case of multilingual sites, the language prefix must also go when
+ // the language of the node making the reference and the language of the
+ // node being referred are the same.
+ case LINKIT_URL_METHOD_ALIAS_FOR_FIELDS:
+ if (language_default()->language != $GLOBALS["language"]->language) {
+ $options['language']->language = '';
+ }
+ $path = url($uri, $options);
+ $path = ltrim($path, "/");
+ break;
}
return $path;
diff --git a/plugins/export_ui/linkit_profiles.inc b/plugins/export_ui/linkit_profiles.inc
index e49bd07..23bd909 100644
--- a/plugins/export_ui/linkit_profiles.inc
+++ b/plugins/export_ui/linkit_profiles.inc
@@ -305,8 +305,14 @@ function _linkit_build_insert_plugin_form_fields(&$form, LinkitProfile $profile)
$form['data']['insert_plugin']['url_method']['#options'][LINKIT_URL_METHOD_ALIAS] = t('Alias paths');
$form['data']['insert_plugin']['url_method'][LINKIT_URL_METHOD_ALIAS] = array(
'#description' => t('This will insert the alias for the result item.
- <br/>The paths will be run through the <em>url()</em> function.', array('%example_link' => 'node/123')),
+ <br/>The paths will be run through the <em>url()</em> function.'),
);
+ $form['data']['insert_plugin']['url_method']['#options'][LINKIT_URL_METHOD_ALIAS_FOR_FIELDS] = t('Alias paths suitable for fields');
+ $form['data']['insert_plugin']['url_method'][LINKIT_URL_METHOD_ALIAS_FOR_FIELDS] = array(
+ '#description' => t('This will insert the alias for the result item, but will strip leading slah and language prefix (if required) to make it possible to have aliased paths on <strong>fields</strong>.
+ <br/>The paths will be run through the <em>url()</em> function.'),
+ );
+
}
}
@@ -496,4 +502,4 @@ function linkit_isnumeric_validate($element, &$form_state, $form) {
if (!empty($element['#value']) && !is_numeric($element['#value'])) {
form_error($element, $element['#title'] . ' should only contains numbers.');
}
-}
\ No newline at end of file
+}