The Google Summer of Code has reached the end of the week #5 of the coding period with my project "Complete porting of Icons API to Drupal 8" being progressing smoothly with interesting challenges along the way.
In my previous blog post, I had mentioned that I'll be implementing the Icon Menu sub-module's form with the select field having the list of icon bundles installed and they will be fetched using the Plugin API and this select field will have an ajax callback which will alter the #autocomplete_route_name value of the Search icon text field.
During this week, I've implemented the form for the menu configuration page with the icon fields attached using the hook_form_alter() hook and this form will be visible to the form with the id menu_link_content_menu_link_content_form and menu_link_edit and as these form have the plugin ID stored at different locations the following snippet of code is used to fetch the desired plugin id from the appropriate form:
$settings = '';
if ($form_id == 'menu_link_edit') {
$settings = $form_state->getBuildInfo()['args'][0]->getPluginId();
}
if ($form_id == 'menu_link_content_menu_link_content_form') {
$settings = $form_state->getBuildInfo()['callback_object']->getEntity()->getPluginId();
}
This form will have all the fields wrapped in the Icon details field and has the following fields:
- Icon Bundle - Lists all the installed icon bundles as select field.
- Search Icon - Textfield which shows the icon based on the input and the icon available in the icon bundle specified.
- Icon Wrapper - HTML element to wrap the icon in with two options i and span.
- Icon Wrapper Classes - Textfield for class attribute value to be used for the icon.
- Position - Where to place the icon with the options as Before Title, After Title, Invisible Title, and Replace Title.
- Show In Breadcrumb - Whether to show the icon in the breadcrumb.
- Title Wrapper - Checkbox for whether to wrap the title of the menu.
- Title Wrapper Element - HTML element to wrap the title icon with.
- Title Wrapper Class - Textfield for class attribute value for the title wrapper.
The above form field values will be stored in the icon_menu.settings configuration and once they are saved the cache.render cache will be cleared using the following code snippet:
\Drupal::service('cache.render')->invalidateAll();
The following screenshot shows the icon menu form in the menu settings page:The following screenshot shows the autocomplete icon list of Font Awesome Bundle when typed in the Search Icon textfield:
The challenges faced during this week was to find a way to update the #autocomplete_route_name value for the Search Icon textfield when there is a change in the Icon Bundle select field and this was achieved using the AJAX Forms by regenerating the Search Icon textfield when there is a change in the Icon Bundle select field.
For the next week, I'll be implementing the a way to alter the menu link title using the template_preprocess_hook() and display the appropriate icon saved from the settings page of individual menu link and registering a new template for the menu link using Twig.
Comments
Post a Comment