function pmpapi_pull_admin_config in Public Media Platform API Integration 7
Form constructor for the PMPAPI pull admin form.
See also
pmpapi_pull_admin_config_validate()
pmpapi_pull_admin_config_submit()
1 string reference to 'pmpapi_pull_admin_config'
- pmpapi_pull_menu in pmpapi_pull/
pmpapi_pull.module - Implements hook_menu().
File
- pmpapi_pull/
pmpapi_pull.admin.inc, line 16 - Basic admin forms, validators, and submit handlers.
Code
function pmpapi_pull_admin_config($form, &$form_state) {
$form = array();
$form['pmpapi_pull_pull_active'] = array(
'#type' => 'radios',
'#title' => t('Activate pull'),
'#default_value' => variable_get('pmpapi_pull_pull_active', 1),
'#options' => array(
'No',
'Yes',
),
);
$pull_user_options = array();
$users = entity_load('user');
foreach ($users as $uid => $user) {
$pull_user_options[$uid] = $user->name;
}
$pull_user_options[0] = variable_get('anonymous', t('Anonymous'));
$form['pmpapi_pull_pull_user'] = array(
'#type' => 'select',
'#title' => t('Pull creator'),
'#default_value' => variable_get('pmpapi_pull_pull_user', 1),
'#options' => $pull_user_options,
'#description' => t('All pulled entities will be created with the uid of the chosen user.'),
);
$available_profiles = array(
0 => 'None',
) + pmpapi_get_profile_list();
foreach (pmpapi_pull_get_entities() as $entity_type => $entity) {
$bundles = $entity['bundles'];
if (!empty($bundles)) {
$form[$entity_type] = array(
'#type' => 'fieldset',
'#title' => $entity['label'] . ' ' . t('entities'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($bundles as $bundle_name => $bundle) {
$label = $bundle['label'];
$uname = $entity_type . '__' . $bundle_name;
$form[$entity_type][$bundle_name . '_settings'] = array(
'#type' => 'fieldset',
'#title' => $label . ' ' . t('settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$profile = variable_get('pmpapi_pull_' . $uname . '_profile', 0);
if (isset($form_state['values'][$uname . '_pull_profile'])) {
$profile = $form_state['values'][$uname . '_pull_profile'];
}
$id = $uname . '-mapping-fields-div';
$form[$entity_type][$bundle_name . '_settings'][$uname . '_pull_profile'] = array(
'#type' => 'select',
'#title' => t('Mapped PMP profile'),
'#description' => 'The PMP profile (e.g., story, image, audio) which will be mapped to the ' . $label . ' entity type.',
'#options' => $available_profiles,
'#default_value' => $profile,
'#ajax' => array(
'callback' => 'pmpapi_pull_admin_mapping_callback',
'wrapper' => $id,
'method' => 'replace',
'effect' => 'fade',
'pmpapi_pull_entity_type' => $entity_type,
'pmpapi_pull_bundle_name' => $bundle_name,
),
);
$local_options = array();
$instances = pmpapi_get_augmented_instances($entity_type, $bundle_name);
foreach ($instances as $instance_name => $instance) {
$local_options[$instance_name] = $instance['label'];
}
$local_options = array(
'None',
) + $local_options;
$map = variable_get('pmpapi_pull_mapping_' . $uname . '_' . $profile, array());
$form[$entity_type][$bundle_name . '_settings'][$bundle_name . '_mappings'] = array(
'#type' => 'fieldset',
'#title' => $label . ' ' . t('mappings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div id="' . $id . '">',
'#suffix' => '</div>',
);
if (!$profile) {
$form[$entity_type][$bundle_name . '_settings'][$bundle_name . '_mappings']['#attributes']['class'][] = 'element-invisible';
}
$pmp_fields = pmpapi_get_profile_info($profile);
foreach ($pmp_fields as $pmp_name => $pmp_field) {
$element = 'pmpapi_pull_mapping_' . $uname . '_' . $pmp_name;
$form[$entity_type][$bundle_name . '_settings'][$bundle_name . '_mappings'][$element] = array(
'#type' => 'select',
'#title' => t('Map the "' . $pmp_name . '" PMP value to the following ' . $bundle_name . ' field:'),
'#options' => $local_options,
'#default_value' => !empty($map[$pmp_name]) ? $map[$pmp_name] : 0,
);
if (!empty($pmp_field['required'])) {
$form[$entity_type][$bundle_name . '_settings'][$bundle_name . '_mappings'][$element]['#required'] = TRUE;
}
}
}
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save settings'),
);
return $form;
}