When enabling readonly module, I get the following error when visiting pages where the forms have been disabled:

The website encountered an unexpected error. Please try again later. TypeError: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in /var/www/docroot/themes/contrib/thunder_admin/thunder_admin.theme on line 259

Readonly removes all the form elements, so it technically is receiving NULL instead of an array.

Wrapping that foreach() with a sanity check of if (isset($form[$field_name]['widget']) && is_array(($form[$field_name]['widget']))) { seems to do the trick.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jnicola created an issue. See original summary.

jnicola’s picture

jnicola’s picture

Title: Working with readonly module » Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array -- Adding variable sanity check in theme file for Working with readonly module
volkerk’s picture

I think the module should not unset these elements, this will probably trigger errors in other places as well.

Instead of unsetting children elements unset($form[$key]);, as its done in the source, it might be a good idea to deny access form[$key]['#access'] = FALSE; instead.

jnicola’s picture

So I haven't found it causing a problem anywhere else, just here.

Also, I think creating code that goes through all forms and finds all elements and disables all of them is arduous by comparison to a little sanity check here.

volkerk’s picture

Title: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array -- Adding variable sanity check in theme file for Working with readonly module » Add sanity check fixing argument error in combination with readonly module
volkerk’s picture

Status: Active » Needs review

  • volkerk authored a062fda on 8.x-3.x
    Issue #3111487 by jnicola, volkerk, chr.fritsch: Add sanity check fixing...

volkerk’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.