function _block_content_has_reusable_condition
Same name in other branches
- 8.9.x core/modules/block_content/block_content.module \_block_content_has_reusable_condition()
- 10 core/modules/block_content/block_content.module \_block_content_has_reusable_condition()
- 11.x core/modules/block_content/block_content.module \_block_content_has_reusable_condition()
Utility function to find nested conditions using the reusable field.
@todo Replace this function with a call to the API in https://www.drupal.org/project/drupal/issues/2984930
Parameters
array $condition: The condition or condition group to check.
array $tables: The tables from the related select query.
Return value
bool Whether the conditions contain any condition using the reusable field.
See also
\Drupal\Core\Database\Query\SelectInterface::getTables
1 call to _block_content_has_reusable_condition()
- block_content_query_entity_reference_alter in core/
modules/ block_content/ block_content.module - Implements hook_query_TAG_alter().
File
-
core/
modules/ block_content/ block_content.module, line 165
Code
function _block_content_has_reusable_condition(array $condition, array $tables) {
// If this is a condition group call this function recursively for each nested
// condition until a condition is found that return TRUE.
if (isset($condition['#conjunction'])) {
foreach (array_filter($condition, 'is_array') as $nested_condition) {
if (_block_content_has_reusable_condition($nested_condition, $tables)) {
return TRUE;
}
}
return FALSE;
}
if (isset($condition['field'])) {
$field = $condition['field'];
if (is_object($field) && $field instanceof ConditionInterface) {
return _block_content_has_reusable_condition($field->conditions(), $tables);
}
$field_parts = explode('.', $field);
$data_table = \Drupal::entityTypeManager()->getDefinition('block_content')
->getDataTable();
foreach ($tables as $table) {
if ($table['table'] === $data_table && $field_parts[0] === $table['alias'] && $field_parts[1] === 'reusable') {
return TRUE;
}
}
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.