diff --git a/core/modules/views/src/Plugin/views/row/RssFields.php b/core/modules/views/src/Plugin/views/row/RssFields.php index a420bb7..fefd2b5 100644 --- a/core/modules/views/src/Plugin/views/row/RssFields.php +++ b/core/modules/views/src/Plugin/views/row/RssFields.php @@ -3,7 +3,8 @@ namespace Drupal\views\Plugin\views\row; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Url; +use Drupal\Core\Path\PathValidatorInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Renders an RSS item based on fields. @@ -19,6 +20,43 @@ class RssFields extends RowPluginBase { /** + * The path validator. + * + * @var \Drupal\Core\Path\PathValidatorInterface + */ + protected $pathValidator; + + /** + * Constructs a RssFields object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Path\PathValidatorInterface $path_validator + * The path validator. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, PathValidatorInterface $path_validator) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->pathValidator = $path_validator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('path.validator') + ); + } + + /** * Does the row plugin support to add fields to it's output. * * @var bool @@ -141,7 +179,12 @@ public function render($row) { $item->title = $this->getField($row_index, $this->options['title_field']); // @todo Views should expect and store a leading /. See: // https://www.drupal.org/node/2423913 - $item->link = Url::fromUserInput('/' . $this->getField($row_index, $this->options['link_field']))->setAbsolute()->toString(); + $item->link = $this->getField($row_index, $this->options['link_field']); + + // Set to a URL if value is a valid path. + if ($url = $this->pathValidator->getUrlIfValid($item->link)) { + $item->link = $url->setAbsolute()->toString(); + } $field = $this->getField($row_index, $this->options['description_field']); $item->description = is_array($field) ? $field : ['#markup' => $field]; @@ -160,7 +203,9 @@ public function render($row) { $guid_is_permalink_string = 'true'; // @todo Enforce GUIDs as system-generated rather than user input? See // https://www.drupal.org/node/2430589. - $item_guid = Url::fromUserInput('/' . $item_guid)->setAbsolute()->toString(); + if ($url = $this->pathValidator->getUrlIfValid($item_guid)) { + $item_guid = $url->setAbsolute()->toString(); + } } $item->elements[] = array( 'key' => 'guid',