- Issue created by @pvbergen
JoinPluginBase::extra mentions the possibility to add a formula in the "field" key of the extra section in a join definition.
I couldn't find any hint in the code for this option, I assume that this is a left over comment from 7.x.
I habe a case where adding a formula would improve the filter performance as I can add some checks directly into the join condition. I could solve it with a having expression but this would mean to join more entries than necessary.
As the option seems to have existed at some point, I added it back in with specific keys "formula" and "left_formula".
Current docs say they allow treating the field key as a formula:
$definition = [
'type' => 'INNER',
'table' => 'node__field_XX',
'field' => 'entity_id',
'left_table' => 'node_field_data',
'left_field' => 'nid',
'operator' => '=',
'extra' => [
0 => [
'field' => '(field_XXX_end_value IS NULL OR field_XXX_end_value > CURDATE() - INTERVAL 1 DAY)',
'value' => '',
'operator' => '',
]
],
];
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$query->queueTable('node__field_XXX', NULL, $join);
This will result in a SQL error as "JoinPluginBase::buildExtra" will treat the expression as a field name.
I extended "JoinPluginBase::buildExtra" to accept new keys "formula" and "left_formula" in the extra section.
The example from above would now look like this:
$definition = [
'type' => 'INNER',
'table' => 'node__field_XX',
'field' => 'entity_id',
'left_table' => 'node_field_data',
'left_field' => 'nid',
'operator' => '=',
'extra' => [
0 => [
'formula' => '(field_XXX_end_value IS NULL OR field_XXX_end_value > CURDATE() - INTERVAL 1 DAY)',
]
],
];
$join = Views::pluginManager('join')->createInstance('standard', $definition);
$query->queueTable('node__field_XXX', NULL, $join);
- Review and tests
- None
- Adds new keys to the extra section of JoinPluginBase.
- None
Active
10.2 ✨
Last updated