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:
parent
8adcf2d8f6
commit
dcace271a2
1 changed files with 12 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue