Problem/Motivation
Error on save, edit or delete the field Draggableviews: Content on Drupal 9.3.2.
TypeError: array_filter(): Argument #1 ($array) must be of type array, null given en array_filter() (line 243 de /web/core/modules/views/src/Plugin/views/field/BulkForm.php)
Steps to reproduce
Add field or edit Draggableviews: Content field, try to save settings of it.
Proposed resolution
Reviewing the error trace i found that the core class BulkForm manipulate the form_state values 'options' and 'selected_actions' and that generate the error since DraggableViewsField class unset that fields.
core/modules/views/src/Plugin/views/field/BulkForm.php
/**
* {@inheritdoc}
*/
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
parent::validateOptionsForm($form, $form_state);
$selected_actions = $form_state->getValue(['options', 'selected_actions']);
$form_state->setValue(['options', 'selected_actions'], array_values(array_filter($selected_actions)));
}
modules/contrib/draggableviews/src/Plugin/views/field/DraggableViewsField.php
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['draggableview_help'] = [
'#markup' => $this->t("A draggable element will be added to the first table column. You do not have to set this field as the first column in your View."),
];
parent::buildOptionsForm($form, $form_state);
// Remove all the fields that would break this or are completely ignored
// when rendering the drag interface.
unset($form['custom_label']);
unset($form['label']);
unset($form['element_label_colon']);
unset($form['action_title']);
unset($form['include_exclude']);
unset('selected_actions');
unset($form['exclude']);
unset($form['alter']);
unset($form['empty_field_behavior']);
unset($form['empty']);
unset($form['empty_zero']);
unset($form['hide_empty']);
unset($form['hide_alter_empty']);
}
I think a solution is not remove the fields by using unset, instead block the access of the fields by the property #access.
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['draggableview_help'] = [
'#markup' => $this->t("A draggable element will be added to the first table column. You do not have to set this field as the first column in your View."),
];
parent::buildOptionsForm($form, $form_state);
// Remove all the fields that would break this or are completely ignored
// when rendering the drag interface.
$form['custom_label']['#access'] = FALSE;
$form['label']['#access'] = FALSE;
$form['element_label_colon']['#access'] = FALSE;
$form['action_title']['#access'] = FALSE;
$form['include_exclude']['#access'] = FALSE;
$form['selected_actions']['#access'] = FALSE;
$form['exclude']['#access'] = FALSE;
$form['alter']['#access'] = FALSE;
$form['empty_field_behavior']['#access'] = FALSE;
$form['empty']['#access'] = FALSE;
$form['empty_zero']['#access'] = FALSE;
$form['hide_empty']['#access'] = FALSE;
$form['hide_alter_empty']['#access'] = FALSE;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | error-adding-or-editing-the-field-draggableviews-content-1.patch | 1.52 KB | maxmendez |
Comments
Comment #2
maxmendez commentedComment #3
damondt commentedConfirmed patch fixes fatal error adding/editing/deleting Draggableviews: Content field.
Comment #4
bohus ulrychThis patch works for me - Drupal 9.3.9
It will be nice to have it next release - existing ones are old several months.
Comment #5
david.qdoscc commentedPatch also works for me on D9.3.15. Would be great to get it committed please.
Comment #7
podarokThank you, merged