Problem/Motivation
I am getting the following error when trying to process a number of view results through vbo_export.
Error: Typed property Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase::$view must not be accessed before initialization in Drupal\vbo_export\Plugin\Action\VboExportBase->setHeader() (line 312 of /code/web/modules/contrib/vbo_export/src/Plugin/Action/VboExportBase.php)
When typed properties were introduced into classes in Php7.4, it became essential to initialise them before they were accessed. This is usually done in the class constructor, but it can be done by specifying a default value in the class where the property is defined.
The typed property protected ViewExecutable $view; in class \Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase is not initialised in the constructor (of final class Drupal\vbo_export\Pugin\Action\VboExportXlsx nor its parents). This gives the potential for the error if the property is accessed before it is set, which is happening in my case.
Proposed resolution
To avoid this problem, it would be useful to assign a default value to the typed property in the class ViewsBulkOperationsActionBase where it is defined. This could be done with a statement like:
protected ?ViewExecutable $view = NULL;
Additional notes
This looks like it is related to the issue #3253404: VBO 4 doesn't process every selected node.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | typed-property-must-not-be-accessed-before-initialisation-3351434-3.patch | 555 bytes | falco010 |
Issue fork views_bulk_operations-3351434
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 #3
falco010We have been using this MR for quite some time when we faced the same issue and it solved the error for us. Marking as RTBC.
Attached is a patch from the MR that can be added via Composer without including any further changes from the MR.
Comment #5
graber commentedComment #7
graber commented