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