public function ServicesClientMappingPlugin::configForm in Services Client 7.2
Configuration form options
Overrides ServicesClientPlugin::configForm
File
- include/
mapping.inc, line 158
Class
- ServicesClientMappingPlugin
- Mapping plugin wrapper which represents mapping row.
Code
public function configForm(&$form, &$form_state) {
$form['reader'] = array(
'#type' => 'select',
'#title' => t('Reader'),
'#description' => t('What type of reader should be used for this mapping'),
'#default_value' => isset($this->config['reader']) ? $this->config['reader'] : NULL,
'#options' => array(
'' => '<' . t('select') . '>',
) + services_client_get_plugins('mapping', TRUE, function ($item) {
return $item['type'] == 'reader';
}),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'services_client_plugin_mapping_ajax',
'wrapper' => 'ajax-wrapper',
),
);
if (!empty($form_state['values']['reader'])) {
// AJAX: Plugin was changed, reset configuration
if (isset($form_state['reader_plugin']) && $form_state['values']['reader'] != get_class($form_state['reader_plugin'])) {
$form_state['values']['reader_config'] = array();
}
$config = !empty($form_state['values']['reader_config']) ? $form_state['values']['reader_config'] : array();
$reader = $this
->getPlugin($form_state['values']['reader'], $config);
$reader
->configForm($form, $form_state);
$form_state['reader_plugin'] = $reader;
}
elseif (!empty($this->config['reader'])) {
$config = !empty($this->config['reader_config']) ? $this->config['reader_config'] : array();
$reader = $this
->getPlugin($this->config['reader'], $config);
$reader
->configForm($form, $form_state);
$form_state['reader_plugin'] = $reader;
}
$form['formatter'] = array(
'#type' => 'select',
'#title' => t('Formatter'),
'#description' => t('What type of formatter should be used for this mapping'),
'#default_value' => isset($this->config['formatter']) ? $this->config['formatter'] : NULL,
'#options' => array(
'' => '<' . t('select') . '>',
) + services_client_get_plugins('mapping', TRUE, function ($item) {
return $item['type'] == 'formatter';
}),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'services_client_plugin_mapping_ajax',
'wrapper' => 'ajax-wrapper',
),
);
if (!empty($form_state['values']['formatter'])) {
// AJAX: Plugin was changed, reset configuration
if (isset($form_state['formatter_plugin']) && $form_state['values']['formatter'] != get_class($form_state['formatter_plugin'])) {
$form_state['values']['formatter_config'] = array();
}
$config = !empty($form_state['values']['formatter_config']) ? $form_state['values']['formatter_config'] : array();
$formatter = $this
->getPlugin($form_state['values']['formatter'], $config);
$formatter
->configForm($form, $form_state);
$form_state['formatter_plugin'] = $formatter;
}
elseif (!empty($this->config['formatter'])) {
$config = !empty($this->config['formatter_config']) ? $this->config['formatter_config'] : array();
$formatter = $this
->getPlugin($this->config['formatter'], $config);
$formatter
->configForm($form, $form_state);
$form_state['formatter_plugin'] = $formatter;
}
$wrapped['wrapper'] = array(
'#tree' => FALSE,
'#theme_wrappers' => array(
'container',
),
'#attributes' => array(
'id' => 'ajax-wrapper',
),
);
foreach (element_children($form) as $id) {
$wrapped['wrapper'][$id] = $form[$id];
}
$form = $wrapped;
}