I am new to drupal and not a coding expert. I get this error: Only variables should be passed by reference in include() for the lines $tmp->role = count($parent->getRoles()) ? end($parent->getRoles()) : ”;
public function getRelations($isAll = false){ $user = DrupaluserEntityUser::load(Drupal::currentUser()->id()); if ($isAll) { /** @var UserService $userService */ $userService = Drupal::service('avofamilles.user_services'); $relations = $userService->getAllRelations($user->id()); } else { $relations = $user->get('field_relations')->getValue(); } $data_relations = []; if ($relations) { foreach ($relations as $relation){ /** @var User $parent */ $parent = DrupaluserEntityUser::load($relation['target_id']); if (!$parent) { continue; } $civility_relation = $parent->get('field_civility')->value; $civility = ""; if ($civility_relation == "father") { $civility = "Ex-Compagnon"; } else if ($civility_relation == "mother") { $civility = "Ex-Compagne"; } else { $civility = "Avocat"; } $image_relation = $parent->get('user_picture')->getValue(); $avatar_relation = ''; if (isset($image_relation[0]['target_id'])) { $file = File::load($image_relation[0]['target_id']); $avatar_relation = file_create_url($file->getFileUri()); } $tmp = new stdClass(); $tmp->uid = $relation['target_id']; $tmp->name = $parent->field_firstname->value; $tmp->email = $parent->getEmail(); $tmp->civility = $civility; $tmp->couleur = $parent->get('field_couleur')->value; $tmp->avatar = $avatar_relation; $tmp->avatar_url = $parent->get("field_avatar")->value; $tmp->is_waiting = $parent->get("field_is_waiting")->value; $tmp->role = count($parent->getRoles()) ? end($parent->getRoles()) : ''; $tmp->roles = $parent->getRoles()[1] ? : null; $data_relations[] = $tmp; } } return $data_relations; }
}
Can anybody see what is wrong ? Thank you for you help