Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions Controller/JsloaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class JsloaderController
*/
private $plainTextTypes;

/**
* @var Boolean
*/
private $createRoutes;


/**
* Create the Controller
Expand All @@ -62,6 +67,7 @@ class JsloaderController
* @param Boolean $useCoffee whether assetic is set up to use coffee script
* @param Boolean $fixedToolbar whether the hallo toolbar is fixed or floating
* @param array $plainTextTypes RDFa types to edit in raw text only
* @param Boolean $createRoutes whether the routes need to be created after content creation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should make this a list of rdf types for which to create routes, defaulting to empty array.

if i create a new simplecms document or a new block, i don't need a route for that...

* @param string $requiredRole
* @param SecurityContextInterface $securityContext
*/
Expand All @@ -72,6 +78,7 @@ public function __construct(
$useCoffee = false,
$fixedToolbar = true,
$plainTextTypes = array(),
$createRoutes = false,
$requiredRole = "IS_AUTHENTICATED_ANONYMOUSLY",
SecurityContextInterface $securityContext = null
) {
Expand All @@ -81,7 +88,7 @@ public function __construct(
$this->coffee = $useCoffee;
$this->fixedToolbar = $fixedToolbar;
$this->plainTextTypes = $plainTextTypes;

$this->createRoutes = $createRoutes;
$this->requiredRole = $requiredRole;
$this->securityContext = $securityContext;
}
Expand Down Expand Up @@ -124,7 +131,8 @@ public function includeJSFilesAction($editor = 'hallo')
'cmfCreateStanbolUrl' => $this->stanbolUrl,
'cmfCreateImageUploadEnabled' => (boolean) $this->imageClass,
'cmfCreateHalloFixedToolbar' => (boolean) $this->fixedToolbar,
'cmfCreateHalloPlainTextTypes' => json_encode($this->plainTextTypes))
'cmfCreateHalloPlainTextTypes' => json_encode($this->plainTextTypes),
'cmfCreateCreateRoutes' => (boolean) $this->createRoutes)
);

return $this->viewHandler->handle($view);
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function getConfigTreeBuilder()
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->scalarNode('create_routes')->defaultFalse()->end()
->arrayNode('rdf_config_dirs')
->useAttributeAsKey('dir')
->prototype('scalar')->end()
Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/SymfonyCmfCreateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,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', $config['create_routes']);

if ($config['auto_mapping']) {
foreach ($container->getParameter('kernel.bundles') as $class) {
$bundle = new \ReflectionClass($class);
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<argument>%symfony_cmf_create.use_coffee%</argument>
<argument>%symfony_cmf_create.fixed_toolbar%</argument>
<argument>%symfony_cmf_create.plain_text_types%</argument>
<argument>%symfony_cmf_create.create_routes%</argument>
<argument>%symfony_cmf_create.role%</argument>
<argument type="service" id="security.context" on-invalid="ignore"/>
</service>
Expand Down
61 changes: 61 additions & 0 deletions Resources/public/js/create-routes-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
jQuery(document).ready(function() {

(function(){

var needRouteCreation = false; //internal trigger for savedentity event

//an entity has been saved and the response of the backend received
$('body').bind('midgardstoragesavedentity', function (event, options) {

//create the routes only when new content has been saved
if (!needRouteCreation || options.entity.id.indexOf(cmfCreateRoutesPrefix, 1) == 1) {
return;
}

var vie = options.entity.vie;

/**
* Common request content
*/
var trimmedSubject = options.entity.id.substr(1, options.entity.id.length - 2);
var lastSlashPos = trimmedSubject.lastIndexOf("/") + 1;
var contentName = trimmedSubject.substr(lastSlashPos, trimmedSubject.length - lastSlashPos);
var partOf = options.entity.attributes["<http://purl.org/dc/terms/partOf>"].models[0]["@subject"];
var trimmedPartOf = partOf.substr(1, partOf.length - 2); // "/cms/content/news"
var lastSlashPos = trimmedPartOf.lastIndexOf("/") + 1;
var parentName = trimmedPartOf.substr(lastSlashPos, trimmedPartOf.length - lastSlashPos);

/**
* Request types
*/
var parentType = "<" + cmfCreateRouteRdfType + "/Parent" + ">";
var nameType = "<" + cmfCreateRouteRdfType + "/Name" + ">";
var routeContentType = "<" + cmfCreateRouteRdfType + "/RouteContent" + ">";
var localeType = "<" + cmfCreateRouteRdfType + "/Locale" + ">";
var partOfType = "<http://purl.org/dc/terms/partOf>";

for(var i in cmfCreateLocales) {
var parentPath = cmfCreateRoutesPrefix + "/" + cmfCreateLocales[i] + "/" + parentName;

var routeRequest = {};
routeRequest["@type"] = "<" + cmfCreateRouteRdfType + ">";
routeRequest[nameType] = contentName;
routeRequest[routeContentType] = trimmedSubject;
routeRequest[partOfType] = [parentPath];
routeRequest[localeType] = cmfCreateLocales[i];
routeRequest[parentType] = parentPath;

var routeEntity = new vie.Entity();
routeEntity.set(routeRequest);
vie.entities.add(routeEntity);
jQuery('body').midgardStorage('saveRemote', routeEntity, options);
}
});

//an entity will be saved and sent to the backend
$('body').bind('midgardstoragesaveentity', function (event, options) {
//TODO: handle the case where new content and updated content is saved at the same time
needRouteCreation = options.entity.isNew();
});
})()
});
19 changes: 18 additions & 1 deletion Resources/views/includejsfiles-create.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
var cmfCreateHalloParentElement = 'body';
{% endif %}
var cmfCreateHalloPlainTextTypes = {{ cmfCreateHalloPlainTextTypes|raw }};

{% if cmfCreateCreateRoutes %}
//TODO: get all these parameters from the config
var cmfCreateLocales = ['en', 'fr', 'de'];
var cmfCreateContentPrefix = '/cms/content';
var cmfCreateRoutesPrefix = '/cms/routes';
var cmfCreateRouteRdfType = "http://cmf.symfony.com/CmfRoute";
{% endif %}

</script>

{% javascripts output="js/create.js"
Expand All @@ -37,6 +46,14 @@
<script src="{{ asset_url }}"></script>
{% endjavascripts %}

{% if cmfCreateCreateRoutes %}
{% javascripts output="js/create.js"
'@SymfonyCmfCreateBundle/Resources/public/js/create-routes-handler.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endif %}

{#
to develop create use this instead of create-min
'@SymfonyCmfCreateBundle/Resources/public/vendor/create/src/*.js'
Expand All @@ -61,4 +78,4 @@ and set up assetic to handle coffee script files
'@SymfonyCmfCreateBundle/Resources/public/js/init-vie-hallo.js'
'@SymfonyCmfCreateBundle/Resources/public/vendor/hallo/hallo.coffee'
'@SymfonyCmfCreateBundle/Resources/public/vendor/hallo/plugins/*.coffee'
#}
#}