88882d39289dfd17cf266ac155f9b8fa2e5e4fcf
[yaffs-website] / web / core / modules / field_layout / field_layout.install
1 <?php
2
3 /**
4  * @file
5  * Contains install and update functions for Field Layout.
6  */
7
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;
13
14 /**
15  * Implements hook_install().
16  */
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();
22     }
23   };
24   array_map($entity_save, EntityViewDisplay::loadMultiple());
25   array_map($entity_save, EntityFormDisplay::loadMultiple());
26
27   // Invalidate the render cache since all content will now have a layout.
28   Cache::invalidateTags(['rendered']);
29 }
30
31 /**
32  * Implements hook_uninstall().
33  */
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();
40     }
41   };
42   array_map($entity_save, EntityViewDisplay::loadMultiple());
43   array_map($entity_save, EntityFormDisplay::loadMultiple());
44
45   // Invalidate the render cache since all content will no longer have a layout.
46   Cache::invalidateTags(['rendered']);
47 }