public function index(Application $app, Request $request)
{
$DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC);
$Templates = $app['eccube.repository.template']->findBy(array('DeviceType' => $DeviceType));
$form = $app->form()->add('selected', 'hidden')->getForm();
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$Template = $app['eccube.repository.template']->find($form['selected']->getData());
// path.(yml|php)の再構築
$file = $app['config']['root_dir'] . '/app/config/eccube/path';
if (file_exists($file . '.php')) {
$config = (require $file . '.php');
} elseif (file_exists($file . '.yml')) {
$config = Yaml::parse(file_get_contents($file . '.yml'));
}
$templateCode = $Template->getCode();
$config['template_code'] = $templateCode;
$config['template_realdir'] = $config['root_dir'] . '/app/template/' . $templateCode;
$config['template_html_realdir'] = $config['public_path_realdir'] . '/template/' . $templateCode;
$config['front_urlpath'] = $config['root_urlpath'] . RELATIVE_PUBLIC_DIR_PATH . '/template/' . $templateCode;
$config['block_realdir'] = $config['template_realdir'] . '/Block';
if (file_exists($file . '.php')) {
file_put_contents($file . '.php', sprintf('<?php return %s', var_export($config, true)) . ';');
}
if (file_exists($file . '.yml')) {
file_put_contents($file . '.yml', Yaml::dump($config));
}
$app->addSuccess('admin.content.template.save.complete', 'admin');
return $app->redirect($app->url('admin_store_template'));
}
}
return $app->render('Store/template.twig', array('form' => $form->createView(), 'Templates' => $Templates));
}