- Issue created by @Grimreaper
- Merge request !43Draft: Issue #3482151 by grimreaper: Menu: fix module check. → (Open) created by Grimreaper
- 🇫🇷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->__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', ];
- 🇫🇷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.
- 🇫🇷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 'Closure' is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php). Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 129)