Commit 30cad25c authored by catch's avatar catch

Issue #2031717 by Berdir, swentel, fago: Make entity module not required.

parent 3afec501
# Schema for Configuration files of the entity module.
entity.view_mode.*.*:
core.entity_view_mode.*.*:
type: mapping
label: 'Entity view mode settings'
mapping:
......@@ -29,7 +29,7 @@ entity.view_mode.*.*:
type: config_dependencies
label: 'Dependencies'
entity.form_mode.*.*:
core.entity_form_mode.*.*:
type: config_entity
label: 'Entity form mode settings'
mapping:
......@@ -47,7 +47,7 @@ entity.form_mode.*.*:
label: 'Cache'
# Overview configuration information for view mode or form mode displays.
entity.view_display.*.*.*:
core.entity_view_display.*.*.*:
type: config_entity
label: 'Entity display'
mapping:
......@@ -79,7 +79,7 @@ entity.view_display.*.*.*:
label: 'Value'
# Overview configuration information for form mode displays.
entity.form_display.*.*.*:
core.entity_form_display.*.*.*:
type: config_entity
label: 'Entity form display'
mapping:
......
......@@ -250,7 +250,7 @@ public function toArray() {
$id_key = $this->getEntityType()->getKey('id');
foreach (array_keys($definition['mapping']) as $name) {
// Special handling for IDs so that computed compound IDs work.
// @see \Drupal\entity\EntityDisplayBase::id()
// @see \Drupal\Core\Entity\EntityDisplayBase::id()
if ($name == $id_key) {
$properties[$name] = $this->id();
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\Config\Entity;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityStorageInterface;
/**
......@@ -17,6 +19,48 @@
*/
abstract class ConfigEntityBundleBase extends ConfigEntityBase {
/**
* Renames displays when a bundle is renamed.
*/
protected function renameDisplays() {
// Rename entity displays.
if ($this->getOriginalId() !== $this->id()) {
foreach ($this->loadDisplays('entity_view_display') as $display) {
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->mode;
$display->set('id', $new_id);
$display->bundle = $this->id();
$display->save();
}
}
// Rename entity form displays.
if ($this->getOriginalId() !== $this->id()) {
foreach ($this->loadDisplays('entity_form_display') as $form_display) {
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->mode;
$form_display->set('id', $new_id);
$form_display->bundle = $this->id();
$form_display->save();
}
}
}
/**
* Deletes display if a bundle is deleted.
*/
protected function deleteDisplays() {
// Remove entity displays of the deleted bundle.
if ($displays = $this->loadDisplays('entity_view_display')) {
$storage = $this->entityManager()->getStorage('entity_view_display');
$storage->delete($displays);
}
// Remove entity form displays of the deleted bundle.
if ($displays = $this->loadDisplays('entity_form_display')) {
$storage = $this->entityManager()->getStorage('entity_form_display');
$storage->delete($displays);
}
}
/**
* {@inheritdoc}
*/
......@@ -27,6 +71,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
entity_invoke_bundle_hook('create', $this->getEntityType()->getBundleOf(), $this->id());
}
elseif ($this->getOriginalId() != $this->id()) {
$this->renameDisplays();
entity_invoke_bundle_hook('rename', $this->getEntityType()->getBundleOf(), $this->getOriginalId(), $this->id());
}
}
......@@ -38,8 +83,29 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
parent::postDelete($storage, $entities);
foreach ($entities as $entity) {
$entity->deleteDisplays();
entity_invoke_bundle_hook('delete', $entity->getEntityType()->getBundleOf(), $entity->id());
}
}
/**
* Returns view or form displays for this bundle.
*
* @param string $entity_type_id
* The entity type ID of the display type to load.
*
* @return \Drupal\Core\Entity\Display\EntityDisplayInterface[]
* A list of matching displays.
*/
protected function loadDisplays($entity_type_id) {
$ids = \Drupal::entityQuery($entity_type_id)
->condition('id', $this->getEntityType()->getBundleOf() . '.' . $this->getOriginalId() . '.', 'STARTS_WITH')
->execute();
if ($ids) {
$storage = $this->entityManager()->getStorage($entity_type_id);
return $storage->loadMultiple($ids);
}
return array();
}
}
......@@ -8,8 +8,8 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity\Entity\EntityFormDisplay;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\entity\Entity\EntityFormDisplay.
* Contains \Drupal\Core\Entity\Entity\EntityFormDisplay.
*/
namespace Drupal\entity\Entity;
namespace Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\EntityDisplayBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity\EntityDisplayBase;
/**
* Configuration entity that contains widget options for all components of a
......@@ -19,7 +19,6 @@
* @ConfigEntityType(
* id = "entity_form_display",
* label = @Translation("Entity form display"),
* config_prefix = "form_display",
* entity_keys = {
* "id" = "id",
* "status" = "status"
......
......@@ -2,16 +2,16 @@
/**
* @file
* Contains \Drupal\entity\Entity\EntityFormMode.
* Contains \Drupal\Core\Entity\Entity\EntityFormMode.
*/
namespace Drupal\entity\Entity;
namespace Drupal\Core\Entity\Entity;
use Drupal\entity\EntityDisplayModeBase;
use Drupal\entity\EntityFormModeInterface;
use Drupal\Core\Entity\EntityDisplayModeBase;
use Drupal\Core\Entity\EntityFormModeInterface;
/**
* Defines the form mode configuration entity class.
* Defines the entity form mode configuration entity class.
*
* Form modes allow entity forms to be displayed differently depending on the
* context. For instance, the user entity form can be displayed with a set of
......@@ -26,27 +26,13 @@
*
* @see \Drupal\Core\Entity\EntityManagerInterface::getAllFormModes()
* @see \Drupal\Core\Entity\EntityManagerInterface::getFormModes()
* @see hook_entity_form_mode_info_alter()
*
* @ConfigEntityType(
* id = "form_mode",
* id = "entity_form_mode",
* label = @Translation("Form mode"),
* handlers = {
* "list_builder" = "Drupal\entity\EntityFormModeListBuilder",
* "form" = {
* "add" = "Drupal\entity\Form\EntityFormModeAddForm",
* "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm",
* "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm"
* }
* },
* admin_permission = "administer display modes",
* entity_keys = {
* "id" = "id",
* "label" = "label"
* },
* links = {
* "delete-form" = "entity.form_mode.delete_form",
* "edit-form" = "entity.form_mode.edit_form"
* }
* )
*/
......
......@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\entity\Entity\EntityViewDisplay.
* Contains \Drupal\Core\Entity\Entity\EntityViewDisplay.
*/
namespace Drupal\entity\Entity;
namespace Drupal\Core\Entity\Entity;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\entity\EntityDisplayBase;
use Drupal\Core\Entity\EntityDisplayBase;
/**
* Configuration entity that contains display options for all components of a
......@@ -19,10 +19,6 @@
* @ConfigEntityType(
* id = "entity_view_display",
* label = @Translation("Entity view display"),
* handlers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigEntityStorage"
* },
* config_prefix = "view_display",
* entity_keys = {
* "id" = "id",
* "status" = "status"
......
......@@ -2,16 +2,16 @@
/**
* @file
* Contains \Drupal\entity\Entity\EntityViewMode.
* Contains \Drupal\Core\Entity\Entity\EntityViewMode.
*/
namespace Drupal\entity\Entity;
namespace Drupal\Core\Entity\Entity;
use Drupal\entity\EntityDisplayModeBase;
use Drupal\entity\EntityViewModeInterface;
use Drupal\Core\Entity\EntityDisplayModeBase;
use Drupal\Core\Entity\EntityViewModeInterface;
/**
* Defines the view mode configuration entity class.
* Defines the entity view mode configuration entity class.
*
* View modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page ('full'
......@@ -30,24 +30,11 @@
* @see hook_entity_view_mode_info_alter()
*
* @ConfigEntityType(
* id = "view_mode",
* id = "entity_view_mode",
* label = @Translation("View mode"),
* handlers = {
* "list_builder" = "Drupal\entity\EntityDisplayModeListBuilder",
* "form" = {
* "add" = "Drupal\entity\Form\EntityDisplayModeAddForm",
* "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm",
* "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm"
* }
* },
* admin_permission = "administer display modes",
* entity_keys = {
* "id" = "id",
* "label" = "label"
* },
* links = {
* "delete-form" = "entity.view_mode.delete_form",
* "edit-form" = "entity.view_mode.edit_form"
* }
* )
*/
......
......@@ -2,13 +2,12 @@
/**
* @file
* Contains \Drupal\entity\EntityDisplayBase.
* Contains \Drupal\Core\Entity\EntityDisplayBase.
*/
namespace Drupal\entity;
namespace Drupal\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\field\Entity\FieldInstanceConfig;
......@@ -186,7 +185,7 @@ public function calculateDependencies() {
}
// Depend on configured modes.
if ($this->mode != 'default') {
$mode_entity = \Drupal::entityManager()->getStorage($this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
$mode_entity = \Drupal::entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
$this->addDependency('entity', $mode_entity->getConfigDependencyName());
}
return $this->dependencies;
......
......@@ -2,14 +2,13 @@
/**
* @file
* Contains \Drupal\entity\EntityDisplayModeBase.
* Contains \Drupal\Core\Entity\EntityDisplayModeBase.
*/
namespace Drupal\entity;
namespace Drupal\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
/**
* Base class for config entity types that hold settings for form and view modes.
......@@ -63,8 +62,8 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
* {@inheritdoc}
*/
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
/** @var \Drupal\entity\EntityDisplayModeInterface $a */
/** @var \Drupal\entity\EntityDisplayModeInterface $b */
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $a */
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $b */
// Sort by the type of entity the view mode is used for.
$a_type = $a->getTargetType();
$b_type = $b->getTargetType();
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\entity\EntityDisplayModeInterface.
* Contains \Drupal\Core\Entity\EntityDisplayModeInterface.
*/
namespace Drupal\entity;
namespace Drupal\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\entity\EntityFormModeInterface.
* Contains \Drupal\Core\Entity\EntityFormModeInterface.
*/
namespace Drupal\entity;
namespace Drupal\Core\Entity;
/**
* Provides an interface defining an entity form mode entity type.
......
......@@ -832,13 +832,14 @@ public function getFormModes($entity_type_id) {
protected function getAllDisplayModesByEntityType($display_type) {
if (!isset($this->displayModeInfo[$display_type])) {
$key = 'entity_' . $display_type . '_info';
$entity_type_id = 'entity_' . $display_type;
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->id;
if ($cache = $this->cacheBackend->get("$key:$langcode")) {
$this->displayModeInfo[$display_type] = $cache->data;
}
else {
$this->displayModeInfo[$display_type] = array();
foreach ($this->getStorage($display_type)->loadMultiple() as $display_mode) {
foreach ($this->getStorage($entity_type_id)->loadMultiple() as $display_mode) {
list($display_mode_entity_type, $display_mode_name) = explode('.', $display_mode->id(), 2);
$this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = $display_mode->toArray();
}
......
......@@ -10,14 +10,13 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\Render\Element;
use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\entity\EntityViewModeInterface.
* Contains \Drupal\Core\Entity\EntityViewModeInterface.
*/
namespace Drupal\entity;
namespace Drupal\Core\Entity;
/**
* Provides an interface defining an entity view mode entity type.
......
......@@ -942,7 +942,19 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
// the module already, which means that it might be loaded, but not
// necessarily installed.
$schema_store = \Drupal::keyValue('system.schema');
$entity_manager = \Drupal::entityManager();
foreach ($module_list as $module) {
// Clean up all entity bundles (including field instances) of every entity
// type provided by the module that is being uninstalled.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {
entity_invoke_bundle_hook('delete', $entity_type_id, $bundle);
}
}
}
// Allow modules to react prior to the uninstallation of a module.
$this->invokeAll('module_preuninstall', array($module));
......@@ -954,7 +966,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
\Drupal::service('config.manager')->uninstall('module', $module);
// Remove any entity schemas belonging to the module.
$entity_manager = \Drupal::entityManager();
$schema = \Drupal::database()->schema();
foreach ($entity_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) {
......
......@@ -24,7 +24,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
*
* @var array
*/
public static $modules = array('block_content_test', 'dblog');
public static $modules = array('block_content_test', 'dblog', 'entity');
/**
* Sets the test up.
......
......@@ -20,7 +20,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Render\Element;
......
......@@ -14,7 +14,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......
......@@ -7,7 +7,7 @@
namespace Drupal\datetime\Tests;
use Drupal\entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Datetime\DrupalDateTime;
......
......@@ -4,4 +4,3 @@ description: 'Generic entity functionality.'
package: Core
version: VERSION
core: 8.x
required: true
entity.view_mode_add:
route_name: entity.view_mode_add
entity.entity_view_mode_add:
route_name: entity.entity_view_mode_add
title: 'Add new view mode'
weight: 1
appears_on:
- entity.view_mode_list
- entity.entity_view_mode_list
entity.form_mode_add:
route_name: entity.form_mode_add
entity.entity_form_mode_add:
route_name: entity.entity_form_mode_add
title: 'Add new form mode'
weight: 1
appears_on:
- entity.form_mode_list
- entity.entity_form_mode_list
......@@ -3,13 +3,13 @@ entity.display_mode:
description: 'Configure what displays are available for your content and forms.'
route_name: entity.display_mode
parent: system.admin_structure
entity.view_mode_list:
entity.entity_view_mode_list:
title: 'View modes'
description: 'Manage custom view modes.'
route_name: entity.view_mode_list
route_name: entity.entity_view_mode_list
parent: entity.display_mode
entity.form_mode_list:
entity.entity_form_mode_list:
title: 'Form modes'
description: 'Manage custom form modes.'
route_name: entity.form_mode_list
route_name: entity.entity_form_mode_list
parent: entity.display_mode
entity.view_mode.edit_form:
entity.entity_view_mode.edit_form:
title: 'Edit'
route_name: entity.view_mode.edit_form
base_route: entity.view_mode.edit_form
route_name: entity.entity_view_mode.edit_form
base_route: entity.entity_view_mode.edit_form
entity.form_mode.edit_form:
entity.entity_form_mode.edit_form:
title: 'Edit'
route_name: entity.form_mode.edit_form
base_route: entity.form_mode.edit_form
route_name: entity.entity_form_mode.edit_form
base_route: entity.entity_form_mode.edit_form
entity.view_mode_list:
entity.entity_view_mode_list:
title: List
route_name: entity.view_mode_list
base_route: entity.view_mode_list
route_name: entity.entity_view_mode_list
base_route: entity.entity_view_mode_list
entity.form_mode_list:
entity.entity_form_mode_list:
title: List
route_name: entity.form_mode_list
base_route: entity.form_mode_list
route_name: entity.entity_form_mode_list
base_route: entity.entity_form_mode_list
......@@ -8,7 +8,6 @@
* entity system.
*/
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Routing\RouteMatchInterface;
/**
......@@ -26,9 +25,9 @@ function entity_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Managing view modes') . '</dt>';
$output .= '<dd>' . t('Each content entity can have various "modes" for viewing. For instance, a content item could be viewed in full content mode on its own page, teaser mode in a list, or RSS mode in a feed. You can create, edit the names of, and delete view modes on the <a href="!view-modes">View modes page</a>. Once a view mode has been set up, you can choose and format fields for the view mode within each entity sub-type on the Manage display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!view-modes' => \Drupal::url('entity.view_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '<dd>' . t('Each content entity can have various "modes" for viewing. For instance, a content item could be viewed in full content mode on its own page, teaser mode in a list, or RSS mode in a feed. You can create, edit the names of, and delete view modes on the <a href="!view-modes">View modes page</a>. Once a view mode has been set up, you can choose and format fields for the view mode within each entity sub-type on the Manage display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!view-modes' => \Drupal::url('entity.entity_view_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '<dt>' . t('Managing form modes') . '</dt>';
$output .= '<dd>' . t('Each content entity can have various editing forms appropriate for different situations, which are known as "form modes". For instance, you might want to define a quick editing mode that allows users to edit the most important fields, and a full editing mode that gives access to all the fields. You can create, edit the names of, and delete form modes on the <a href="!form-modes">Manage custom form modes page</a>. Once a form mode has been set up, you can choose which fields are available on that form within each entity sub-type on the Manage form display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!form-modes' => \Drupal::url('entity.form_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '<dd>' . t('Each content entity can have various editing forms appropriate for different situations, which are known as "form modes". For instance, you might want to define a quick editing mode that allows users to edit the most important fields, and a full editing mode that gives access to all the fields. You can create, edit the names of, and delete form modes on the <a href="!form-modes">Manage custom form modes page</a>. Once a form mode has been set up, you can choose which fields are available on that form within each entity sub-type on the Manage form display page. See the <a href="!field_ui">Field UI module help page</a> for more information.', array('!form-modes' => \Drupal::url('entity.entity_form_mode_list'), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</dd>';
$output .= '</dl>';
return $output;
}
......@@ -46,70 +45,26 @@ function entity_permission() {
}
/**
* Implements hook_entity_bundle_rename().
* Implements hook_entity_type_alter().
*/
function entity_entity_bundle_rename($entity_type_id, $bundle_old, $bundle_new) {
// Rename entity displays.
$entity_type = \Drupal::entityManager()->getDefinition('entity_view_display');
if ($bundle_old !== $bundle_new) {
$ids = \Drupal::configFactory()->listAll('entity.view_display.' . $entity_type_id . '.' . $bundle_old . '.');
foreach ($ids as $id) {
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
$display = entity_load('entity_view_display', $id);
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $display->mode;
$display->set('id', $new_id);
$display->bundle = $bundle_new;
$display->save();
}
}
function entity_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$form_mode = $entity_types['entity_form_mode'];
$form_mode->setListBuilderClass('Drupal\entity\EntityFormModeListBuilder');
$form_mode->setFormClass('add', 'Drupal\entity\Form\EntityFormModeAddForm');
$form_mode->setFormClass('edit', 'Drupal\entity\Form\EntityDisplayModeEditForm');
$form_mode->setFormClass('delete', 'Drupal\entity\Form\EntityDisplayModeDeleteForm');
$form_mode->set('admin_permission', 'administer display modes');
$form_mode->setLinkTemplate('delete-form', 'entity.entity_form_mode.delete_form');
$form_mode->setLinkTemplate('edit-form', 'entity.entity_form_mode.edit_form');
// Rename entity form displays.
$entity_type = \Drupal::entityManager()->getDefinition('entity_form_display');
if ($bundle_old !== $bundle_new) {
$ids = \Drupal::configFactory()->listAll('entity.form_display.' . $entity_type_id . '.' . $bundle_old . '.');
foreach ($ids as $id) {
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
$form_display = entity_load('entity_form_display', $id);
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $form_display->mode;
$form_display->set('id', $new_id);
$form_display->bundle = $bundle_new;
$form_display->save();
}
}
$view_mode = $entity_types['entity_view_mode'];
$view_mode->setListBuilderClass('Drupal\entity\EntityDisplayModeListBuilder');
$view_mode->setFormClass('add', 'Drupal\entity\Form\EntityDisplayModeAddForm');
$view_mode->setFormClass('edit', 'Drupal\entity\Form\EntityDisplayModeEditForm');
$view_mode->setFormClass('delete', 'Drupal\entity\Form\EntityDisplayModeDeleteForm');
$view_mode->set('admin_permission', 'administer display modes');
$view_mode->setLinkTemplate('delete-form', 'entity.entity_view_mode.delete_form');
$view_mode->setLinkTemplate('edit-form', 'entity.entity_view_mode.edit_form');
}
/**
* Implements hook_entity_bundle_delete().
*/
function entity_entity_bundle_delete($entity_type_id, $bundle) {
// Remove entity displays of the deleted bundle.
$entity_type = \Drupal::entityManager()->getDefinition('entity_view_display');
$ids = \Drupal::configFactory()->listAll('entity.view_display.' . $entity_type_id . '.' . $bundle . '.');
foreach ($ids as &$id) {
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
}
entity_delete_multiple('entity_view_display', $ids);
// Remove entity form displays of the deleted bundle.
$entity_type = \Drupal::entityManager()->getDefinition('entity_form_display');
$ids = \Drupal::configFactory()->listAll('entity.form_display.' . $entity_type_id . '.' . $bundle . '.');
foreach ($ids as &$id) {
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix());
}
entity_delete_multiple('entity_form_display', $ids);
}
/**
* Implements hook_module_preuninstall().