Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions Controller/JsloaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* This controller includes the correct twig file to bootstrap the javascript
Expand Down Expand Up @@ -43,6 +44,26 @@ class JsloaderController
*/
private $plainTextTypes;

/**
* @var array
*/
private $createRoutesForTypes;

/**
* @var array locales of the application
*/
private $locales;

/**
* @var string content prefix in the repository path, like /cms/content
*/
private $contentPrefix;

/**
* @var string routes prefix in the repository path, like /cms/routes
*/
private $routesPrefix;


/**
* Create the Controller
Expand All @@ -52,32 +73,48 @@ class JsloaderController
* @param string $imageClass used to determine whether image upload should be activated
* @param Boolean $fixedToolbar whether the hallo toolbar is fixed or floating
* @param array $plainTextTypes RDFa types to edit in raw text only
* @param string $requiredRole
* @param array $createRoutesForTypes types for which it is needed to create a route
* @param string $requiredRole the role name for the security check
* @param SecurityContextInterface $securityContext
* @param array $locales the locales of the application
* @param string $contentPrefix content prefix in the repository path
* @param string $routesPrefix routes prefix in the repository path
*/
public function __construct(
ViewHandlerInterface $viewHandler,
$stanbolUrl,
$imageClass,
$fixedToolbar = true,
$plainTextTypes = array(),
array $plainTextTypes = array(),
array $createRoutesForTypes = array(),
$requiredRole = "IS_AUTHENTICATED_ANONYMOUSLY",
SecurityContextInterface $securityContext = null
SecurityContextInterface $securityContext = null,
array $locales,
$contentPrefix,
$routesPrefix
) {
$this->viewHandler = $viewHandler;
$this->stanbolUrl = $stanbolUrl;
$this->imageClass = $imageClass;
$this->fixedToolbar = $fixedToolbar;
$this->plainTextTypes = $plainTextTypes;

$this->createRoutesForTypes = $createRoutesForTypes;
$this->requiredRole = $requiredRole;
$this->securityContext = $securityContext;
$this->locales = $locales;
$this->contentPrefix = $contentPrefix;
$this->routesPrefix = $routesPrefix;
}

/**
* Render js inclusion for create.js and dependencies and bootstrap code.
*
* The hallo editor is bundled with create.js and available automatically.
<<<<<<< HEAD
* To use aloha, you need to download the zip, as explained in step 8 of
* the README.
=======
>>>>>>> master
*
* When using hallo, the controller can include the compiled js files from
* hallo's examples folder or use the assetic coffee filter.
Expand All @@ -101,11 +138,17 @@ public function includeJSFilesAction($editor = 'hallo')

$view->setTemplate(sprintf('SymfonyCmfCreateBundle::includejsfiles-%s.html.twig', $editor));



$view->setData(array(
'cmfCreateStanbolUrl' => $this->stanbolUrl,
'cmfCreateImageUploadEnabled' => (boolean) $this->imageClass,
'cmfCreateHalloFixedToolbar' => (boolean) $this->fixedToolbar,
'cmfCreateHalloPlainTextTypes' => json_encode($this->plainTextTypes)
'cmfCreateHalloPlainTextTypes' => json_encode($this->plainTextTypes),
'cmfCreateCreateRoutesTypes' => json_encode($this->createRoutesForTypes),
'cmfCreateLocales' => json_encode($this->locales),
'cmfCreateContentPrefix' => $this->contentPrefix,
'cmfCreateRoutesPrefix' => $this->routesPrefix
)
);

Expand Down
10 changes: 8 additions & 2 deletions Controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ public function postDocumentAction(Request $request)
$this->performSecurityChecks();

$rdfType = trim($request->request->get('@type'), '<>');

$type = $this->typeFactory->getTypeByRdf($rdfType);

$result = $this->restHandler->run($request->request->all(), $type, null, RestService::HTTP_POST);
$result = null;
try {
$result = $this->restHandler->run($request->request->all(), $type, null, RestService::HTTP_POST);
} catch (\Exception $e) {
return Response::create("The document '$rdfType' could not be created: " . $e->getMessage(), 500);
}

if (!is_null($result)) {
$view = View::create($result)->setFormat('json');
return $this->viewHandler->handle($view, $request);
}

return Response::create('The document could not be created', 500);
return Response::create("The document '$rdfType' could not be created", 500);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function getConfigTreeBuilder()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->arrayNode('rdfmapper')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->scalarNode('role')->defaultValue('IS_AUTHENTICATED_ANONYMOUSLY')->end()
->arrayNode('image')
->canBeUnset()
Expand All @@ -43,6 +47,10 @@ public function getConfigTreeBuilder()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->arrayNode('create_routes_types')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->arrayNode('rdf_config_dirs')
->useAttributeAsKey('dir')
->prototype('scalar')->end()
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/SymfonyCmfCreateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function load(array $configs, ContainerBuilder $container)

$container->setParameter($this->getAlias().'.map', $config['map']);

$container->setParameter($this->getAlias().'.rdfmapper', $config['rdfmapper']);

$container->setParameter($this->getAlias().'.stanbol_url', $config['stanbol_url']);

$container->setParameter($this->getAlias().'.role', $config['role']);
Expand All @@ -52,6 +54,8 @@ public function load(array $configs, ContainerBuilder $container)
}
$container->setParameter($this->getAlias().'.plain_text_types', $config['plain_text_types']);

$container->setParameter($this->getAlias().'.create_routes_types', $config['create_routes_types']);

if ($config['auto_mapping']) {
foreach ($container->getParameter('kernel.bundles') as $class) {
$bundle = new \ReflectionClass($class);
Expand Down
33 changes: 33 additions & 0 deletions Mapper/RouteDoctrinePhpcrOdmMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Symfony\Cmf\Bundle\CreateBundle\Mapper;

use Midgard\CreatePHP\Mapper\DoctrinePhpcrOdmMapper;

use Midgard\CreatePHP\Entity\PropertyInterface;

use Symfony\Cmf\Bundle\RoutingExtraBundle\Document\Route;

/**
* Mapper to handle route documents stored in PHPCR-ODM.
*/
class RouteDoctrinePhpcrOdmMapper extends DoctrinePhpcrOdmMapper
{
public function setPropertyValue($object, PropertyInterface $property, $value)
{
if ($object instanceof Route && $property->getIdentifier() === 'locale') {
$object->setDefault('_locale', $value);
$object->setRequirement('_locale', $value);
return $object;
}
return parent::setPropertyValue($object, $property, $value);
}

public function getPropertyValue($object, PropertyInterface $property)
{
if ($object instanceof Route && $property->getIdentifier() === 'locale') {
return $object->getDefault('_locale');
}
return parent::getPropertyValue($object, $property);
}
}
64 changes: 64 additions & 0 deletions Metadata/ContainerRdfTypeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Symfony\Cmf\Bundle\CreateBundle\Metadata;

use Midgard\CreatePHP\RdfMapperInterface;
use Midgard\CreatePHP\Type\TypeInterface;

use Midgard\CreatePHP\Metadata\RdfTypeFactory;

use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Midgard\CreatePHP\Metadata\RdfDriverInterface;

/**
* Factory for createphp types based on class names. If available, the mappers
* for the requested class are loaded from the Symfony service container.
*/
class ContainerRdfTypeFactory extends RdfTypeFactory implements ContainerAwareInterface
{
/**
* @var array service names of the mappers per type
*/
private $mapperServices;

/**
* @var ContainerInterface
*/
protected $container;

/**
* @param RdfMapperInterface $defaultMapper the default mapper to use if there is no specific one
* @param RdfDriverInterface $driver the driver to load types from
* @param array $mapperServices rdf mappers service names per type
*/
public function __construct(RdfMapperInterface $defaultMapper, RdfDriverInterface $driver, array $mapperServices = array())
{
$this->mapperServices = $mapperServices;
parent::__construct($defaultMapper, $driver);
}

/**
* Get the mapper for type $name in the $symfony container, or the defaultMapper if there is no specific one
*
* @param string $name the type name for which to get the mapper
*
* @return RdfMapperInterface
*/
protected function getMapper($name)
{
if (isset($this->mapperServices[$name])) {
return $this->container->get($this->mapperServices[$name]);
}

return parent::getMapper($name);
}

/**
* @see ContainerAwareInterface::setContainer()
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
7 changes: 7 additions & 0 deletions Resources/config/phpcr_odm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<parameters>
<parameter key="symfony_cmf_create.phpcr_odm_mapper_class">Midgard\CreatePHP\Mapper\DoctrinePhpcrOdmMapper</parameter>
<parameter key="symfony_cmf_create.route_doctrine_phpcr_odm_mapper_class">Symfony\Cmf\Bundle\CreateBundle\Mapper\RouteDoctrinePhpcrOdmMapper</parameter>
</parameters>

<services>
Expand All @@ -16,5 +17,11 @@
<argument>null</argument>
</service>

<service id="symfony_cmf_create.route_doctrine_phpcr_odm_mapper" class="%symfony_cmf_create.route_doctrine_phpcr_odm_mapper_class%" public="true">
<argument>%symfony_cmf_create.map%</argument>
<argument type="service" id="doctrine_phpcr"/>
<argument>null</argument>
</service>

</services>
</container>
16 changes: 12 additions & 4 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<parameter key="symfony_cmf_create.jsloader.controller.class">Symfony\Cmf\Bundle\CreateBundle\Controller\JsloaderController</parameter>
<parameter key="symfony_cmf_create.rest.controller.class">Symfony\Cmf\Bundle\CreateBundle\Controller\RestController</parameter>
<parameter key="symfony_cmf_create.rdf_type_factory_class">Midgard\CreatePHP\Metadata\RdfTypeFactory</parameter>
<parameter key="symfony_cmf_create.container_rdf_type_factory_class">Symfony\Cmf\Bundle\CreateBundle\Metadata\ContainerRdfTypeFactory</parameter>
<parameter key="symfony_cmf_create.rest.handler_class">Midgard\CreatePHP\RestService</parameter>
</parameters>

Expand All @@ -18,32 +19,39 @@
<argument>%symfony_cmf_create.image.model_class%</argument>
<argument>%symfony_cmf_create.fixed_toolbar%</argument>
<argument>%symfony_cmf_create.plain_text_types%</argument>
<argument>%symfony_cmf_create.create_routes_types%</argument>
<argument>%symfony_cmf_create.role%</argument>
<argument type="service" id="security.context" on-invalid="ignore"/>
<argument>%locales%</argument>
<argument>%symfony_cmf_content.content_basepath%</argument>
<argument>%symfony_cmf_routing_extra.routing_repositoryroot%</argument>
</service>

<service id="symfony_cmf_create.rest.controller" class="%symfony_cmf_create.rest.controller.class%">
<argument type="service" id="fos_rest.view_handler"/>
<argument type="service" id="symfony_cmf_create.object_mapper"/>
<argument type="service" id="symfony_cmf_create.rdf_type_factory"/>
<argument type="service" id="symfony_cmf_create.container_rdf_type_factory"/>
<argument type="service" id="symfony_cmf_create.rest.handler"/>
<argument>%symfony_cmf_create.role%</argument>
<argument type="service" id="security.context" on-invalid="ignore"/>
</service>

<service id="symfony_cmf_create.twig_extension" class="Midgard\CreatePHP\Extension\Twig\CreatephpExtension">
<argument type="service" id="symfony_cmf_create.rdf_type_factory"/>
<argument type="service" id="symfony_cmf_create.container_rdf_type_factory"/>
<tag name="twig.extension"/>
</service>

<service id="symfony_cmf_create.rdf_driver" class="Midgard\CreatePHP\Metadata\RdfDriverXml">
<argument>%symfony_cmf_create.rdf_config_dirs%</argument>
</service>

<service id="symfony_cmf_create.rdf_type_factory" class="%symfony_cmf_create.rdf_type_factory_class%" public="true">
<service id="symfony_cmf_create.container_rdf_type_factory" class="%symfony_cmf_create.container_rdf_type_factory_class%" public="true">
<argument type="service" id="symfony_cmf_create.object_mapper"/>
<argument type="service" id="symfony_cmf_create.rdf_driver"/>
<argument>%symfony_cmf_create.map%</argument>
<argument>%symfony_cmf_create.rdfmapper%</argument>
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>

<service id="symfony_cmf_create.rest.handler" class="%symfony_cmf_create.rest.handler_class%" public="true">
Expand Down
Loading