Storage handlers control the loading, saving, and deleting of an entity. The \Drupal\Core\Entity\ContentEntityType
provides the base entity type definition for all content entity types. If it is not specified, then the default storage handler is \Drupal\Core\Entity\Sql\SqlContentEntityStorage
. This class can be extended to implement alternative load
methods or adjustments on saving.
In this recipe, we will implement a method that supports loading an entity by a specific property instead of having to write a specific loadByProperties
method call.
You will need a custom module to place the code into to implement a configuration entity type. Create an src
directory for your PSR-4 style classes. A custom content entity type needs to be implemented, such as the one in the Creating a content entity type recipe of this chapter.