Skip to content

Instantly share code, notes, and snippets.

@cornobils
Created May 21, 2018 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornobils/4d1dccfdb9eb11311caf2135f1987503 to your computer and use it in GitHub Desktop.
Save cornobils/4d1dccfdb9eb11311caf2135f1987503 to your computer and use it in GitHub Desktop.
[Sulu] Article fixture example
<?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