我的解决方案:
/**
* Implements hook_form_FORM_ID_alter()
*/
function ebep_users_feature_form_ebep_exhibitor_profile_node_form_alter(&$form, &$form_state, $form_id) {
foreach(_ebep_users_feature_getUserListFieldNames() as $fieldName) {
$form[$fieldName]['und']['#prefix'] = '<div id="'.$fieldName . '_wrapper">';
$form[$fieldName]['und']['#suffix'] = '</div>';
$form[$fieldName]['und']['#options'] = _ebep_users_feature_getOptionsValuesFromIEFList($form_state);
}
$form['#attached']['css'] = array(
drupal_get_path('module', 'ebep_users_feature') . '/assets/styles.css',
);
$form['#attached']['js'] = array(
drupal_get_path('module', 'ebep_users_feature') . '/assets/scripts.js',
);
$form['users_refresh'] = array(
'#type' => 'submit',
'#value' => t('Refresh users list'),
'#ajax' => array(
'callback' => 'ebep_users_feature_users_list_ajax',
),
);
}
function ebep_users_feature_users_list_ajax($form, $form_state) {
$commands = array();
foreach(_ebep_users_feature_getUserListFieldNames() as $fieldName) {
$form[$fieldName]['und']['#options'] = _ebep_users_feature_getOptionsValuesFromIEFList($form_state);
$commands[] = ajax_command_replace('#'.$fieldName.'_wrapper', drupal_render($form[$fieldName]));
}
return array('#type' => 'ajax', '#commands' => $commands);
}
function _ebep_users_feature_getOptionsValuesFromIEFList($form_state) {
static $options = array();
if (empty($options)) {
$ief = array_shift($form_state['inline_entity_form']);
$options['_node'] = t('- None -');
foreach($ief['entities'] as $data) {
$options[$data['entity']->uid] = $data['entity']->name;
}
}
return $options;
}
Related
右边列出的此处有任何问题解决了吗?