Problem/Motivation

According to the class code comment, this is the property of the link property on an instance of a MenuLinkContent:

@property \Drupal\link\LinkItemInterface $link

This seems to not be the case. It's in fact a Drupal\Core\Field\FieldItemList so basically a list of Drupal\link\Plugin\Field\FieldType\LinkItem objects. Or a list of LinkItemInterface if you want.

To verify this in a clean install of Drupal 10.1.x I did the following:

  • Installed the standard profile
  • Created a menu link
  • Ran the script below
<?php

use Drupal\menu_link_content\Entity\MenuLinkContent;

// The link with an ID of 1 is the one I just created.
$link = MenuLinkContent::load(1);
var_dump([
  get_class($link),
  get_class($link->link),
  get_class($link->link->first()),
]);

The output was as follows:

array(3) {
  [0]=>
  string(47) "Drupal\menu_link_content\Entity\MenuLinkContent"
  [1]=>
  string(31) "Drupal\Core\Field\FieldItemList"
  [2]=>
  string(43) "Drupal\link\Plugin\Field\FieldType\LinkItem"
}

Steps to reproduce

See above

Proposed resolution

Change the doc comment

Remaining tasks

Agree on this
Commit

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

CommentFileSizeAuthor
#2 3364867.patch577 byteseiriksm

Issue fork drupal-3364867

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

eiriksm created an issue. See original summary.

eiriksm’s picture

Status: Active » Needs review
StatusFileSize
new577 bytes

Waiting for the issue fork. Here is a patch

eiriksm’s picture

Ah, there it was. Sorry for the double MR and patch. They should be the same though

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Simple change looks good.

longwave’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +ddd2023

Committed and pushed c1b8fdd9d9 to 11.x and 69e1c13c5a to 10.1.x. Thanks!

  • longwave committed 69e1c13c on 10.1.x
    Issue #3364867 by eiriksm: Wrong type of property MenuLinkContent::$link...

  • longwave committed c1b8fdd9 on 11.x
    Issue #3364867 by eiriksm: Wrong type of property MenuLinkContent::$link
    

Status: Fixed » Closed (fixed)

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