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.

Command icon 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

jlscott created an issue. See original summary.

falco010’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new555 bytes

We 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.

graber made their first commit to this issue’s fork.

graber’s picture

Version: 4.2.x-dev » 4.4.x-dev

  • graber committed 4ff3062b on 4.4.x authored by jayelless
    Issue #3351434: Typed property must not be accessed before...
graber’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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