Commit 804cc94c authored by boobaa's avatar boobaa Committed by John Fiala
Browse files

Issue #609560 by Boobaa: Provide token for hostname

parent 66706b62
......@@ -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.
*/
......
......@@ -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));
......
Markdown is supported
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