![]() |
|
ahAdminGeneratorThemesPlugin - 1.0.1The `ahAdminGeneratorThemesPlugin` is a symfony plugin that provides two symfony admin generator themes with additional features. |
|
![]() |
10
users
Sign-in
to change your status |
The |
The ahAdminGeneratorThemesPlugin is a symfony plugin that provides two symfony admin generator themes with additional features.
| Name | Status | |
|---|---|---|
|
|
lead | ed.ngisedpasa <<ta>> ofni |
Copyright (c) 2010 asaphosting (Daniel Lohse)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.0.1stable | MIT license | 1.0.0stable | 09/11/2010 |
| 1.0.0stable | MIT license | 1.0.0stable | 19/07/2010 |
| 0.8.3beta | MIT license | 0.8.0beta | 25/03/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.1stable | MIT license | 1.0.0stable | 09/11/2010 |
| 1.0.0stable | MIT license | 1.0.0stable | 19/07/2010 |
| 0.8.3beta | MIT license | 0.8.0beta | 25/03/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.1stable | MIT license | 1.0.0stable | 09/11/2010 |
| 1.0.0stable | MIT license | 1.0.0stable | 19/07/2010 |
| 0.8.3beta | MIT license | 0.8.0beta | 25/03/2010 |
bugfix: sorting on virtual columns (and partials for that matter) did not work!
bugfix only in ahAdminGeneratorThemesPluginAdmin: merged in security-related bugfix from symfony Core team (sorting)
and finally: version 1.0!!! :)
Initial release.
The ahAdminGeneratorThemesPlugin is a symfony plugin that provides two symfony admin generator themes with additional features.
A big thanks goes out to Francois Zaninotto who provided the Propel implementation of this. I simply ported it to Doctrine. :)
Install the plugin (via a package)
symfony plugin:install ahAdminGeneratorThemesPlugin
Install the plugin (via a Subversion checkout)
svn co http://svn.symfony-project.com/plugins/ahAdminGeneratorThemesPlugin/trunk plugins/ahAdminGeneratorThemesPlugin
Install the plugin (via a Git clone)
git clone git://github.com/annismckenzie/ahAdminGeneratorThemesPlugin
Activate the plugin in config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins(array( 'sfDoctrinePlugin', 'ahAdminGeneratorThemesPlugin', '...' )); } }
To enable a theme, edit your generator.yml and change the theme property from admin to ahAdmin (or ahAdminGeneratorThemesPluginAdmin), as follows:
generator:
class: sfDoctrineGenerator
param:
model_class: Book
theme: ahAdmin # or: ahAdminGeneratorThemesPluginAdmin
non_verbose_templates: true
with_show: false
singular: Book
plural: Books
route_prefix: book
with_doctrine_route: true
actions_base_class: sfActionsClear your cache
symfony cc
You can now use the additional features listed below.
The new theme provides an easy way to make virtual columns sortable in the list view. Just declare the corresponding fields with is_sortable to true, and the generated module will look for an orderByXXX() method in the generated query. For instance, to allow a book list to be sortable on the author name:
# in generator.yml
list:
display: [title, Author]
fields:
- Author: { is_sortable: true }
Then the generator will try to execute BookTable::orderByAuthor() whenever the user clicks on the Author header to sort on this column. The method must be implemented as follows:
class BookTable extends Doctrine_Table { public function orderByAuthor(Doctrine_Query $q, $direction = 'asc') { return $q->orderBy($q->getRootAlias().'.Author.Lastname '.$direction); } }
You can override the default sorting method name for a field by setting the sort_method parameter:
# in generator.yml
list:
display: [title, Author]
fields:
- Author: { is_sortable: true, sort_method: orderByAuthorLastName }
The generator will execute BookTable::orderByAuthorLastName() instead of BookTable::orderByAuthor() in that case.
And there you have it. Now it's possible to sort on any column, be that a virtual column or a partial. What you have to figure out for yourself is, especially for partials that display multiple columns, the sort column and the direction, so the sorting is meaningful for the user.
With the standard admin generator theme it's tedious to style the titles (list, new and edit) because they are hard-coded like this:
<h1>[List, New, Edit] Title</h1>
To mitigate this I wrapped this up in the module_header slot. All you need to do is add a partial "_module_header.php" with the following content:
<h1 class="whatever"><?php echo get_slot('module_header') ?></h1>
And include that partial in your layout like so:
<?php include_partial('module_or_global/module_header') ?>
Unfortunately, you'll need to do this even if you don't want to add CSS classes or other things to your headers but I think the advantages far outweigh the disadvantages. :)
I also recommend you install the tsTitlePlugin as it will make html <title> cascading possible like so: "AdminModule > Object".
This theme is not for the faint of heart. It needs the plugins ahToolkitPlugin and sfDoctrineGuardPlugin to work and you'll need to add a method to your myUser.class.php.
# in apps/frontend/lib/myUser.class.php class myUser extends sfGuardSecurityUser { public function getNextRedirect($remove = true) { return $remove ? $this->getAttributeHolder()->remove('next_redirect', '@homepage') : $this->getAttribute('next_redirect', '@homepage'); } public function setNextRedirect($route) { $this->setAttribute('next_redirect', $route); } }
Now, activate the ahCommon module in your settings.yml and add this to your layout:
<?php include_partial('ahCommon/flashes') ?>
This is to display the flash messages.
You'll also need to change the default class parameters from sfDoctrineGenerator to ahDoctrineGenerator like so:
generator: class: ahDoctrineGenerator ...
singular and plural generator.yml parametersSymfony's default admin generator theme the singular and plural have no real use which I changed. :) In your generator.yml you'll need to set those like so:
generator:
class: ahDoctrineGenerator
param:
...
singular: Book
plural: Books
...
You can even set those to be more than one word which crashes symfony's default admin generator. Like so:
generator:
class: ahDoctrineGenerator
param:
...
singular: Test Scenario
plural: Test Scenarios
...
Those will now be used in the view titles (if you don't change the default title in the list, new, or edit sections in the generator.yml).
Now, here comes another thing you'll need to do (you'll hate me for this, I think): you'll need to provide a quite extensive i18n file to go with this because the singular and plural form is also used to provide much better flash messages. Take a look into the messages.de.xml.sample file that comes with the plugin. All in all you'll need to provide at least 10 translations per module.
Phew, I might have forgotten something. But you can contact me, see the end of this README. :)
Activate the show view generation in the generator.yml:
generator:
class: sfDoctrineGenerator
param:
...
with_show: true
...
And configure it like so:
# in generator.yml show: display: [...]
This should be pretty self-explanatory:
# in generator.yml new: class: NewBookForm edit: class: EditBookForm
I can be reached via e-mail: info@asapdesign.de
If you find bugs, have questions and/or feature requests, you can post to the symfony-user mailing list, of which I am an avid follower. :)
