diff --git a/link.module b/link.module index b0c53c3..5cea78a 100644 --- a/link.module +++ b/link.module @@ -700,6 +700,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), ), @@ -885,6 +888,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'), @@ -1016,6 +1024,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']) : ''; +} + +/** * Formats a link as an absolute URL. */ function theme_link_formatter_link_absolute($vars) { diff --git a/tests/link.attribute.test b/tests/link.attribute.test index 603847e..36e6be5 100644 --- a/tests/link.attribute.test +++ b/tests/link.attribute.test @@ -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));