Tokens evaluated too late, URL Validation fails

Created on 20 June 2023, about 1 year ago
Updated 4 July 2023, 12 months ago

Problem/Motivation

The redirect URL field allows to use tokens. Most simple example is to use [site:url]. Another one would be to use a link field and its token, like: [term:field_url]

But then the following error appears, when opening the taxonomy term overview page (admin/structure/taxonomy/manage/category/overview)

InvalidArgumentException: The user-entered string '' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 216 of core/lib/Drupal/Core/Url.php).

Drupal\rabbit_hole_href\Plugin\RabbitHoleBehaviorPlugin\PageRedirectHref->getActionTarget() (Line: 70)
Drupal\rabbit_hole_href\CanonicalLinkModifier->getNewCanonicalUrl() (Line: 33)
Drupal\rabbit_hole_href\CanonicalLinkModifier->getCanonicalUrl() (Line: 60)
rabbit_hole_href_redirect_uri()
call_user_func() (Line: 193)
Drupal\Core\Entity\EntityBase->toUrl() (Line: 358)
Drupal\taxonomy\Form\OverviewTerms->buildForm()
call_user_func_array() (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 169)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 49)
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

So I guess the token is replaced AFTER the validation.

When trying to edit the term containing the link field, something similar happens:

InvalidArgumentException: The user-entered string 'entity:node/1000000' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 216 of core/lib/Drupal/Core/Url.php).

Drupal\rabbit_hole_href\Plugin\RabbitHoleBehaviorPlugin\PageRedirectHref->getActionTarget() (Line: 70)
Drupal\rabbit_hole_href\CanonicalLinkModifier->getNewCanonicalUrl() (Line: 33)
Drupal\rabbit_hole_href\CanonicalLinkModifier->getCanonicalUrl() (Line: 60)
rabbit_hole_href_redirect_uri()
call_user_func() (Line: 193)
Drupal\Core\Entity\EntityBase->toUrl() (Line: 32)
Drupal\path\Plugin\Field\FieldType\PathFieldItemList->computeValue() (Line: 33)
Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
count() (Line: 74)
Drupal\Core\Field\WidgetBase->form() (Line: 183)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm() (Line: 121)
Drupal\Core\Entity\ContentEntityForm->form() (Line: 98)
Drupal\taxonomy\TermForm->form() (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm()
call_user_func_array() (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 169)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 49)
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 718)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

See above

Proposed resolution

Check the reason and eventually replace the token earlier.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024