Use fromRoute instead of fromUri in views field plugins

Created on 18 May 2023, about 1 year ago
Updated 21 July 2023, 11 months ago

Problem/Motivation

I'm trying to move the ShURLy links to a different path / menu structure as requested by a customer.
But the views field plugins use hard-coded path with Url::fromUri() which will not work once I override the path of the routes.

Steps to reproduce

namespace Drupal\mymodule\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('shurly.create')) {
      $route->setPath('/admin/content/shurly');
    }
    if ($route = $collection->get('shurly.edit')) {
      $route->setPath('/admin/content/shurly/edit/{rid}');
    }
    if ($route = $collection->get('shurly.deactivate')) {
      $route->setPath('/admin/content/shurly/deactivate/{rid}');
    }
  }
}

edit and deactivate links will not work anymore on /admin/shurly page

Proposed resolution

use Url::fromRoute() instead of Url::fromUri()
also, use dependency injection for services

Remaining tasks

create a patch

User interface changes

none

API changes

none

Data model changes

none

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇷🇴Romania reszli Târgu Mureș

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

Comments & Activities

Production build 0.69.0 2024