Views Data Export not compatible 'Views: Filter by entity reference view' filter

Created on 23 June 2025, about 1 month ago

I have a view with a filter configured to use a 'Views: Filter by an entity reference view' reference method.

The filter is not compatible with Views Data Export.

When I try to export the csv I get a "submitted value... is not allowed" for the filter.

🐛 Bug report
Status

Active

Version

1.6

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lelkneralfaro
  • After some debugging I have more information.

    The issue is not the 'Views: Filter by entity reference view' filter itself; that works when the 'Standard' export method is used rather than 'Batch'.

    When using the 'Batch' export method, problems arise. In my case I am using the 'Views: Filter by entity reference view' to construct a select element in an exposed filter. The options in the select element are determined by filtering a bundle based on a value in the path ( foo/2 uses the 2 to filter). The problem is that with batched export when the Entity Reference Source view is built the request is coming from /batch instead of /foo/2, so the url value used for filtering is unavailable, the select element options are never constructed and the data export throws an error because the exposed form entity reference select element has an option selected when submitted and the data export is initiated, but when the batch tries to recreate the view it does not populate that same entity reference select element with options. So, an option is selected in the page view, but the data export view does not have the option available when doing the batched export.

    I found that I could get it to work by passing the view arguments to getReferenceableEntities like this:

    diff --git a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionInterface.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionInterface.php
    index d2f9bf3063c..1fa32701706 100644
    --- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionInterface.php
    +++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionInterface.php
    @@ -35,7 +35,7 @@ interface SelectionInterface extends PluginFormInterface {
        *   entity bundle, which contains an array of entity labels (escaped),
        *   keyed by the entity ID.
        */
    -  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0);
    +  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $args = []);
     
       /**
        * Counts entities that are referenceable.
    
    diff --git a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    index 3f6b1c5695e..5912af50560 100644
    --- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    +++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
    @@ -229,7 +229,12 @@ protected function initializeView($match = NULL, $match_operator = 'CONTAINS', $
       /**
        * {@inheritdoc}
        */
    -  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    +  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0, $args = []) {
    +    $configuration = $this->getConfiguration();
    +    $configuration['view']['arguments'] = $args;
    +    if (!empty($args)) {
    +      $this->setConfiguration($configuration);
    +    }
         $entities = [];
         if ($display_execution_results = $this->getDisplayExecutionResults($match, $match_operator, $limit)) {
           $entities = $this->stripAdminAndAnchorTagsFromResults($display_execution_results);
    diff --git a/core/modules/views/src/Plugin/views/filter/EntityReference.php b/core/modules/views/src/Plugin/views/filter/EntityReference.php
    index b46a398ef73..3b0fc4d182c 100644
    --- a/core/modules/views/src/Plugin/views/filter/EntityReference.php
    +++ b/core/modules/views/src/Plugin/views/filter/EntityReference.php
    @@ -565,7 +565,7 @@ protected function getDefaultSelectedEntities(): array {
       protected function getValueOptionsCallback(SelectionInterface $selection_handler): array {
         $entity_data = [];
         if ($this->options['widget'] === static::WIDGET_SELECT) {
    -      $entity_data = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', static::WIDGET_SELECT_LIMIT);
    +      $entity_data = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', static::WIDGET_SELECT_LIMIT, $this->view->args);
         }
    
    

    But this requires making a change to core and feels like an undesirable approach. But it illustrates the problem.

Production build 0.71.5 2024