Issue #3202166 by xjm, vakulrai, paulocs, Neslee Canil Pinto, rubenvarela, Gauravmahlawat, Abhijith S, larowlan: Allow saving <button> on menu LinkWidget

merge-requests/814/head
xjm 2021-06-26 21:29:11 -05:00
parent a314cb12e6
commit 53bc00ed1c
2 changed files with 17 additions and 3 deletions

View File

@ -115,7 +115,7 @@ class LinkWidget extends WidgetBase {
$uri = 'entity:node/' . $entity_id;
}
// Support linking to nothing.
elseif (in_array($string, ['<nolink>', '<none>'], TRUE)) {
elseif (in_array($string, ['<nolink>', '<none>', '<button>'], TRUE)) {
$uri = 'route:' . $string;
}
// Detect a schemeless string, map to 'internal:' URI.
@ -216,12 +216,12 @@ class LinkWidget extends WidgetBase {
// element prefix and description.
if (!$this->supportsExternalLinks()) {
$element['uri']['#field_prefix'] = rtrim(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), '/');
$element['uri']['#description'] = $this->t('This must be an internal path such as %add-node. You can also start typing the title of a piece of content to select it. Enter %front to link to the front page. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%add-node' => '/node/add', '%front' => '<front>', '%nolink' => '<nolink>', '%button' => 'route:<button>']);
$element['uri']['#description'] = $this->t('This must be an internal path such as %add-node. You can also start typing the title of a piece of content to select it. Enter %front to link to the front page. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%add-node' => '/node/add', '%front' => '<front>', '%nolink' => '<nolink>', '%button' => '<button>']);
}
// If the field is configured to allow both internal and external links,
// show a useful description.
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. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%front' => '<front>', '%add-node' => '/node/add', '%url' => 'http://example.com', '%nolink' => '<nolink>', '%button' => 'route:<button>']);
$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. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%front' => '<front>', '%add-node' => '/node/add', '%url' => 'http://example.com', '%nolink' => '<nolink>', '%button' => '<button>']);
}
// If the field is configured to allow only external links, show a useful
// description.

View File

@ -821,6 +821,20 @@ class LinkFieldTest extends BrowserTestBase {
$output = $this->renderTestEntity($id);
$expected_link = (string) $this->container->get('link_generator')->generate('Title, none', Url::fromUri('route:<none>'));
$this->assertStringContainsString($expected_link, $output);
// Test a link with a <button> uri.
$edit = [
"{$field_name}[0][title]" => 'Title, button',
"{$field_name}[0][uri]" => '<button>',
];
$this->drupalGet('/entity_test/add');
$this->submitForm($edit, 'Save');
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1];
$output = $this->renderTestEntity($id);
$expected_link = (string) $this->container->get('link_generator')->generate('Title, button', Url::fromUri('route:<button>'));
$this->assertStringContainsString($expected_link, $output);
}
/**