create(FixtureBlueprint::class, $class); $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) { /** @var SiteTree $obj */ $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); }); $factory->define($class, $blueprint); } return $factory; } /** * Find or create a redirector page and link to another existing page. * Example: Given a "page" "My Redirect" which redirects to a "page" "Page 1" * * @Given /^(?:(an|a|the) )"(?[^"]+)" "(?[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?[^"]+)" "(?[^"]+)"$/ * @param string $type * @param string $id * @param string $targetType * @param string $targetId */ public function stepCreateRedirectorPage($type, $id, $targetType, $targetId) { $class = RedirectorPage::class; $targetClass = $this->convertTypeToClass($targetType); $targetObj = $this->fixtureFactory->get($targetClass, $targetId); if (!$targetObj) { $targetObj = $this->fixtureFactory->get($targetClass, $targetId); } $fields = ['LinkToID' => $targetObj->ID]; /** @var RedirectorPage $obj */ $obj = $this->fixtureFactory->get($class, $id); if ($obj) { $obj->update($fields); } else { $obj = $this->fixtureFactory->createObject($class, $id, $fields); } $obj->write(); $obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); } }