I'm developing a template system for webpages. A template consists of the following properties.
A name (part of the "template" class)
Sections (linked to the template class)
Fields (linked to a section)
It's pretty basic and it works when I got the template all setup in the database itself.
Now I want to create a template in my CMS application. To accomplish this I have rendered a pretty basic formtype form which has the name property of the template.
After the user has entered a name for the template, the user should be able to create sections and fields on the fly(directly from the rendered page itself). To spare me some time I want to ask you if it's possible to attach the sections and fields to the formtype dynamically so Doctrine can pick it up and persist the objects automatically without too much trouble.
What you are looking for is probably a combination of Form Events and Collection of Forms
Related
I am using Sonata Admin bundle in my Symfony app with doctrine. Now I am facing to some specific requirement whose solution or good/best practice I could not find anywhere.
To explain my issue I will use three simple entities as below.
So every news can have title and description different for every language.
Now what I need. In form view (detail) of news I want to:
have inputs of news attributes. (like code or created_date in this case)
then I want to see titles and descriptions for all languages related to current news. And in case, that news has not translation for some language, it means that there is no relation in News_Translation, I want to see empty inputs.
So everything in one view (maybe split it into more tabs). And here is a simple example of news detail (form view) for better understanding
Is it possible to attain something like this? I am open to any other ideas how to solve it using sonata-admin.
KunstmaanTranslatorBundle is a bundle which enables editing translations in the admin interface without need for editing the translations files. Translations will be stored in a (default) database and retrieved on the most efficient way possible.
KunstmaanTranslatorBundle
Doc
How to add a custom form to sulu CMS (example: complex contact form) and save values to database? Is there any good example? Documentation does not mention about custom development.
Regards,
As long as your forms are static (meaning the content manager is not able to choose which fields are appearing), you can simply do what is described in the Symfony documentation.
There are two (probably even more) different possibilities to include Symfony forms:
The first one is to create your own route and controller, working with Symfony forms as you would do in any other Symfony application.
The second one is to use the template system of Sulu as described in our documentation. Then you can add a few fields for content management around the form the content manager can use. In the template defined in the <view> tag of the XML you can again use Symfony form stuff. If you need any special information from the system you can even change the <controller> tag of the XML, to pass more than only the data from the content management.
There are also some ideas concerning a more sophisticated form manager floating around, but that's far from being published.
After hours of googling and experimenting, I gave up :(
I need to add form to my articles in Joomla 3, that collects data from article's additional fields and emails them. Articles are managed by Flexicontent. Flexicontent overrides standard content manager so I tried to make a plugin inside 'content' plugins (later I tried 'flexicontent' as well). Basing on articles:
http://docs.joomla.org/Adding_custom_fields_to_the_article_component
http://betweenbrain.com/notes/72-fun-with-joomla-forms
https://github.com/joomla/joomla-cms/blob/master/plugins/user/profile/profile.php#L168
which all override some kind of form (user, content or contact).
I made my plugin folder, plugin php file, plugin manifest (xml file) and xmls with form fields. Then in my php file I wrote onContentPrepareForm(), as instructed. However, when I checked "$this" variable in my flexiconent template, there were no signs of any form. How should I place this form in my template?
In my admin section i have a block maker.
The block is very simple, block_title, block_content.
What is the simplest way to show / determine a themes layout in the admin section so the user can position the blocks?
One idea is to use numbers so, 1 = block area one, 2 = block area two etc
A function in the front end could look like this:
function showBlocksForArea(1) {
// Return blocks Array where block_area=1
}
Rendered in the theme / template as:
echo'<div id="block_area_one">';
foreach($view->showBlocksForArea(1) as $row) {
echo '
<div class="block_wrap">
<div class="block_title">'.$row['block_title'].'</div>
<div class="block_body">'.$row['block_body'].'</div>
</div>
';
}
echo '</div>';
This is fine, accept the user doesn't know without looking at the theme where those areas are.
The Admin Section
Something like this would be perfect if i could grab just the HTML of the layout:
Is there a simpler way?
The following is an answer based on the chat that occurred here: https://chat.stackexchange.com/rooms/18020/room-for-xdaevax-and-codex
Here is my understanding of your goals:
You are creating a type of CMS application used to create websites
The websites are modular and will allow administrators to easily customize both the look and feel of their website and the content, without having extensive code knowledge
To facilitate this, you've created a system of templates, and content, that can be combined in various ways to create these themed pages. This is driven primarily by a set of PHP functions that extract the template and block data from the DB.
As new themes are created, the admin is able to "just work" without any modification because the functions can pull in any theme and it can be combined with any template.
The templates will have to have a naming structure that is generic so that CSS can be easily swapped out.
Given this information, I would suggets doing the following:
Database Schema
I would set up a database structure to something that resembles this schema I made:
The idea here is that a Template record can have any number of "slots". The DB is agnostic in terms of where the slots go on the page (this is the responsibility of the theme), but the TemplateSlots are used to provide "place holders" for where content (Blocks) can be placed.
Each time a user creates a new Page, a Page record is added and the page is associated with a Template, from which it also has information about the slots. The Template also defines a file (a PHP file most likely) that specifies place holders where the slots are placed. The Page gets the Theme information from the Site which it is associated with. Each Theme can have a set of ThemeContents (multiple CSS files, js files, images, etc....).
Blocks can be created that could have content assigned to them. These blocks are independent of a Template initially, and the DB could be pre-populated with common building 'blocks'. These blocks can be associated with a Template and assigned a TemplateSlot once a block is assigned to a Page by having a PageBlock record created.
DB Conclusion
This structure allows a great deal of flexibility and allows the Database to handle many potentially complex user scenarios. By segmenting the Template and Slots into separate tables, you can dynamically create templates of all shapes and sizes without having to make any code changes.
PHP Admin
For your admin, you can use whatever mechanism you like to pull the data out of the DB. But the user workflow would look something like this:
Log in to admin
Select Operation (a-> Create New, b-> Update Existing)
Select Page Template
Assign content blocks to template slots
Preview
Compile changes (a -> Save New Page, b-> Update Existing)
So i've added several some custom profile fields (administer -> profiles) which is all fine but completely useless if I can't store the information in a database. I've been searching for hours now trying to figure out the "best practices" way for doing this with very little luck.
Do I add the new columns to the Users table? Do I create a whole new table? I even found a vague reference that the core profile module should have added those columns for me anyway? And that you should be able to use CCK in the core profile module (but I don't have any options for that)?
And then I would obviously want to allow user to update their own fields but the the custom profile fields aren't included in the $form array...
PS arrrggg! Drupal is driving me around the bend with its inconsistencies and having to hack it all the time!
If you use the core profile module, the database storage is provided automatically and you will not need to modify anything in the database. On install, the module adds two tables to the database, profile_fields to store your custom field definitions and profile_values to store the user supplied data for those fields.
The fields are automatically added to the user edit forms, via the hook_user implementation in profile_user() - the same mechanism is used to add the values of those fields to the user object when that gets loaded.
So if those fields don't show up for you, something is fishy - have you added your fields with 'categories'? If so, they won't show on the standard user edit page, but on additional new pages (one per category). These are added as menu type MENU_LOCAL_TASK, so they should create new 'tab' entries at the top of the user edit page - maybe you have a theme that does not display the tabs?
Another thing to check would be the fields visibility settings chosen on the fields configuration form. If that is set to 'hidden', the field is only accessible for administrators and module/theme code. You should at least set it to 'private' if the user is supposed to edit it himself.
As for using CCK fields, I don't think that this is possible with the core profile module (maybe some extension module provides this). A different approach is taken by the Content Profile Module. It creates a custom node type for user profiles so that the profile values are stored as standard Drupal nodes. One advantage of this is that you can use all CCK fields for profiles, as you just need to add those to the created node type.