sfGenExtraPlugin
0.9.0beta
for sf 1.2 MIT
Several extra components to work with Symfony's generated forms.
3 way sort on admin generated forms:
In the standard admin forms, you can click on a column header in list view to sort the list by that field, a second click will reverse the order but after you sort by one field you cannot get rid of the sort other than sorting by another field.
If the original order was the primary key and you don't have it displayed in a column, you simply cannot get back to it.
This allows a third click on a column to remove all sorts.
Filter on a range of numbers instead of exact values:
By default, with strings and dates, you can filter on partial or a range of values, but with numbers, you are limited to exact values.
This allows you to filter on a range of numbers.
Validate a field against a constant value
The sfValidatorSchemaCompare class allows you to have validation comparing 2 fields, but does not allow comparing a field to a constant value.
The constantValidatorSchemaCompare class just allows you to do that.
Widget for the Symfony 1.0 style date and date range filter entry
Developers
License
Copyright (c) 2008 Jacques B. Philip
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.
sfGenExtraPlugin - Form and Generator Components
Author
Copyright (C) 2008 Jacques Philip.
License
MIT
Prerequisites
- Symfony 1.2 for generator components
- Symfony 1.1 for form components
Installation
Install plugin as usual from svn or command line.
Do not forget to enable the plugin in your main configuration file.
Components
3 way sort on admin generated forms:
In the standard admin forms, you can click on a column header in list view to sort the list by that field, a second click will reverse the order but after you sort by one field you cannot get rid of the sort other than sorting by another field.
If the original order was the primary key and you don't have it displayed in a column, you simply cannot get back to it.
This allows a third click on a column to remove all sorts.
This is accomplished through a listener and it can be disabled in the settings.yml file in 2 ways:
gen_extra_disable_3_way_sort: on
To disable the 3 way switch only
or
gen_extra_disable_pre_execute_listener: on
To disable the whole listener
Filter on a range of numbers instead of exact values:

By default, with strings and dates, you can filter on partial or a range of values, but with numbers, you are limited to exact values.
This allows you to filter on a range of numbers.
First you have to replace or insert the widget and validator for the field concerned in your form class:
//In setup method of custom forms or initialize method of generated forms
$this->setWidgets(array(
...
'number_field' => new genExtraWidgetFormFilterNumber(array('from_number' => new sfWidgetFormInput(), 'to_number' => new sfWidgetFormInput(), 'with_empty' => true)),
...
$this->setValidators(array(
...
'number_field' => new genExtraValidatorNumberRange(array('required' => false, 'from_number' => new sfValidatorInteger(array('required' => false)), 'to_number' => new sfValidatorInteger(array('required' => false)))),
...
Second you need in the Doctrine version to override the addNumberQuery method of the base filter form.
The plugin provides the Doctrine version in the genExtraFormFilterDoctrine class.
If anyone comes up with the Propel version, please send it to me, I will add it.
All you have to do is to inherit your base filter form class from genExtraFormFilterDoctrine:
abstract class BaseFormFilterDoctrine extends genExtraFormFilterDoctrine
{
}
Validate a field against a constant value
The sfValidatorSchemaCompare class allows you to have validation comparing 2 fields, but does not allow comparing a field to a constant value.
The constantValidatorSchemaCompare class just allows you to do that.
The syntax is the same as sfValidatorSchemaCompare except that the third parameter is a constant and it can be used with AND or OR validators to create complex validation:
$this->validatorSchema->setPostValidator(
new sfValidatorAnd(array(
new sfValidatorOr(array(
new constantValidatorSchemaCompare('current_residence_city_other', '!=', '',
array('throw_global_error' => false),
array('invalid' => "Current residence other is required for 'Other AK', 'Non AK' and 'Multiple'")),
new constantValidatorSchemaCompare('current_residence_city_id', '<', 99980,
array('throw_global_error' => false),
array('invalid' => "Current residence other is required for 'Other AK', 'Non AK' and 'Multiple'")),
new constantValidatorSchemaCompare('current_residence_city_id', '>', 99982,
array('throw_global_error' => false),
array('invalid' => "Current residence other is required for 'Other AK', 'Non AK' and 'Multiple'"))
)),
new sfValidatorOr(array(
new constantValidatorSchemaCompare('birth_mother_residence_city_other', '!=', '',
array('throw_global_error' => false),
array('invalid' => "Birth residence other is required for 'Other AK', 'Non AK' and 'Multiple'")),
new constantValidatorSchemaCompare('birth_mother_residence_city_id', '<', 99980,
array('throw_global_error' => false),
array('invalid' => "Birth residence other is required for 'Other AK', 'Non AK' and 'Multiple'")),
new constantValidatorSchemaCompare('birth_mother_residence_city_id', '>', 99982,
array('throw_global_error' => false),
array('invalid' => "Birth residence other is required for 'Other AK', 'Non AK' and 'Multiple'"))
))
)));
Widget for the Symfony 1.0 style date and date range filter entry
You have to replace or insert the widget and validator for the field concerned in your form class:
//In setup method of custom forms or initialize method of generated forms
...
'date_field' => new sfWidgetFormFilterDate(array('from_date' => new genExtraWidgetFormRichDate(), 'to_date' => new genExtraWidgetFormRichDate(), 'with_empty' => true)),
...
$this->setValidators(array(
...
'date_field' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
...