Problem/Motivation

ParagraphsWidget introduces getSettingOptions method to retrieve list of available options. If another widget uses the same settings_name as ParagraphsWidget, ie. edit_mode, closed_mode, autocollapse or add_mode, but provides custom list of options switching back to Paragraphs EXPERIMENTAL widget will cause AjaxError, because selected option could not be found in the array returned by getSettingOptions.

Here's the problematic code fragment:

    $edit_mode = $this->getSettingOptions('edit_mode')[$this->getSetting('edit_mode')];
    $closed_mode = $this->getSettingOptions('closed_mode')[$this->getSetting('closed_mode')];
    $add_mode = $this->getSettingOptions('add_mode')[$this->getSetting('add_mode')];

Ex. if $this->getSetting('add_mode') returns radios, because it was a valid option for previously selected widget, the code above will fail with Undefined offset error.

Proposed resolution

Add method to retrieve option label and fallback to key if the label cannot be found.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3047907-2-option-label.patch2.25 KBzaporylie

Comments

zaporylie created an issue. See original summary.

zaporylie’s picture

Status: Active » Needs review
StatusFileSize
new2.25 KB

This patch introduces new method, getSettingOptionLabel, that returns the label OR the key if label could not be found.

j.cowher’s picture

This issue still exists in 1.14. I am seeing the following error in when viewing /admin/structure/types/manage/[bundle]/form-display. I am using Drupal 9.3 and PHP 8.0.

Warning: Undefined array key "paragraphs_browser" in /app/web/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php on line 322

It appears that ParagraphsWidget::getSettingOptions() only considers the core options provided by the Paragraphs module and not other modules such as Paragraphs Browser.

The patch from #2 worked for me.

damienmckenna’s picture

Status: Needs review » Reviewed & tested by the community

Still seeing this problem with Paragraphs Browser on D11.3, and the patch resolves the problem for me.