Problem/Motivation
Assume the node type 'Product' with the additional view modes 'Specifications' and 'Reviews'. How do I link to the view_mode_page patterned URLs with ?
Input:
$url = Url::fromRoute('view_mode_page.display_entity', ['view_mode' => 'specifications', 'entity_type' => 'node', 'entity_id' => $node->id()]);
$output = Link::fromTextAndUrl($this->t('Specifications'), $url)->toString();
Expected output:
<a href="/products/lawn-mower/specifications">Specifications</a>
Actual output:
<a href="/view_mode_page/specifications/node/3">Specifications</a>
Proposed resolution
Either:
- Provide canonical URLs for view_mode_page routes based on the underlying entity canonical URL.
- Document how to link to the view_mode_page patterned URL using Drupal\Core\Link
Remaining tasks
To be determined.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | view_mode_page-path_processor_full-2875737-10-do-not-test.patch | 6.15 KB | idebr |
| #10 | view_mode_page-review_outbound_paths-2875737-10.patch | 6.63 KB | idebr |
| #10 | interdiff-6-10.txt | 2.41 KB | idebr |
Comments
Comment #2
davy-r commentedUnfortunately the processOutbound-method isn't added yet in the DynamicPathProcessor, so it's just not possible at this moment.. I started working on this a while ago, but hadn't had time to finish it..
Comment #3
idebr commentedAttached patch rewrites the outbound view_mode_page paths to the first applicable view_mode_page_pattern.
Comment #4
tvoesenek commentedSmall fix to prevent double language prefix in the generated urls when language is enabled.
Comment #5
tvoesenek commentedBetter patch, using the path alias without the language prefix, instead of stripping it from the url.
Comment #6
idebr commentedThe outbound path processor did not check for content translations. I have updated the patch with a fix that extends the changes in #2881652: The inbound path processor does not check for content translations, so this patch now depends on the related issue.
For testing purposes I have attached a combined patch as well.
Comment #7
idebr commentedview_mode_page-path_processor_full-2875737-6-do-not-test.patch did not contain the code from both this issue and #2881652: The inbound path processor does not check for content translations. Attached patch does.
Comment #8
idebr commentedThe patch in #7 had an indentation error in view_mode_page.services.yml
Comment #9
wilfred waltman commentedFixed indention error on previous patch #7.
Comment #10
idebr commentedUrl can be called with additional options, for example to generate a link to a different language. This option should be applied to the outbound path processor.
Again a combined patch with #2881652: The inbound path processor does not check for content translations is available for testing purposes.
Comment #12
davy-r commentedThanks for contributing!