protected EntityDisplayBase::init()
Initializes the display.
This fills in default options for components:
- that are not explicitly known as either "visible" or "hidden" in the display,
- or that are not supposed to be configurable.
File
- core/lib/Drupal/Core/Entity/EntityDisplayBase.php, line 154
Class
- EntityDisplayBase
- Provides a common base class for entity view and form displays.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 | protected function init() { // Only populate defaults for "official" view modes and form modes. if ( $this ->mode !== static ::CUSTOM_MODE) { // Fill in defaults for extra fields. $context = $this ->displayContext == 'view' ? 'display' : $this ->displayContext; $extra_fields = \Drupal::entityManager()->getExtraFields( $this ->targetEntityType, $this ->bundle); $extra_fields = isset( $extra_fields [ $context ]) ? $extra_fields [ $context ] : array (); foreach ( $extra_fields as $name => $definition ) { if (!isset( $this ->content[ $name ]) && !isset( $this ->hidden[ $name ])) { // Extra fields are visible by default unless they explicitly say so. if (!isset( $definition [ 'visible' ]) || $definition [ 'visible' ] == TRUE) { $this ->content[ $name ] = array ( 'weight' => $definition [ 'weight' ] ); } else { $this ->hidden[ $name ] = TRUE; } } } // Fill in defaults for fields. $fields = $this ->getFieldDefinitions(); foreach ( $fields as $name => $definition ) { if (! $definition ->isDisplayConfigurable( $this ->displayContext) || (!isset( $this ->content[ $name ]) && !isset( $this ->hidden[ $name ]))) { $options = $definition ->getDisplayOptions( $this ->displayContext); if (! empty ( $options [ 'type' ]) && $options [ 'type' ] == 'hidden' ) { $this ->hidden[ $name ] = TRUE; } elseif ( $options ) { $this ->content[ $name ] = $this ->pluginManager->prepareConfiguration( $definition -> getType (), $options ); } // Note: (base) fields that do not specify display options are not // tracked in the display at all, in order to avoid cluttering the // configuration that gets saved back. } } } } |
Please login to continue.