Loading core/config/schema/core.entity.schema.yml +17 −0 Original line number Diff line number Diff line Loading @@ -23,19 +23,36 @@ core.entity_view_mode.*.*: core.entity_form_mode.*.*: type: config_entity label: 'Entity form mode settings' constraints: FullyValidatable: ~ mapping: id: type: string label: 'ID' # Form mode IDs can only contain lowercase letters, numbers, and underscores # prefixed by entity type name this form mode is used for and a dot. # @see \Drupal\field_ui\Form\EntityDisplayModeFormBase::form() constraints: Regex: pattern: '/^[a-z0-9_]+\.[a-z0-9_]+$/' message: "The ID %value is not valid." label: type: required_label label: 'Label' description: type: text label: 'Description' nullable: true constraints: NotBlank: allowNull: true targetEntityType: type: string label: 'Target entity type' constraints: PluginExists: manager: entity_type.manager interface: Drupal\Core\Entity\ContentEntityInterface cache: type: boolean label: 'Cache' Loading core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD * * @var string|null */ protected ?string $description; protected ?string $description = NULL; /** * The entity type this form or view mode is used for. Loading core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +13 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; Loading Loading @@ -298,4 +299,16 @@ private function getDisplayByContext(string $bundle, string $display_mode_name): }; } /** * {@inheritdoc} */ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state): void { // Config schema dictates that the description value // cannot be empty string. So, if it is empty, make it NULL. if ($form_state->hasValue('description') && trim($form_state->getValue('description')) === '') { $form_state->setValue('description', NULL); } parent::copyFormValuesToEntity($entity, $form, $form_state); } } core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ public function testEntityFormModeUI(): void { $edit = [ 'id' => $this->randomMachineName(), 'label' => $this->randomString(), 'description' => $this->randomString(), ]; $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains("Saved the {$edit['label']} form mode."); Loading core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -270,6 +270,7 @@ public function testFormModeLocalTasksOrder(): void { 'id' => 'node.big', 'label' => 'Big Form', 'targetEntityType' => 'node', 'description' => 'Test description', ])->save(); EntityFormMode::create([ 'id' => 'node.little', Loading Loading
core/config/schema/core.entity.schema.yml +17 −0 Original line number Diff line number Diff line Loading @@ -23,19 +23,36 @@ core.entity_view_mode.*.*: core.entity_form_mode.*.*: type: config_entity label: 'Entity form mode settings' constraints: FullyValidatable: ~ mapping: id: type: string label: 'ID' # Form mode IDs can only contain lowercase letters, numbers, and underscores # prefixed by entity type name this form mode is used for and a dot. # @see \Drupal\field_ui\Form\EntityDisplayModeFormBase::form() constraints: Regex: pattern: '/^[a-z0-9_]+\.[a-z0-9_]+$/' message: "The ID %value is not valid." label: type: required_label label: 'Label' description: type: text label: 'Description' nullable: true constraints: NotBlank: allowNull: true targetEntityType: type: string label: 'Target entity type' constraints: PluginExists: manager: entity_type.manager interface: Drupal\Core\Entity\ContentEntityInterface cache: type: boolean label: 'Cache' Loading
core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD * * @var string|null */ protected ?string $description; protected ?string $description = NULL; /** * The entity type this form or view mode is used for. Loading
core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +13 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; Loading Loading @@ -298,4 +299,16 @@ private function getDisplayByContext(string $bundle, string $display_mode_name): }; } /** * {@inheritdoc} */ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state): void { // Config schema dictates that the description value // cannot be empty string. So, if it is empty, make it NULL. if ($form_state->hasValue('description') && trim($form_state->getValue('description')) === '') { $form_state->setValue('description', NULL); } parent::copyFormValuesToEntity($entity, $form, $form_state); } }
core/modules/field_ui/tests/src/Functional/EntityDisplayModeTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ public function testEntityFormModeUI(): void { $edit = [ 'id' => $this->randomMachineName(), 'label' => $this->randomString(), 'description' => $this->randomString(), ]; $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains("Saved the {$edit['label']} form mode."); Loading
core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -270,6 +270,7 @@ public function testFormModeLocalTasksOrder(): void { 'id' => 'node.big', 'label' => 'Big Form', 'targetEntityType' => 'node', 'description' => 'Test description', ])->save(); EntityFormMode::create([ 'id' => 'node.little', Loading