function EntityDisplayRebuilder::rebuildEntityTypeDisplays
Same name in other branches
- 8.9.x core/modules/field/src/EntityDisplayRebuilder.php \Drupal\field\EntityDisplayRebuilder::rebuildEntityTypeDisplays()
- 10 core/modules/field/src/EntityDisplayRebuilder.php \Drupal\field\EntityDisplayRebuilder::rebuildEntityTypeDisplays()
- 11.x core/modules/field/src/EntityDisplayRebuilder.php \Drupal\field\EntityDisplayRebuilder::rebuildEntityTypeDisplays()
Rebuild displays for single Entity Type.
Parameters
string $entity_type_id: The entity type machine name.
string $bundle: The bundle we need to rebuild.
File
-
core/
modules/ field/ src/ EntityDisplayRebuilder.php, line 76
Class
- EntityDisplayRebuilder
- Rebuilds all form and view modes for a passed entity bundle.
Namespace
Drupal\fieldCode
public function rebuildEntityTypeDisplays($entity_type_id, $bundle) {
// Get the displays.
$view_modes = $this->entityDisplayRepository
->getViewModeOptions($entity_type_id);
$form_modes = $this->entityDisplayRepository
->getFormModeOptions($entity_type_id);
// Save view mode displays.
$view_mode_ids = array_map(function ($view_mode) use ($entity_type_id, $bundle) {
return "{$entity_type_id}.{$bundle}.{$view_mode}";
}, array_keys($view_modes));
foreach ($this->entityTypeManager
->getStorage('entity_view_display')
->loadMultiple($view_mode_ids) as $display) {
$display->save();
}
// Save form mode displays.
$form_mode_ids = array_map(function ($form_mode) use ($entity_type_id, $bundle) {
return "{$entity_type_id}.{$bundle}.{$form_mode}";
}, array_keys($form_modes));
foreach ($this->entityTypeManager
->getStorage('entity_form_display')
->loadMultiple($form_mode_ids) as $display) {
$display->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.