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)
Comments
Comment #2
aronne CreditAttribution: aronne at bmeme commentedI've created a patch that solves this kind of bug.
Hope it helps.
Comment #3
dawehnerDo 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 :)Comment #4
aronne CreditAttribution: aronne at bmeme commentedOk 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:
Let me know if this is what you were asking for ;)
Comment #5
LendudeFix looks good now. This still needs test.
Comment #6
aronne CreditAttribution: aronne at bmeme commentedHi, I've added a patch containing tests.
Let me know if it's ok for you.
Comment #7
LendudeLooking good, bit of nitpicking:
"Test rendering with a more link." i'd say.
maybe add some @params to the docbloc for the params
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.
Comment #9
aronne CreditAttribution: aronne at bmeme commentedOk 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.
Comment #10
aronne CreditAttribution: aronne at bmeme commentedChanging status on "needs review" in order to starting tests.
Comment #11
Lendude@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 :)
Comment #12
aronne CreditAttribution: aronne at bmeme commented@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.
Comment #13
LendudeWe have a test, we have a fix. Nice!
Comment #14
evanjenkins CreditAttribution: evanjenkins at ActiveLAMP commentedI 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.
Comment #15
alexpott@evanjenkins hmm... I think #14 should have a new issue this issue was rtbc and the additional work has not been reviewed.
Comment #16
Lendude@evanjenkins yes please open a new issue for #14, the fix you added looks fine and needed but
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
Comment #17
alexpottRe-uploading #9 so it is the last patch on the issue.
Comment #18
alexpottCommitted 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.
Comment #20
aronne CreditAttribution: aronne at bmeme commentedNice, hope to receive credits for my patch at least for 8.2 version.
Comment #21
alexpottCommitted e977d1e and pushed to 8.2.x. Thanks!
Comment #24
johnpicozziCan 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.
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).
Comment #25
Lendude@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.
Comment #26
johnpicozziWill do. Putting back the version number.