Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
link
Commits
804cc94c
Commit
804cc94c
authored
Dec 09, 2015
by
boobaa
Committed by
John Fiala
Dec 09, 2015
Browse files
Issue #609560 by Boobaa: Provide token for hostname
parent
66706b62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
link.module
link.module
+16
-0
tests/link.attribute.test
tests/link.attribute.test
+35
-0
No files found.
link.module
View file @
804cc94c
...
...
@@ -726,6 +726,9 @@ function link_theme() {
'link_formatter_link_plain'
=>
array
(
'variables'
=>
array
(
'element'
=>
NULL
,
'field'
=>
NULL
),
),
'link_formatter_link_host'
=>
array
(
'variables'
=>
array
(
'element'
=>
NULL
),
),
'link_formatter_link_absolute'
=>
array
(
'variables'
=>
array
(
'element'
=>
NULL
,
'field'
=>
NULL
),
),
...
...
@@ -911,6 +914,11 @@ function link_field_formatter_info() {
'field types'
=>
array
(
'link_field'
),
'multiple values'
=>
FIELD_BEHAVIOR_DEFAULT
,
),
'link_host'
=>
array
(
'label'
=>
t
(
'Host, as plain text'
),
'field types'
=>
array
(
'link_field'
),
'multiple values'
=>
FIELD_BEHAVIOR_DEFAULT
,
),
'link_url'
=>
array
(
'label'
=>
t
(
'URL, as link'
),
'field types'
=>
array
(
'link_field'
),
...
...
@@ -1041,6 +1049,14 @@ function theme_link_formatter_link_plain($vars) {
return
empty
(
$vars
[
'element'
][
'url'
])
?
check_plain
(
$vars
[
'element'
][
'title'
])
:
url
(
$vars
[
'element'
][
'url'
],
$link_options
);
}
/**
* Theme function for 'host' text field formatter.
*/
function
theme_link_formatter_link_host
(
$vars
)
{
$host
=
@
parse_url
(
$vars
[
'element'
][
'url'
]);
return
isset
(
$host
[
'host'
])
?
check_plain
(
$host
[
'host'
])
:
''
;
}
/**
* Formats a link as an absolute URL.
*/
...
...
tests/link.attribute.test
View file @
804cc94c
...
...
@@ -254,6 +254,41 @@ class LinkAttributeCrudTest extends DrupalWebTestCase {
}
}
function
testFormatterHost
()
{
$content_type_friendly
=
$this
->
randomName
(
20
);
$content_type_machine
=
strtolower
(
$this
->
randomName
(
10
));
$this
->
drupalCreateContentType
(
array
(
'type'
=>
$content_type_machine
,
'name'
=>
$content_type_friendly
,
));
// Now add a singleton field.
$single_field_name_friendly
=
$this
->
randomName
(
20
);
$single_field_name_machine
=
strtolower
(
$this
->
randomName
(
10
));
//$single_field_name = 'field_'. $single_field_name_machine;
$this
->
createSimpleLinkField
(
$single_field_name_machine
,
$single_field_name_friendly
,
$content_type_machine
);
// Okay, now we want to make sure this display is changed:
$this
->
drupalGet
(
'admin/structure/types/manage/'
.
$content_type_machine
.
'/display'
);
$edit
=
array
(
'fields[field_'
.
$single_field_name_machine
.
'][label]'
=>
'above'
,
'fields[field_'
.
$single_field_name_machine
.
'][type]'
=>
'link_host'
,
);
$this
->
drupalPost
(
NULL
,
$edit
,
t
(
'Save'
));
$this
->
createNodeTypeUser
(
$content_type_machine
);
$link_text
=
'Display'
;
$link_url
=
'http://www.example.com/'
;
$this
->
createNodeForTesting
(
$content_type_machine
,
$content_type_friendly
,
$single_field_name_machine
,
$link_text
,
$link_url
);
$this
->
assertText
(
'www.example.com'
);
$this
->
assertNoText
(
$link_text
);
$this
->
assertNoLinkByHref
(
$link_url
);
}
function
testFormatterURL
()
{
$content_type_friendly
=
$this
->
randomName
(
20
);
$content_type_machine
=
strtolower
(
$this
->
randomName
(
10
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment