Problem/Motivation

Drupal 9 removed the EntityBase::url, EntityBase::urlInfo() and EntityBase::link() methods, as per https://www.drupal.org/node/2614344
Webform still has Webform::url, Webform::urlInfo and Webform::link.

Steps to reproduce

Install webform under Drupal 9 and call the \Drupal\webform\Entity\Webform::url method.

Proposed resolution

Put in the same BC layer that Drupal core did for later releases of Drupal 8, and mark the method as deprecated, then remove it in webform 7.

Remaining tasks

Everything.

User interface changes

None.

API changes

Deprecation of the \Drupal\webform\Entity\Webform::url method, and removal in webform 7 as a follow up.

Data model changes

Issue fork webform-3251189

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Steven Jones created an issue. See original summary.

paulocs made their first commit to this issue’s fork.

paulocs’s picture

Assigned: Unassigned » paulocs
paulocs’s picture

As this issue is causing problems with drupal 9 compatibility I agree to have the resolution proposed in the issue summary while webform supports Drupal 8.

I'm expanding the issue scope to include Webform::url(), Webform::urlInfo() and Webform::link(). I'll open a followup issue for remove those methods when webform supports Drupal 9 only.

paulocs’s picture

Title: [Drupal 9] \Drupal\webform\Entity\Webform::url method call fails » [Drupal 9] Webform::url, Webform::urlInfo() and Webform::link() method call fails
Assigned: paulocs » Unassigned
Issue summary: View changes
Status: Active » Needs review

jrockowitz made their first commit to this issue’s fork.

  • jrockowitz committed 7041a7d on 6.x authored by paulocs
    Issue #3251189 by paulocs: [Drupal 9] Webform::url, Webform::urlInfo()...
jrockowitz’s picture

Status: Needs review » Fixed
steven jones’s picture

Status: Fixed » Needs work

So thanks for the fast work on this one, but I don't think the fix is correct.

For example, the url method has been changed to merely return the value of toUrl but the return type of the former is a string, whereas the return type of the latter is \Drupal\Core\Url

I think you want the code from Drupal 8.9 core, so it should look like:

public function url($rel = 'canonical', $options = []) {
  @trigger_error('EntityInterface::url() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. EntityInterface::toUrl() instead. Note, a \\Drupal\\Core\\Url object is returned. See https://www.drupal.org/node/2614344', E_USER_DEPRECATED);

  // While self::toUrl() will throw an exception if the entity has no id,
  // the expected result for a URL is always a string.
  if ($this
    ->id() === NULL || !$this
    ->hasLinkTemplate($rel)) {
    return '';
  }
  $uri = $this
    ->toUrl($rel);
  $options += $uri
    ->getOptions();
  $uri
    ->setOptions($options);
  return $uri
    ->toString();
}

But equally the deprecation notice should probably reference the next version of Webform, rather than Drupal core?

The other methods might have similar issues, I've not checked, sorry.

paulocs’s picture

Status: Needs work » Needs review
steven jones’s picture

Status: Needs review » Reviewed & tested by the community

Looks better, thanks!

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs review

I don't think we have to deprecate these methods because they are already broken in Drupal 9 and marked as deprecated in Drupal 8 because the parent ConfigEntityBase has these methods.

Once we are only supporting Drupal 9, we should remove these methods. I would make this ticket postponed until we only support Drupal 9.

paulocs’s picture

Status: Needs review » Reviewed & tested by the community

Actually I think we can commit this issue as Webform still supports D9 and D8. I created this issue to remove the methods when webform drops supports on D8 #3251295: [Drupal 9.x] Remove Webform::url, Webform::urlInfo() and Webform::link() methods.

As @Steven Jones said, if this issue is not committed, if we call those methods in a drupal 9 project, we have a problem.
I'm moving back the issue to RTBC.

jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

  • jrockowitz committed 443f6e7 on 6.x authored by paulocs
    Issue #3251189 by paulocs, jrockowitz: [Drupal 9] Webform::url, Webform...
jrockowitz’s picture

Makes sense. Thanks for the PR.

Status: Fixed » Closed (fixed)

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