4f: Build up the getAll() method

Inject the entity type manager service into the ArticleRepository, and
use it to load and return all nodes.

This fails as not enough arguments are passed to the article repository
service from the container.
This commit is contained in:
Oliver Davies 2020-03-19 21:14:48 +00:00
parent 8adcf2d8f6
commit dcace271a2

View file

@ -2,10 +2,21 @@
namespace Drupal\my_module\Repository;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class ArticleRepository {
/**
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
private $nodeStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
}
public function getAll(): array {
return [];
return $this->nodeStorage->loadMultiple();
}
}