diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php index 1b1fa30..b72b14e 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -9,7 +9,6 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\UrlHelper; -use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Request; /** @@ -34,34 +33,37 @@ class ConfirmFormHelper { */ public static function buildCancelLink(ConfirmFormInterface $form, Request $request) { // Prepare cancel link. + $link = array(); $query = $request->query; // If a destination is specified, that serves as the cancel link. if ($query->has('destination')) { $options = UrlHelper::parse($query->get('destination')); $link = array( + '#type' => 'link', + '#title' => $form->getCancelText(), '#href' => $options['path'], '#options' => $options, ); } // Check for a route-based cancel link. elseif ($route = $form->getCancelRoute()) { - if (!($route instanceof Url)) { - if (empty($route['route_name'])) { - throw new \UnexpectedValueException(String::format('Missing route name in !class::getCancelRoute().', array('!class' => get_class($form)))); - } - // Ensure there is something to pass as the params and options. - $route += array( - 'route_parameters' => array(), - 'options' => array(), - ); - $route = new Url($route['route_name'], $route['route_parameters'], $route['options']); + if (empty($route['route_name'])) { + throw new \UnexpectedValueException(String::format('Missing route name in !class::getCancelRoute().', array('!class' => get_class($form)))); } - - $link = $route->toRenderArray(); + $route += array( + 'route_parameters' => array(), + 'options' => array(), + ); + // Ensure there is something to pass as the params and options. + $link = array( + '#type' => 'link', + '#title' => $form->getCancelText(), + '#route_name' => $route['route_name'], + '#route_parameters' => $route['route_parameters'], + '#options' => $route['options'], + ); } - $link['#type'] = 'link'; - $link['#title'] = $form->getCancelText(); return $link; } diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index c463022..35665e5 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -370,31 +370,6 @@ public function toArray() { } /** - * Returns a link type render array. - * - * @param string $link_title - * The title to be used in the render array. - * - * @return array - * A link render array. - */ - public function toLinkRenderArray($link_title = '') { - $build = array( - '#type' => 'link', - '#title' => $link_title, - '#options' => $this->getOptions(), - ); - if ($this->isExternal()) { - $build['#href'] = $this->getPath(); - } - else { - $build['#route_name'] = $this->getRouteName(); - $build['#route_parameters'] = $this->getRouteParameters(); - } - return $build; - } - - /** * Returns the internal path (system path) for this route. * * This path will not include any prefixes, fragments, or query strings. diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldFormatter/LinkFormatter.php index 63fbdb3..232d349 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -143,7 +143,18 @@ public function viewElements(FieldItemListInterface $items) { ); } else { - $element[$delta] = $url->toLinkRenderArray($link_title); + $element[$delta] = array( + '#type' => 'link', + '#title' => $link_title, + '#options' => $url->getOptions(), + ); + if ($url->isExternal()) { + $element[$delta]['#href'] = $url->getPath(); + } + else { + $element[$delta]['#route_name'] = $url->getRouteName(); + $element[$delta]['#route_parameters'] = $url->getRouteParameters(); + } } } diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php index a19dbfb..89a7abe 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php @@ -109,6 +109,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen /** * Is the LinkItem field definition configured to support links to routes? + * + * @return bool + * TRUE or FALSE */ protected function supportsInternalLinks() { $link_type = $this->getFieldSetting('link_type'); @@ -117,6 +120,9 @@ protected function supportsInternalLinks() { /** * Is the LinkItem field definition configured to support external URLs? + * + * @return bool + * TRUE or FALSE */ protected function supportsExternalLinks() { $link_type = $this->getFieldSetting('link_type');