I've tried to get into custom element creation but ran into problems with
#value_callback and when
#element_validate, more specifically their lack of documentation.
Imagine you have a custom element called db_connection whose output is supposed to be a is supposed to be an SQL connection string.
The element itself consist of a few select elements and one textfield. The user then simply selects (let's say) the database in the first one, table in the second one, and writes numerical of desired row in the last textfield.
My question is, when should you go trough the individual inputs and create the SQL connection string from them? Should it be in
#value_callback or in
The names suggest the latter should be more suitable but my experience so far say the very opposite... It also seems to me that other modules (date) do it in the former one.
If one should really do it in
#value_callback then how should he approach validation? As far as I know, the value callback is called before validation happens so it might have to deal with invalid individual inputs from which it might be impossible to construct the final output (SQL connection string in our example)?
And if it in fact is to be done in #value_callback than what purpose does #value_callback serve? What should it do, what should it return, ...?
As of my research:
This article suggests that one should use
#value_callback to transform 'default_value' to element friendly data form and use
#element_validate to transform inputed data to store / later use friendly form.
So basically it suggests to go with
#element_validate for the SQL connection string creation and use the
#value_callback only to properly set up the element in case the SQL connection string is given as default value.
In addition to this question I also have this one (that is more about Already partially answered.