-
Notifications
You must be signed in to change notification settings - Fork 31
[WIP] Create routes from the front end #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
97ddd4a
bf1da4a
7cb10a0
c3bfd15
96c7324
3dfb241
59aa2c5
3ca8690
544d7e0
b154d18
34115e0
d436362
2468b8a
4fdffc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| namespace Symfony\Cmf\Bundle\CreateBundle\Document; | ||
|
|
||
| use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; | ||
|
|
||
| use Symfony\Cmf\Bundle\RoutingExtraBundle\Document\Route; | ||
|
|
||
| /** | ||
| * @PHPCRODM\Document | ||
| */ | ||
| class CmfRoute extends Route | ||
|
||
| { | ||
| /** | ||
| * Set the _locale requirement and the default _locale | ||
| * @param array $locale | ||
| */ | ||
| public function setLocale($locale) { | ||
|
||
| parent::setDefault('_locale', $locale); | ||
| parent::setRequirement('_locale', $locale); | ||
| } | ||
|
|
||
| /** | ||
| * Get the default _locale for this route | ||
| * @return string | ||
| */ | ||
| public function getLocale() { | ||
| return parent::getDefault('_locale'); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| jQuery(document).ready(function() { | ||
|
|
||
| (function(){ | ||
|
|
||
| var createRouteForTypes = []; //types currently needing a route creation | ||
|
|
||
| //an entity has been saved and the response of the backend received | ||
| $('body').bind('midgardstoragesavedentity', function (event, options) { | ||
|
|
||
| var createdType = options.entity.attributes["@type"]; | ||
| //remove the enclosing <> | ||
| createdType = createdType.substring(1, createdType.length - 1); | ||
|
|
||
| if (!$.inArray(createdType, createRouteForTypes)) { | ||
| return; | ||
| } | ||
| //reset the types for which route creation is currently needed | ||
| createRouteForTypes.splice($.inArray(createdType, createRouteForTypes),1); | ||
|
|
||
| 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) { | ||
| if (options.entity.isNew() && | ||
| $.inArray(options.entity.attributes['@type'], cmfCreateCreateRoutesTypes)) { | ||
| createRouteForTypes.push(options.entity.attributes['@type']); | ||
| } | ||
| }); | ||
| })() | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <type | ||
| xmlns:dcterms="http://purl.org/dc/terms/" | ||
| xmlns:cmf="http://cmf.symfony.com/" | ||
| xmlns:route="http://cmf.symfony.com/CmfRoute/" | ||
| xmlns:skos="http://www.w3.org/2004/02/skos/core#" | ||
| typeof="cmf:CmfRoute" | ||
| itemtype="http://cmf.symfony.com/CmfRoute" | ||
| > | ||
| <rev>dcterms:partOf</rev> | ||
| <children> | ||
| <property property="route:Parent" identifier="parent"> | ||
| <config key="doctrine:reference" value=""/> | ||
| </property> | ||
| <property property="route:RouteContent" identifier="routeContent"> | ||
| <config key="doctrine:reference" value=""/> | ||
| </property> | ||
| <property property="route:Name" identifier="name" /> | ||
| <property property="route:Locale" identifier="locale" /> | ||
| </children> | ||
| </type> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer you inject the parameters explicitly .. if you want you can inject them all as an array