Created
May 21, 2018 08:02
-
-
Save chornobils/4d1dccfdb9eb11311caf2135f1987503 to your computer and use it in GitHub Desktop.
[Sulu] Article fixture example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace AppBundle\DataFixtures\Document; | |
use Sulu\Component\DocumentManager\DocumentManager; | |
use Sulu\Bundle\DocumentManagerBundle\DataFixtures\DocumentFixtureInterface; | |
use Sulu\Component\Content\Document\WorkflowStage; | |
final class ArticleFixture implements DocumentFixtureInterface | |
{ | |
public function load(DocumentManager $documentManager) | |
{ | |
for ($i = 0; $i < 200; $i++) { | |
/** @var \Sulu\Bundle\ContentBundle\Document\PageDocument $document */ | |
$document = $documentManager->create('article'); | |
$document->setLocale('en'); | |
$document->setTitle('foo bar page ' . $i); | |
$document->setStructureType('article_default'); | |
$document->setWorkflowStage(WorkflowStage::PUBLISHED); | |
$document->getStructure()->bind(array( | |
'title' => 'foo bar page', | |
)); | |
$document->setExtension( | |
'excerpt', | |
[ | |
'title' => 'foo title', | |
'description' => 'bar description for fixture #' . $i, | |
'categories' => [], | |
'tags' => [] | |
] | |
); | |
$documentManager->persist($document, 'en', array( | |
'parent_path' => '<create an article manually before it and paste its uuid here>', | |
)); | |
# Optional: If you don't want your document to be published, remove this line | |
$documentManager->publish($document, 'en'); | |
} | |
$documentManager->flush(); | |
} | |
public function getOrder() | |
{ | |
return 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment