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

8.0.x
Nathaniel Catchpole 2014-09-02 10:36:57 +01:00
parent 3afec501d4
commit 30cad25c71
76 changed files with 241 additions and 239 deletions

View File

@ -1,6 +1,6 @@
# Schema for Configuration files of the entity module. # Schema for Configuration files of the entity module.
entity.view_mode.*.*: core.entity_view_mode.*.*:
type: mapping type: mapping
label: 'Entity view mode settings' label: 'Entity view mode settings'
mapping: mapping:
@ -29,7 +29,7 @@ entity.view_mode.*.*:
type: config_dependencies type: config_dependencies
label: 'Dependencies' label: 'Dependencies'
entity.form_mode.*.*: core.entity_form_mode.*.*:
type: config_entity type: config_entity
label: 'Entity form mode settings' label: 'Entity form mode settings'
mapping: mapping:
@ -47,7 +47,7 @@ entity.form_mode.*.*:
label: 'Cache' label: 'Cache'
# Overview configuration information for view mode or form mode displays. # Overview configuration information for view mode or form mode displays.
entity.view_display.*.*.*: core.entity_view_display.*.*.*:
type: config_entity type: config_entity
label: 'Entity display' label: 'Entity display'
mapping: mapping:
@ -79,7 +79,7 @@ entity.view_display.*.*.*:
label: 'Value' label: 'Value'
# Overview configuration information for form mode displays. # Overview configuration information for form mode displays.
entity.form_display.*.*.*: core.entity_form_display.*.*.*:
type: config_entity type: config_entity
label: 'Entity form display' label: 'Entity form display'
mapping: mapping:

View File

@ -250,7 +250,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
$id_key = $this->getEntityType()->getKey('id'); $id_key = $this->getEntityType()->getKey('id');
foreach (array_keys($definition['mapping']) as $name) { foreach (array_keys($definition['mapping']) as $name) {
// Special handling for IDs so that computed compound IDs work. // 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) { if ($name == $id_key) {
$properties[$name] = $this->id(); $properties[$name] = $this->id();
} }

View File

@ -7,6 +7,8 @@
namespace Drupal\Core\Config\Entity; namespace Drupal\Core\Config\Entity;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
/** /**
@ -17,6 +19,48 @@ use Drupal\Core\Entity\EntityStorageInterface;
*/ */
abstract class ConfigEntityBundleBase extends ConfigEntityBase { 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} * {@inheritdoc}
*/ */
@ -27,6 +71,7 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
entity_invoke_bundle_hook('create', $this->getEntityType()->getBundleOf(), $this->id()); entity_invoke_bundle_hook('create', $this->getEntityType()->getBundleOf(), $this->id());
} }
elseif ($this->getOriginalId() != $this->id()) { elseif ($this->getOriginalId() != $this->id()) {
$this->renameDisplays();
entity_invoke_bundle_hook('rename', $this->getEntityType()->getBundleOf(), $this->getOriginalId(), $this->id()); entity_invoke_bundle_hook('rename', $this->getEntityType()->getBundleOf(), $this->getOriginalId(), $this->id());
} }
} }
@ -38,8 +83,29 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
parent::postDelete($storage, $entities); parent::postDelete($storage, $entities);
foreach ($entities as $entity) { foreach ($entities as $entity) {
$entity->deleteDisplays();
entity_invoke_bundle_hook('delete', $entity->getEntityType()->getBundleOf(), $entity->id()); 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();
}
} }

View File

@ -8,8 +8,8 @@
namespace Drupal\Core\Entity; namespace Drupal\Core\Entity;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\entity\Entity\EntityFormDisplay;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**

View File

@ -2,15 +2,15 @@
/** /**
* @file * @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\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\EntityDisplayBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\entity\EntityDisplayBase;
/** /**
* Configuration entity that contains widget options for all components of a * Configuration entity that contains widget options for all components of a
@ -19,7 +19,6 @@ use Drupal\entity\EntityDisplayBase;
* @ConfigEntityType( * @ConfigEntityType(
* id = "entity_form_display", * id = "entity_form_display",
* label = @Translation("Entity form display"), * label = @Translation("Entity form display"),
* config_prefix = "form_display",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "status" = "status" * "status" = "status"

View File

@ -2,16 +2,16 @@
/** /**
* @file * @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\Core\Entity\EntityDisplayModeBase;
use Drupal\entity\EntityFormModeInterface; 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 * 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 * context. For instance, the user entity form can be displayed with a set of
@ -26,27 +26,13 @@ use Drupal\entity\EntityFormModeInterface;
* *
* @see \Drupal\Core\Entity\EntityManagerInterface::getAllFormModes() * @see \Drupal\Core\Entity\EntityManagerInterface::getAllFormModes()
* @see \Drupal\Core\Entity\EntityManagerInterface::getFormModes() * @see \Drupal\Core\Entity\EntityManagerInterface::getFormModes()
* @see hook_entity_form_mode_info_alter()
* *
* @ConfigEntityType( * @ConfigEntityType(
* id = "form_mode", * id = "entity_form_mode",
* label = @Translation("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 = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "label" * "label" = "label"
* },
* links = {
* "delete-form" = "entity.form_mode.delete_form",
* "edit-form" = "entity.form_mode.edit_form"
* } * }
* ) * )
*/ */

