protected EntityDisplayRepository::getDisplayModeOptionsByBundle($display_type, $entity_type_id, $bundle)
Returns an array of enabled display mode options by bundle.
Parameters
$display_type: The display type to be retrieved. It can be "view_mode" or "form_mode".
string $entity_type_id: The entity type whose display mode options should be returned.
string $bundle: The name of the bundle.
Return value
array An array of display mode labels, keyed by the display mode ID.
File
- core/lib/Drupal/Core/Entity/EntityDisplayRepository.php, line 210
Class
- EntityDisplayRepository
- Provides a repository for entity display objects (view modes and form modes).
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | protected function getDisplayModeOptionsByBundle( $display_type , $entity_type_id , $bundle ) { // Collect all the entity's display modes. $options = $this ->getDisplayModeOptions( $display_type , $entity_type_id ); // Filter out modes for which the entity display is disabled // (or non-existent). $load_ids = array (); // Get the list of available entity displays for the current bundle. foreach ( array_keys ( $options ) as $mode ) { $load_ids [] = $entity_type_id . '.' . $bundle . '.' . $mode ; } // Load the corresponding displays. $displays = $this ->entityTypeManager ->getStorage( $display_type == 'form_mode' ? 'entity_form_display' : 'entity_view_display' ) ->loadMultiple( $load_ids ); // Unset the display modes that are not active or do not exist. foreach ( array_keys ( $options ) as $mode ) { $display_id = $entity_type_id . '.' . $bundle . '.' . $mode ; if (!isset( $displays [ $display_id ]) || ! $displays [ $display_id ]->status()) { unset( $options [ $mode ]); } } return $options ; } |
Please login to continue.