I am new on Drupal 8 , so i have created a service class which return a list of data, 'articles' (node entities), and I call this service class inside a controller, but no data showing up :
My getArticles() method inside my service:
public function getArticles(){
$storage = \Drupal::service('entity_type.manager')->getStorage('node');
$my_entity_ids = $storage->getQuery()
->condition('type', 'article')
->condition('status', 1)
->execute();
$my_entities = $storage->loadMultiple($my_entity_ids);
return $my_entities;
}
My controller:
public function myPage() {
$data = \Drupal::service('mymodule.service');
$dataService = $data->getArticles();
return $dataService;
}
My result is a blank white page when I view the path routed to my controller, but I see the following message in my error log:
Recoverable fatal error : Object of class Drupal\node\Entity\Node could not be converted to string dans Drupal\Component\Utility\Xss::filter()'' -----"Warning : strlen() expects parameter 1 to be string, array given dans Drupal\Component\Utility\Unicode::validateUtf8()
Can anyone tell me please why i can't get the articles?