silverstripe/silverstripe-framework — pull request #2522 by tractorcow (2013-10-10 22:13:50+00:00)
Title: API GridState_Data values can have default values specified during retrieval.

With this fix it's now possible to define a default value for any `GridState` keys. Currently, attempting to retrieve a key from the `GridState` for the first time returns a `GridState_Data` object; Not very useful if you are expecting a `DataObject` ID or string value.

This fix also adds value by allowing keys to be retrieved using the `__call` magic function, meaning that the `$state->Sort` field could also be accessed with `$state->Sort()`, optionally being passed a parameter to specify a reasonable default value (e.g. `$state->Sort('asc')`). If Sort isn't yet defined you'll get `'asc'` as a returned value instead of a `GridState_Data` object, which would make no sense in this context. This will remain the default default if nothing is specified (so that calling it as a field or a parameterless method are symmetrical).

https://github.com/silverstripe/silverstripe-framework/pull/1360 depends on this fix, because up until now `DataObject::get_by_id` has been sent lots of `GridState_Data` values as IDs, and it's not really pragmatic to have to check for empty and non-value type IDs being sent into the parametrised query interface (especially since at times these could be valid parameters, such as when a BLOB or a `SQLConditionGroup` object are used).

I've also trimmed some dead code from `GridFieldAddExistingAutocompleter` which wasn't doing (or able to do) anything.

I've added the phpdoc for $State to GridField for better IDE auto-completion.