Commit d309714c authored by webchick's avatar webchick

Issue #2265913 by pwolanin: LinkGenerator::generateFromUrl() fatal (uncaught...

Issue #2265913 by pwolanin: LinkGenerator::generateFromUrl() fatal (uncaught exception) with external URL.
parent b45b871c
......@@ -85,7 +85,7 @@ public function generateFromUrl($text, Url $url) {
}
// Set the "active" class if the 'set_active_class' option is not empty.
if (!empty($variables['options']['set_active_class'])) {
if (!empty($variables['options']['set_active_class']) && !$url->isExternal()) {
// Add a "data-drupal-link-query" attribute to let the
// drupal.active-link library know the query in a standardized manner.
if (!empty($variables['options']['query'])) {
......
......@@ -121,7 +121,7 @@ public function testGenerateHrefs($route_name, array $parameters, $absolute, $ur
}
/**
* Tests the generateFromUrl() method.
* Tests the generateFromUrl() method with a route.
*
* @covers ::generateFromUrl()
*/
......@@ -148,6 +148,38 @@ public function testGenerateFromUrl() {
), $result);
}
/**
* Tests the generateFromUrl() method with an external URL.
*
* The set_active_class option is set to TRUE to ensure this does not cause
* an error together with an external URL.
*
* @covers ::generateFromUrl()
*/
public function testGenerateFromUrlExternal() {
$this->urlGenerator->expects($this->once())
->method('generateFromPath')
->with('http://drupal.org', array('set_active_class' => TRUE) + $this->defaultOptions)
->will($this->returnValue('http://drupal.org'));
$this->moduleHandler->expects($this->once())
->method('alter')
->with('link', $this->isType('array'));
$url = Url::createFromPath('http://drupal.org');
$url->setUrlGenerator($this->urlGenerator);
$url->setOption('set_active_class', TRUE);
$result = $this->linkGenerator->generateFromUrl('Drupal', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
'href' => 'http://drupal.org',
),
'content' => 'Drupal',
), $result);
}
/**
* Tests the link method with additional attributes.
*
......
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