Problem/Motivation

There's only one usage in core and very few in contrib which could be replaced with $url->access()

Steps to reproduce

- http://codcontrib.hank.vps-private.net/search?text=renderAccess&filename= shows usage of both methods in contrib code

Proposed resolution

- Deprecate Url::toRenderArray() and Url::renderAccess()
- File follow-up to remove both in 11.0 #3343153: Remove deprecated code from \Drupal\Core\Url

Remaining tasks

- change record
- patch and test
- review/commit

User interface changes

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
Issue tags: +Needs change record updates
StatusFileSize
new2.81 KB

CR and initial patch, as there's contrib usage CR needs to be updated for Url::renderAccess() (marked @internal ATM)

andypost’s picture

+++ b/core/modules/shortcut/src/Form/SetCustomize.php
@@ -55,7 +55,9 @@ public function form(array $form, FormStateInterface $form_state) {
-      ] + $url->toRenderArray();
+        '#url' => $url,
+        '#options' => $url->getOptions(),

There's access check few lines above so no need for $render_array['#access_callback'] = [get_class(), 'renderAccess'];

andypost’s picture

StatusFileSize
new656 bytes
new2.84 KB

and now unset() no longer needed

catch’s picture

I checked the contrib usages, they are all doing:

if ($url->renderAccess($url->toRenderArray()))

Which seems like an extremely long way to do:

if ($url->access())

There are only two modules with a couple of usages each, so I think we could go ahead and deprecate both methods here.

andypost’s picture

StatusFileSize
new2.07 KB
new4.07 KB
andypost’s picture

Title: Deprecate Url::toRenderArray » Deporecate Url::toRenderArray() and Url::renderAccess()

better title

andypost’s picture

StatusFileSize
new1.49 KB
new4.08 KB

Fix CS for deprecation

catch’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Url.php
    @@ -770,8 +770,14 @@ public function toString($collect_bubbleable_metadata = FALSE) {
    +    @trigger_error('The ' . __METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use to inline its implementation. See https://www.drupal.org/node/3342977', E_USER_DEPRECATED);
    

    Maybe 'There is no direct replacement' instead of 'inline its implementation? - The uses in contrib should be refactored to something else entirely.

  2. +++ b/core/lib/Drupal/Core/Url.php
    @@ -836,8 +842,14 @@ public function access(AccountInterface $account = NULL, $return_as_object = FAL
       public static function renderAccess(array $element) {
    +    @trigger_error('The ' . __METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use to inline its implementation. See https://www.drupal.org/node/3342977', E_USER_DEPRECATED);
         return $element['#url']->access();
    

    Same here.

andypost’s picture

Status: Needs work » Needs review
Related issues: +#3342991: Deprecate LinkGeneratorInterface::generateFromLink()
StatusFileSize
new3.72 KB
new4.07 KB

Thanks, changed to suggested

andypost’s picture

Issue summary: View changes
Issue tags: -Needs change record updates

CR updated

catch’s picture

Title: Deporecate Url::toRenderArray() and Url::renderAccess() » Deprecate Url::toRenderArray() and Url::renderAccess()
Status: Needs review » Reviewed & tested by the community

The example in the CR is clear and covers literally every usage in contrib.

I think this is ready to go now.

rohan-sinha’s picture

Reviewed Patch on #10, issue has been resolved as observed, can be merged.

quietone’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.61 KB
new4.01 KB

The deprecation message for a method does not start with 'The'. And I was getting a phpcs errors. So, I updated the patch.

I also too the liberty of removing 'direct' from the deprecation message. It did not seem to be adding information.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thank you, curious why phpcs does not report it in CI

  • longwave committed 95bae2b6 on 10.1.x
    Issue #3342975 by andypost, quietone, catch: Deprecate Url::...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 10.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

pcambra’s picture

I know I'm late to the party, but why is toRenderArray deprecated? I only see the access method discussed.