class ServicesClientPropertyFormatter in Services Client 7.2
Formats data to property.
Hierarchy
- class \ServicesClientPlugin implements ServicesClientConfigurableInterface
- class \ServicesClientMapperPlugin implements ServicesClientMappingInterface
- class \ServicesClientPropertyFormatter implements ServicesClientMappingFormatterInterface
- class \ServicesClientMapperPlugin implements ServicesClientMappingInterface
Expanded class hierarchy of ServicesClientPropertyFormatter
7 string references to 'ServicesClientPropertyFormatter'
- ServicesClientErrorWebTestCase::testServicesClientErrors in services_client_error/
tests/ services_client_error.test - ServicesClientHooksWebTestCase::testServicesClientHooks in tests/
services_client.test - ServicesClientWebTestCase::testAddingEvent in tests/
services_client.test - Test basic event configuration actions.
- ServicesClientWebTestCase::testServicesClientProcessing in tests/
services_client.test - services_client_migrate_add_mapping in ./
services_client.legacy.inc - Create mapping plugins by old configurration.
File
- include/
mapping.inc, line 495
View source
class ServicesClientPropertyFormatter extends ServicesClientMapperPlugin implements ServicesClientMappingFormatterInterface {
/**
* Retrieve default configuration.
*
* @return array
* Default configuration.
*/
protected function getDefaultConfiguration() {
return array(
'property' => '',
'multivalue' => 'force_single',
'empty' => 'no_field',
'default_value' => '',
);
}
/**
* Get plugin configuration summary.
*
* @return string
* Configuration overview string.
*/
public function getSummary() {
if (empty($this->config['property'])) {
return '[PropertyFormatter - not configured]';
}
else {
return "\$object-><b>{$this->config['property']}</b>";
}
}
/**
* Format source value to destination.
*
* @param ServicesClientMappingValue $source
* Source value gathered from Reader.
*
* @return array
* Value specified by 'key' => 'name', 'value' => 'mixed'
*/
public function format(ServicesClientMappingValue $source) {
// Handle empty values
if ($source
->isEmpty()) {
if ($this->config['empty'] == 'no_field') {
return NULL;
}
elseif ($this->config['empty'] == 'null_field') {
return array(
'key' => $this->config['property'],
'value' => NULL,
);
}
elseif ($this->config['empty'] == 'default_value') {
return array(
'key' => $this->config['property'],
'value' => $this->config['default_value'],
);
}
}
// If single value is forced.
$value = $source
->getValue();
if ($this->config['multivalue'] == 'force_single') {
$value = reset($value);
}
// Return resulting value.
return array(
'key' => $this->config['property'],
'value' => $value,
);
}
public function configForm(&$form, &$form_state) {
$form['formatter_config'] = array(
'#type' => 'fieldset',
'#title' => t('Property formatter'),
'#tree' => TRUE,
);
$form['formatter_config']['property'] = array(
'#type' => 'textfield',
'#title' => t('Property name'),
'#description' => t('Enter property name'),
'#default_value' => $this->config['property'],
);
$form['formatter_config']['multivalue'] = array(
'#type' => 'select',
'#title' => t('Multiple values'),
'#description' => t('How to handle multiple values'),
'#options' => array(
'force_single' => t('Always force single simple value of property'),
'force_array' => t('Always send array even with single value'),
),
'#default_value' => $this->config['multivalue'],
);
$form['formatter_config']['empty'] = array(
'#type' => 'select',
'#title' => t('Empty values'),
'#description' => t('How to handle empty values'),
'#options' => array(
'no_field' => t("Don't create any field"),
'null_field' => t("Create null field."),
'default_value' => t('Provide default value'),
),
'#default_value' => $this->config['empty'],
);
$form['formatter_config']['default_value'] = array(
'#type' => 'textfield',
'#title' => t('Default value'),
'#description' => t('Provide default value if reader will provide empty value.'),
'#default_value' => $this->config['default_value'],
'#states' => array(
'visible' => array(
':input[name="formatter_config[empty]"]' => array(
array(
'value' => 'default_value',
),
),
),
),
);
}
public function configFormSubmit(&$form, &$form_state) {
$this->config['property'] = $form_state['values']['formatter_config']['property'];
$this->config['multivalue'] = $form_state['values']['formatter_config']['multivalue'];
$this->config['empty'] = $form_state['values']['formatter_config']['empty'];
$this->config['default_value'] = $form_state['values']['formatter_config']['default_value'];
}
}