diff --git a/link.module b/link.module index c7af1ff..e1c5d33 100644 --- a/link.module +++ b/link.module @@ -551,6 +551,9 @@ function link_theme() { 'link_formatter_link_plain' => array( 'variables' => array('element' => NULL), ), + 'link_formatter_link_host' => array( + 'variables' => array('element' => NULL), + ), 'link_formatter_link_title_plain' => array( 'variables' => array('element' => NULL), ), @@ -710,6 +713,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_short' => array( 'label' => t('Short, as link with title "Link"'), 'field types' => array('link_field'), @@ -780,6 +788,14 @@ function theme_link_formatter_link_plain($vars) { } /** + * 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']) : ''; +} + +/** * Theme function for 'title_plain' text field formatter. */ function theme_link_formatter_link_title_plain($vars) { diff --git a/tests/link.attribute.test b/tests/link.attribute.test index 398713a..111d0df 100644 --- a/tests/link.attribute.test +++ b/tests/link.attribute.test @@ -276,6 +276,37 @@ class LinkAttributeCrudTest extends DrupalWebTestCase { $this->assertNoLinkByHref($link_url); } + function testFormatterHost() { + $content_type_friendly = $this->randomName(20); + $content_type_machine = strtolower($this->randomName(10)); + + $this->createNodeType($content_type_machine, $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 testFormatterPlainWithQuerystring() { $content_type_friendly = $this->randomName(20); $content_type_machine = strtolower($this->randomName(10));