Index: link.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/link/link.module,v retrieving revision 1.24.4.34 diff -u -p -r1.24.4.34 link.module --- link.module 14 Jun 2010 18:14:11 -0000 1.24.4.34 +++ link.module 25 Jun 2010 13:46:05 -0000 @@ -715,6 +715,7 @@ function link_token_list($type = 'all') $tokens['link']['url'] = t("Link URL"); $tokens['link']['title'] = t("Link title"); $tokens['link']['view'] = t("Formatted html link"); + $tokens['link']['host'] = t("Link host"); return $tokens; } @@ -727,6 +728,8 @@ function link_token_values($type, $objec $tokens['url'] = $item['url']; $tokens['title'] = $item['title']; $tokens['view'] = isset($item['view']) ? $item['view'] : ''; + $host = @parse_url($item['url']); + $tokens['host'] = isset($host['host']) ? $host['host'] : ''; return $tokens; } Index: tests/link.token.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/link/tests/Attic/link.token.test,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 link.token.test --- tests/link.token.test 14 Jun 2010 18:14:11 -0000 1.1.2.7 +++ tests/link.token.test 25 Jun 2010 13:46:05 -0000 @@ -423,4 +423,57 @@ class LinkTokenTest extends ContentCrudT $this->assertRaw(l($input['label'], $input['href'] .'/'. $account->uid)); } + + /** + * Creates a link field with a required title enabled for user-entered tokens. + * Creates a node with a token in the link title and checks the value. + */ + function testHostTokenLinkCreate() { + $account = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content')); + $this->drupalLogin($account); + + // create field + $name = strtolower($this->randomName()); + $edit = array( + '_add_new_field[label]' => $name, + '_add_new_field[field_name]' => $name, + '_add_new_field[type]' => 'link', + '_add_new_field[widget_type]' => 'link', + ); + $this->drupalPost('admin/content/node-type/page/fields', $edit, t('Save')); + $this->drupalPost(NULL, array( + 'title' => 'required', + 'enable_tokens' => 1), t('Save field settings')); + + // Is field created? + $this->assertRaw(t('Added field %label.', array('%label' => $name)), 'Field added'); + + // create page form + $this->drupalGet('node/add/page'); + $field_name = 'field_' . $name; + $this->assertField($field_name . '[0][title]', 'Title found'); + $this->assertField($field_name . '[0][url]', 'URL found'); + + $input = array( + 'href' => 'http://example.com/' . $this->randomName(), + 'label' => $this->randomName(), + ); + + $this->drupalLogin($account); + $this->drupalGet('node/add/page'); + + $edit = array( + 'title' => $input['label'], + $field_name . '[0][title]' => $input['label'] . " [$field_name-host]", + $field_name . '[0][url]' => $input['href'], + ); + $this->drupalPost(NULL, $edit, t('Save')); + $url = $this->getUrl(); + + // change to anonymous user + $this->drupalLogout(); + $this->drupalGet($url); + + $this->assertRaw(l($input['label'] . ' example.com', $input['href'])); + } }