Menu Import function doesn't work with menu extra items fields

Created on 24 July 2020, almost 4 years ago
Updated 30 August 2023, 10 months ago

Problem/Motivation

Menu import function does not work with extra fields from menu item extras.

Steps to reproduce

After export a menu with extra fields from menu item extras module, like and image field, and try to import it in the server, it fails with a message:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: Field field_image is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->get('field_image') (Line: 628)
Drupal\Core\Entity\ContentEntityBase->set('field_image', ) (Line: 85)
Drupal\menu_export\Form\MenuImportForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)

Proposed resolution

During the first import, when we use the function MenuLinkContent::create(), save it to generate the correct id/uuid for the entry and then load it so the system will be able to handle the values.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡·Brazil aluzzardi Pelotas, RS

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.

  • πŸ‡¦πŸ‡·Argentina hanoii πŸ‡¦πŸ‡·UTC-3

    Re-rolled #6.

  • @hanoii opened merge request.
  • πŸ‡¦πŸ‡·Argentina hanoii πŸ‡¦πŸ‡·UTC-3

    ON #12, I first re-rolled #6 into 1.x, then tried it a bit, and I noticed it didn't really work very well, you seem to need to import it twice for the fields to work.

    I then tried #10, it didn't really work, a simple text field out of a vanilla drupal import on a menu item failed to import once exported (then removed) and then re-imported. It gave a fatal error on a missing field.

    I then tried #7 and it actually worked pretty good. I think this could be the better solution. And although I wouldn't mind to include all of the dependency injection and coding standard fixes, I agree with #10 that for reviewing purposes the changes are a lot. It wasn't at first, but I now agree those changes could go on a separate follow up issue.

    MR!9 opened with this change.

  • πŸ‡¨πŸ‡¦Canada SKAUGHT

    tested. at least this seems to be helping. I am testing using with a menu that has
    - a link
    - an image
    -a plain text item
    -a list,text.

    basic item and nested levels is made but field data is not working..

Production build 0.69.0 2024