Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
30cad25c
Commit
30cad25c
authored
Sep 02, 2014
by
catch
Browse files
Issue
#2031717
by Berdir, swentel, fago: Make entity module not required.
parent
3afec501
Changes
76
Hide whitespace changes
Inline
Side-by-side
core/
modules/entity/
config/schema/entity.data_types.schema.yml
→
core/config/schema/
core.
entity.data_types.schema.yml
View file @
30cad25c
File moved
core/
modules/entity/
config/schema/entity.schema.yml
→
core/config/schema/
core.
entity.schema.yml
View file @
30cad25c
# 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
:
...
...
core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
View file @
30cad25c
...
...
@@ -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\
e
ntity\EntityDisplayBase::id()
// @see \Drupal\
Core\E
ntity\EntityDisplayBase::id()
if
(
$name
==
$id_key
)
{
$properties
[
$name
]
=
$this
->
id
();
}
...
...
core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php
View file @
30cad25c
...
...
@@ -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
();
}
}
core/lib/Drupal/Core/Entity/ContentEntityForm.php
View file @
30cad25c
...
...
@@ -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
;
/**
...
...
core/
modules/e
ntity/
src/
Entity/EntityFormDisplay.php
→
core/
lib/Drupal/Core/E
ntity/Entity/EntityFormDisplay.php
View file @
30cad25c
...
...
@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\
e
ntity\Entity\EntityFormDisplay.
* Contains \Drupal\
Core\E
ntity\Entity\EntityFormDisplay.
*/
namespace
Drupal\
e
ntity\Entity
;
namespace
Drupal\
Core\E
ntity\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"
...
...
core/
modules/e
ntity/
src/
Entity/EntityFormMode.php
→
core/
lib/Drupal/Core/E
ntity/Entity/EntityFormMode.php
View file @
30cad25c
...
...
@@ -2,16 +2,16 @@
/**
* @file
* Contains \Drupal\
e
ntity\Entity\EntityFormMode.
* Contains \Drupal\
Core\E
ntity\Entity\EntityFormMode.
*/
namespace
Drupal\
e
ntity\Entity
;
namespace
Drupal\
Core\E
ntity\Entity
;
use
Drupal\
e
ntity\EntityDisplayModeBase
;
use
Drupal\
e
ntity\EntityFormModeInterface
;
use
Drupal\
Core\E
ntity\EntityDisplayModeBase
;
use
Drupal\
Core\E
ntity\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"
* }
* )
*/
...
...
core/
modules/e
ntity/
src/
Entity/EntityViewDisplay.php
→
core/
lib/Drupal/Core/E
ntity/Entity/EntityViewDisplay.php
View file @
30cad25c
...
...
@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\
e
ntity\Entity\EntityViewDisplay.
* Contains \Drupal\
Core\E
ntity\Entity\EntityViewDisplay.
*/
namespace
Drupal\
e
ntity\Entity
;
namespace
Drupal\
Core\E
ntity\Entity
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\Core\Entity\Display\EntityViewDisplayInterface
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\
e
ntity\EntityDisplayBase
;
use
Drupal\
Core\E
ntity\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"
...
...
core/
modules/e
ntity/
src/
Entity/EntityViewMode.php
→
core/
lib/Drupal/Core/E
ntity/Entity/EntityViewMode.php
View file @
30cad25c
...
...
@@ -2,16 +2,16 @@
/**
* @file
* Contains \Drupal\
e
ntity\Entity\EntityViewMode.
* Contains \Drupal\
Core\E
ntity\Entity\EntityViewMode.
*/
namespace
Drupal\
e
ntity\Entity
;
namespace
Drupal\
Core\E
ntity\Entity
;
use
Drupal\
e
ntity\EntityDisplayModeBase
;
use
Drupal\
e
ntity\EntityViewModeInterface
;
use
Drupal\
Core\E
ntity\EntityDisplayModeBase
;
use
Drupal\
Core\E
ntity\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"
* }
* )
*/
...
...
core/
modules/e
ntity/
src/
EntityDisplayBase.php
→
core/
lib/Drupal/Core/E
ntity/EntityDisplayBase.php
View file @
30cad25c
...
...
@@ -2,13 +2,12 @@
/**
* @file
* Contains \Drupal\
e
ntity\EntityDisplayBase.
* Contains \Drupal\
Core\E
ntity\EntityDisplayBase.
*/
namespace
Drupal\
e
ntity
;
namespace
Drupal\
Core\E
ntity
;
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
;
...
...
core/
modules/e
ntity/
src/
EntityDisplayModeBase.php
→
core/
lib/Drupal/Core/E
ntity/EntityDisplayModeBase.php
View file @
30cad25c
...
...
@@ -2,14 +2,13 @@
/**
* @file
* Contains \Drupal\
e
ntity\EntityDisplayModeBase.
* Contains \Drupal\
Core\E
ntity\EntityDisplayModeBase.
*/
namespace
Drupal\
e
ntity
;
namespace
Drupal\
Core\E
ntity
;
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\
e
ntity\EntityDisplayModeInterface $a */
/** @var \Drupal\
e
ntity\EntityDisplayModeInterface $b */
/** @var \Drupal\
Core\E
ntity\EntityDisplayModeInterface $a */
/** @var \Drupal\
Core\E
ntity\EntityDisplayModeInterface $b */
// Sort by the type of entity the view mode is used for.
$a_type
=
$a
->
getTargetType
();
$b_type
=
$b
->
getTargetType
();
...
...
core/
modules/e
ntity/
src/
EntityDisplayModeInterface.php
→
core/
lib/Drupal/Core/E
ntity/EntityDisplayModeInterface.php
View file @
30cad25c
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\
e
ntity\EntityDisplayModeInterface.
* Contains \Drupal\
Core\E
ntity\EntityDisplayModeInterface.
*/
namespace
Drupal\
e
ntity
;
namespace
Drupal\
Core\E
ntity
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
...
...
core/
modules/e
ntity/
src/
EntityFormModeInterface.php
→
core/
lib/Drupal/Core/E
ntity/EntityFormModeInterface.php
View file @
30cad25c
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\
e
ntity\EntityFormModeInterface.
* Contains \Drupal\
Core\E
ntity\EntityFormModeInterface.
*/
namespace
Drupal\
e
ntity
;
namespace
Drupal\
Core\E
ntity
;
/**
* Provides an interface defining an entity form mode entity type.
...
...
core/lib/Drupal/Core/Entity/EntityManager.php
View file @
30cad25c
...
...
@@ -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
(
$
displa
y_type
)
->
loadMultiple
()
as
$display_mode
)
{
foreach
(
$this
->
getStorage
(
$
entit
y_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
();
}
...
...
core/lib/Drupal/Core/Entity/EntityViewBuilder.php
View file @
30cad25c
...
...
@@ -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\
e
ntity\Entity\EntityViewDisplay
;
use
Drupal\
Core\E
ntity\Entity\EntityViewDisplay
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
...
...
core/
modules/e
ntity/
src/
EntityViewModeInterface.php
→
core/
lib/Drupal/Core/E
ntity/EntityViewModeInterface.php
View file @
30cad25c
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\
e
ntity\EntityViewModeInterface.
* Contains \Drupal\
Core\E
ntity\EntityViewModeInterface.
*/
namespace
Drupal\
e
ntity
;
namespace
Drupal\
Core\E
ntity
;
/**
* Provides an interface defining an entity view mode entity type.
...
...
core/lib/Drupal/Core/Extension/ModuleHandler.php
View file @
30cad25c
...
...
@@ -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
)
{
...
...
core/modules/aggregator/config/install/entity
.
view_mode.aggregator_item.summary.yml
→
core/modules/aggregator/config/install/
core.
entity
_
view_mode.aggregator_item.summary.yml
View file @
30cad25c
File moved
core/modules/block_content/config/install/entity
.
view_mode.block_content.full.yml
→
core/modules/block_content/config/install/
core.
entity
_
view_mode.block_content.full.yml
View file @
30cad25c
File moved
core/modules/block_content/src/Tests/BlockContentCreationTest.php
View file @
30cad25c
...
...
@@ -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.
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment