In trying to get the Wizard API to edit existing pages in Page Manager, I encountered an issue where the getOperations() method wasn't able to setup the list of steps for a existing page entity (as opposed to a new page entity).

Basically, the problem is that getOperations() was using $this->getTempstore()->get($wizard->getMachineName()) to get the entity, but it was being called before there was a chance to set anything in the tempstore. However, in every case, the actual $cached_values were available to the calling code - so why not just pass them in?

This also makes getOperations() consistent with getOperation() and other methods which already take the $cached_values.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dsnopek created an issue. See original summary.

dsnopek’s picture

Status: Active » Needs review
FileSize
8.19 KB

Patch is attached! This still needs tests. Also, we could modify the interface in a backwards-compatible way by giving a default value for $cached_values of NULL, but I'm not sure if that makes sense or not.

dsnopek’s picture

Issue tags: -Needs tests
FileSize
22.02 KB
30.15 KB

Alright! I've written some tests for entity wizards that demonstrate the problem I encountered. Here's two patches: one with the tests only that fails, and another with the functional changes that passes.

The last submitted patch, 3: ctools-wizard-edit-2607552-3-FAIL.patch, failed testing.

EclipseGc’s picture

  1. +++ b/tests/modules/ctools_wizard_test/src/Entity/ExampleConfigEntity.php
    @@ -0,0 +1,88 @@
    + *       "add" = "Drupal\ctools_wizard_test\Wizard\EntityWizardTest",
    + *       "edit" = "Drupal\ctools_wizard_test\Wizard\EntityWizardTest"
    

    Make these two different wizards. Edit doesn't need to implement the getRouteName() method, and the Add can extend Edit and JUST implement the getRouteName() method.

  2. +++ b/tests/modules/ctools_wizard_test/src/Form/ExampleConfigEntityGeneralForm.php
    @@ -0,0 +1,70 @@
    +    /*
    +    $form['label'] = array(
    +      '#type' => 'textfield',
    +      '#title' => $this->t('Label'),
    +      '#maxlength' => 255,
    +      '#default_value' => $config_entity->label(),
    +      '#description' => $this->t("Label for the Example config entity."),
    +      '#required' => TRUE,
    +    );
    +
    +    $form['id'] = array(
    +      '#type' => 'machine_name',
    +      '#default_value' => $config_entity->id(),
    +      '#machine_name' => array(
    +        'exists' => '\Drupal\ctools_wizard_test\Entity\ExampleConfigEntity::load',
    +      ),
    +      '#disabled' => !$config_entity->isNew(),
    +    );
    +    */
    

    Remove

  3. +++ b/tests/modules/ctools_wizard_test/src/Wizard/EntityWizardTest.php
    @@ -0,0 +1,87 @@
    + * Created by PhpStorm.
    + * User: dsnopek
    + * Date: 11/4/15
    + * Time: 8:26 AM
    

    Please fix.

Otherwise I think this looks really good.

Eclipse

dsnopek’s picture

FileSize
29.5 KB
8.33 KB

Thanks, @EclipseGC! Here's a new patch that addresses the review from #5.

  • EclipseGc committed cd98232 on 8.x-3.x authored by dsnopek
    Issue #2607552 by dsnopek: Pass $cached_values to WizardFormInterface::...
EclipseGc’s picture

Status: Needs review » Fixed
  1. +++ b/tests/modules/ctools_wizard_test/src/Wizard/EntityAddWizardTest.php
    @@ -0,0 +1,19 @@
    \ No newline at end of file
    

    new line :-S

  2. +++ b/tests/modules/ctools_wizard_test/src/Wizard/EntityEditWizardTest.php
    @@ -0,0 +1,75 @@
    \ No newline at end of file
    

    ...

fixed these on commit.

Eclipse

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.