Added superficial tests for addConditionsToQuery

This commit is contained in:
2022-05-15 19:22:30 +01:00
parent b000e9414b
commit f1965ff3c1
3 changed files with 45 additions and 9 deletions

View File

@ -6,20 +6,22 @@ use \Drupal;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use RuntimeException;
class Utils {
// public function __construct(
// EntityTypeManager $entityTypeManager = null
// ) {
// if ($entityTypeManager == null) {
// $entityTypeManager = Drupal::entityTypeManager();
// }
// $this->entityTypeManager = $entityTypeManager;
// }
public function __construct(
EntityTypeManagerInterface $entityTypeManager = null
) {
if ($entityTypeManager == null) {
$entityTypeManager = Drupal::entityTypeManager();
}
$this->entityTypeManager = $entityTypeManager;
}
public function addConditionsToQuery(QueryInterface $query, array $conditions): void {
foreach($conditions as $condition) {
if (sizeof($condition) != 3) throw new RuntimeException('Utils::addConditionsToQuery needs each condition to consist of 3 strings');
$field = $condition[0];
$value = $condition[1];
$operator = $condition[2];