ullTableToolGenerator default handling
Introduction
Types of form defaults:
- SQL column defaults (not directly used in ullright)
- Doctrine schema defaults (commonly used for booleans, sometimes for integers)
- ColumnConfig defaults (e.g. a html template for a WYSIWYG editor field)
- sfForm defaults
- sfWidget defaults (Not supported in ullright, overwritten with form defaults by generator)
- Object values (values of the bound object)
At Work
BaseUllGeneratorActions::executeEdit() -> getEditGenerator()
UllTableToolGenerator::__construct() (or descendant)
UllTableToolGenerator::buildColumnsConfig()
-
Builds the ColumnsConfig for the given model
-
In the ColumnsConfig custom default values can be set foreach field/column
Example: For UllUser the default MailingLists are set
BaseUllGeneratorActions::executeEdit() -> UllTableToolGenerator::buildForm($row)
- $defaults = $this->getDefaults(); // defaults from ColumnsConfig
- $form = new ullTableToolGeneratorForm($row, $columnsConfig, $requestAction, $defaults, $cultures)
- ullGeneratorForm::_construct($object (=$row), $columnsConfig, $requestAction, $defaults, $cultures)
- ullTableToolGeneratorForm::updateDefaultsFromObject()
- ullGeneratorForm::updateDefaultsFromObject()
- ullGeneratorForm::patchedSfFormDoctrineUpdateDefaultsFromObject()
Improves default setting for new objects (see special section below) - Unsets defaults for inactive columns (from columnsConfig)
- ullGeneratorForm::patchedSfFormDoctrineUpdateDefaultsFromObject()
- Load defaults from related models for ullMetaWidgetManyToMany
- Move translation default values into plain array (e.g. "subject_translation_de")
- setDefaults($defaults)
- ullGeneratorForm::updateDefaultsFromObject()
- Add widgets to Form
- ullGeneratorForm::updateDefaults() // Why after adding widgets? Why not using updateDefaultsFromObject?
// Update defaults for relations and injection.- Check for "ull"-Relations (list view query reduction) and load their defaults
- Check for object defaults for artificial columns (e.g. ullRateable behaviour)
- Inject identifier (Widgets get array with value and primary id instead of id only)
- Inject fields (Advanced method to pass column values to the widgets)
Finaly sfForm()::render() calls the widgets and passes the default value to it.
Default setting for new objects
ullGeneratorForm::patchedSfFormDoctrineUpdateDefaultsFromObject()
Where do default values come from?
from column config - $defaults
examples for UllUser
- firstname = Klemens
- country = AT
- function = well paid slacker
- mailinglists = 2,3 (m:n, no native UllUser object property)
from object - $object->toArray(false)
examples for UllUser
- function = workaholic
code before 2014-01-27
$defaults = array_merge($this->getObject()->toArray(false), $defaults);
Problems:
- column config defaults overwrite object defaults
code before 2013-12-12
// better: use the object defaults first, then use the column config // defaults in case there is no object default per field $objectDefaults = $this->getObject()->toArray(false); foreach ($objectDefaults as $field => $objectDefault) { if ($objectDefault === null && array_key_exists($field, $defaults)) { $objectDefaults[$field] = $defaults[$field]; } } $defaults = $objectDefaults;
Problems:
- Column config defaults of non object-native columns (e.g. newsletter subscriptions) are ignored
new code 2014-01-27
$columnConfigDefaults = $defaults; $objectDefaults = $this->getObject()->toArray(false); // Create a combined list of fields, as there can be non-native object // fields in the columns config defaults (=$defaults) e.g. m:n defaults // like UllUser->Mailinglists $combinedDefaults = array_merge( array_keys($objectDefaults), array_keys($columnConfigDefaults) ); // Reset $defaults $defaults = array(); // Iterate the combined list - to not miss a field foreach ($combinedDefaults as $field) { // First, get the column config default for the current field // (if one is set) if (array_key_exists($field, $columnConfigDefaults) && null !== $columnConfigDefaults[$field]) { $defaults[$field] = $columnConfigDefaults[$field]; } // Then, get the object default for the current field (if one is set) // An existing column config default will be overwritten if (array_key_exists($field, $objectDefaults) && null !== $objectDefaults[$field]) { $defaults[$field] = $objectDefaults[$field]; } }
Some problem candidates:
- UllNewsletter -> edit -> copy into new
- column config "body" default overwrited object default (=body of the existing newsletter)
- UllUser -> create
- Default mailing lists not set