Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Contains install and update functions for Field Layout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Drupal\Core\Cache\Cache;
|
2018-09-20 12:16:43 +00:00
|
|
|
use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
|
|
|
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.
|
2018-09-20 12:16:43 +00:00
|
|
|
$entity_save = function (EntityDisplayInterface $entity) {
|
|
|
|
if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
|
|
|
$entity->ensureLayout()->save();
|
|
|
|
}
|
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
|
|
|
};
|
|
|
|
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.
|
2018-09-20 12:16:43 +00:00
|
|
|
$entity_save = function (EntityDisplayInterface $entity) {
|
|
|
|
if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
|
|
|
$entity->setLayoutId('layout_onecol')->save();
|
|
|
|
}
|
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
|
|
|
};
|
|
|
|
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']);
|
|
|
|
}
|