Loading src/Plugin/views/area/Link.php +5 −2 Original line number Diff line number Diff line Loading @@ -297,7 +297,7 @@ class Link extends TokenizeAreaPluginBase { // If we have no $path and no $url_info['url'], we have nothing to work // with, so we just return the text. if (empty($path)) { return $text; return $this->options['link_text']; } // If no scheme is provided in the $path, assign the default 'http://'. Loading Loading @@ -476,7 +476,10 @@ class Link extends TokenizeAreaPluginBase { } /** * Takes the generated link ant transforms it into a 'local action' link. * Takes the generated link and transforms it into a 'local action' link. * * Wrapping with hard-coded HTML is ugly but basically copied from * \Drupal\block\Controller\BlockLibraryController::buildLocalActions() * * @param array $link * The link to transform. Loading tests/src/Kernel/Plugin/LinkTest.php +56 −9 Original line number Diff line number Diff line Loading @@ -3,11 +3,9 @@ namespace Drupal\Tests\views_linkarea\Kernel\Plugin; use Drupal\views\Entity\View; use Drupal\views\Tests\ViewTestData; use Drupal\views\Views; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Symfony\Component\HttpFoundation\Request; /** * Tests the page display plugin. Loading @@ -17,6 +15,8 @@ use Symfony\Component\HttpFoundation\Request; */ class LinkAreaTest extends ViewsKernelTestBase { protected $entityId; /** * Modules to enable. * Loading @@ -39,6 +39,15 @@ class LinkAreaTest extends ViewsKernelTestBase { if ($import_test_views) { ViewTestData::createTestViews(get_class($this), ['views_test_linkarea']); } $random_label = $this->randomMachineName(); $data = array('bundle' => 'entity_test', 'name' => $random_label); $entity_test = $this->container->get('entity.manager') ->getStorage('entity_test') ->create($data); $entity_test->save(); $this->entityId = $entity_test->id(); \Drupal::state() ->set('entity_test_entity_access.view.' . $entity_test->id(), TRUE); } /** Loading @@ -54,20 +63,58 @@ class LinkAreaTest extends ViewsKernelTestBase { /** * Tests the area handler. * * @param $options * @param $expected_text * @param $expected_link * @param bool $no_dest * * @dataProvider providerTestLinkArea */ public function testLinkArea() { public function testLinkArea($options, $expected_text, $expected_link, $no_dest = TRUE) { if ($no_dest) { // Set destination query string to off. $options['destination'] = 0; } $view = Views::getView('test_entity_linkarea'); $display = $view->getDisplay(); $plugin = Views::pluginManager('area')->createInstance('linkarea'); $options = [ 'path' => '<front>', 'link_text' => 'SSSSSS', ]; // Initialize the plugin. $plugin->init($view, $display, $options); $build = $plugin->render(); $this->assertEquals($options['link_text'], $build['#title']); $this->assertEquals($expected_text, $build['#title']); $this->assertEquals($expected_link, $build['#url']->toString()); } /** * @return array */ public function providerTestLinkArea() { $data = []; $data[] = [ [ 'path' => '<front>', 'link_text' => 'SSSSSS', ], 'SSSSSS', '/' ]; $data[] = [ [ 'path' => 'route:user.pass', 'link_text' => '<b>Pass</b>', ], 'Pass', '/user/password' ]; $data[] = [ [ 'path' => 'entity:entity_test/1', 'link_text' => '<b>Pass</b>', ], 'Pass', '/entity_test/1' ]; return $data; } } Loading
src/Plugin/views/area/Link.php +5 −2 Original line number Diff line number Diff line Loading @@ -297,7 +297,7 @@ class Link extends TokenizeAreaPluginBase { // If we have no $path and no $url_info['url'], we have nothing to work // with, so we just return the text. if (empty($path)) { return $text; return $this->options['link_text']; } // If no scheme is provided in the $path, assign the default 'http://'. Loading Loading @@ -476,7 +476,10 @@ class Link extends TokenizeAreaPluginBase { } /** * Takes the generated link ant transforms it into a 'local action' link. * Takes the generated link and transforms it into a 'local action' link. * * Wrapping with hard-coded HTML is ugly but basically copied from * \Drupal\block\Controller\BlockLibraryController::buildLocalActions() * * @param array $link * The link to transform. Loading
tests/src/Kernel/Plugin/LinkTest.php +56 −9 Original line number Diff line number Diff line Loading @@ -3,11 +3,9 @@ namespace Drupal\Tests\views_linkarea\Kernel\Plugin; use Drupal\views\Entity\View; use Drupal\views\Tests\ViewTestData; use Drupal\views\Views; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Symfony\Component\HttpFoundation\Request; /** * Tests the page display plugin. Loading @@ -17,6 +15,8 @@ use Symfony\Component\HttpFoundation\Request; */ class LinkAreaTest extends ViewsKernelTestBase { protected $entityId; /** * Modules to enable. * Loading @@ -39,6 +39,15 @@ class LinkAreaTest extends ViewsKernelTestBase { if ($import_test_views) { ViewTestData::createTestViews(get_class($this), ['views_test_linkarea']); } $random_label = $this->randomMachineName(); $data = array('bundle' => 'entity_test', 'name' => $random_label); $entity_test = $this->container->get('entity.manager') ->getStorage('entity_test') ->create($data); $entity_test->save(); $this->entityId = $entity_test->id(); \Drupal::state() ->set('entity_test_entity_access.view.' . $entity_test->id(), TRUE); } /** Loading @@ -54,20 +63,58 @@ class LinkAreaTest extends ViewsKernelTestBase { /** * Tests the area handler. * * @param $options * @param $expected_text * @param $expected_link * @param bool $no_dest * * @dataProvider providerTestLinkArea */ public function testLinkArea() { public function testLinkArea($options, $expected_text, $expected_link, $no_dest = TRUE) { if ($no_dest) { // Set destination query string to off. $options['destination'] = 0; } $view = Views::getView('test_entity_linkarea'); $display = $view->getDisplay(); $plugin = Views::pluginManager('area')->createInstance('linkarea'); $options = [ 'path' => '<front>', 'link_text' => 'SSSSSS', ]; // Initialize the plugin. $plugin->init($view, $display, $options); $build = $plugin->render(); $this->assertEquals($options['link_text'], $build['#title']); $this->assertEquals($expected_text, $build['#title']); $this->assertEquals($expected_link, $build['#url']->toString()); } /** * @return array */ public function providerTestLinkArea() { $data = []; $data[] = [ [ 'path' => '<front>', 'link_text' => 'SSSSSS', ], 'SSSSSS', '/' ]; $data[] = [ [ 'path' => 'route:user.pass', 'link_text' => '<b>Pass</b>', ], 'Pass', '/user/password' ]; $data[] = [ [ 'path' => 'entity:entity_test/1', 'link_text' => '<b>Pass</b>', ], 'Pass', '/entity_test/1' ]; return $data; } }