class ServicesClientFieldReader in Services Client 7.2
Reads data from drupal field.
Hierarchy
- class \ServicesClientPlugin implements ServicesClientConfigurableInterface
- class \ServicesClientMapperPlugin implements ServicesClientMappingInterface
- class \ServicesClientFieldReader implements ServicesClientMappingReaderInterface
- class \ServicesClientMapperPlugin implements ServicesClientMappingInterface
Expanded class hierarchy of ServicesClientFieldReader
6 string references to 'ServicesClientFieldReader'
- ServicesClientErrorWebTestCase::testServicesClientErrors in services_client_error/
tests/ services_client_error.test - ServicesClientHooksWebTestCase::testServicesClientHooks in tests/
services_client.test - ServicesClientWebTestCase::testServicesClientProcessing in tests/
services_client.test - services_client_migrate_add_mapping in ./
services_client.legacy.inc - Create mapping plugins by old configurration.
- services_client_services_client_mapping in ./
services_client.plugins.inc - List available mapping plugins.
File
- include/
mapping.inc, line 375
View source
class ServicesClientFieldReader extends ServicesClientMapperPlugin implements ServicesClientMappingReaderInterface {
/**
* Retrieve default configuration.
*
* @return array
* Default configuration.
*/
protected function getDefaultConfiguration() {
return array(
'field' => '',
'language' => LANGUAGE_NONE,
'property' => '',
'all_values' => TRUE,
);
}
/**
* Get plugin configuration summary.
*
* @return string
* Configuration overview string.
*/
public function getSummary() {
if (empty($this->config['field'])) {
return '[FieldReader - not configured]';
}
else {
$delta = !empty($this->config['all_values']) ? '*' : '0';
return "\$source-><b>{$this->config['field']}[{$this->config['language']}][{$delta}][{$this->config['property']}]</b>";
}
}
/**
* Read property from entity.
*
* @param object $entity
* Entity that is being read.
*
* @return array
*/
public function read($entity) {
$value = new ServicesClientMappingValue();
$items = isset($entity->{$this->config['field']}[$this->config['language']]) ? $entity->{$this->config['field']}[$this->config['language']] : NULL;
if (!empty($items)) {
// We read only single value
if ($this->config['all_values'] == FALSE) {
$items = array(
reset($items),
);
}
$out = array();
foreach ($items as $item) {
if (isset($item[$this->config['property']])) {
$out[] = $item[$this->config['property']];
}
}
if (!empty($out)) {
$value
->setValue($out);
}
else {
$value
->setEmpty();
}
}
else {
$value
->setEmpty();
}
return $value;
}
/**
* Configuration form.
*/
public function configForm(&$form, &$form_state) {
$form['reader_config'] = array(
'#type' => 'fieldset',
'#title' => t('Property reader'),
'#tree' => TRUE,
);
$form['reader_config']['field'] = array(
'#type' => 'textfield',
'#title' => t('Field name'),
'#description' => t('Enter the name of the field'),
'#default_value' => $this->config['field'],
);
$form['reader_config']['language'] = array(
'#type' => 'textfield',
'#title' => t('Language'),
'#description' => t('Enter property name'),
'#default_value' => $this->config['language'],
);
$form['reader_config']['property'] = array(
'#type' => 'textfield',
'#title' => t('Property name'),
'#description' => t('Enter property name'),
'#default_value' => $this->config['property'],
);
$form['reader_config']['all_values'] = array(
'#type' => 'checkbox',
'#tilte' => t('Read all values'),
'#description' => t('Leave checked if this should read all values from field.'),
'#default_value' => $this->config['all_values'],
);
}
/**
* Submit handler;
*/
public function configFormSubmit(&$form, &$form_state) {
$this->config['field'] = $form_state['values']['reader_config']['field'];
$this->config['language'] = $form_state['values']['reader_config']['language'];
$this->config['property'] = $form_state['values']['reader_config']['property'];
$this->config['all_values'] = $form_state['values']['reader_config']['all_values'];
}
}