View File

@ -2,15 +2,15 @@
/** /**
* @file * @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\Component\Utility\NestedArray;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\ContentEntityInterface; 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 * Configuration entity that contains display options for all components of a
@ -19,10 +19,6 @@ use Drupal\entity\EntityDisplayBase;
* @ConfigEntityType( * @ConfigEntityType(
* id = "entity_view_display", * id = "entity_view_display",
* label = @Translation("Entity view display"), * label = @Translation("Entity view display"),
* handlers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigEntityStorage"
* },
* config_prefix = "view_display",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "status" = "status" * "status" = "status"

View File

@ -2,16 +2,16 @@
/** /**
* @file * @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\Core\Entity\EntityDisplayModeBase;
use Drupal\entity\EntityViewModeInterface; 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. * View modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page ('full' * For instance, a node can be displayed differently on its own page ('full'
@ -30,24 +30,11 @@ use Drupal\entity\EntityViewModeInterface;
* @see hook_entity_view_mode_info_alter() * @see hook_entity_view_mode_info_alter()
* *
* @ConfigEntityType( * @ConfigEntityType(
* id = "view_mode", * id = "entity_view_mode",
* label = @Translation("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 = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "label" * "label" = "label"
* },
* links = {
* "delete-form" = "entity.view_mode.delete_form",
* "edit-form" = "entity.view_mode.edit_form"
* } * }
* ) * )
*/ */

View File

@ -2,13 +2,12 @@
/** /**
* @file * @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\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldInstanceConfig;
@ -186,7 +185,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
} }
// Depend on configured modes. // Depend on configured modes.
if ($this->mode != 'default') { 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()); $this->addDependency('entity', $mode_entity->getConfigDependencyName());
} }
return $this->dependencies; return $this->dependencies;

View File

@ -2,14 +2,13 @@
/** /**
* @file * @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\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface; 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. * 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} * {@inheritdoc}
*/ */
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) { public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
/** @var \Drupal\entity\EntityDisplayModeInterface $a */ /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $a */
/** @var \Drupal\entity\EntityDisplayModeInterface $b */ /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $b */
// Sort by the type of entity the view mode is used for. // Sort by the type of entity the view mode is used for.
$a_type = $a->getTargetType(); $a_type = $a->getTargetType();
$b_type = $b->getTargetType(); $b_type = $b->getTargetType();

View File

@ -2,10 +2,10 @@
/** /**
* @file * @file
* Contains \Drupal\entity\EntityDisplayModeInterface. * Contains \Drupal\Core\Entity\EntityDisplayModeInterface.
*/ */
namespace Drupal\entity; namespace Drupal\Core\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface;

View File

@ -2,10 +2,10 @@
/** /**
* @file * @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. * Provides an interface defining an entity form mode entity type.

View File

@ -832,13 +832,14 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
protected function getAllDisplayModesByEntityType($display_type) { protected function getAllDisplayModesByEntityType($display_type) {
if (!isset($this->displayModeInfo[$display_type])) { if (!isset($this->displayModeInfo[$display_type])) {
$key = 'entity_' . $display_type . '_info'; $key = 'entity_' . $display_type . '_info';
$entity_type_id = 'entity_' . $display_type;
$langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->id; $langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)->id;
if ($cache = $this->cacheBackend->get("$key:$langcode")) { if ($cache = $this->cacheBackend->get("$key:$langcode")) {
$this->displayModeInfo[$display_type] = $cache->data; $this->displayModeInfo[$display_type] = $cache->data;
} }
else { else {
$this->displayModeInfo[$display_type] = array(); $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); 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(); $this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = $display_mode->toArray();
} }

View File

@ -10,14 +10,13 @@ namespace Drupal\Core\Entity;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\TypedData\TranslatableInterface; use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**

View File

@ -2,10 +2,10 @@
/** /**
* @file * @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. * Provides an interface defining an entity view mode entity type.

View File

@ -942,7 +942,19 @@ class ModuleHandler implements ModuleHandlerInterface {
// the module already, which means that it might be loaded, but not // the module already, which means that it might be loaded, but not
// necessarily installed. // necessarily installed.
$schema_store = \Drupal::keyValue('system.schema'); $schema_store = \Drupal::keyValue('system.schema');
$entity_manager = \Drupal::entityManager();
foreach ($module_list as $module) { 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. // Allow modules to react prior to the uninstallation of a module.
$this->invokeAll('module_preuninstall', array($module)); $this->invokeAll('module_preuninstall', array($module));
@ -954,7 +966,7 @@ class ModuleHandler implements ModuleHandlerInterface {
\Drupal::service('config.manager')->uninstall('module', $module); \Drupal::service('config.manager')->uninstall('module', $module);
// Remove any entity schemas belonging to the module. // Remove any entity schemas belonging to the module.
$entity_manager = \Drupal::entityManager();
$schema = \Drupal::database()->schema(); $schema = \Drupal::database()->schema();
foreach ($entity_manager->getDefinitions() as $entity_type) { foreach ($entity_manager->getDefinitions() as $entity_type) {
if ($entity_type->getProvider() == $module) { if ($entity_type->getProvider() == $module) {

View File

@ -24,7 +24,7 @@ class BlockContentCreationTest extends BlockContentTestBase {
* *
* @var array * @var array
*/ */
public static $modules = array('block_content_test', 'dblog'); public static $modules = array('block_content_test', 'dblog', 'entity');
/** /**
* Sets the test up. * Sets the test up.

View File

@ -20,7 +20,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface; 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\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;

View File

@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder; use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;

View File

@ -7,7 +7,7 @@
namespace Drupal\datetime\Tests; namespace Drupal\datetime\Tests;
use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;

View File

@ -4,4 +4,3 @@ description: 'Generic entity functionality.'
package: Core package: Core
version: VERSION version: VERSION
core: 8.x core: 8.x
required: true

View File

@ -1,13 +1,13 @@
entity.view_mode_add: entity.entity_view_mode_add:
route_name: entity.view_mode_add route_name: entity.entity_view_mode_add
title: 'Add new view mode' title: 'Add new view mode'
weight: 1 weight: 1
appears_on: appears_on:
- entity.view_mode_list - entity.entity_view_mode_list
entity.form_mode_add: entity.entity_form_mode_add:
route_name: entity.form_mode_add route_name: entity.entity_form_mode_add
title: 'Add new form mode' title: 'Add new form mode'
weight: 1 weight: 1
appears_on: appears_on:
- entity.form_mode_list - entity.entity_form_mode_list

View File

@ -3,13 +3,13 @@ entity.display_mode:
description: 'Configure what displays are available for your content and forms.' description: 'Configure what displays are available for your content and forms.'
route_name: entity.display_mode route_name: entity.display_mode
parent: system.admin_structure parent: system.admin_structure
entity.view_mode_list: entity.entity_view_mode_list:
title: 'View modes' title: 'View modes'
description: 'Manage custom view modes.' description: 'Manage custom view modes.'
route_name: entity.view_mode_list route_name: entity.entity_view_mode_list
parent: entity.display_mode parent: entity.display_mode
entity.form_mode_list: entity.entity_form_mode_list:
title: 'Form modes' title: 'Form modes'
description: 'Manage custom form modes.' description: 'Manage custom form modes.'
route_name: entity.form_mode_list route_name: entity.entity_form_mode_list
parent: entity.display_mode parent: entity.display_mode

View File

@ -1,19 +1,19 @@
entity.view_mode.edit_form: entity.entity_view_mode.edit_form:
title: 'Edit' title: 'Edit'
route_name: entity.view_mode.edit_form route_name: entity.entity_view_mode.edit_form
base_route: 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' title: 'Edit'
route_name: entity.form_mode.edit_form route_name: entity.entity_form_mode.edit_form
base_route: entity.form_mode.edit_form base_route: entity.entity_form_mode.edit_form
entity.view_mode_list: entity.entity_view_mode_list:
title: List title: List
route_name: entity.view_mode_list route_name: entity.entity_view_mode_list
base_route: entity.view_mode_list base_route: entity.entity_view_mode_list
entity.form_mode_list: entity.entity_form_mode_list:
title: List title: List
route_name: entity.form_mode_list route_name: entity.entity_form_mode_list
base_route: entity.form_mode_list base_route: entity.entity_form_mode_list

View File

@ -8,7 +8,6 @@
* entity system. * entity system.
*/ */
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
/** /**
@ -26,9 +25,9 @@ function entity_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>'; $output .= '<dl>';
$output .= '<dt>' . t('Managing view modes') . '</dt>'; $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 .= '<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>'; $output .= '</dl>';
return $output; 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) { function entity_entity_type_alter(array &$entity_types) {
// Rename entity displays. /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_type = \Drupal::entityManager()->getDefinition('entity_view_display'); $form_mode = $entity_types['entity_form_mode'];
if ($bundle_old !== $bundle_new) { $form_mode->setListBuilderClass('Drupal\entity\EntityFormModeListBuilder');
$ids = \Drupal::configFactory()->listAll('entity.view_display.' . $entity_type_id . '.' . $bundle_old . '.'); $form_mode->setFormClass('add', 'Drupal\entity\Form\EntityFormModeAddForm');
foreach ($ids as $id) { $form_mode->setFormClass('edit', 'Drupal\entity\Form\EntityDisplayModeEditForm');
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix()); $form_mode->setFormClass('delete', 'Drupal\entity\Form\EntityDisplayModeDeleteForm');
$display = entity_load('entity_view_display', $id); $form_mode->set('admin_permission', 'administer display modes');
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $display->mode; $form_mode->setLinkTemplate('delete-form', 'entity.entity_form_mode.delete_form');
$display->set('id', $new_id); $form_mode->setLinkTemplate('edit-form', 'entity.entity_form_mode.edit_form');
$display->bundle = $bundle_new;
$display->save();
}
}
// Rename entity form displays. $view_mode = $entity_types['entity_view_mode'];
$entity_type = \Drupal::entityManager()->getDefinition('entity_form_display'); $view_mode->setListBuilderClass('Drupal\entity\EntityDisplayModeListBuilder');
if ($bundle_old !== $bundle_new) { $view_mode->setFormClass('add', 'Drupal\entity\Form\EntityDisplayModeAddForm');
$ids = \Drupal::configFactory()->listAll('entity.form_display.' . $entity_type_id . '.' . $bundle_old . '.'); $view_mode->setFormClass('edit', 'Drupal\entity\Form\EntityDisplayModeEditForm');
foreach ($ids as $id) { $view_mode->setFormClass('delete', 'Drupal\entity\Form\EntityDisplayModeDeleteForm');
$id = ConfigEntityStorage::getIDFromConfigName($id, $entity_type->getConfigPrefix()); $view_mode->set('admin_permission', 'administer display modes');
$form_display = entity_load('entity_form_display', $id); $view_mode->setLinkTemplate('delete-form', 'entity.entity_view_mode.delete_form');
$new_id = $entity_type_id . '.' . $bundle_new . '.' . $form_display->mode; $view_mode->setLinkTemplate('edit-form', 'entity.entity_view_mode.edit_form');
$form_display->set('id', $new_id);
$form_display->bundle = $bundle_new;
$form_display->save();
}
}
} }
/**
* 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().
*/
function entity_module_preuninstall($module) {
// Clean up all entity bundles (including field instances) of every entity
// type provided by the module that is being uninstalled.
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) {
foreach (array_keys(entity_get_bundles($entity_type_id)) as $bundle) {
entity_invoke_bundle_hook('delete', $entity_type_id, $bundle);
}
}
}
}

View File

@ -6,15 +6,15 @@ entity.display_mode:
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.view_mode_list: entity.entity_view_mode_list:
path: '/admin/structure/display-modes/view' path: '/admin/structure/display-modes/view'
defaults: defaults:
_entity_list: 'view_mode' _entity_list: 'entity_view_mode'
_title: 'View modes' _title: 'View modes'
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.view_mode_add: entity.entity_view_mode_add:
path: '/admin/structure/display-modes/view/add' path: '/admin/structure/display-modes/view/add'
defaults: defaults:
_content: '\Drupal\entity\Controller\EntityDisplayModeController::viewModeTypeSelection' _content: '\Drupal\entity\Controller\EntityDisplayModeController::viewModeTypeSelection'
@ -22,39 +22,39 @@ entity.view_mode_add:
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.view_mode_add_type: entity.entity_view_mode_add_type:
path: '/admin/structure/display-modes/view/add/{entity_type_id}' path: '/admin/structure/display-modes/view/add/{entity_type_id}'
defaults: defaults:
_entity_form: 'view_mode.add' _entity_form: 'entity_view_mode.add'
_title: 'Add view mode' _title: 'Add view mode'
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.view_mode.edit_form: entity.entity_view_mode.edit_form:
path: '/admin/structure/display-modes/view/manage/{view_mode}' path: '/admin/structure/display-modes/view/manage/{entity_view_mode}'
defaults: defaults:
_entity_form: 'view_mode.edit' _entity_form: 'entity_view_mode.edit'
_title: 'Edit view mode' _title: 'Edit view mode'
requirements: requirements:
_entity_access: 'view_mode.update' _entity_access: 'entity_view_mode.update'
entity.view_mode.delete_form: entity.entity_view_mode.delete_form:
path: '/admin/structure/display-modes/view/manage/{view_mode}/delete' path: '/admin/structure/display-modes/view/manage/{entity_view_mode}/delete'
defaults: defaults:
_entity_form: 'view_mode.delete' _entity_form: 'entity_view_mode.delete'
_title: 'Delete view mode' _title: 'Delete view mode'
requirements: requirements:
_entity_access: 'view_mode.delete' _entity_access: 'entity_view_mode.delete'
entity.form_mode_list: entity.entity_form_mode_list:
path: '/admin/structure/display-modes/form' path: '/admin/structure/display-modes/form'
defaults: defaults:
_entity_list: 'form_mode' _entity_list: 'entity_form_mode'
_title: 'Form modes' _title: 'Form modes'
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.form_mode_add: entity.entity_form_mode_add:
path: '/admin/structure/display-modes/form/add' path: '/admin/structure/display-modes/form/add'
defaults: defaults:
_content: '\Drupal\entity\Controller\EntityDisplayModeController::formModeTypeSelection' _content: '\Drupal\entity\Controller\EntityDisplayModeController::formModeTypeSelection'
@ -62,26 +62,26 @@ entity.form_mode_add:
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.form_mode_add_type: entity.entity_form_mode_add_type:
path: '/admin/structure/display-modes/form/add/{entity_type_id}' path: '/admin/structure/display-modes/form/add/{entity_type_id}'
defaults: defaults:
_entity_form: 'form_mode.add' _entity_form: 'entity_form_mode.add'
_title: 'Add form mode' _title: 'Add form mode'
requirements: requirements:
_permission: 'administer display modes' _permission: 'administer display modes'
entity.form_mode.edit_form: entity.entity_form_mode.edit_form:
path: '/admin/structure/display-modes/form/manage/{form_mode}' path: '/admin/structure/display-modes/form/manage/{entity_form_mode}'
defaults: defaults:
_entity_form: 'form_mode.edit' _entity_form: 'entity_form_mode.edit'
_title: 'Edit form mode' _title: 'Edit form mode'
requirements: requirements:
_entity_access: 'form_mode.update' _entity_access: 'entity_form_mode.update'
entity.form_mode.delete_form: entity.entity_form_mode.delete_form:
path: '/admin/structure/display-modes/form/manage/{form_mode}/delete' path: '/admin/structure/display-modes/form/manage/{entity_form_mode}/delete'
defaults: defaults:
_entity_form: 'form_mode.delete' _entity_form: 'entity_form_mode.delete'
_title: 'Delete form mode' _title: 'Delete form mode'
requirements: requirements:
_entity_access: 'form_mode.delete' _entity_access: 'entity_form_mode.delete'

View File

@ -27,7 +27,7 @@ class EntityDisplayModeController extends ControllerBase {
if ($entity_type->isFieldable() && $entity_type->hasViewBuilderClass()) { if ($entity_type->isFieldable() && $entity_type->hasViewBuilderClass()) {
$entity_types[$entity_type_id] = array( $entity_types[$entity_type_id] = array(
'title' => $entity_type->getLabel(), 'title' => $entity_type->getLabel(),
'url' => new Url('entity.view_mode_add_type', array('entity_type_id' => $entity_type_id)), 'url' => new Url('entity.entity_view_mode_add_type', array('entity_type_id' => $entity_type_id)),
'localized_options' => array(), 'localized_options' => array(),
); );
} }
@ -50,7 +50,7 @@ class EntityDisplayModeController extends ControllerBase {
if ($entity_type->isFieldable() && $entity_type->hasFormClasses()) { if ($entity_type->isFieldable() && $entity_type->hasFormClasses()) {
$entity_types[$entity_type_id] = array( $entity_types[$entity_type_id] = array(
'title' => $entity_type->getLabel(), 'title' => $entity_type->getLabel(),
'url' => new Url('entity.form_mode_add_type', array('entity_type_id' => $entity_type_id)), 'url' => new Url('entity.entity_form_mode_add_type', array('entity_type_id' => $entity_type_id)),
'localized_options' => array(), 'localized_options' => array(),
); );
} }

View File

@ -21,7 +21,7 @@ class EntityDisplayModeTest extends WebTestBase {
* *
* @var array * @var array
*/ */
public static $modules = array('entity_test'); public static $modules = array('entity_test', 'entity');
/** /**
* Tests the EntityViewMode user interface. * Tests the EntityViewMode user interface.

View File

@ -7,6 +7,7 @@
namespace Drupal\entity\Tests; namespace Drupal\entity\Tests;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\simpletest\DrupalUnitTestBase; use Drupal\simpletest\DrupalUnitTestBase;
/** /**
@ -78,12 +79,12 @@ class EntityDisplayTest extends DrupalUnitTestBase {
// Check that CreateCopy() creates a new component that can be correclty // Check that CreateCopy() creates a new component that can be correclty
// saved. // saved.
entity_create('view_mode', array('id' => $display->targetEntityType . '.other_view_mode', 'targetEntityType' => $display->targetEntityType))->save(); EntityViewMode::create(array('id' => $display->targetEntityType . '.other_view_mode', 'targetEntityType' => $display->targetEntityType))->save();
$new_display = $display->createCopy('other_view_mode'); $new_display = $display->createCopy('other_view_mode');
$new_display->save(); $new_display->save();
$new_display = entity_load('entity_view_display', $new_display->id()); $new_display = entity_load('entity_view_display', $new_display->id());
$dependencies = $new_display->calculateDependencies(); $dependencies = $new_display->calculateDependencies();
$this->assertEqual(array('entity' => array('entity.view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies); $this->assertEqual(array('entity' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies);
$this->assertEqual($new_display->targetEntityType, $display->targetEntityType); $this->assertEqual($new_display->targetEntityType, $display->targetEntityType);
$this->assertEqual($new_display->bundle, $display->bundle); $this->assertEqual($new_display->bundle, $display->bundle);
$this->assertEqual($new_display->mode, 'other_view_mode'); $this->assertEqual($new_display->mode, 'other_view_mode');
@ -233,7 +234,7 @@ class EntityDisplayTest extends DrupalUnitTestBase {
// Check that saving the display only writes data for fields whose display // Check that saving the display only writes data for fields whose display
// is configurable. // is configurable.
$display->save(); $display->save();
$config = \Drupal::config('entity.view_display.' . $display->id()); $config = \Drupal::config('core.entity_view_display.' . $display->id());
$data = $config->get(); $data = $config->get();
$this->assertFalse(isset($data['content']['test_no_display'])); $this->assertFalse(isset($data['content']['test_no_display']));
$this->assertFalse(isset($data['hidden']['test_no_display'])); $this->assertFalse(isset($data['hidden']['test_no_display']));
@ -275,9 +276,9 @@ class EntityDisplayTest extends DrupalUnitTestBase {
$type->type = 'article_rename'; $type->type = 'article_rename';
$type->save(); $type->save();
$old_display = entity_load('entity_view_display', 'node.article.default'); $old_display = entity_load('entity_view_display', 'node.article.default');
$this->assertFalse($old_display); $this->assertFalse((bool) $old_display);
$old_form_display = entity_load('entity_form_display', 'node.article.default'); $old_form_display = entity_load('entity_form_display', 'node.article.default');
$this->assertFalse($old_form_display); $this->assertFalse((bool) $old_form_display);
$new_display = entity_load('entity_view_display', 'node.article_rename.default'); $new_display = entity_load('entity_view_display', 'node.article_rename.default');
$this->assertEqual('article_rename', $new_display->bundle); $this->assertEqual('article_rename', $new_display->bundle);
$this->assertEqual('node.article_rename.default', $new_display->id); $this->assertEqual('node.article_rename.default', $new_display->id);
@ -302,9 +303,9 @@ class EntityDisplayTest extends DrupalUnitTestBase {
// Delete the bundle. // Delete the bundle.
$type->delete(); $type->delete();
$display = entity_load('entity_view_display', 'node.article_rename.default'); $display = entity_load('entity_view_display', 'node.article_rename.default');
$this->assertFalse($display); $this->assertFalse((bool) $display);
$form_display = entity_load('entity_form_display', 'node.article_rename.default'); $form_display = entity_load('entity_form_display', 'node.article_rename.default');
$this->assertFalse($form_display); $this->assertFalse((bool) $form_display);
} }
/** /**
@ -326,7 +327,7 @@ class EntityDisplayTest extends DrupalUnitTestBase {
$instance->save(); $instance->save();
// Create default and teaser entity display. // Create default and teaser entity display.
entity_create('view_mode', array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
entity_create('entity_view_display', array( entity_create('entity_view_display', array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',

View File

@ -7,6 +7,7 @@
namespace Drupal\entity\Tests; namespace Drupal\entity\Tests;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\simpletest\DrupalUnitTestBase; use Drupal\simpletest\DrupalUnitTestBase;
/** /**
@ -146,7 +147,7 @@ class EntityFormDisplayTest extends DrupalUnitTestBase {
// Check that saving the display only writes data for fields whose display // Check that saving the display only writes data for fields whose display
// is configurable. // is configurable.
$display->save(); $display->save();
$config = \Drupal::config('entity.form_display.' . $display->id()); $config = \Drupal::config('core.entity_form_display.' . $display->id());
$data = $config->get(); $data = $config->get();
$this->assertFalse(isset($data['content']['test_no_display'])); $this->assertFalse(isset($data['content']['test_no_display']));
$this->assertFalse(isset($data['hidden']['test_no_display'])); $this->assertFalse(isset($data['hidden']['test_no_display']));
@ -190,7 +191,7 @@ class EntityFormDisplayTest extends DrupalUnitTestBase {
$instance->save(); $instance->save();
// Create default and compact entity display. // Create default and compact entity display.
entity_create('form_mode', array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save(); EntityFormMode::create(array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save();
entity_create('entity_form_display', array( entity_create('entity_form_display', array(
'targetEntityType' => 'entity_test', 'targetEntityType' => 'entity_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',

View File

@ -119,7 +119,7 @@ function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfi
* Widgets are @link forms_api_reference.html Form API @endlink * Widgets are @link forms_api_reference.html Form API @endlink
* elements with additional processing capabilities. The methods of the * elements with additional processing capabilities. The methods of the
* WidgetInterface object are typically called by respective methods in the * WidgetInterface object are typically called by respective methods in the
* \Drupal\entity\Entity\EntityFormDisplay class. * \Drupal\Core\Entity\Entity\EntityFormDisplay class.
* *
* @see field * @see field
* @see field_types * @see field_types

View File

@ -7,6 +7,8 @@
namespace Drupal\field\Tests; namespace Drupal\field\Tests;
use Drupal\Core\Entity\Entity\EntityViewMode;
/** /**
* Tests the field display API. * Tests the field display API.
* *
@ -99,7 +101,7 @@ class DisplayApiTest extends FieldUnitTestBase {
->setComponent($this->field_name, $this->display_options['default']) ->setComponent($this->field_name, $this->display_options['default'])
->save(); ->save();
// Create a display for the teaser view mode. // Create a display for the teaser view mode.
entity_create('view_mode', array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
entity_get_display($instance['entity_type'], $instance['bundle'], 'teaser') entity_get_display($instance['entity_type'], $instance['bundle'], 'teaser')
->setComponent($this->field_name, $this->display_options['teaser']) ->setComponent($this->field_name, $this->display_options['teaser'])
->save(); ->save();

View File

@ -10,7 +10,7 @@ namespace Drupal\field_test\Form;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityFormDisplay;
/** /**
* Provides a form for field_test routes. * Provides a form for field_test routes.

View File

@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\entity\EntityViewModeInterface; use Drupal\Core\Entity\EntityViewModeInterface;
use Drupal\field_ui\FieldUI; use Drupal\field_ui\FieldUI;
use Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask; use Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask;

View File

@ -9,7 +9,7 @@ namespace Drupal\migrate\Plugin\migrate\destination;
/** /**
* @MigrateDestination( * @MigrateDestination(
* id = "entity:view_mode" * id = "entity:entity_view_mode"
* ) * )
*/ */
class EntityViewMode extends EntityConfigBase { class EntityViewMode extends EntityConfigBase {

View File

@ -33,7 +33,7 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$row->setDestinationProperty($key, $value); $row->setDestinationProperty($key, $value);
} }
$entity = $this->getMockBuilder('Drupal\entity\Entity\EntityViewDisplay') $entity = $this->getMockBuilder('Drupal\Core\Entity\Entity\EntityViewDisplay')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$entity->expects($this->once()) $entity->expects($this->once())

View File

@ -33,7 +33,7 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$row->setDestinationProperty($key, $value); $row->setDestinationProperty($key, $value);
} }
$entity = $this->getMockBuilder('Drupal\entity\Entity\EntityFormDisplay') $entity = $this->getMockBuilder('Drupal\Core\Entity\Entity\EntityFormDisplay')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$entity->expects($this->once()) $entity->expects($this->once())

View File

@ -37,4 +37,4 @@ process:
status: 'constants/status' status: 'constants/status'
destination: destination:
plugin: entity:view_mode plugin: entity:entity_view_mode

View File

@ -11,7 +11,7 @@ use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
/** /**
* Upgrade comment subject variable to entity.form_display.comment.*.default.yml * Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml
* *
* @group migrate_drupal * @group migrate_drupal
*/ */

View File

@ -8,7 +8,7 @@
namespace Drupal\migrate_drupal\Tests\d6; namespace Drupal\migrate_drupal\Tests\d6;
/** /**
* Upgrade comment variables to entity.form_display.node.*.default.yml. * Upgrade comment variables to core.entity_form_display.node.*.default.yml.
* *
* @group migrate_drupal * @group migrate_drupal
*/ */

View File

@ -7,6 +7,7 @@
namespace Drupal\migrate_drupal\Tests\d6; namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
@ -33,7 +34,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupalTestBase {
entity_create('node_type', array('type' => 'test_page'))->save(); entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save(); entity_create('node_type', array('type' => 'story'))->save();
// Create the node preview view mode. // Create the node preview view mode.
entity_create('view_mode', array('id' => 'node.preview', 'targetEntityType' => 'node'))->save(); EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save();
// Add some id mappings for the dependant migrations. // Add some id mappings for the dependant migrations.
$id_mappings = array( $id_mappings = array(

View File

@ -7,6 +7,7 @@
namespace Drupal\migrate_drupal\Tests\d6; namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase; use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
@ -43,7 +44,7 @@ class MigrateViewModesTest extends MigrateDrupalTestBase {
*/ */
public function testViewModes() { public function testViewModes() {
// Test a new view mode. // Test a new view mode.
$view_mode = entity_load('view_mode', 'node.preview'); $view_mode = EntityViewMode::load('node.preview');
$this->assertEqual(is_null($view_mode), FALSE, 'Preview view mode loaded.'); $this->assertEqual(is_null($view_mode), FALSE, 'Preview view mode loaded.');
$this->assertEqual($view_mode->label(), 'Preview', 'View mode has correct label.'); $this->assertEqual($view_mode->label(), 'Preview', 'View mode has correct label.');
// Test the Id Map. // Test the Id Map.

View File

@ -13,7 +13,6 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
@ -141,9 +140,9 @@ class NodePreviewForm extends FormBase implements ContainerInjectionInterface {
$view_modes = $this->entityManager->getViewModes('node'); $view_modes = $this->entityManager->getViewModes('node');
// Get the list of available view modes for the current node's bundle. // Get the list of available view modes for the current node's bundle.
$ids = $this->configFactory->listAll('entity.view_display.node.' . $node->bundle()); $ids = $this->configFactory->listAll('core.entity_view_display.node.' . $node->bundle());
foreach ($ids as $id) { foreach ($ids as $id) {
$config_id = str_replace('entity.view_display' . '.', '', $id); $config_id = str_replace('core.entity_view_display' . '.', '', $id);
$load_ids[] = $config_id; $load_ids[] = $config_id;
} }
$displays = entity_load_multiple('entity_view_display', $load_ids); $displays = entity_load_multiple('entity_view_display', $load_ids);

View File

@ -86,9 +86,9 @@ class NodeTypeRenameConfigImportTest extends WebTestBase {
$expected = array( $expected = array(
'node.type.' . $active_type . '::node.type.' . $staged_type, 'node.type.' . $active_type . '::node.type.' . $staged_type,
'core.base_field_override.node.' . $active_type . '.status::core.base_field_override.node.' . $staged_type . '.status', 'core.base_field_override.node.' . $active_type . '.status::core.base_field_override.node.' . $staged_type . '.status',
'entity.form_display.node.' . $active_type . '.default::entity.form_display.node.' . $staged_type . '.default', 'core.entity_form_display.node.' . $active_type . '.default::core.entity_form_display.node.' . $staged_type . '.default',
'entity.view_display.node.' . $active_type . '.default::entity.view_display.node.' . $staged_type . '.default', 'core.entity_view_display.node.' . $active_type . '.default::core.entity_view_display.node.' . $staged_type . '.default',
'entity.view_display.node.' . $active_type . '.teaser::entity.view_display.node.' . $staged_type . '.teaser', 'core.entity_view_display.node.' . $active_type . '.teaser::core.entity_view_display.node.' . $staged_type . '.teaser',
'field.instance.node.' . $active_type . '.body::field.instance.node.' . $staged_type . '.body', 'field.instance.node.' . $active_type . '.body::field.instance.node.' . $staged_type . '.body',
); );
$renames = $this->configImporter()->getUnprocessedConfiguration('rename'); $renames = $this->configImporter()->getUnprocessedConfiguration('rename');

View File

@ -15,7 +15,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\user\TempStoreFactory; use Drupal\user\TempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;

View File

@ -12,7 +12,7 @@ use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface; use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface;
use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay;
/** /**
* Generates in-place editing metadata for an entity field. * Generates in-place editing metadata for an entity field.

View File

@ -147,7 +147,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
*/ */
protected function selectViewMode($entity_type) { protected function selectViewMode($entity_type) {
$view_modes = \Drupal::entityManager() $view_modes = \Drupal::entityManager()
->getStorage('view_mode') ->getStorage('entity_view_mode')
->loadByProperties(array('targetEntityType' => $entity_type)); ->loadByProperties(array('targetEntityType' => $entity_type));
if (empty($view_modes)) { if (empty($view_modes)) {

View File

@ -12,7 +12,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityFormDisplay;
/** /**
* Filter that limits test entity list to revisable ones. * Filter that limits test entity list to revisable ones.

View File

@ -6,5 +6,3 @@ version: VERSION
core: 8.x core: 8.x
required: true required: true
configure: user.admin_index configure: user.admin_index
dependencies:
- entity

View File

@ -96,9 +96,9 @@ class AreaEntityTest extends ViewTestBase {
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.'); $this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
// Mark entity_test test view_mode as customizable. // Mark entity_test test view_mode as customizable.
$view_mode = \Drupal::entityManager()->getStorage('view_mode')->load('entity_test.test'); $entity_view_mode = \Drupal::entityManager()->getStorage('entity_view_mode')->load('entity_test.test');
$view_mode->enable(); $entity_view_mode->enable();
$view_mode->save(); $entity_view_mode->save();
// Change the view mode of the area handler. // Change the view mode of the area handler.
$view = Views::getView('test_entity_area'); $view = Views::getView('test_entity_area');

View File

@ -27,7 +27,7 @@ content:
label: above label: above
dependencies: dependencies:
entity: entity:
- entity.view_mode.node.teaser - core.entity_view_mode.node.teaser
- field.instance.node.article.body - field.instance.node.article.body
- field.instance.node.article.field_image - field.instance.node.article.field_image
- field.instance.node.article.field_tags - field.instance.node.article.field_tags

View File

@ -16,7 +16,7 @@ hidden:
status: true status: true
dependencies: dependencies:
entity: entity:
- entity.view_mode.user.compact - core.entity_view_mode.user.compact
module: module:
- image - image
- user - user

View File

@ -19,6 +19,7 @@ dependencies:
- block_content - block_content
- quickedit - quickedit
- editor - editor
- entity
- entity_reference - entity_reference
- help - help
- image - image

View File

@ -11,7 +11,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
/** /**
* @coversDefaultClass \Drupal\entity\EntityDisplayModeBase * @coversDefaultClass \Drupal\Core\Entity\EntityDisplayModeBase
* @group Config * @group Config
*/ */
class EntityDisplayModeBaseUnitTest extends UnitTestCase { class EntityDisplayModeBaseUnitTest extends UnitTestCase {
@ -19,7 +19,7 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
/** /**
* The entity under test. * The entity under test.
* *
* @var \Drupal\entity\EntityDisplayModeBase|\PHPUnit_Framework_MockObject_MockObject * @var \Drupal\Core\Entity\EntityDisplayModeBase|\PHPUnit_Framework_MockObject_MockObject
*/ */
protected $entity; protected $entity;
@ -94,7 +94,7 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
->with($this->entityType) ->with($this->entityType)
->will($this->returnValue($this->entityInfo)); ->will($this->returnValue($this->entityInfo));
$this->entity = $this->getMockBuilder('\Drupal\entity\EntityDisplayModeBase') $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\EntityDisplayModeBase')
->setConstructorArgs(array($values, $this->entityType)) ->setConstructorArgs(array($values, $this->entityType))
->setMethods(array('getFilterFormat')) ->setMethods(array('getFilterFormat'))
->getMock(); ->getMock();