entityTypeManager = $entityTypeManager; $this->date_field = $date_field; $this->conditions = $conditions; $this->date_format = $date_format; $this->entity_type = $entity_type; } final public function update(string $time_elapsed, array $old_values, array $new_values): void { $query = $this->entityTypeManager->getStorage($this->entity_type)->getQuery(); foreach($this->conditions as $cond_field=>$cond_value) { $query->condition($cond_field, $cond_value); } foreach($old_values as $old_field=>$old_value) { $query->condition($old_field, $old_value); } $query->condition($this->date_field, date($this->date_format, strtotime('-'.$time_elapsed)), "<"); foreach($query->execute() as $id) { $entity = $this->entityTypeManager->getStorage($this->entity_type)->load($id); foreach($new_values as $new_field=>$new_value) { $entity->$new_field = $new_value; } $entity->save(); } } }