entityTypeManager = $entityTypeManager; $this->utils = $utils; $this->date_field = $date_field; $this->date_format = $date_format; $this->entity_type = $entity_type; $this->bundle = $bundle; } final public function update(array $conditions, string $time_elapsed, array $new_values): void { $query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery(); $conditions[] = [$this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"]; $conditions[] = ['type', $this->bundle, '=']; $this->utils->addConditionsToQuery($query, $conditions); foreach($query->execute() as $id) { $this->updateEntity($id, $new_values); } } private function updateEntity(int $entity_id, array $new_values): void { $entity = $this->entityTypeManager->getStorage($this->entity_type)->load($entity_id); foreach($new_values as $new_field=>$new_value) { $entity->$new_field = $new_value; } $entity->save(); } }