function BlockContentHooks::hasReusableConditions
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 BlockContentHooks::hasReusableConditions()
- BlockContentHooks::queryEntityReferenceAlter in core/
modules/ block_content/ src/ Hook/ BlockContentHooks.php - Implements hook_query_TAG_alter().
File
-
core/
modules/ block_content/ src/ Hook/ BlockContentHooks.php, line 203
Class
- BlockContentHooks
- Hook implementations for block_content.
Namespace
Drupal\block_content\HookCode
protected function hasReusableConditions(array $condition, array $tables) : bool {
// 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 ($this->hasReusableConditions($nested_condition, $tables)) {
return TRUE;
}
}
return FALSE;
}
if (isset($condition['field'])) {
$field = $condition['field'];
if ($field instanceof ConditionInterface) {
return $this->hasReusableConditions($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.