class ServicesClientFieldCondition in Services Client 7.2
Hierarchy
- class \ServicesClientPlugin implements ServicesClientConfigurableInterface
- class \ServicesClientConditionPlugin implements ServicesClientConditionInterface
- class \ServicesClientFieldCondition
- class \ServicesClientConditionPlugin implements ServicesClientConditionInterface
Expanded class hierarchy of ServicesClientFieldCondition
2 string references to 'ServicesClientFieldCondition'
- ServicesClientWebTestCase::testAddingEvent in tests/
services_client.test - Test basic event configuration actions.
- services_client_services_client_condition in ./
services_client.plugins.inc - List availalable condition plugins.
File
- include/
condition.inc, line 191
View source
class ServicesClientFieldCondition extends ServicesClientConditionPlugin {
/**
* Retrieve default configuration.
*/
protected function getDefaultConfiguration() {
return array(
'field' => '',
'condition' => NULL,
);
}
/**
* Retrieve configuration summary.
*/
public function getSummary() {
if (empty($this->config['field'])) {
return '[ ' . t('Field condition - not configured') . ' ]';
}
else {
$path = "{$this->config['field']}[{$this->config['language']}][*][{$this->config['property']}]";
return format_string('<b>@path</b> @condition <b>@value</b>', array(
'@path' => $path,
'@condition' => $this->config['condition'],
'@value' => $this->config['value'],
));
}
}
/**
* Check if configured property is empty.
*
* @param stdClass $entity
* Drupal entity that is tested.
*
* @return boolean
* TRUE if empty
*/
protected function isEmpty($entity) {
return empty($entity->{$this->config['field']}[$this->config['language']]);
}
/**
* Check if configured property equals configured value.
*
* @param stdClass $entity
* Drupal entity that is tested.
*
* @return boolean
* TRUE if empty
*/
protected function equals($entity) {
if ($this
->isEmpty($entity)) {
return FALSE;
}
else {
$items = isset($entity->{$this->config['field']}[$this->config['language']]) ? $entity->{$this->config['field']}[$this->config['language']] : NULL;
foreach ((array) $items as $item) {
if (isset($item[$this->config['property']]) && $item[$this->config['property']] == $this->config['value']) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Match entity with condition.
*
* @param stdClass $entity
* Drupal entity.
*
* @return boolean
* TRUE if entity matches condition.
*/
public function match($entity) {
switch ($this->config['condition']) {
case 'empty':
return $this
->isEmpty($entity);
case 'not_empty':
return !$this
->isEmpty($entity);
case 'equals':
return $this
->equals($entity);
case 'not_equals':
return !$this
->equals($entity);
default:
return FALSE;
}
}
/**
* Configuration form.
*/
public function configForm(&$form, &$form_state) {
$form['field'] = array(
'#type' => 'textfield',
'#title' => t('Field name'),
'#required' => TRUE,
'#description' => t('Enter field name like field_first_name'),
'#default_value' => isset($this->config['field']) ? $this->config['field'] : NULL,
);
$form['language'] = array(
'#type' => 'textfield',
'#title' => t('Language'),
'#required' => TRUE,
'#description' => t('Enter field language'),
'#default_value' => isset($this->config['language']) ? $this->config['language'] : LANGUAGE_NONE,
);
$form['property'] = array(
'#type' => 'textfield',
'#title' => t('Property name'),
'#required' => TRUE,
'#description' => t('Enter field property name like "value"'),
'#default_value' => isset($this->config['property']) ? $this->config['property'] : NULL,
);
$form['condition'] = array(
'#type' => 'select',
'#title' => t('Condition'),
'#options' => array(
'is_empty' => t('Is Empty'),
'not_empty' => t('Not Empty'),
'equals' => t('Equals'),
'not_equals' => t('Not equals'),
),
'#required' => TRUE,
'#default_value' => isset($this->config['condition']) ? $this->config['condition'] : NULL,
);
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Value'),
'#description' => t('Value that should be tested.'),
'#default_value' => isset($this->config['value']) ? $this->config['value'] : NULL,
'#states' => array(
'invisible' => array(
':input[name="condition"]' => array(
array(
'value' => 'is_empty',
),
array(
'value' => 'not_empty',
),
),
),
),
);
}
/**
* Submit handler.
*/
public function configFormSubmit(&$form, &$form_state) {
$this->config['field'] = $form_state['values']['field'];
$this->config['language'] = $form_state['values']['language'];
$this->config['property'] = $form_state['values']['property'];
$this->config['condition'] = $form_state['values']['condition'];
$this->config['value'] = $form_state['values']['value'];
}
}