Wrong type of property MenuLinkContent::$link

Created on 5 June 2023, over 1 year ago
Updated 22 July 2023, over 1 year ago

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

🐛 Bug report
Status

Fixed

Version

10.1

Component
Documentation 

Last updated 2 days ago

No maintainer
Created by

🇳🇴Norway eiriksm Norway

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

Comments & Activities

Production build 0.71.5 2024