create forms; get values and make a d
This commit is contained in:
parent
991369e91d
commit
1e3c1b3bca
@ -30,7 +30,49 @@ function fulcrm_collection_menu() {
|
||||
return $items;
|
||||
}
|
||||
|
||||
function fulcrm_collection_to_form( $collection_data, $d = array() ) {
|
||||
function fulcrm_collection_get_d_value( $d, $key ) {
|
||||
$key = explode( '.', $key );
|
||||
foreach ( $key as $bit ) {
|
||||
if ( array_key_exists( $bit, $d ) )
|
||||
$d = $d[ $bit ];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
return $d;
|
||||
}
|
||||
|
||||
function _fulcrm_collection_set_d_value( &$d, $key, $value ) {
|
||||
switch ( count( $key ) ) {
|
||||
case 0:
|
||||
return NULL;
|
||||
case 1:
|
||||
$d[ $key[ 0 ] ] = $value;
|
||||
return $value;
|
||||
default:
|
||||
if ( !array_key_exists( $key[ 0 ], $d ) )
|
||||
$d[ $key[ 0 ] ] = array();
|
||||
return _fulcrm_collection_set_value( $d[ $key[ 0 ] ], array_slice( $key, 1 ), $value );
|
||||
}
|
||||
}
|
||||
|
||||
function fulcrm_collection_set_d_value( &$d, $key, $value ) {
|
||||
return _fulcrm_collection_set_d_value( $d, explode( '.', $key ), $value );
|
||||
}
|
||||
|
||||
function fulcrm_collection_form_values_to_d( $prefix, $values ) {
|
||||
$d = array();
|
||||
|
||||
foreach ( $values as $k => $v ) {
|
||||
$bits = explode( '/fulcrm/', $k );
|
||||
if ( ( count( $bits ) === 2 ) && ( $bits[ 0 ] === $prefix ) ) {
|
||||
fulcrm_collection_set_d_value( $d, $bits[ 1 ], $v );
|
||||
}
|
||||
}
|
||||
|
||||
return $d;
|
||||
}
|
||||
|
||||
function fulcrm_collection_to_form( $prefix, $collection_data, $d = array() ) {
|
||||
$form = array();
|
||||
|
||||
foreach ( $collection_data[ '_structure' ] as $set_data ) {
|
||||
@ -46,10 +88,11 @@ function fulcrm_collection_to_form( $collection_data, $d = array() ) {
|
||||
case 'text':
|
||||
case 'email':
|
||||
case 'tel':
|
||||
$fieldset[ $field_data[ 'key' ] ] = array( '#type' => 'textfield',
|
||||
$fieldset[ $prefix . '/fulcrm/' . $field_data[ 'key' ] ] = array( '#type' => 'textfield',
|
||||
'#title' => $field_data[ 'name' ],
|
||||
'#description' => $field_data[ 'description' ],
|
||||
'#required' => $field_data[ 'required' ],
|
||||
'#default_value' => fulcrm_collection_get_d_value( $d, $field_data[ 'key' ] ),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user