Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291721

Add getters to EntityQuery

$
0
0

Currently the entity query has no methods that would provide information about applied conditions, sorts,.. to the query. This does not follow the typical \Drupal\Core\Database\Query\Select in any way.

For example, if someone wants to retrieve the conditions, the only way to do it is a bit dirty:

      $reflection = new \ReflectionClass($query);
      $property = $reflection->getProperty('condition');
      $property->setAccessible(TRUE);
      $conditions = $property->getValue($query);
      $values = $conditions->conditions();

or sorting:

      $reflection = new \ReflectionClass($query);
      $property = $reflection->getProperty('sort');
      $property->setAccessible(TRUE);
      $values = $property->getValue($query);

I have various filter forms that apply filters to entity queries and I need to know which filters were already applied so I can proceed accordingly(ie. add additional conditions or remove certain conditions to figure out ranges or available options ...).

The EQ was created so we won't have to write "manual" queries anymore but it looks like no one expected that someone would like to retrieve any data from these queries, just like we can/do from the good old Drupal\Core\Database\Query\Select.

Additionally there is no way to reset any of the parameters since there are no referenced getters. So if I want to completely change the order/sort of the results I cannot just unset the already applied sorts or conditions like I can do in the simple query where there are the &conditions() or &getOrderBy() methods.

For me, this is critical for my application and without this I have to use simple query instead because even though I can get the protected data via reflection I cannot unset it, only add to it or alter it.

To implement:

  • &getConditions()
  • &getSort()
  • &getAggregate()
  • &getRange()
  • ...

Viewing all articles
Browse latest Browse all 291721

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>