public function prefill(Request $request)
{
// Determine the Contenttypes that we're doing the prefill for
$choices = [];
foreach ($this->getOption('contenttypes') as $key => $contentType) {
$nameKey = 'contenttypes.' . $key . '.name.plural';
$nameTrans = Trans::__($nameKey, [], 'contenttypes');
$name = $nameTrans === $nameKey ? $contentType['name'] : $nameTrans;
$choices[$name] = $key;
}
// Create the form
$form = $this->createFormBuilder(FormType::class)->add('contenttypes', ChoiceType::class, ['choices_as_values' => true, 'choices' => $choices, 'multiple' => true, 'expanded' => true])->getForm();
if ($request->isMethod('POST') || $request->get('force') == 1) {
$form->handleRequest($request);
$contenttypes = $form->get('contenttypes')->getData();
try {
$content = $this->storage()->preFill($contenttypes);
$this->flashes()->success($content);
} catch (RequestException $e) {
$msg = "Timeout attempting connection to the 'Lorem Ipsum' generator. Unable to add dummy content.";
$this->flashes()->error($msg);
$this->app['logger.system']->error($msg, ['event' => 'storage']);
}
return $this->redirectToRoute('prefill');
}
$context = ['contenttypes' => $choices, 'form' => $form->createView()];
return $this->render('@bolt/prefill/prefill.twig', $context);
}