silverstripe/silverstripe-framework — pull request #2637 by sunnysideup (2013-11-03 23:56:26+00:00)
Title: automatic link child class (has_one parent) in addNewForm

this HACK is a great improvement to the CMS. That is, it needs to be improved in terms of code BUT it adds an important feature.

Imagine you have a DataObject Country with a linked DataObject cities (one country has_many cities - a city has_one country). Then, using default form field scaffolding in the CMS, iF you edit a country and click on the "Add City" button, the presented "create new city" form does NOT link back to the Country by default (i.e. there is a country dropdown for you to select the right country, but it does NOT - by default - select the country you "came from" (the country you want to add the city to). In my opinion this is not good enough... It should, at least by default, select the parent country in the dropdown field. The hack here fixes this. I am sure there is a better way to do this, but I am not sure how..... PLEASE HELP!

Alternative ways to do this may include:

* add parameters in "add new ... " button
* add parent + child references in controlling classes (e.g. modeladmin related classes).

What I really need to find out is where and how this relationship of the parent and child (as expressed in the URL) comes from so that rather than dissecting the URL and hacking it, we can automatically set the link to the parent right at the source.