Mercurial > hg > isophonics-drupal-site
diff core/modules/field_layout/field_layout.install @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/field_layout/field_layout.install Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,42 @@ +<?php + +/** + * @file + * Contains install and update functions for Field Layout. + */ + +use Drupal\Core\Cache\Cache; +use Drupal\Core\Entity\Entity\EntityFormDisplay; +use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface; + +/** + * Implements hook_install(). + */ +function field_layout_install() { + // Ensure each entity display has a layout. + $entity_save = function (EntityDisplayWithLayoutInterface $entity) { + $entity->ensureLayout()->save(); + }; + array_map($entity_save, EntityViewDisplay::loadMultiple()); + array_map($entity_save, EntityFormDisplay::loadMultiple()); + + // Invalidate the render cache since all content will now have a layout. + Cache::invalidateTags(['rendered']); +} + +/** + * Implements hook_uninstall(). + */ +function field_layout_uninstall() { + // Reset each entity display to use the one-column layout to best approximate + // the absence of layouts. + $entity_save = function (EntityDisplayWithLayoutInterface $entity) { + $entity->setLayoutId('layout_onecol')->save(); + }; + array_map($entity_save, EntityViewDisplay::loadMultiple()); + array_map($entity_save, EntityFormDisplay::loadMultiple()); + + // Invalidate the render cache since all content will no longer have a layout. + Cache::invalidateTags(['rendered']); +}