Skip to content

Commit

Permalink
Use entity to generate form edit URL
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsokolowski06 committed Oct 8, 2024
1 parent 38a1e64 commit 17a66e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/CommerceContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Behat\Gherkin\Node\TableNode;
use Drupal\commerce_product\ProductVariationStorageInterface;
use Drupal\commerce_promotion\Entity\PromotionInterface;
use Drupal\DrupalExtension\Context\RawDrupalContext;

/**
Expand Down Expand Up @@ -71,6 +72,7 @@ public function couponCreate($coupon) {
* @Then I visit promotion :title edit page
*/
public function iVisitPromotionEditPage($title) {
/** @var \Drupal\commerce_promotion\Entity\PromotionInterface[] $promotions */
$promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion')
->loadByProperties([
'name' => $title,
Expand All @@ -79,8 +81,8 @@ public function iVisitPromotionEditPage($title) {
throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions));
}

$id = reset($promotions)->id();
$this->getSession()->visit($this->locatePath("promotion/$id/edit"));
$promotion = reset($promotions);
$this->getSession()->visit($this->locatePath($promotion->toUrl('edit-form')->toString()));
}

/**
Expand Down

0 comments on commit 17a66e0

Please sign in to comment.