Problem with SearchList in formatter, widget and .module

Created on 12 December 2024, 10 days ago

Problem/Motivation

I am getting an error with trying to set a icon on field_link.
Error loading icons: SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data:
in bootstrapicon-iconpicker-menu.js

And the error
Error loading icons: Error: Failed to fetch icons:
in bootstrapicon-iconpicker-menu.js while trying to set the default icon on the widget or formatter

As far as I can see the bootstrapicon-iconpicker-menu.js wants a path to iconSearch.json file and not an array of icons, which the settingsForm() function in the formatter and widget are giving.

Also the formatters, widget and .module is trying the access the iconSearch.json file with

$base_path = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$searchList = $base_path . $this->extensionListModule->getPath('menu_bootstrap_icon') . '/js/iconSearch.json';

If the site has a language prefix as default, will result in it trying to find the file in /enmodules/contrib/menu_bootstrap_icon/js/iconSearch.json.
The correct path is /modules/contrib/menu_bootstrap_icon/js/iconSearch.json

Steps to reproduce

Have the site language set to English as default and set "English (en) path prefix (Default language)" as 'en'

The error on the settings form for the formatter and widget:

  1. Create a new content type with link field
  2. Set the formatter or widget to "link (with bootstrap icon)" on the link field
  3. Open the setting for "link (with bootstrap icon)"
  4. The error appears in the console and a new entry in the recent log messages as "page not found"

The error while adding a icon to a link on content type:

  1. Create a new content type with link field
  2. Set the widget to "link (with bootstrap icon)" on the link field
  3. Try to create a new content and the error appears in the console and a new entry in the recent log messages as "page not found"

Proposed resolution

Use the function
base_path()
instead of
Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
to ignore the language prefix.

And set
['#attached']['drupalSettings']['menu_bootstrap_icon']['icons']
to be the path to iconSearch.json instead of an array of icons.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden danielmellin

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

Comments & Activities

Production build 0.71.5 2024