Document how Link Attribute support works

Created on 1 May 2020, over 4 years ago
Updated 29 April 2024, 8 months ago

See the original issue at https://github.com/Ymbra/migrate_default_content/issues/62

jameswilson commented on Mar 11, 2018

Trying to import some default classes (via link_attributes module) with my default menu_link_content.

On the edit form the field name is link[0][options][attributes][class].

Link Attributes integration with Drupal core menus leverages the menu_link_content_data database table's link__options column and the data is serialized.

screenshot 2018-03-12 10 02 05

I've tried importing this value in a couple formats (see below) and neither work.

screenshot 2018-03-11 12 12 40

Attempt 1:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
class: icon-twitter
weight: -10

Attempt 2:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
optionsAttributesClass: icon-twitter
weight: -10

Attempt 3:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
options:
attributes:
class: icon-twitter
weight: -10

Attempt 4:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
linkOptionsAttributesClass: icon-twitter
weight: -10

Attempt 5:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
link:
options:
attributes:
class: icon-twitter
weight: -10

Attempt 6:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
options: 'a:1:{s:10:"attributes";a:1:{s:5:"class";s:12:"icon-twitter";}}'
weight: -10

Attempt 7:

-
title: Twitter
menu_name: social-links
uid: 1
linkUri: https://twitter.com/myhandle
linkOptions: 'a:1:{s:10:"attributes";a:1:{s:5:"class";s:12:"icon-twitter";}}'
weight: -10

Attempt 8:

-
title: Twitter
menu_name: social-links
uid: 1
link:
uri: https://twitter.com/myhandle
options: 'a:1:{s:10:"attributes";a:1:{s:5:"class";s:12:"icon-twitter";}}'
weight: -10

^ this last one actually triggered an error message but was also the only one of them all to result in an actual value (N;) ending up in the link__options column, however the link__uri field was empty.

The error was:

Call to a member function getUrl() on null in Drupal\menu_link_content\Entity\MenuLinkContent->getUrlObject() (line 78 of web/core/modules/menu_link_content/src/Entity/MenuLinkContent.php)

If I handle / prevent that error from happening in the MenuLinkContent.php getUrlObject function, it doesn't really solve the problem.

Do you have any suggestions? Thanks.

📌 Task
Status

Fixed

Version

2.0

Component

Documentation

Created by

🇪🇸Spain rodrigoaguilera Barcelona

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024