Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
301
Merge Requests
301
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
518c4d10
Commit
518c4d10
authored
May 19, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1875992
by amateescu, swentel, yched: Add EntityFormDisplay objects for entity forms.
parent
750b5273
Changes
122
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
122 changed files
with
1748 additions
and
1216 deletions
+1748
-1216
core/includes/entity.api.php
core/includes/entity.api.php
+21
-0
core/includes/entity.inc
core/includes/entity.inc
+90
-3
core/lib/Drupal/Core/Entity/EntityFormController.php
core/lib/Drupal/Core/Entity/EntityFormController.php
+39
-0
core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php
.../lib/Drupal/Core/Entity/EntityFormControllerInterface.php
+25
-0
core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
+8
-0
core/modules/block/block.install
core/modules/block/block.install
+9
-1
core/modules/block/custom_block/custom_block.module
core/modules/block/custom_block/custom_block.module
+7
-1
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
...ck/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
+9
-8
core/modules/comment/comment.module
core/modules/comment/comment.module
+9
-0
core/modules/datetime/datetime.module
core/modules/datetime/datetime.module
+0
-2
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php
...l/datetime/Plugin/field/widget/DatetimeDatelistWidget.php
+3
-14
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php
...al/datetime/Plugin/field/widget/DatetimeDefaultWidget.php
+3
-14
core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
.../datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
+16
-14
core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
+14
-0
core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
+7
-4
core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
+8
-4
core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
+7
-3
core/modules/entity/entity.install
core/modules/entity/entity.install
+40
-1
core/modules/entity/entity.module
core/modules/entity/entity.module
+23
-3
core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php
core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php
+282
-0
core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php
...s/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php
+84
-0
core/modules/entity/lib/Drupal/entity/EntityDisplayInterface.php
...dules/entity/lib/Drupal/entity/EntityDisplayInterface.php
+3
-70
core/modules/entity/lib/Drupal/entity/EntityFormDisplayInterface.php
...s/entity/lib/Drupal/entity/EntityFormDisplayInterface.php
+28
-0
core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php
...ty/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php
+12
-243
core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php
...ib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php
+92
-0
core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
...ules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
+5
-5
core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
.../entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
+121
-0
core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php
...b/Drupal/entity_reference/EntityReferenceAutocomplete.php
+2
-1
core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
.../entity_reference/Tests/EntityReferenceAutoCreateTest.php
+6
-0
core/modules/field/field.api.php
core/modules/field/field.api.php
+14
-76
core/modules/field/field.attach.inc
core/modules/field/field.attach.inc
+16
-9
core/modules/field/field.info.inc
core/modules/field/field.info.inc
+9
-40
core/modules/field/field.install
core/modules/field/field.install
+66
-21
core/modules/field/field.module
core/modules/field/field.module
+0
-21
core/modules/field/lib/Drupal/field/FieldInstanceInterface.php
...modules/field/lib/Drupal/field/FieldInstanceInterface.php
+0
-8
core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
...eld/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
+5
-72
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php
.../field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php
+1
-12
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetFactory.php
...eld/lib/Drupal/field/Plugin/Type/Widget/WidgetFactory.php
+1
-1
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php
...b/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php
+58
-9
core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
...dules/field/lib/Drupal/field/Plugin/views/field/Field.php
+1
-13
core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php
+0
-3
core/modules/field/lib/Drupal/field/Tests/CrudTest.php
core/modules/field/lib/Drupal/field/Tests/CrudTest.php
+0
-3
core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php
.../modules/field/lib/Drupal/field/Tests/FieldAccessTest.php
+0
-3
core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
...les/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
+3
-0
core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php
...s/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php
+1
-5
core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
+1
-11
core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php
...es/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php
+0
-17
core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php
...odules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php
+7
-5
core/modules/field/lib/Drupal/field/Tests/FormTest.php
core/modules/field/lib/Drupal/field/Tests/FormTest.php
+57
-16
core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php
core/modules/field/lib/Drupal/field/Tests/ShapeItemTest.php
+0
-3
core/modules/field/lib/Drupal/field/Tests/TestItemTest.php
core/modules/field/lib/Drupal/field/Tests/TestItemTest.php
+0
-3
core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php
...dules/field/lib/Drupal/field/Tests/TranslationWebTest.php
+4
-0
core/modules/field/tests/modules/field_test/field_test.entity.inc
...ules/field/tests/modules/field_test/field_test.entity.inc
+2
-0
core/modules/field/tests/modules/field_test/field_test.module
.../modules/field/tests/modules/field_test/field_test.module
+4
-22
core/modules/field/tests/modules/field_test_config/config/field.instance.test_entity.test_bundle.field_test_import.yml
...ld.instance.test_entity.test_bundle.field_test_import.yml
+0
-6
core/modules/field/tests/modules/field_test_config/staging/field.instance.test_entity.test_bundle.field_test_import_staging.yml
...nce.test_entity.test_bundle.field_test_import_staging.yml
+0
-6
core/modules/field_ui/field_ui.admin.inc
core/modules/field_ui/field_ui.admin.inc
+2
-1
core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php
.../modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php
+9
-9
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+42
-28
core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
...eld_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
+16
-19
core/modules/field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php
...field_ui/lib/Drupal/field_ui/Form/FieldWidgetTypeForm.php
+9
-11
core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php
core/modules/field_ui/lib/Drupal/field_ui/OverviewBase.php
+2
-2
core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php
.../modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php
+0
-112
core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
...s/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
+30
-11
core/modules/file/file.field.inc
core/modules/file/file.field.inc
+0
-1
core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
.../modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
+13
-6
core/modules/forum/forum.install
core/modules/forum/forum.install
+7
-3
core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php
core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.php
+1
-1
core/modules/image/lib/Drupal/image/ImageStyleStorageController.php
...es/image/lib/Drupal/image/ImageStyleStorageController.php
+7
-4
core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
...ge/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
+5
-1
core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php
...dules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php
+7
-6
core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
+0
-3
core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php
+22
-14
core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php
core/modules/link/lib/Drupal/link/Tests/LinkItemTest.php
+0
-3
core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php
...modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php
+2
-1
core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php
...b/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php
+6
-8
core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php
...odules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php
+3
-0
core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
+16
-13
core/modules/node/node.module
core/modules/node/node.module
+7
-1
core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
...odules/number/lib/Drupal/number/Tests/NumberFieldTest.php
+10
-5
core/modules/number/lib/Drupal/number/Tests/NumberItemTest.php
...modules/number/lib/Drupal/number/Tests/NumberItemTest.php
+0
-3
core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php
.../Drupal/options/Plugin/field/widget/OptionsWidgetBase.php
+2
-2
core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php
...ons/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php
+6
-3
core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php
...les/options/lib/Drupal/options/Tests/OptionsFieldTest.php
+5
-3
core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
...s/options/lib/Drupal/options/Tests/OptionsFieldUITest.php
+6
-0
core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php
...ons/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php
+6
-3
core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
...s/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php
+36
-19
core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
+6
-0
core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
...st/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php
+1
-1
core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
...les/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php
+3
-0
core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php
.../system/lib/Drupal/system/Tests/Entity/EntityFormTest.php
+11
-0
core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php
...tem/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php
+1
-1
core/modules/system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php
...system/lib/Drupal/system/Tests/Entity/FieldAccessTest.php
+1
-1
core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php
...tem/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php
+10
-5
core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php
...dules/system/lib/Drupal/system/Tests/Form/RebuildTest.php
+3
-0
core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php
.../lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php
+39
-9
core/modules/system/tests/modules/entity_test/entity_test.install
...ules/system/tests/modules/entity_test/entity_test.install
+4
-4
core/modules/system/tests/modules/entity_test/entity_test.module
...dules/system/tests/modules/entity_test/entity_test.module
+14
-0
core/modules/system/tests/upgrade/drupal-7.field.database.php
.../modules/system/tests/upgrade/drupal-7.field.database.php
+6
-1
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php
+5
-3
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php
...b/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php
+0
-3
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php
...Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php
+5
-3
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
...ules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
+5
-3
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php
...ules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php
+10
-6
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php
+18
-12
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php
...s/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php
+5
-3
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
...nomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php
+7
-4
core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
...lephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php
+7
-4
core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php
...elephone/lib/Drupal/telephone/Tests/TelephoneItemTest.php
+0
-3
core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
...ext/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php
+0
-7
core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php
+11
-13
core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSyncImageTest.php
...anslation_entity/Tests/EntityTranslationSyncImageTest.php
+0
-4
core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationTestBase.php
...al/translation_entity/Tests/EntityTranslationTestBase.php
+6
-4
core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php
...dules/user/lib/Drupal/user/Tests/UserRegistrationTest.php
+3
-0
core/modules/user/user.install
core/modules/user/user.install
+28
-22
core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
...modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
+0
-8
core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php
...es/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php
+12
-3
core/profiles/standard/config/entity.display.node.article.default.yml
...s/standard/config/entity.display.node.article.default.yml
+1
-1
core/profiles/standard/config/entity.display.node.article.teaser.yml
...es/standard/config/entity.display.node.article.teaser.yml
+1
-1
core/profiles/standard/config/entity.form_display.node.article.default.yml
...ndard/config/entity.form_display.node.article.default.yml
+25
-0
core/profiles/standard/config/field.instance.node.article.field_image.yml
...andard/config/field.instance.node.article.field_image.yml
+0
-7
core/profiles/standard/config/field.instance.node.article.field_tags.yml
...tandard/config/field.instance.node.article.field_tags.yml
+0
-8
No files found.
core/includes/entity.api.php
View file @
518c4d10
...
...
@@ -451,6 +451,27 @@ function hook_entity_display_alter(\Drupal\entity\Plugin\Core\Entity\EntityDispl
}
}
/**
* Alters the settings used for displaying an entity form.
*
* @param \Drupal\entity\Plugin\Core\Entity\EntityFormDisplay $form_display
* The entity_form_display object that will be used to display the entity form
* components.
* @param array $context
* An associative array containing:
* - entity_type: The entity type, e.g., 'node' or 'user'.
* - bundle: The bundle, e.g., 'page' or 'article'.
* - form_mode: The form mode, e.g. 'default', 'profile', 'register'...
*/
function
hook_entity_form_display_alter
(
\
Drupal\entity\Plugin\Core\Entity\EntityFormDisplay
$form_display
,
array
$context
)
{
// Hide the 'user_picture' field from the register form.
if
(
$context
[
'entity_type'
]
==
'user'
&&
$context
[
'form_mode'
]
==
'register'
)
{
$form_display
->
setComponent
(
'user_picture'
,
array
(
'type'
=>
'hidden'
,
));
}
}
/**
* Define custom entity properties.
*
...
...
core/includes/entity.inc
View file @
518c4d10
...
...
@@ -662,7 +662,7 @@ function entity_get_display($entity_type, $bundle, $view_mode) {
$display
=
entity_create
(
'entity_display'
,
array
(
'targetEntityType'
=>
$entity_type
,
'bundle'
=>
$bundle
,
'
viewM
ode'
=>
$view_mode
,
'
m
ode'
=>
$view_mode
,
));
}
...
...
@@ -691,7 +691,7 @@ function entity_get_display($entity_type, $bundle, $view_mode) {
* @return \Drupal\entity\Plugin\Core\Entity\EntityDisplay
* The display object that should be used to render the entity.
*
* @see entity_get_
render_
display().
* @see entity_get_display().
*/
function
entity_get_render_display
(
EntityInterface
$entity
,
$view_mode
)
{
$entity_type
=
$entity
->
entityType
();
...
...
@@ -704,11 +704,98 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) {
$render_view_mode
=
!
empty
(
$view_mode_settings
[
$view_mode
][
'status'
])
?
$view_mode
:
'default'
;
$display
=
entity_get_display
(
$entity_type
,
$bundle
,
$render_view_mode
);
$display
->
original
View
Mode
=
$view_mode
;
$display
->
originalMode
=
$view_mode
;
return
$display
;
}
/**
* Returns the entity_form_display object associated to a bundle and form mode.
*
* The function reads the entity_form_display object from the current
* configuration, or returns a ready-to-use empty one if configuration entry
* exists yet for this bundle and form mode. This streamlines manipulation of
* EntityFormDisplay objects by always returning a consistent object that
* reflects the current state of the configuration.
*
* Example usage:
* - Set the 'body' field to be displayed with the 'text_textarea_with_summary'
* widget and the 'field_image' field to be hidden on article nodes in the
* 'default' form mode.
* @code
* entity_get_form_display('node', 'article', 'default')
* ->setComponent('body', array(
* 'type' => 'text_textarea_with_summary',
* 'weight' => 1,
* ))
* ->setComponent('field_image', array(
* 'type' => 'hidden',
* ))
* ->save();
* @endcode
*
* @param string $entity_type
* The entity type.
* @param string $bundle
* The bundle.
* @param string $form_mode
* The form mode.
*
* @return \Drupal\entity\Plugin\Core\Entity\EntityFormDisplay
* The EntityFormDisplay object associated to the form mode.
*/
function
entity_get_form_display
(
$entity_type
,
$bundle
,
$form_mode
)
{
// Try loading the entity from configuration.
$entity_form_display
=
entity_load
(
'entity_form_display'
,
$entity_type
.
'.'
.
$bundle
.
'.'
.
$form_mode
);
// If not found, create a fresh entity object. We do not preemptively create
// new EntityFormDisplay configuration entries for each existing entity type
// and bundle whenever a new form mode becomes available. Instead,
// configuration entries are only created when a EntityFormDisplay object is
// explicitly configured and saved.
if
(
!
$entity_form_display
)
{
$entity_form_display
=
entity_create
(
'entity_form_display'
,
array
(
'targetEntityType'
=>
$entity_type
,
'bundle'
=>
$bundle
,
'mode'
=>
$form_mode
,
));
}
return
$entity_form_display
;
}
/**
* Returns the entity_form_display object used to render an entity form.
*
* This function should only be used internally when rendering an entity form.
* When assigning suggested form display options for a component in a given form
* mode, entity_get_form_display() should be used instead, in order to avoid
* inadvertently modifying the output of other form modes that might happen to
* use the 'default' form display too. Those options will then be effectively
* applied only if the form mode is configured to use them.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity for which the form is being rendered.
* @param string $form_mode
* The form mode being rendered.
*
* @return \Drupal\entity\Plugin\Core\Entity\EntityFormDisplay
* The form display object that should be used to render the entity form.
*
* @see entity_get_form_display().
*/
function
entity_get_render_form_display
(
EntityInterface
$entity
,
$form_mode
)
{
$entity_type
=
$entity
->
entityType
();
$bundle
=
$entity
->
bundle
();
// @todo Form modes don't have custom settings yet, so just return the display
// for the form mode that was requested.
$form_display
=
entity_get_form_display
(
$entity_type
,
$bundle
,
$form_mode
);
$form_display
->
originalMode
=
$form_mode
;
return
$form_display
;
}
/**
* Generic access callback for entity pages.
*
...
...
core/lib/Drupal/Core/Entity/EntityFormController.php
View file @
518c4d10
...
...
@@ -7,6 +7,8 @@
namespace
Drupal\Core\Entity
;
use
Drupal\entity\EntityFormDisplayInterface
;
/**
* Base class for entity form controllers.
*/
...
...
@@ -117,6 +119,20 @@ protected function init(array &$form_state) {
// module-provided form handlers there.
$form_state
[
'controller'
]
=
$this
;
$this
->
prepareEntity
();
// @todo Allow the usage of different form modes by exposing a hook and the
// UI for them.
$form_display
=
entity_get_render_form_display
(
$this
->
entity
,
'default'
);
// Let modules alter the form display.
$form_display_context
=
array
(
'entity_type'
=>
$this
->
entity
->
entityType
(),
'bundle'
=>
$this
->
entity
->
bundle
(),
'form_mode'
=>
'default'
,
);
\
Drupal
::
moduleHandler
()
->
alter
(
'entity_form_display'
,
$form_display
,
$form_display_context
);
$this
->
setFormDisplay
(
$form_display
,
$form_state
);
}
/**
...
...
@@ -132,6 +148,14 @@ public function form(array $form, array &$form_state) {
if
(
!
empty
(
$info
[
'fieldable'
]))
{
field_attach_form
(
$entity
,
$form
,
$form_state
,
$this
->
getFormLangcode
(
$form_state
));
}
// Assign the weights configured in the form display.
foreach
(
$this
->
getFormDisplay
(
$form_state
)
->
getComponents
()
as
$name
=>
$options
)
{
if
(
isset
(
$form
[
$name
]))
{
$form
[
$name
][
'#weight'
]
=
$options
[
'weight'
];
}
}
if
(
!
isset
(
$form
[
'langcode'
]))
{
// If the form did not specify otherwise, default to keeping the existing
// language of the entity or defaulting to the site default language for
...
...
@@ -393,6 +417,21 @@ protected function prepareEntity() {
// @todo Perform common prepare operations and add a hook.
}
/**
* {@inheritdoc}
*/
public
function
getFormDisplay
(
array
$form_state
)
{
return
isset
(
$form_state
[
'form_display'
])
?
$form_state
[
'form_display'
]
:
NULL
;
}
/**
* {@inheritdoc}
*/
public
function
setFormDisplay
(
EntityFormDisplayInterface
$form_display
,
array
&
$form_state
)
{
$form_state
[
'form_display'
]
=
$form_display
;
return
$this
;
}
/**
* Implements \Drupal\Core\Entity\EntityFormControllerInterface::getOperation().
*/
...
...
core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php
View file @
518c4d10
...
...
@@ -8,6 +8,7 @@
namespace
Drupal\Core\Entity
;
use
Drupal\Core\Form\BaseFormIdInterface
;
use
Drupal\entity\EntityFormDisplayInterface
;
/**
* Defines a common interface for entity form controller classes.
...
...
@@ -44,6 +45,30 @@ public function isDefaultFormLangcode(array $form_state);
*/
public
function
getOperation
();
/**
* Returns the form display.
*
* @param array $form_state
* An associative array containing the current state of the form.
*
* @return \Drupal\entity\EntityFormDisplayInterface
* The current form display.
*/
public
function
getFormDisplay
(
array
$form_state
);
/**
* Sets the form display.
*
* Sets the form display which will be used for populating form element
* defaults.
*
* @param \Drupal\entity\EntityFormDisplayInterface $form_display
* The form display that the current form operates with.
* @param array $form_state
* An associative array containing the current state of the form.
*/
public
function
setFormDisplay
(
EntityFormDisplayInterface
$form_display
,
array
&
$form_state
);
/**
* Returns the form entity.
*
...
...
core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
View file @
518c4d10
...
...
@@ -30,6 +30,14 @@ public function form(array $form, array &$form_state) {
if
(
!
empty
(
$info
[
'fieldable'
]))
{
field_attach_form
(
$entity
,
$form
,
$form_state
,
$this
->
getFormLangcode
(
$form_state
));
}
// Assign the weights configured in the form display.
foreach
(
$this
->
getFormDisplay
(
$form_state
)
->
getComponents
()
as
$name
=>
$options
)
{
if
(
isset
(
$form
[
$name
]))
{
$form
[
$name
][
'#weight'
]
=
$options
[
'weight'
];
}
}
return
$form
;
}
...
...
core/modules/block/block.install
View file @
518c4d10
...
...
@@ -259,11 +259,19 @@ function block_update_8008() {
'entity_type'
=>
'custom_block'
,
'bundle'
=>
'basic'
,
'label'
=>
'Block body'
,
'widget'
=>
array
(
'type'
=>
'text_textarea_with_summary'
),
'settings'
=>
array
(
'display_summary'
=>
FALSE
),
);
_update_7000_field_create_instance
(
$body_field
,
$instance
);
module_load_install
(
'entity'
);
// Assign form settings for the 'default' form mode.
$form_display
=
_update_8000_entity_get_form_display
(
'custom_block'
,
'basic'
,
'default'
);
$form_display
->
set
(
'content.user_picture'
,
array
(
'type'
=>
'text_textarea_with_summary'
,
))
->
save
();
update_config_manifest_add
(
'entity.form_display'
,
array
(
$form_display
->
get
(
'id'
)));
// Initialize state for future calls.
$sandbox
[
'last'
]
=
0
;
$sandbox
[
'count'
]
=
0
;
...
...
core/modules/block/custom_block/custom_block.module
View file @
518c4d10
...
...
@@ -214,11 +214,17 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') {
'entity_type'
=>
'custom_block'
,
'bundle'
=>
$block_type_id
,
'label'
=>
$label
,
'widget'
=>
array
(
'type'
=>
'text_textarea_with_summary'
),
'settings'
=>
array
(
'display_summary'
=>
FALSE
),
);
$instance
=
field_create_instance
(
$instance
);
// Assign widget settings for the 'default' form mode.
entity_get_form_display
(
'custom_block'
,
$block_type_id
,
'default'
)
->
setComponent
(
'block_body'
,
array
(
'type'
=>
'text_textarea_with_summary'
,
))
->
save
();
// Assign display settings for 'default' view mode.
entity_get_display
(
'custom_block'
,
$block_type_id
,
'default'
)
->
setComponent
(
'block_body'
,
array
(
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php
View file @
518c4d10
...
...
@@ -77,17 +77,18 @@ public function testBlockFields() {
'settings'
=>
array
(
'title'
=>
DRUPAL_OPTIONAL
,
),
'widget'
=>
array
(
'type'
=>
'link_default'
,
),
);
$display_options
=
array
(
'type'
=>
'link'
,
'label'
=>
'hidden'
,
);
field_create_instance
(
$this
->
instance
);
entity_get_form_display
(
'custom_block'
,
'link'
,
'default'
)
->
setComponent
(
$this
->
field
[
'field_name'
],
array
(
'type'
=>
'link_default'
,
))
->
save
();
entity_get_display
(
'custom_block'
,
'link'
,
'default'
)
->
setComponent
(
$this
->
field
[
'field_name'
],
$display_options
)
->
setComponent
(
$this
->
field
[
'field_name'
],
array
(
'type'
=>
'link'
,
'label'
=>
'hidden'
,
))
->
save
();
// Create a block.
...
...
core/modules/comment/comment.module
View file @
518c4d10
...
...
@@ -365,6 +365,15 @@ function _comment_body_field_create($info) {
'required'
=>
TRUE
,
);
field_create_instance
(
$instance
);
// Assign widget settings for the 'default' form mode.
entity_get_form_display
(
'comment'
,
'comment_node_'
.
$info
->
type
,
'default'
)
->
setComponent
(
'comment_body'
,
array
(
'type'
=>
'text_textarea'
,
))
->
save
();
// Assign display settings for the 'default' view mode.
entity_get_display
(
'comment'
,
'comment_node_'
.
$info
->
type
,
'default'
)
->
setComponent
(
'comment_body'
,
array
(
'label'
=>
'hidden'
,
...
...
core/modules/datetime/datetime.module
View file @
518c4d10
...
...
@@ -134,9 +134,7 @@ function datetime_field_settings_form($field, $instance, $has_data) {
* Implements hook_field_instance_settings_form().
*/
function
datetime_field_instance_settings_form
(
$field
,
$instance
)
{
$widget
=
$instance
[
'widget'
];
$settings
=
$instance
[
'settings'
];
$widget_settings
=
$instance
[
'widget'
][
'settings'
];
$form
[
'default_value'
]
=
array
(
'#type'
=>
'select'
,
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php
View file @
518c4d10
...
...
@@ -36,23 +36,12 @@
class
DateTimeDatelistWidget
extends
WidgetBase
{
/**
* Constructs a DateTimeDatelist Widget object.
*
* @param array $plugin_id
* The plugin_id for the widget.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance
* The field instance to which the widget is associated.
* @param array $settings
* The widget settings.
* @param int $weight
* The widget weight.
* {@inheritdoc}
*/
public
function
__construct
(
$plugin_id
,
array
$plugin_definition
,
FieldInstance
$instance
,
array
$settings
,
$weight
)
{
public
function
__construct
(
$plugin_id
,
array
$plugin_definition
,
FieldInstance
$instance
,
array
$settings
)
{
// Identify the function used to set the default value.
$instance
[
'default_value_function'
]
=
$this
->
defaultValueFunction
();
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$instance
,
$settings
,
$weight
);
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$instance
,
$settings
);
}
/**
...
...
core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php
View file @
518c4d10
...
...
@@ -30,23 +30,12 @@
class
DateTimeDefaultWidget
extends
WidgetBase
{
/**
* Constructs a DateTimeDefault Widget object.
*
* @param array $plugin_id
* The plugin_id for the widget.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance
* The field instance to which the widget is associated.
* @param array $settings
* The widget settings.
* @param int $weight
* The widget weight.
* {@inheritdoc}
*/
public
function
__construct
(
$plugin_id
,
array
$plugin_definition
,
FieldInstance
$instance
,
array
$settings
,
$weight
)
{
public
function
__construct
(
$plugin_id
,
array
$plugin_definition
,
FieldInstance
$instance
,
array
$settings
)
{
// Identify the function used to set the default value.
$instance
[
'default_value_function'
]
=
$this
->
defaultValueFunction
();
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$instance
,
$settings
,
$weight
);
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$instance
,
$settings
);
}
/**
...
...
core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php
View file @
518c4d10
...
...
@@ -57,14 +57,17 @@ function setUp() {
'field_name'
=>
$this
->
field
[
'field_name'
],
'entity_type'
=>
'test_entity'
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
'type'
=>
'datetime_default'
,
),
'settings'
=>
array
(
'default_value'
=>
'blank'
,
),
));
entity_get_form_display
(
$this
->
instance
[
'entity_type'
],
$this
->
instance
[
'bundle'
],
'default'
)
->
setComponent
(
$this
->
field
[
'field_name'
],
array
(
'type'
=>
'datetime_default'
,
))
->
save
();
$this
->
display_options
=
array
(
'type'
=>
'datetime_default'
,
'label'
=>
'hidden'
,
...
...
@@ -217,17 +220,16 @@ function testDatelistWidget() {
field_update_field
(
$this
->
field
);
// Change the widget to a datelist widget.
$increment
=
1
;
$date_order
=
'YMD'
;
$time_type
=
'12'
;
$this
->
instance
[
'widget'
][
'type'
]
=
'datetime_datelist'
;
$this
->
instance
[
'widget'
][
'settings'
]
=
array
(
'increment'
=>
$increment
,
'date_order'
=>
$date_order
,
'time_type'
=>
$time_type
,
);
field_update_instance
(
$this
->
instance
);
entity_get_form_display
(
$this
->
instance
[
'entity_type'
],
$this
->
instance
[
'bundle'
],
'default'
)
->
setComponent
(
$this
->
instance
[
'field_name'
],
array
(
'type'
=>
'datetime_datelist'
,
'settings'
=>
array
(
'increment'
=>
1
,
'date_order'
=>
'YMD'
,
'time_type'
=>
'12'
,
),
))
->
save
();
field_cache_clear
();
// Display creation form.
...
...
core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php
View file @
518c4d10
...
...
@@ -59,6 +59,20 @@ protected function init(array &$form_state, EntityInterface $entity, $field_name
$form_state
[
'entity'
]
=
$entity
;
$form_state
[
'field_name'
]
=
$field_name
;
// @todo Allow the usage of different form modes by exposing a hook and the
// UI for them.
$form_display
=
entity_get_render_form_display
(
$entity
,
'default'
);
// Let modules alter the form display.
$form_display_context
=
array
(
'entity_type'
=>
$entity
->
entityType
(),
'bundle'
=>
$entity
->
bundle
(),
'form_mode'
=>
'default'
,
);
\
Drupal
::
moduleHandler
()
->
alter
(
'entity_form_display'
,
$form_display
,
$form_display_context
);
$form_state
[
'form_display'
]
=
$form_display
;
}
/**
...
...
core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php
View file @
518c4d10
...
...
@@ -70,13 +70,16 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst
'description'
=>
$label
,
'weight'
=>
mt_rand
(
0
,
127
),
'settings'
=>
$instance_settings
,
'widget'
=>
array
(
);
field_create_instance
(
$this
->
$instance
);
entity_get_form_display
(
'entity_test'
,
'entity_test'
,
'default'
)
->
setComponent
(
$field_name
,
array
(
'type'
=>
$widget_type
,
'label'
=>
$label
,
'settings'
=>
$widget_settings
,
),
);
field_create_instance
(
$this
->
$instance
);
))
->
save
();
entity_get_display
(
'entity_test'
,
'entity_test'
,
'default'
)
->
setComponent
(
$field_name
,
array
(
...
...
core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php
View file @
518c4d10
...
...
@@ -54,14 +54,18 @@ function testEmailField() {
'field_name'
=>
$this
->
field
[
'field_name'
],
'entity_type'
=>
'test_entity'
,
'bundle'
=>
'test_bundle'
,
'widget'
=>
array
(
);
field_create_instance
(
$this
->
instance
);
// Create a form display for the default form mode.
entity_get_form_display
(
'test_entity'
,
'test_bundle'
,
'default'
)
->
setComponent
(
$this
->
field
[
'field_name'
],
array
(
'type'
=>
'email_default'
,
'settings'
=>
array
(
'placeholder'
=>
'example@example.com'
,
),
),
);
field_create_instance
(
$this
->
instance
);
))
->
save
();
// Create a display for the full view mode.
entity_get_display
(
'test_entity'
,
'test_bundle'
,
'full'
)
->
setComponent
(
$this
->
field
[
'field_name'
],
array
(
...
...
core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php
View file @
518c4d10
...
...
@@ -44,11 +44,15 @@ public function setUp() {
'entity_type'
=>
'entity_test'
,
'field_name'
=>
'field_email'
,
'bundle'
=>
'entity_test'
,
'widget'
=>
array
(
'type'
=>
'email_default'
,
),
);
field_create_instance
(
$this
->
instance
);
// Create a form display for the default form mode.
entity_get_form_display
(
'entity_test'
,
'entity_test'
,
'default'
)
->
setComponent
(
'field_email'
,
array
(
'type'
=>
'email_default'
,
))