Architecture of CMS on Top Symfony CMF - symfony-cmf

Im building a very custom CMS on top of Symfony CMF Components/Bundles. I read almost everything i could about the CMF Components/Bundles and i have the "architecture" kinda defined. Im experienced/familiarized with Symfony2 components.
The CMS should provide a way to manage multiple sites.
A Site contains Pages.
A Page, requires a title and may have content. A page can also have blocks associated(Those already provided by the Block Bundle, and others with custom functionality developed by me for the CMS).
For now i defined two Documents(Site and Page).
Based on the application requirements im using the CoreBundle, BlockBundle, RoutingBundle, DoctrinePHPCRBundle, and DoctrinePHPCRAdminBundle.
Based on this requirements the expected Repository Tree should be something like:
/sites
/site1 ( nodename of the Site Document )
/pages ( all pages of this site )
/page1 ( nodename of a Page Document )
/page2
/routes ( all routes of this site )
/site2
/pages
...
The configurations for CoreBundle:
cmf_core:
persistence:
phpcr:
basepath: /sites
enabled: true
Because i need nodes(/pages, /routes) for each site, how can i initialize them? My first idea was onPostPersist event of a Site document i initialize the required nodes.
use PHPCR\Util\NodeHelper;
...
public function initSiteNodes(ManagerRegistry $registry, Site $site)
{
$session = $registry->getConnection();
NodeHelper::createPath($session, $site->getId()./pages);
NodeHelper::createPath($session, $site->getId()./routes);
$session->save();
}
So my questions are:
Is this architecture feasible and is SonataAdminBundle prepared for such a structure?

Great to hear you are building a custom CMS on top of the CMF. This is one of the main intended use cases for it.
For your usecase, one important thing to note is that the route base paths can be an array of paths. If you know the sites that will exist, you can simply configure base paths for all of them.
If they can be dynamically created, you will need some more work. You could check if the expression language can help you, or write a symfony request listener that comes very early and sets the right base path on the cmf_routing.phpcr_candidates_prefix service.
The sonata phpcr-odm admin was not really optimized for multisite use cases. However, with the help of the permission system, you should be able to control who may see what.
You could also write to the symfony-cmf-users mailing list. A couple of people did multisite projects with the CMF and might have additional ideas or inputs. And feel free to open pull requests or issues on the corresponding CMF repositories if you see things that could be improved.

Related

How decides Typo3 Neos which Settings.yaml to choose?

i use one Neos installation for multiple domains with different content.
duplicating the package TYPO3.NeosDemoTypo3Org, removing the node-identifier and doing some replacements brought me nearby everything i need.
But only the first Settings.yaml found in Packages/Sites/ seems to be parsed. All changes to the Settings.yaml found in other packages (Test1 and Test2 in the following example) are ignored.
Packages/Sites/TYPO3.NeosDemoTypo3Org/Configuration/Settings.yaml
TYPO3:
Form:
yamlPersistenceManager:
savePath: 'resource://TYPO3.NeosDemoTypo3Org/Private/Form/'
Packages/Sites/UDF.Test1/Configuration/Settings.yaml
TYPO3:
Form:
yamlPersistenceManager:
savePath: 'resource://UDF.Test1/Private/Form/'
Packages/Sites/UDF.Test2/Configuration/Settings.yaml
TYPO3:
Form:
yamlPersistenceManager:
savePath: 'resource://UDF.Test2/Private/Form/'
When i delete the first Settings.yaml (Packages/Sites/UDF.Test2/Configuration/Settings.yaml), the next Setting.yaml in alphabetical order (Packages/Sites/UDF.Test1/Configuration/Settings.yaml) is used for all 3 site packages. When i also delete this file, the Settings.yaml from UDF.Test2 is used and so on.
would be awesome if somebody can enlighten me. I am new to flow and neos and any help is welcome. RTFM, i know, but as described here i have to believe, that it should work like i did?
alternative way?
is it possible not to set the savePath in the site package configuration but in the common settings ./Packages/Application/TYPO3.Form/Configuration/Settings.yaml
I see a {#package} placeholder in
### BASE ELEMENTS ###
# NAMING: base class for everything is RENDERABLE
'TYPO3.Form:Base':
renderingOptions:
templatePathPattern: 'resource://{#package}/Private/Form/{#type}.html'
but this doesn't work here
TYPO3:
Form:
yamlPersistenceManager:
#savePath: '%FLOW_PATH_DATA%Forms/'
savePath: 'resource://{#package}/Private/Form/'
as you see i am not really experienced with this stuff but i am very motivated.
All Settings.yaml are used, but the settings are merged in order of the package loading.
The loading order of packages again is based on their dependencies.
All three packages probably have the same dependencies so they are loaded one after the other (would need to check with which ordering), so third Settings.yaml is loaded, then second Settings.yaml is loaded and overwrites the third, then the first is loaded and again overwrites the second. Every setting path can only be set once, that's why.
In any case what you are trying to archive probably won't work. This is one of the things we have to fix (site package dependent configuration).
A possible workaround is either using a common package with the form configuration and just set the savePath to this package or using diferent subcontexts (like Production/Domain1 Production/Domain2) and setting this setting different per subcontext, then you could define the subcontext by domain (as the sites are triggered by domain anyway).

How can I move multiple Pylons Applications into a single Composite Application?

We have several single Pylon websites running but would like to make these more easily reusable.
There is a concept of a "Composite Application" inside pylons, but there seems to be limited instructions on how to achieve this.
Has anyone done this or is aware of a good tutorial on "How to convert multiple pylons apps into a composite app?" ?
I've tried - perhaps too optimistically - to simply copy an existing app into another app and fiddle with the development.ini file, but this does not seem to work. (I'm getting the error "pkg_resources.DistributionNotFound: wiki" in that case)
Thanks
This is done by modifying the WSGI pipeline to dispatch a request to different applications based on request properties (usually URL). The simplest way to modify the pipeline is by PasteDeploy (the package that controls your INI files).
[composite:main]
use = egg:Paste#urlmap
/foo = foo
/bar = bar
/ = baz
[app:foo]
use = myapp#main
[app:bar]
use = yourapp#main
[app:baz]
use = myapp#baz
This creates a composite application that dispatches to different endpoints based on the URL prefix.

grails - subdomain based projects and links

I am trying to develop a grails application that has "root" content (www.mydomain.com/about for example) but will also support "projects" based upon the subdomain of the request; for example myproject.mydomain.com > www.mydomain.com/myproject. As a first pass, i have the URL configuration below:
"/$controller/$action?/$id?" {
...
}
"/$project/$controller/$action?/$id?" {
constraints {
}
}
The main drawback so far is that the $project variable must be injected manually into every link (tedious and not DRY):
<g:link controller="foo" action="bar" params="${[project: params.project]}">link</g:link>
Is there a way to automatically inject the $project parameter into all links if it is present, or is there a better way to approach this problem?
Basically you can create a grails plugin that will inject into the controller a new project param with a value based on a custom TagLib <g:project bean="myproject"/> (for instance)
It will force you to define this tagLib on each gsp page of your project but it is still DRYer than each link.
Hope it helps,
Fabien.
I can think of a couple of things.
a) You can place a proxy (Apache or something else) in front of your app-server and do some url-rewriting. Bonus: This would also allow you to do some caching of static resources.
b) This solution is a little more technically interesting. You can look up the project based on the http host header (the subdomain part). This will save you from rewriting all urls, all Grails conventions will still apply so you shouldn't run into any problems with third party plugins and so on.

Scaffolding Web Services in Grails

I need to implement a web app, but instead of using relational database I need to use different SOAP Web Services as a back-end. An important part of application only calls web services and displays the result. Since Web Services are clearly defined in form of Operation: In parameters and Return Type it seems to me that basic GUI could be easily constructed just like in the case of scaffolding based on Domain Entities.
For example in case of SearchProducts web service operation I need to enter search parameters as input, so the search page can be constructed. Operation will return a list of products, so I need a page that will display this list in some kind of table.
Is there already some library in grails that let you achieve this. If not, how would you go about creating one?
Probably the easiest approach is to use wsimport on the WSDL files to generate the client-side stubs. Then you can call methods in the stubs from Groovy just as you would have called them from Java.
For example, consider the WSDL file for Microsoft's TerraServer, located at http://terraservice.net/TerraService.asmx?wsdl . Then you run something like
wsimport -d src -keep http://terraservice.net/TerraService.asmx?WSDL
which puts all the compiled stubs in the src directory. Then you can write Groovy code like
import com.terraserver_usa.terraserver.*;
TerraServiceSoap sei = new TerraService().getTerraServiceSoap()
Place home = new Place(city:'Boston',state:'MA',country:'US')
def pt = sei.convertPlaceToLonLatPt(home)
println "$pt.lat, $pt.lon"
assert Math.abs(pt.lat - 42.360000) < 0.001
assert Math.abs(pt.lon - -71.05000) < 0.001
If you want to access a lot of web services, generate the stubs for all of them. Or you can use dynamic proxies instead.
The bottom line, though, is to let Java do what it already does well, and use Groovy where it makes your life easier.
You should be able to use XFire or CXF Plugins. For automatic scaffolding, modify your Controller.groovy template in scaffolding templates so it auto-generates methods you need.

Multiple languages in an ASP.NET MVC application?

What is the best way to support multiple languages for the interface in an ASP.NET MVC application? I've seen people use resource files for other applications. Is this still the best way?
If you're using the default view engines, then local resources work in the views. However, if you need to grab resource strings within a controller action, you can't get local resources, and have to use global resources.
This makes sense when you think about it because local resources are local to an aspx page and in the controller, you haven't even selected your view.
I found this resource to be very helpful
Its a wrapper round the HttpContext.Current.GetGlobalResourceString and HttpContext.Current.GetLocalResourceString that allows you to call the resources like this...
// default global resource
Html.Resource("GlobalResource, ResourceName")
// global resource with optional arguments for formatting
Html.Resource("GlobalResource, ResourceName", "foo", "bar")
// default local resource
Html.Resource("ResourceName")
// local resource with optional arguments for formatting
Html.Resource("ResourceName", "foo", "bar")
The only problem I found is that controllers don't have access to local resouce strings.
Yes resources are still the best way to support multiple languages in the .NET environment. Because they are easy to reference and even easier to add new languages.
Site.resx
Site.en.resx
Site.en-US.resx
Site.fr.resx
etc...
So you are right still use the resource files.
The Orchard project uses a shortcut method called "T" to do all in-page string translations. So you'll see tags with a #T("A String to Translate").
I intend to look at how this is implemented behind the scenes and potentially use it in future projects. The short name keeps the code cleaner since it will be used a lot.
What I like about this approach is the original string (english, in this case) is still easily visible in the code, and doesnt require a lookup in a resource tool or some other location to decode what the actual string should be here.
See http://orchardproject.net for more info.
Some of the other solutions mentioned as answer do not work for the released version of MVC (they worked with previous versions of alpha/beta).
Here is a good article describing a way to implement localization that will be strongly-typed and will not break the unit testing of controllers and views: localization guide for MVC v1
This is another option, and you'll have access to the CurrentUICulture in the controller:
Check MVC3-multi-language

Resources