function finder_i18nstrings_map_from_form in Finder 7
Same name and namespace in other branches
- 6 modules/finder_i18nstrings/finder_i18nstrings.module \finder_i18nstrings_map_from_form()
Get a default map of which fields are translatable from the form.
1 call to finder_i18nstrings_map_from_form()
- finder_i18nstrings_map in modules/
finder_i18nstrings/ finder_i18nstrings.module - Get a map of which fields are translatable.
File
- modules/
finder_i18nstrings/ finder_i18nstrings.module, line 147 - The finder string translation module.
Code
function finder_i18nstrings_map_from_form($object, $translatable_types, $form = NULL, $id = NULL, $parents = array()) {
$map = array();
// Don't do any processing if $translatable_types was emptied via hook_finder_i18nstrings_types_alter.
if (!empty($translatable_types)) {
if (is_null($form)) {
$args = array();
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
);
if (isset($object->finder_element_id)) {
$args[] = 'finder_admin_element_edit';
$args[] =& $form_state;
if (!isset($object->finder_id)) {
$object = finder_element_load($object->finder_element_id);
}
$args[] = finder_load($object->finder_id);
$args[] = $object->finder_element_id;
$id = 'finder:e' . $object->finder_element_id . ':';
}
else {
// Ensure the admin include file is present.
finder_inc('admin');
$args[] = 'finder_admin_edit';
$args[] =& $form_state;
$args[] = $object;
$id = 'finder:f' . $object->finder_id . ':';
}
$form = call_user_func_array('drupal_retrieve_form', $args);
$form_build_id = 'form-' . md5(uniqid(mt_rand(), TRUE));
$form['#build_id'] = $form_build_id;
drupal_prepare_form($form_id, $form, $form_state);
}
foreach (element_children($form) as $key) {
$path = $parents;
$path[] = $key;
if (in_array($form[$key]['#type'], $translatable_types) && $path != array(
'path',
)) {
$translatable =& $form[$key]['#translatable'];
// If #translatable is set to TRUE, or if it is not set.
if (isset($translatable) && $translatable || !isset($translatable)) {
$map[$key]['#i18nstrings'] = $id . implode('][', $path);
}
}
$children = finder_i18nstrings_map_from_form($object, $translatable_types, $form[$key], $id, $path);
if (!empty($children)) {
$map[$key] = array_merge((array) $map[$key], $children);
}
}
}
return $map;
}