Problem/Motivation
When creating a new view for displaying nodes, the wizard can throw cause "Notice: Trying to access array offset on value of type null in Drupal\node\Plugin\views\wizard\Node->buildFilters() (line 288 of core/modules/node/src/Plugin/views/wizard/Node.php)."
This happens because the node wizard scans for all taxonomy term reference fields on the selected content type and then checks if any of them have the autocomplete form widget configured for the entity form display:
foreach ($taxonomy_fields as $field_name => $field) {
$widget = $display->getComponent($field_name);
// We define "tag-like" taxonomy fields as ones that use the
// "Autocomplete (Tags style)" widget.
if ($widget['type'] == 'entity_reference_autocomplete_tags') {
$tag_fields[$field_name] = $field;
}
}
The problem is $display->getComponent()
will return null
if the component is hidden on the form display. This causes the next if statement to throw the notice as you're trying to access the 'type' property of NULL.
This notice is new to PHP 7.4.
Note that EntityDisplayInterface::getComponent is already documented that it can return null
:
/**
* Gets the display options set for a component.
*
* @param string $name
* The name of the component.
*
* @return array|null
* The display options for the component, or NULL if the component is not
* displayed.
*/
public function getComponent($name);
Steps to reproduce
- Make sure error logging/notices are configured to be displayed.
- Create a content type with a taxonomy term reference field.
- Configure form display for that content type so the reference field is hidden.
- Visit /admin/structure/views/add to create a new view. Make sure "Content" is selected. You should see the PHP notice.
Proposed resolution
Check that the component actually exists and is not null before trying to use it.
Remaining tasks
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A