API page: http://api.drupal.org/api/drupal/includes%21entity.inc/function/EntityFi...
I'm having trouble working out how to use EntityFieldQuery's "tableSort" functionality. The docs refer to an "EFQ Header array" - even with the example provided in the comments (drawn from entity_query.test) it's not apparent how to build one of these, how it differs from a normal TableSort header, what the specifier/type keys are, or what to do to get the whole thing to work with theme_table.
I've had some success with simple properties, by simply including both (EFQ) specifier/type and (theme_table) field, like so:
$header = array(
'sku' => array(
'data' => t('Product code'),
'type' => 'property',
'specifier' => 'sku',
'field' => 'sku',
),
);
... But this does not help me sort by field values or - heaven forfend - field values on referenced entities.
Comment | File | Size | Author |
---|---|---|---|
#2 | entity_tablesort_doc_fix-1924622-2.patch | 841 bytes | babruix |
Comments
Comment #1
jhodgdonYeah, that definitely needs better documentation -- thanks for filing this issue!
It looks like in Drupal 8 the equivalent function is documented on this interface:
http://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Query!Query...
and the implementing method has essentially the same code as the d7 method:
http://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Query!Query...
It says:
$headers: An array of headers of the same struucture as described in theme_table(). Use a 'specifier' in place of a 'field' to specify what to sort on. This can be an entity or a field as described in condition().
Looking at the functions called here to figure out how to sort, it does look like the documentation should be:
An array of headers of the same structure as described in theme_table().
Seems like a good Novice project to fix that documentation for D7.
Comment #2
babruix CreditAttribution: babruix commentedChanged "
An EFQ Header array based on which the order clause
" to simple "An array of headers of the same structure as described in theme_table().
" as suggested by jhodgdon.Please, review.
Comment #3
jhodgdonThanks, looks good! I'll get this committed when it turns green (just in case).
Comment #4
kingandy CreditAttribution: kingandy commentedA theme_table header array is the one thing this is not. theme_table requires the 'field' element, whereas EFQ takes a 'type' and this arcane, unspecified 'specifier' entry which according to this example may be a string or an array of 'field' and 'column'. That's the part that needs documenting.
Comment #5
jhodgdonIn that case we need to fix the Drupal 8 documentation first.
Comment #6
kingandy CreditAttribution: kingandy commentedThe Drupal 8 documentation does at least say to "Use a 'specifier' in place of a 'field' to specify what to sort on. This can be an entity or a field as described in condition()." I'm not sure why that was left out of the D7 patch.
It still needs some work, as I don't know what condition() is being referred to.
Comment #7
babruix CreditAttribution: babruix commentedIn D8 it has misspelling in tableSort @param $headers: "An array of headers of the same struucture".
For me is not clear, should I change D7 patch or how if we going to change D8 first, what exactly should be checked and changed?
Comment #8
jhodgdonWe always fix problems in Drupal 8 before backporting them to Drupal 7. At this point, I'm pretty confused about what the Drupal 8 docs should say, so I am not sure how to fix them. I'm hoping that kingandy or someone else who understands what the inputs should be can fix the D8 docs so that they are clear.
Comment #9
kingandy CreditAttribution: kingandy commentedThis is kind of the problem, I know it needs documenting because I was trying to find out how it works and I couldn't find any docs on it :D
As far as I can see, the D8 docs seem to be basically correct but we need to clarify what "an entity or a field as described in condition()" is referencing. My first thought was QueryInterface::condition(), but I can't see anything in there that maps to the 'specifier' element.
Comment #10
kristiaanvandeneyndeSo far I've figured out that if you want to:
Sort on an entity's property, you use:
Sort on metadata of an entity (i.e. bundle, ...), you use:
Sort on an entity's field, you use:
Comment #11
kristiaanvandeneyndeJust noticed that all three 'known' types have an OrderBy counterpart method:
So it seems to me that those are the three only possible options.
Comment #20
catch