private function getPublicResourcesForm()
{
$em = $this->getDoctrine()->getManager();
$router = $this->container->get('router');
$collection = $router->getRouteCollection();
$allRoutes = $collection->all();
// TODO:
// * add way to allow anonymous access for comments posting (if it's enabled in publications settings)
// * add way to allow anonymous access for feedback posting
$apiRoutes = array();
foreach ($allRoutes as $key => $route) {
if (strpos($key, 'newscoop_gimme_') !== false) {
$routeMethods = $route->getMethods();
if (in_array('GET', $route->getMethods())) {
$apiRoutes[$key] = '[' . $routeMethods[0] . '] ' . str_replace('{_format}', 'json', $route->getPath());
}
}
}
$existingResources = array();
foreach ($em->getRepository('\\Newscoop\\GimmeBundle\\Entity\\PublicApiResource')->findAll() as $resource) {
$existingResources[$resource->getResource()] = $resource->getResource();
}
$form = $this->createForm(new PublicResourcesType(), null, array('choices' => $apiRoutes, 'data' => $existingResources, 'action' => $this->generateUrl('configure_api'), 'method' => 'POST'));
return $form;
}