|
19 | 19 |
|
20 | 20 | namespace Drupal\apigee_edge\Entity\Query;
|
21 | 21 |
|
| 22 | +use Drupal\Core\Cache\CacheableMetadata; |
22 | 23 | use Drupal\Core\Entity\EntityInterface;
|
23 | 24 | use Drupal\Core\Entity\EntityTypeInterface;
|
24 | 25 | use Drupal\Core\Entity\EntityTypeManagerInterface;
|
@@ -84,9 +85,40 @@ public function execute() {
|
84 | 85 | // Basically, DeveloperAppQuery already applies a condition on the returned
|
85 | 86 | // result because this function gets called.
|
86 | 87 | $all_records = $this->getFromStorage();
|
87 |
| - $filter = $this->condition->compile($this); |
88 | 88 |
|
| 89 | + // @todo Proper entity query support that is aligned with the implementation |
| 90 | + // in \Drupal\Core\Entity\Query\Sql\Query::prepare() can be only added |
| 91 | + // if the following Entity API module issue is solved. |
| 92 | + // https://www.drupal.org/project/entity/issues/3332956 |
| 93 | + // (Having a fix for a similar Group module issue is a nice to have, |
| 94 | + // https://www.drupal.org/project/group/issues/3332963.) |
| 95 | + if ($this->accessCheck) { |
| 96 | + // Read meta-data from query, if provided. |
| 97 | + if (!$account = $this->getMetaData('account')) { |
| 98 | + // @todo DI dependency. |
| 99 | + $account = \Drupal::currentUser(); |
| 100 | + } |
| 101 | + $cacheability = CacheableMetadata::createFromRenderArray([]); |
| 102 | + $all_records = array_filter($all_records, static function (EntityInterface $entity) use ($cacheability, $account) { |
| 103 | + // Bubble up cacheability information even from a revoked access result. |
| 104 | + $result = $entity->access('view', $account, TRUE); |
| 105 | + $cacheability->addCacheableDependency($result); |
| 106 | + return $result->isAllowed(); |
| 107 | + }); |
| 108 | + // @todo DI dependencies. |
| 109 | + /** @var \Symfony\Component\HttpFoundation\Request $request */ |
| 110 | + $request = \Drupal::requestStack()->getCurrentRequest(); |
| 111 | + $renderer = \Drupal::service('renderer'); |
| 112 | + if ($request->isMethodCacheable() && $renderer->hasRenderContext()) { |
| 113 | + $build = []; |
| 114 | + $cacheability->applyTo($build); |
| 115 | + $renderer->render($build); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + $filter = $this->condition->compile($this); |
89 | 120 | $result = array_filter($all_records, $filter);
|
| 121 | + |
90 | 122 | if ($this->count) {
|
91 | 123 | return count($result);
|
92 | 124 | }
|
|
0 commit comments