I wrote my own implementation of OutboundPathProcessorInterface
to rewrite the URL of nodes to use the content of their field_project_url field.
namespace DrupalmymodulePathProcessor; use DrupalCoreRenderBubbleableMetadata; use DrupalCorePathProcessor; use DrupalCorePathProcessorInboundPathProcessorInterface; use DrupalCorePathProcessorOutboundPathProcessorInterface; use DrupalnodeEntityNode; use SymfonyComponentHttpFoundationRequest; class MymoduleFieldRedirectPathProcessor implements OutboundPathProcessorInterface { public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { if (isset($options['entity']) && is_object($options['entity']) && method_exists($options['entity'], 'hasField')) { $node = $options['entity']; if ($node->hasField('field_project_url') && !$node->field_project_url->isEmpty()) { $project_url = $node->field_project_url->getValue(); if (preg_match("/^/node/[0-9]+/(edit|translate|delete|translations)$/i", $path)) { // dont alter operational paths } else { $path = $project_url[0]['uri']; dpm($project_url[0]['uri']); // 'http://url.com' $options['absolute'] = TRUE; $options['external'] = TRUE; $options['base_url'] = null; $options['prefix'] = null; } if ($bubbleable_metadata) { $bubbleable_metadata->addCacheableDependency($node); } } } return $path; } }
The teaser of that view has a title, an image linked to the content, and smart trimmed version of the body field, also linking to the content.
The value is appended, giving (for example) http://localhost:8888/myprojecthttp%3A//url.com.
This used to work, but I can’t even get this right with older Drupal 8 versions.
What am I doing wrong?
Sponsored by SupremePR