class ServicesClientMappingPlugin in Services Client 7.2
Mapping plugin wrapper which represents mapping row.
Hierarchy
- class \ServicesClientPlugin implements ServicesClientConfigurableInterface
- class \ServicesClientMappingPlugin
Expanded class hierarchy of ServicesClientMappingPlugin
3 string references to 'ServicesClientMappingPlugin'
- services_client_migrate_add_mapping in ./
services_client.legacy.inc - Create mapping plugins by old configurration.
- services_client_ui::add_plugin_page in plugins/
export_ui/ services_client_ui.class.php - Page callback; Add new plugin.
- services_client_wizard_form_mapping_submit in ./
services_client.admin.inc - Submit handler; Build event and save it to DB.
File
- include/
mapping.inc, line 132
View source
class ServicesClientMappingPlugin extends ServicesClientPlugin {
protected function getPlugin($name, $config) {
$reflection = new ReflectionClass($name);
return $reflection
->newInstanceArgs(array(
$this->event,
$config,
));
}
protected function getPluginInstance($type, $name = NULL) {
$name = !empty($name) ? $name : $this->config[$type];
if (!empty($name)) {
$config = isset($this->config[$type . '_config']) ? $this->config[$type . '_config'] : array();
return $this
->getPlugin($name, $config);
}
else {
return NULL;
}
}
public function getReader($name = NULL) {
return $this
->getPluginInstance('reader', $name);
}
public function getFormatter($name = NULL) {
return $this
->getPluginInstance('formatter', $name);
}
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;
}
public function configFormSubmit(&$form, &$form_state) {
if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#value'] == t('Cancel')) {
return;
}
$this->config['reader'] = $form_state['values']['reader'];
$this->config['formatter'] = $form_state['values']['formatter'];
if (!empty($form_state['reader_plugin'])) {
$form_state['reader_plugin']
->configFormSubmit($form, $form_state);
$this->config['reader_config'] = $form_state['reader_plugin']
->getConfiguration();
}
if (!empty($form_state['formatter_plugin'])) {
$form_state['formatter_plugin']
->configFormSubmit($form, $form_state);
$this->config['formatter_config'] = $form_state['formatter_plugin']
->getConfiguration();
}
}
public function getSummary() {
if (isset($this->config['reader']) && isset($this->config['formatter'])) {
return format_string('!reader ==> !formatter', array(
'!reader' => $this
->getReaderSummary(),
'!formatter' => $this
->getFormatterSummary(),
));
}
else {
return '[ ' . t('Not configured') . ' ]';
}
}
/**
* Get reader summary text.
*
* @return string
* Reader plugin summary.
*/
public function getReaderSummary() {
$reader = $this
->getReader();
return !empty($reader) ? $reader
->getSummary() : '<b>NO READER</b>';
}
/**
* Get formatter summary text.
*
* @return string
* Formatter plugin summary.
*/
public function getFormatterSummary() {
$formatter = $this
->getFormatter();
return !empty($formatter) ? $formatter
->getSummary() : '<b>NO FORMATTER</b>';
}
}