Commit d16f1dbd authored by webchick's avatar webchick

Issue #2421021 by YesCT, lhuacho, martin107, shashikant_chauhan, amateescu,...

Issue #2421021 by YesCT, lhuacho, martin107, shashikant_chauhan, amateescu, tremix: Missing help text for external url only for link widget
parent 5538c44b
......@@ -208,6 +208,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
elseif ($this->supportsExternalLinks() && $this->supportsInternalLinks()) {
$element['uri']['#description'] = $this->t('Start typing the title of a piece of content to select it. You can also enter an internal path such as %add-node or an external URL such as %url. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => '/node/add', '%url' => 'http://example.com'));
}
// If the field is configured to allow only external links, show a useful
// description.
elseif ($this->supportsExternalLinks() && !$this->supportsInternalLinks()) {
$element['uri']['#description'] = $this->t('This must be an external URL such as %url.', array('%url' => 'http://example.com'));
}
$element['title'] = array(
'#type' => 'textfield',
......
......@@ -9,6 +9,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\link\LinkItemInterface;
use Drupal\simpletest\WebTestBase;
/**
......@@ -27,25 +28,35 @@ class LinkFieldUITest extends WebTestBase {
*/
public static $modules = ['node', 'link', 'field_ui', 'block'];
/**
* A user that can edit content types.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['administer content types', 'administer node fields', 'administer node display']));
$this->adminUser = $this->drupalCreateUser(['administer content types', 'administer node fields', 'administer node display']);
$this->drupalLogin($this->adminUser);
$this->drupalPlaceBlock('system_breadcrumb_block');
}
/**
* Tests that link field UI functionality does not generate warnings.
* Tests the link field UI.
*/
function testFieldUI() {
// Add a content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
// Add a link field to the newly-created type.
// Add a link field to the newly-created type. It defaults to allowing both
// internal and external links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link');
......@@ -55,6 +66,32 @@ function testFieldUI() {
// @todo Mess with the formatter settings a bit here.
$this->drupalGet("$type_path/display");
$this->assertText(t('Link text trimmed to @limit characters', array('@limit' => 80)));
// Test the help text displays when the link field allows both internal and
// external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$this->drupalGet($add_path);
$this->assertRaw('You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>.');
// Log in an admin to set up the next content type.
$this->drupalLogin($this->adminUser);
// Add a different content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
// Add a link field to the newly-created type. Specify it must allow
// external only links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$field_edit = ['field[settings][link_type]' => LinkItemInterface::LINK_EXTERNAL];
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link', array(), $field_edit);
// Test the help text displays when link allows only external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$this->drupalGet($add_path);
$this->assertRaw('This must be an external URL such as <em class="placeholder">http://example.com</em>.');
}
}
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