diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
index de988916d7..9f2e6770fb 100644
--- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
+++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php
@@ -267,7 +267,7 @@ public function getTransitions(array $transition_ids = NULL) {
   }
 
   /**
-   * Sort states or transitions by weight and label.
+   * Sort states or transitions by weight, label, and key.
    *
    * @param \Drupal\workflows\StateInterface[]|\Drupal\workflows\TransitionInterface[] $objects
    *   Objects to multi-sort.
@@ -286,12 +286,8 @@ protected static function labelWeightMultisort($objects) {
       }
       // Sort weights, labels, and keys in the same order as each other.
       array_multisort(
-        $weights,
-        SORT_NUMERIC,
-        SORT_ASC,
-        $labels,
-        SORT_NATURAL,
-        SORT_ASC,
+        $weights, SORT_NUMERIC, SORT_ASC,
+        $labels, SORT_NATURAL, SORT_ASC,
         $keys
       );
       // Combine keys and weights to make sure the weights are keyed with the
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php
index 679b314d19..a466a7d571 100644
--- a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeStateForm.php
@@ -22,7 +22,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
       '#type' => 'textfield',
       '#title' => $this->t('Extra'),
       '#description' => $this->t('Extra information added to state'),
-      '#default_value' => isset($configuration['states'][$state->id()]['extra']) ? $configuration['states'][$state->id()]['extra'] : '',
+      '#default_value' => $state && isset($configuration['states'][$state->id()]['extra']) ? $configuration['states'][$state->id()]['extra'] : '',
     ];
     return $form;
   }
diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php
index 45e15139b9..a88306c750 100644
--- a/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php
+++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Form/ComplexTestTypeTransitionForm.php
@@ -22,7 +22,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
       '#type' => 'textfield',
       '#title' => $this->t('Extra'),
       '#description' => $this->t('Extra information added to transition'),
-      '#default_value' => isset($configuration['transitions'][$transition->id()]['extra']) ? $configuration['transitions'][$transition->id()]['extra'] : '',
+      '#default_value' => $transition && isset($configuration['transitions'][$transition->id()]['extra']) ? $configuration['transitions'][$transition->id()]['extra'] : '',
     ];
     return $form;
   }
diff --git a/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php b/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
index fcbcbd0448..886750161c 100644
--- a/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
+++ b/core/modules/workflows/tests/src/Functional/WorkflowUiTest.php
@@ -293,4 +293,29 @@ public function testWorkflowConfigurationForm() {
     $this->assertEquals('Extra global settings', $workflow->getTypePlugin()->getConfiguration()['example_setting']);
   }
 
+  /**
+   * Test a workflow, state, and transition can have a numeric ID and label.
+   */
+  public function testNumericIds() {
+    $this->drupalLogin($this->createUser(['administer workflows']));
+    $this->drupalGet('admin/config/workflow/workflows');
+    $this->clickLink('Add workflow');
+    $this->submitForm(['label' => 123, 'id' => 123, 'workflow_type' => 'workflow_type_complex_test'], 'Save');
+
+    $this->assertSession()->addressEquals('admin/config/workflow/workflows/manage/123/add_state');
+
+    $this->submitForm(['label' => 456, 'id' => 456], 'Save');
+    $this->assertSession()->pageTextContains('Created 456 state.');
+
+    $this->clickLink('Add a new transition');
+    $this->submitForm(['id' => 789, 'label' => 789, 'from[456]' => 456, 'to' => 456], 'Save');
+    $this->assertSession()->pageTextContains('Created 789 transition.');
+
+    $workflow = $this->container->get('entity_type.manager')->getStorage('workflow')->loadUnchanged(123);
+    $this->assertEquals(123, $workflow->id());
+    $this->assertEquals(456, $workflow->getTypePlugin()->getState(456)->id());
+    $this->assertEquals(789, $workflow->getTypePlugin()->getTransition(789)->id());
+    $this->assertEquals(456, $workflow->getTypePlugin()->getTransition(789)->to()->id());
+  }
+
 }
