I've a content type with 2 fields:

  • Link
  • Body

I've created a view which displays body text trimmed with a "Read more" link using the URL stored into the Link field (excluded from display).
I've done it by using the options located within the "Rewrite results" fieldset as shown into the image file attached to this issue.

If the More link path (in this case the Link field replacement token) is external, Views throws the following Exception (even if the More link path description says "This can be an internal Drupal path such as node/add or an external URL such as "https://www.drupal.org". You may use the "Replacement patterns" above."):

InvalidArgumentException: The internal path component 'http://www.example.com' is external. You are not allowed to specify an external URL together with internal:/. in Drupal\Core\Url::fromInternalUri() (line 409 of core/lib/Drupal/Core/Url.php).
Drupal\Core\Url::fromUri('internal:/http://www.example.com', Array) (Line: 208)
Drupal\Core\Url::fromUserInput('/http://www.example.com', Array) (Line: 1274)
Drupal\views\Plugin\views\field\FieldPluginBase->renderText(Array) (Line: 1155)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 224)
template_preprocess_views_view_field(Array, 'views_view_field', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render(Array, Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 1703)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 765)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
call_user_func(Array, Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 713)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array) (Line: 580)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, 1) (Line: 467)
Drupal\views\Plugin\views\style\StylePluginBase->render(Array) (Line: 2116)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1518)
Drupal\views\ViewExecutable->render() (Line: 117)
Drupal\views\Plugin\views\display\Block->execute() (Line: 1615)
Drupal\views\ViewExecutable->executeDisplay('block_1', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array) (Line: 42)
Drupal\views\Plugin\Block\ViewsBlock->build() (Line: 202)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 381)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 130)
__TwigTemplate_fdca15b1b51c38a5e80e5e157757289d16cb2e2a158b188c8efa56c82094ef82->doDisplay(Array, Array) (Line: 387)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/bartik/templates/page.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 90)
__TwigTemplate_c8a2bb394530e45042bff84ca34b44365823673d6fd886e0ec8b803e36c0e3a4->doDisplay(Array, Array) (Line: 387)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/layout/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aronne created an issue. See original summary.

aronne’s picture

I've created a patch that solves this kind of bug.
Hope it helps.

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php
@@ -1271,7 +1271,9 @@ public function renderText($alter) {
+        $more_link_path = !UrlHelper::isExternal($more_link_path) ? CoreUrl::fromUserInput('/' . $more_link_path, $options) : CoreUrl::fromUri($more_link_path, $options);

Do you mind turning around this condition? Its always nice to avoid a !. Note: $more_link_path is kinda not the best variable name, better go with $more_link_url, given what this is :)

aronne’s picture

Ok no problem, I've updated the patch replacing the ternary operator with an if / else statement (in order to avoid a too long code line) removing the ! within the condition.
I've also changed the final variable name from $more_link_path to $more_link_url.

Note: I was using $more_link_path variable name just because it's defined at line 1261 of the same function:

$more_link_path = $this->options['alter']['more_link_path'];
$more_link_path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($more_link_path, $tokens)));

Let me know if this is what you were asking for ;)

Lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Fix looks good now. This still needs test.

aronne’s picture

Hi, I've added a patch containing tests.
Let me know if it's ok for you.

Lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Looking good, bit of nitpicking:

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -259,6 +259,67 @@ public function testRenderTrimmedWithMoreLink() {
+   * Test rendering as a link with a path.

"Test rendering with a more link." i'd say.

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -259,6 +259,67 @@ public function testRenderTrimmedWithMoreLink() {
+  public function testRenderTrimmedWithMoreLinkAndPath($path, $url) {

maybe add some @params to the docbloc for the params

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -259,6 +259,67 @@ public function testRenderTrimmedWithMoreLink() {
+    $data[] = ['', '/%3Cfront%3E'];

this tests the same thing as testRenderTrimmedWithMoreLink(), so lets just remove testRenderTrimmedWithMoreLink().

This is a good test-only patch, so we still need a patch with both the test and the fix.

Setting to needs review to kick the testbot into motion.

Status: Needs review » Needs work
aronne’s picture

Ok Leandude, I've followed your suggestions so here it is the updated patch containing both fix and tests.
Hope it'll be fine this time :)
Thx and let me know if it's ok for you.

aronne’s picture

Status: Needs work » Needs review

Changing status on "needs review" in order to starting tests.

Lendude’s picture

@aronne looking good to me, lets see what the testbot thinks. Just an FYI, if you set the status to 'needs review' when you upload a patch, the patch will automatically get tested by the testbot.

Edit: Ah cross post :)

aronne’s picture

@Lendude ahah you're so right man, 2 times the same mistake :)
Well tests seem to be ok! That's nice.

It's been a pleasure guys. let me know about the next steps to come.

Lendude’s picture

Assigned: aronne » Unassigned
Status: Needs review » Reviewed & tested by the community

We have a test, we have a fix. Nice!

evanjenkins’s picture

I was having the same issue but just with entering in a custom url. I have applied the previous patch and also fixed the `renderMoreLink` function in DisplayPluginBase.php to allow for external paths. Also applied it to 8.2.x.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@evanjenkins hmm... I think #14 should have a new issue this issue was rtbc and the additional work has not been reviewed.

Lendude’s picture

Status: Needs work » Reviewed & tested by the community

@evanjenkins yes please open a new issue for #14, the fix you added looks fine and needed but

+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
--- /dev/null
+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php.orig

it has this in the patch file and it doesn't seem to add test coverage. So that would still need some work. Lets not hang up this issue on that work.

So, RTBC'ing again for #9

alexpott’s picture

Re-uploading #9 so it is the last patch on the issue.

alexpott’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed 497bf11 and pushed to 8.3.x. Thanks!

Setting to patch to be ported so this change be cherry-picked to 8.2.x once 8.2.x has been released.

  • alexpott committed 497bf11 on 8.3.x
    Issue #2800799 by aronne, Lendude: Views throws InvalidArgumentException...
aronne’s picture

Nice, hope to receive credits for my patch at least for 8.2 version.

alexpott’s picture

Status: Patch (to be ported) » Fixed

Committed e977d1e and pushed to 8.2.x. Thanks!

  • alexpott committed e977d1e on 8.2.x
    Issue #2800799 by aronne, Lendude: Views throws InvalidArgumentException...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

johnpicozzi’s picture

Version: 8.2.x-dev » 8.9.x-dev
FileSize
104.9 KB

Can we re-open this issue for review as I'm having the same problem with a "Link to Content" field in a view if the "Use Absolute link" checkbox is checked. Note I updated the version as I just upgraded to 8.9.1.

Drupal views field config with Use Absolute link checkbox checked

Error is as follows
InvalidArgumentException: The internal path component 'https://example.com/node/8' is external. You are not allowed to specify an external URL together with internal:/. in Drupal\Core\Url::fromInternalUri() (line 419 of /app/web/core/lib/Drupal/Core/Url.php).

Lendude’s picture

@johnpicozzi please open up a new issue for that, feel free to post the link to the new issue here if you feel it is related.

johnpicozzi’s picture

Version: 8.9.x-dev » 8.2.x-dev

Will do. Putting back the version number.