Menu: support non content menu links

Created on 21 October 2024, about 2 months ago
✨ Feature request
Status

Active

Version

1.0

Component

UI Icons Menu

Created by

🇫🇷France Grimreaper France 🇫🇷

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

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    about 2 months ago
    Total: 167s
    #315928
  • 🇫🇷France Grimreaper France 🇫🇷

    To store overrides, it would be nice to be able to store into core.menu.static_menu_link_overrides.yml like core does, but the allowed keys of the overrides are hardcoded, not possible to extend currently.

    Maybe in a second time when icons in core will have more implementations.

    So I will currently store in a ui_icons_menu.settings.yml

  • 🇫🇷France Grimreaper France 🇫🇷

    When I try to add an element with:

    function ui_icons_menu_form_menu_link_edit_alter(&$form, FormStateInterface $form_state, $form_id) {
      $options = $form_state->getBuildInfo()['args'][0]->getOptions();
    
      $form['icon'] = [
        '#type'  => 'details',
        '#title' => t('Icon'),
      ];
    
      $form['icon']['icon'] = [
        '#type'          => 'icon_autocomplete',
        '#title'         => t('Icon'),
        '#default_value' => !empty($options['icon']['icon']) ? $options['icon']['icon'] : '',
        '#show_settings' => TRUE,
      ];
    
    

    I got an ajax error after selecting an icon.

    <em class="placeholder">LogicException</em>
    : The database connection is not serializable. This probably means you are serializing an object that has an indirect reference to the database connection. Adjust your code so that is not necessary. Alternatively, look at DependencySerializationTrait as a temporary solution. in <em class="placeholder">Drupal\Core\Database\Connection-&gt;__sleep()</em>
    (line <em class="placeholder">1920</em>
    of <em class="placeholder">core/lib/Drupal/Core/Database/Connection.php</em>
    ). <pre class="backtrace">serialize(Array) (Line: 14)
    Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 129)
    

    I trie to put the DependencySerializationTrait in multiple classes in ui_icons, not better.

    The problem comes from ui_icons/src/Element/IconAutocomplete.php::processIconAjaxForm

    $element['icon_id']['#ajax'] = [
          'callback' => [static::class, 'buildSettingsAjaxCallback'],
          'options' => [
            'query' => [
              'element_parents' => implode('/', $element['#array_parents']),
            ],
          ],
          // Autocomplete is already doing the ajax progress.
          'progress' => [
            'type' => 'none',
          ],
          'disable-refocus' => TRUE,
          'wrapper' => $ajax_wrapper_id,
          'effect' => 'none',
          // As we used autocomplete we want matching events.
          // @todo check for too early errors related to change.
          'event' => 'autocompleteclose change',
        ];
    
  • Pipeline finished with Failed
    about 2 months ago
    Total: 311s
    #316086
  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    Except for the AJAX problem, MR is ok for review.

    I have not executed code quality tools for now as it is more in a POC state waiting for maintainers feedback.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 164s
    #316938
  • 🇫🇷France Grimreaper France 🇫🇷

    Wondering about translatability of the alt settings in case of YAML declared links.

  • 🇫🇷France mogtofu33

    I took some of the code here to fix the menu and allow the admin display.

    For the non menu link content, I checked and cannot find a solution for the serialization on the preview, perhaps the FormElement with autocomplete is simply not compatible here.

    As there is the workaround to manually create the same menu for non content link, I think it's less important for beta3 and can be pushed later.

  • 🇫🇷France Grimreaper France 🇫🇷

    Can I create a minimal "recovery mode" formElement to use in this case so for the moment a minimal version can be used?

    And then later it can be improved.

    To avoid to have a medium size MR which will rot and then rebasing will be time consuming.

  • 🇫🇷France mogtofu33

    What do you mean with minimal? Create an other element without the #ajax?

    In the meantime I guess the problem is perhaps from the renderer service called in buildSettingsAjaxCallback, which by the way is a wrong name as it's for the preview not the settings.

    For this part I took inspiration from ManagedFile::uploadAjaxCallback but perhaps I made it wrong and we don't need this render root. Need to investigate.

  • 🇫🇷France Grimreaper France 🇫🇷

    Create an other element without the #ajax?

    Yes, something like that.

  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    I have the same error when menu link content entities.

    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/structure/menu/item/25/edit?element_parents=link/widget/0/icon&destination=/admin/structure/menu/manage/footer-social-links&ajax_form=1
    StatusText: error
    ResponseText: 
    ...
    The website encountered an unexpected error. Try again later.Exception: Serialization of &#039;Closure&#039; is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php). Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 129)
    
Production build 0.71.5 2024