5 * Contains install and update functions for Field Layout.
8 use Drupal\Core\Cache\Cache;
9 use Drupal\Core\Entity\Entity\EntityFormDisplay;
10 use Drupal\Core\Entity\Entity\EntityViewDisplay;
11 use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
14 * Implements hook_install().
16 function field_layout_install() {
17 // Ensure each entity display has a layout.
18 $entity_save = function (EntityDisplayWithLayoutInterface $entity) {
19 $entity->ensureLayout()->save();
21 array_map($entity_save, EntityViewDisplay::loadMultiple());
22 array_map($entity_save, EntityFormDisplay::loadMultiple());
24 // Invalidate the render cache since all content will now have a layout.
25 Cache::invalidateTags(['rendered']);
29 * Implements hook_uninstall().
31 function field_layout_uninstall() {
32 // Reset each entity display to use the one-column layout to best approximate
33 // the absence of layouts.
34 $entity_save = function (EntityDisplayWithLayoutInterface $entity) {
35 $entity->setLayoutId('layout_onecol')->save();
37 array_map($entity_save, EntityViewDisplay::loadMultiple());
38 array_map($entity_save, EntityFormDisplay::loadMultiple());
40 // Invalidate the render cache since all content will no longer have a layout.
41 Cache::invalidateTags(['rendered']);