Commit e26a156a authored by alexpott's avatar alexpott

Issue #1801268 by falcon03, mgifford, Risse, heddn, larowlan: Change link...

Issue #1801268 by falcon03, mgifford, Risse, heddn, larowlan: Change link field 'title' field to 'link text'.
parent 88e6a760
......@@ -150,17 +150,17 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$settings = $this->getSettings();
foreach ($items as $delta => $item) {
// By default use the full URL as the link title.
// By default use the full URL as the link text.
$link_title = $item['url'];
// If the title field value is available, use it for the link title.
// If the title field value is available, use it for the link text.
if (empty($settings['url_only']) && !empty($item['title'])) {
// Unsanitizied token replacement here because $options['html'] is FALSE
// by default in theme_link().
$link_title = \Drupal::token()->replace($item['title'], array($entity->entityType() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
}
// Trim the link title to the desired length.
// Trim the link text to the desired length.
if (!empty($settings['trim_length'])) {
$link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
}
......
......@@ -23,7 +23,7 @@
* @Plugin(
* id = "link_separate",
* module = "link",
* label = @Translation("Separate title and URL"),
* label = @Translation("Separate link text and URL"),
* field_types = {
* "link"
* },
......@@ -44,20 +44,20 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$settings = $this->getSettings();
foreach ($items as $delta => $item) {
// By default use the full URL as the link title.
// By default use the full URL as the link text.
$link_title = $item['url'];
// If the title field value is available, use it for the link title.
// If the link text field value is available, use it for the text.
if (empty($settings['url_only']) && !empty($item['title'])) {
// Unsanitized token replacement here because $options['html'] is FALSE
// by default in theme_link().
$link_title = \Drupal::token()->replace($item['title'], array($entity->entityType() => $entity), array('sanitize' => FALSE, 'clear' => TRUE));
}
// The link_separate formatter has two titles; the link title (as in the
// field values) and the URL itself. If there is no title value,
// The link_separate formatter has two titles; the link text (as in the
// field values) and the URL itself. If there is no link text value,
// $link_title defaults to the URL, so it needs to be unset.
// The URL title may need to be trimmed as well.
// The URL version may need to be trimmed as well.
if (empty($item['title'])) {
$link_title = NULL;
}
......
......@@ -45,7 +45,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr
);
$element['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#title' => t('Link text'),
'#placeholder' => $this->getSetting('placeholder_title'),
'#default_value' => isset($items[$delta]['title']) ? $items[$delta]['title'] : NULL,
'#maxlength' => 255,
......@@ -93,7 +93,7 @@ public function settingsForm(array $form, array &$form_state) {
);
$elements['placeholder_title'] = array(
'#type' => 'textfield',
'#title' => t('Placeholder for link title'),
'#title' => t('Placeholder for link text'),
'#default_value' => $this->getSetting('placeholder_title'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
'#states' => array(
......
......@@ -111,7 +111,7 @@ function testURLValidation() {
}
/**
* Tests the title settings of a link field.
* Tests the link title settings of a link field.
*/
function testLinkTitle() {
// Create a field with settings to validate.
......@@ -135,7 +135,7 @@ function testLinkTitle() {
'type' => 'link_default',
'settings' => array(
'placeholder_url' => 'http://example.com',
'placeholder_title' => 'Enter a title for this link',
'placeholder_title' => 'Enter the text for this link',
),
))
->save();
......@@ -148,9 +148,9 @@ function testLinkTitle() {
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Verify that the title field works according to the field setting.
// Verify that the link text field works according to the field setting.
foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) {
// Update the title field setting.
// Update the link title field setting.
$this->instance['settings']['title'] = $title_setting;
field_update_instance($this->instance);
......@@ -162,41 +162,41 @@ function testLinkTitle() {
$this->assertRaw('placeholder="http://example.com"');
if ($title_setting === DRUPAL_DISABLED) {
$this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field not found.');
$this->assertNoRaw('placeholder="Enter a title for this link"');
$this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Link text field not found.');
$this->assertNoRaw('placeholder="Enter the text for this link"');
}
else {
$this->assertRaw('placeholder="Enter a title for this link"');
$this->assertRaw('placeholder="Enter the text for this link"');
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field found.');
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Link text field found.');
if ($title_setting === DRUPAL_REQUIRED) {
// Verify that the title is required, if the URL is non-empty.
// Verify that the link text is required, if the URL is non-empty.
$edit = array(
"{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertText(t('!name field is required.', array('!name' => t('Title'))));
$this->assertText(t('!name field is required.', array('!name' => t('Link text'))));
// Verify that the title is not required, if the URL is empty.
// Verify that the link text is not required, if the URL is empty.
$edit = array(
"{$this->field['field_name']}[$langcode][0][url]" => '',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertNoText(t('!name field is required.', array('!name' => t('Title'))));
$this->assertNoText(t('!name field is required.', array('!name' => t('Link text'))));
// Verify that a URL and title meets requirements.
// Verify that a URL and link text meets requirements.
$this->drupalGet('test-entity/add/test_bundle');
$edit = array(
"{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com',
"{$this->field['field_name']}[$langcode][0][title]" => 'Example',
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertNoText(t('!name field is required.', array('!name' => t('Title'))));
$this->assertNoText(t('!name field is required.', array('!name' => t('Link text'))));
}
}
}
// Verify that a link without title is rendered using the URL as link text.
// Verify that a link without link text is rendered using the URL as text.
$value = 'http://www.example.com/';
$edit = array(
"{$this->field['field_name']}[$langcode][0][url]" => $value,
......@@ -211,7 +211,7 @@ function testLinkTitle() {
$expected_link = l($value, $value);
$this->assertRaw($expected_link);
// Verify that a link with title is rendered using the title as link text.
// Verify that a link with text is rendered using the link text.
$title = $this->randomName();
$edit = array(
"{$this->field['field_name']}[$langcode][0][title]" => $title,
......@@ -262,7 +262,7 @@ function testLinkFormatter() {
// Create an entity with two link field values:
// - The first field item uses a URL only.
// - The second field item uses a URL and title.
// - The second field item uses a URL and link text.
// For consistency in assertion code below, the URL is assigned to the title
// variable for the first field.
$this->drupalGet('test-entity/add/test_bundle');
......@@ -402,7 +402,7 @@ function testLinkSeparateFormatter() {
// Create an entity with two link field values:
// - The first field item uses a URL only.
// - The second field item uses a URL and title.
// - The second field item uses a URL and link text.
// For consistency in assertion code below, the URL is assigned to the title
// variable for the first field.
$this->drupalGet('test-entity/add/test_bundle');
......
......@@ -35,7 +35,7 @@ public function getPropertyDefinitions() {
);
self::$propertyDefinitions['title'] = array(
'type' => 'string',
'label' => t('Title'),
'label' => t('Link text'),
);
self::$propertyDefinitions['attributes'] = array(
'type' => 'map',
......
......@@ -15,7 +15,7 @@ function link_help($path, $arg) {
case 'admin/help#link':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Link module defines a simple link field type for the Field module. Links are external URLs, can have an optional title for each link, and they can be formatted when displayed. See the <a href="@field-help">Field module help page</a> for more information about fields.', array('@field-help' => url('admin/help/field'))) . '</p>';
$output .= '<p>' . t('The Link module defines a simple link field type for the Field module. Links are external URLs, can have an optional link text for each link, and they can be formatted when displayed. See the <a href="@field-help">Field module help page</a> for more information about fields.', array('@field-help' => url('admin/help/field'))) . '</p>';
return $output;
}
}
......@@ -26,7 +26,7 @@ function link_help($path, $arg) {
function link_field_info() {
$types['link'] = array(
'label' => t('Link'),
'description' => t('Stores a URL string, optional varchar title, and optional blob of attributes to assemble a link.'),
'description' => t('Stores a URL string, optional varchar link text, and optional blob of attributes to assemble a link.'),
'instance_settings' => array(
'title' => DRUPAL_OPTIONAL,
),
......@@ -43,7 +43,7 @@ function link_field_info() {
function link_field_instance_settings_form($field, $instance) {
$form['title'] = array(
'#type' => 'radios',
'#title' => t('Allow link title'),
'#title' => t('Allow link text'),
'#default_value' => isset($instance['settings']['title']) ? $instance['settings']['title'] : DRUPAL_OPTIONAL,
'#options' => array(
DRUPAL_DISABLED => t('Disabled'),
......@@ -84,7 +84,7 @@ function link_field_is_empty($item, $field) {
*/
function link_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => &$item) {
// Trim any spaces around the URL and title.
// Trim any spaces around the URL and link text.
$item['url'] = trim($item['url']);
$item['title'] = trim($item['title']);
......@@ -105,7 +105,7 @@ function link_theme() {
}
/**
* Formats a link as separate title and URL elements.
* Formats a link as separate link title and URL elements.
*/
function theme_link_formatter_link_separate($vars) {
$output = '';
......
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