On Drupal 8, in a custom entity class, I'm trying to load a repository in the constructor to be able to use custom functions in the preSave()
.
class MyEntity extends ContentEntityBase implements MyModuleInterface {
private $customStuff;
public function __construct(array $values, $entity_type, &$bundle = FALSE, $translations = []) {
$this->customStuff = \Drupal::service('mymodule.mymodule_repository');
}
(The service is defined in .services.yml in the correct module)
But I have the error :
The website encountered an unexpected error. Please try again later.Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 133 of core/lib/Drupal/Core/Entity/EntityTypeManager.php). Drupal\Core\Entity\EntityManager->getDefinition(NULL) (Line: 410)
How to inject custom dependence in custom entity ?