diff --git a/src/Form/PageEditForm.php b/src/Form/PageEditForm.php index 3994ebd..28d0c0f 100644 --- a/src/Form/PageEditForm.php +++ b/src/Form/PageEditForm.php @@ -7,6 +7,7 @@ namespace Drupal\page_manager\Form; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\ctools\Form\AjaxFormTrait; @@ -171,7 +172,7 @@ public function form(array $form, FormStateInterface $form_state) { '#type' => 'operations', '#links' => $operations, ]; - $form['variant_section']['variants'][$page_variant->uuid()] = $row; + $form['variant_section']['variants'][$page_variant->id()] = $row; } if ($access_conditions = $this->entity->getAccessConditions()) { @@ -252,9 +253,9 @@ public function form(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) { if (!$form_state->isValueEmpty('variants')) { foreach ($form_state->getValue('variants') as $variant_plugin_id => $data) { - if ($variant_plugin = $this->entity->getVariant($variant_plugin_id)) { - $variant_plugin->setWeight($data['weight']); - $variant_plugin->save(); + if ($variant_entity = $this->entity->getVariant($variant_plugin_id)) { + $variant_entity->setWeight($data['weight']); + $variant_entity->save(); } } } @@ -263,4 +264,14 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirect('entity.page.collection'); } + /** + * {@inheritdoc} + */ + protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) { + // Variants will be handled independently. + $variants = $form_state->getValue('variants'); + $form_state->unsetValue('variants'); + parent::copyFormValuesToEntity($entity, $form, $form_state); + $form_state->setValue('variants', $variants); + } } diff --git a/src/Tests/PageManagerAdminTest.php b/src/Tests/PageManagerAdminTest.php index 3e43566..5e633c0 100644 --- a/src/Tests/PageManagerAdminTest.php +++ b/src/Tests/PageManagerAdminTest.php @@ -65,7 +65,6 @@ public function testAdmin() { $this->doTestEditBlock(); $this->doTestExistingPathWithoutParameters(); $this->doTestDeletePage(); - $this->doTestExistingRoutes(); } /** @@ -112,7 +111,7 @@ protected function doTestAddPage() { // Set the weight of the 'Default' variant to 10. $default_variant = $this->findVariantByLabel('foo', 'Default'); $edit = [ - 'variants[' . $default_variant->uuid() . '][weight]' => 10, + 'variants[' . $default_variant->id() . '][weight]' => 10, ]; $this->drupalPostForm(NULL, $edit, 'Save'); @@ -262,9 +261,9 @@ protected function doTestReorderVariants() { } $this->assertEqual($expected, $links); - $variant_plugin = $this->findVariantByLabel('foo', 'Default'); + $variant_entity = $this->findVariantByLabel('foo', 'Default'); $edit = [ - 'variants[' . $variant_plugin->uuid() . '][weight]' => -10, + 'variants[' . $variant_entity->id() . '][weight]' => -10, ]; $this->drupalPostForm('admin/structure/page_manager/manage/foo', $edit, 'Save'); $this->drupalGet('admin/foo'); @@ -421,8 +420,7 @@ protected function doTestDeletePage() { /** * Tests that default arguments are not removed from existing routes. */ - public function doTestExistingRoutes() { - + public function testExistingRoutes() { // Test that the page without placeholder is accessible. $edit = [ 'label' => 'Placeholder test 2',