Problem/Motivation
I have a case where I want to add a condition to the query in an EntityListBuilder. To do this I have to copy and override the entire getEntityIds() method:
/**
* Loads entity IDs using a pager sorted by the entity id.
*
* @return array
* An array of entity IDs.
*/
protected function getEntityIds() {
$query = $this->getStorage()->getQuery()
->accessCheck(TRUE)
->sort($this->entityType->getKey('id'));
// Only add the pager if a limit is specified.
if ($this->limit) {
$query->pager($this->limit);
}
return $query->execute();
}
By extracting the query to its own method, this would be easier to extend.
Steps to reproduce
Proposed resolution
Add a getQuery() method:
protected function getEntityIds() {
return $this->getQuery()->execute();
}
protected function getQuery() {
$query = $this->getStorage()->getQuery()
->accessCheck(TRUE)
->sort($this->entityType->getKey('id'));
// Only add the pager if a limit is specified.
if ($this->limit) {
$query->pager($this->limit);
}
return $query;
}
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
prabuela commentedComment #3
prabuela commentedComment #4
prabuela commentedComment #5
prabuela commentedComment #6
prabuela commentedComment #7
longwaveThanks, this method needs some documentation but this looks good otherwise.
Comment #8
prabuela commentedComment #9
prabuela commentedComment #10
joachim commentedGood idea, just a few things to fix:
That doesn't make sense as a @return. Does this need changing?
That's wrong.
Looks like the docblocks have got swapped around maybe?
As this is a new method, and protected, it should have a return type.
Comment #11
prabuela commentedComment #12
prabuela commentedComment #13
prabuela commentedComment #14
smustgrave commentedSeems the points from #10 have not been addressed
Also please include an interdiff with patches
Patch file names also seem incorrect.
Comment #15
akram khanadded updated patch and address comment #10
Comment #16
prabuela commentedComment #17
smustgrave commentedStill doesn't seem correct
+ protected function getQuery(): QueryInterface {
But the doc is saying an array is returned.
Comment #18
akram khanmade changes according to comment #17
Comment #19
akram khanComment #20
smustgrave commentedStill doesn't seem correct.
Someone should check the code vs doing what's just written here.
But this reading now as
getQuery returns query object used to load entity IDs.
But description says Loads entity IDs using the entity id.
Comment #21
akram khanmade changes now updated comment is more accurate and clarifies that the getQuery() method returns a query object for loading entity IDs from the storage
Comment #22
akram khanfixed CCF #21
Comment #23
smustgrave commentedThink it's ready for committer review.
Comment #25
longwaveIt's still an array of entity IDs, the return type here hasn't changed. I fixed this on commit.
Committed and pushed 46853e85a1 to 10.1.x. Thanks!