diff --git a/core/modules/workspace/src/Entity/Workspace.php b/core/modules/workspace/src/Entity/Workspace.php index beba88a..af39e08 100644 --- a/core/modules/workspace/src/Entity/Workspace.php +++ b/core/modules/workspace/src/Entity/Workspace.php @@ -78,14 +78,24 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setRequired(TRUE) ->addConstraint('UniqueField') ->addConstraint('DeletedWorkspace') - ->addPropertyConstraints('value', ['Regex' => ['pattern' => '/^[a-z0-9_]+$/']]); + ->addPropertyConstraints('value', ['Regex' => ['pattern' => '/^[a-z0-9_]+$/']]) + ->setDisplayOptions('form', [ + 'type' => 'machine_name', + 'weight' => -5, + 'settings' => [ + 'source_field' => 'label', + ], + ]); $fields['label'] = BaseFieldDefinition::create('string') ->setLabel(new TranslatableMarkup('Workspace name')) - ->setDescription(new TranslatableMarkup('The workspace name.')) ->setRevisionable(TRUE) ->setSetting('max_length', 128) - ->setRequired(TRUE); + ->setRequired(TRUE) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => -10, + ]); $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(new TranslatableMarkup('Owner')) diff --git a/core/modules/workspace/src/Form/WorkspaceForm.php b/core/modules/workspace/src/Form/WorkspaceForm.php index c0085b4..57bddae 100644 --- a/core/modules/workspace/src/Form/WorkspaceForm.php +++ b/core/modules/workspace/src/Form/WorkspaceForm.php @@ -4,7 +4,6 @@ use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Entity\ContentEntityForm; -use Drupal\Core\Entity\EntityConstraintViolationListInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; @@ -69,25 +68,6 @@ public function form(array $form, FormStateInterface $form_state) { if ($this->operation == 'edit') { $form['#title'] = $this->t('Edit workspace %label', ['%label' => $workspace->label()]); } - $form['label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Label'), - '#maxlength' => 255, - '#default_value' => $workspace->label(), - '#required' => TRUE, - ]; - - $form['id'] = [ - '#type' => 'machine_name', - '#title' => $this->t('Workspace ID'), - '#maxlength' => 255, - '#default_value' => $workspace->id(), - '#disabled' => !$workspace->isNew(), - '#machine_name' => [ - 'exists' => '\Drupal\workspace\Entity\Workspace::load', - ], - '#element_validate' => [], - ]; return parent::form($form, $form_state); } @@ -95,34 +75,6 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - protected function getEditedFieldNames(FormStateInterface $form_state) { - return array_merge([ - 'label', - 'id', - ], parent::getEditedFieldNames($form_state)); - } - - /** - * {@inheritdoc} - */ - protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) { - // Manually flag violations of fields not handled by the form display. This - // is necessary as entity form displays only flag violations for fields - // contained in the display. - $field_names = [ - 'label', - 'id', - ]; - foreach ($violations->getByFields($field_names) as $violation) { - list($field_name) = explode('.', $violation->getPropertyPath(), 2); - $form_state->setErrorByName($field_name, $violation->getMessage()); - } - parent::flagViolations($violations, $form, $form_state); - } - - /** - * {@inheritdoc} - */ public function save(array $form, FormStateInterface $form_state) { $workspace = $this->entity; $workspace->setNewRevision(TRUE); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php b/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php index 41f337f..44f310d 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceTestUtilities.php @@ -55,8 +55,8 @@ protected function getOneEntityByLabel($type, $label) { */ protected function createWorkspaceThroughUi($label, $id) { $this->drupalPostForm('/admin/config/workflow/workspace/add', [ - 'id' => $id, - 'label' => $label, + 'id[0][value]' => $id, + 'label[0][value]' => $label, ], 'Save'); $this->getSession()->getPage()->hasContent("$label ($id)");