The getFormIconField function in Drupal\material_icons\Plugin\Field\FieldWidget\MaterialIcons assumes the icon field to be in a location within the form array that isn't always the case in the line:
return (!is_null($parents)) ? $form[$parents[3]][$parents[2]][$parents[1]]['icon'] : NULL;
It returning null results in the error
ResponseText: TypeError: Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse(): Argument #1 ($main_content) must be of type array, null given, called in /app/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php on line 89 in Drupal\Core\Render\MainContent\AjaxRenderer->renderResponse() (line 49 of /app/web/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php).
at paths like
/layout_builder/update/block/overrides/node.9316/0/blb_region_col_1/3c9a37a5-f66c-45ba-80f9-a804ea7108af?destination=/node/9316/layout&_wrapper_format=drupal_ajax&ajax_form=1
The $parents array where I saw this issue looks like this:

It's not clear if this is a problem with the $parents array pointing to the wrong location or other assumptions about the location that are incorrect.
It appears this issue may be caused by nesting the field type this module provides within a paragraph.
Steps to Reproduce
- Add a paragraph type with a material icons field
- Add a paragraph field to an entity referencing new paragraph type
- Add a paragraph and material icon value
- Change the "Icon Style" for the material icon field value
| Comment | File | Size | Author |
|---|
Issue fork material_icons-3457701
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
damondt commentedComment #3
damondt commentedComment #4
darvanenCan confirm this is happening to me too, trying to track down the cause, don't hold your breath.
Comment #6
darvanenWell I haven't found out *why* the array keys are not in the positions this module expects them to be on a particular request, but I have found a way to prevent the error, which doesn't affect the widget's behaviour as far as I can tell.
It seems with the
!is_null(there are times when the $parents variable is expected to be unavailable, so I think it's reasonable to assume that maybe in some situations it will be available but not in exactly the expected format. So I've made an MR to use a null coalesce operator instead of only checking the main variable.The same may well be applied at line 195 but I wanted to keep the initial MR to the scope defined within the issue.
Comment #7
damondt commentedIn the case I'm looking at the issue is that the icon field is nested within a paragraph field. There may be other issues with the logic in this function that the provided patch would work for, but it does not solve for every case.
Comment #8
damondt commentedComment #9
darvanenYou're absolutely right, for one thing we need to retain the null check on the parent variable. I've added a commit to that effect.
This does work for me for a field nested within paragraphs, are you saying it didn't work for you?
Comment #10
damondt commentedIt doesn't solve the issue I'm seeing, the paragraph is on a block content entity where I'm investigating which could be related
Comment #11
damondt commentedPushed progress on fixing this, problems identified:
- Assumes the nested depth of form field in form, this is not true if in paragraphs.
- Tries to return a field value as an ajax response, must be render array for field or ajax command.
I haven't fully solved the second issue yet, so leaving as "needs work" for now. It no longer errors on style value change, but the icon value is yet not updated successfully.
Comment #12
damondt commentedFixed ajax issue, marking as needs review.
Comment #13
darvanenI tested out a patch from the latest diff of the MR, in my situation there was still an error:
A difference might be that https://www.drupal.org/project/paragraphs_browser is in use on this site.
Comment #14
damondt commentedSorry about that, just pushed a fix.
Comment #15
darvanenAll good man, no apologies please - we're all in this together :)
I've tried out the latest code and at least on that project, it passes manual testing. I don't think that's enough to call it reviewed, but it's a start.
Comment #17
vladimirausexitstops the program. To exit the loop, usebreak.Comment #21
prasanth_n commentedFixed PHPCS violations and replaced exit with break.
Comment #22
vladimirausLooks good. 👍
Comment #24
b_sharpe commentedI'm having a hard time recreating this. I've tried inside a paragraph on a block inside Layout builder and not seeing any errors. Can you provide a step by step?
Comment #25
b_sharpe commentedNevermind, found it, but I think this is wayyyy over architecting. Let me try something new here.
Comment #28
b_sharpe commentedMuch cleaner using
NestedArray::getValue().Please review.
Comment #29
darvanenCode looks good - I'm afraid I don't have access to the projects I was using this on any more so I can't try it out.
Comment #31
b_sharpe commented