EntityDisplayRepository
class EntityDisplayRepository implements EntityDisplayRepositoryInterface (View source)
Provides a repository for entity display objects (view modes and form modes).
Traits
Provides methods to use a cache backend while respecting a 'use caches' flag.
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Properties
| protected CacheBackendInterface | $cacheBackend | Cache backend instance. |
from UseCacheBackendTrait |
| protected bool | $useCaches | Flag whether caches should be used or skipped. |
from UseCacheBackendTrait |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected array | $displayModeInfo | Static cache of display modes information. |
|
| protected LanguageManagerInterface | $languageManager | The language manager. |
|
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler. |
Methods
Fetches from the cache backend, respecting the use caches flag.
Stores data in the persistent cache, respecting the use caches flag.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a new EntityDisplayRepository.
Gets the entity view mode info for all entity types.
Gets the entity view mode info for a specific entity type.
Gets the entity form mode info for all entity types.
Gets the entity form mode info for a specific entity type.
Gets the entity display mode info for all entity types.
Gets the entity display mode info for a specific entity type.
Gets an array of view mode options.
Gets an array of form mode options.
Returns an array of enabled view mode options by bundle.
Returns an array of enabled form mode options by bundle.
Gets an array of display mode options.
Returns an array of enabled display mode options by bundle.
Clears the gathered display mode info.
Returns the entity view display associated with a bundle and view mode.
Returns the entity form display associated with a bundle and form mode.
Details
protected object|false
cacheGet(string $cid)
Fetches from the cache backend, respecting the use caches flag.
protected
cacheSet(string $cid, mixed $data, int $expire = Cache::PERMANENT, array $tags = [])
Stores data in the persistent cache, respecting the use caches flag.
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager)
Constructs a new EntityDisplayRepository.
array
getAllViewModes()
Gets the entity view mode info for all entity types.
array
getViewModes(string $entity_type_id)
Gets the entity view mode info for a specific entity type.
array
getAllFormModes()
Gets the entity form mode info for all entity types.
array
getFormModes(string $entity_type_id)
Gets the entity form mode info for a specific entity type.
protected array
getAllDisplayModesByEntityType(string $display_type)
Gets the entity display mode info for all entity types.
protected array
getDisplayModesByEntityType(string $display_type, string $entity_type_id)
Gets the entity display mode info for a specific entity type.
array
getViewModeOptions($entity_type)
Gets an array of view mode options.
array
getFormModeOptions(string $entity_type_id)
Gets an array of form mode options.
array
getViewModeOptionsByBundle(string $entity_type_id, string $bundle)
Returns an array of enabled view mode options by bundle.
array
getFormModeOptionsByBundle(string $entity_type_id, string $bundle)
Returns an array of enabled form mode options by bundle.
protected array
getDisplayModeOptions(string $display_type, string $entity_type_id)
Gets an array of display mode options.
protected array
getDisplayModeOptionsByBundle($display_type, string $entity_type_id, string $bundle)
Returns an array of enabled display mode options by bundle.
$this
clearDisplayModeInfo()
Clears the gathered display mode info.
EntityViewDisplayInterface
getViewDisplay(string $entity_type, string $bundle, string $view_mode = self::DEFAULT_DISPLAY_MODE)
Returns the entity view display associated with a bundle and view mode.
Use this function when assigning suggested display options for a component in a given view mode. Note that they will only be actually used at render time if the view mode itself is configured to use dedicated display settings for the bundle; if not, the 'default' display is used instead.
The function reads the entity view display from the current configuration, or returns a ready-to-use empty one if configuration entry exists yet for this bundle and view mode. This streamlines manipulation of display objects by always returning a consistent object that reflects the current state of the configuration.
Example usage:
- Set the 'body' field to be displayed and the 'field_image' field to be hidden on article nodes in the 'default' display.
EntityFormDisplayInterface
getFormDisplay(string $entity_type, string $bundle, string $form_mode = self::DEFAULT_DISPLAY_MODE)
Returns the entity form display associated with a bundle and form mode.
The function reads the entity form display object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for this bundle and form mode. This streamlines manipulation of entity form displays by always returning a consistent object that reflects the current state of the configuration.
Example usage:
- Set the 'body' field to be displayed with the 'text_textarea_with_summary' widget and the 'field_image' field to be hidden on article nodes in the 'default' form mode.