Use routes and route parameters instead of paths in Controller

Created on 14 June 2023, over 1 year ago
Updated 16 September 2024, 2 months ago

Problem/Motivation

In the Controller:

      $edit_url = Link::fromTextAndUrl(t('Edit'), Url::fromUri('internal:/admin/config/login/role_login_settings/edit/' . $login_menu_data->rl_id, $url_options))
        ->toString();
      $delete_url = Link::fromTextAndUrl(t('Delete'), Url::fromUri('internal:/admin/config/login/role_login_settings/delete/' . $login_menu_data->rl_id, $url_options))
        ->toString();

better use routes and route parameters instead of internal: Uri's. Much cleaner and less prone to security flaws.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

RTBC

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • First commit to issue fork.
  • Status changed to Needs review 4 months ago
  • The changes I have made in the controller includes, edit and delete URLs are generated using Url::fromRoute() and corresponding Link objects are created, and these links are included in an $actions array which is then rendered and included in the table rows for display. additionally, I have also included injecting the database connection via dependency injection by using use Drupal\Core\Database\Connection and Symfony\Component\DependencyInjection\ContainerInterface, rather than directly using Database::getConnection()
    Please review the MR.

  • Status changed to RTBC 2 months ago
  • 🇮🇳India Tirupati_Singh

    Hi, I've applied the provided MR as a patch and it applied cleanly with no errors. I can confirm that the module functionality is working perfectly after applying the patch. I'm attaching the before and after fixes screenshots for reference. As the patch is resolving the issue and getting no errors while using the module hence moving the issue status to RTBC.

    Thanks!

Production build 0.71.5 2024