You are here

class ServicesClientPropertyCondition in Services Client 7.2

Test property condition of entity against value.

Hierarchy

Expanded class hierarchy of ServicesClientPropertyCondition

7 string references to 'ServicesClientPropertyCondition'
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_hook in ./services_client.legacy.inc
Migrate old hook with mapping to new system.

... See full list

File

include/condition.inc, line 56

View source
class ServicesClientPropertyCondition extends ServicesClientConditionPlugin {

  /**
   * Retrieve default configuration.
   */
  protected function getDefaultConfiguration() {
    return array(
      'property' => '',
      'condition' => NULL,
    );
  }

  /**
   * Retrieve configuration summary.
   */
  public function getSummary() {
    if (empty($this->config['property'])) {
      return '[ ' . t('Property condition - not configured') . ' ]';
    }
    else {
      return format_string('<b>@property</b> @condition <b>@value</b>', array(
        '@property' => $this->config['property'],
        '@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['property']});
  }

  /**
   * 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 (!isset($entity->{$this->config['property']})) {
      return FALSE;
    }
    else {
      return $entity->{$this->config['property']} == $this->config['value'];
    }
  }

  /**
   * 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['property'] = array(
      '#type' => 'textfield',
      '#title' => t('Property name'),
      '#required' => TRUE,
      '#description' => t('Enter property name like, "type" or "status"'),
      '#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['property'] = $form_state['values']['property'];
    $this->config['condition'] = $form_state['values']['condition'];
    $this->config['value'] = $form_state['values']['value'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicesClientConditionPlugin::__construct public function Constructor. Overrides ServicesClientPlugin::__construct
ServicesClientPlugin::$config protected property Plugin specific configuration
ServicesClientPlugin::$event protected property Event definition
ServicesClientPlugin::configFormValidate public function Validate configuration form. Overrides ServicesClientConfigurableInterface::configFormValidate 1
ServicesClientPlugin::getConfiguration public function Retrieve current plugin configuration. Overrides ServicesClientConfigurableInterface::getConfiguration
ServicesClientPlugin::setConfiguration public function Set configuration of plugin. Overrides ServicesClientConfigurableInterface::setConfiguration
ServicesClientPropertyCondition::configForm public function Configuration form. Overrides ServicesClientPlugin::configForm
ServicesClientPropertyCondition::configFormSubmit public function Submit handler. Overrides ServicesClientPlugin::configFormSubmit
ServicesClientPropertyCondition::equals protected function Check if configured property equals configured value.
ServicesClientPropertyCondition::getDefaultConfiguration protected function Retrieve default configuration. Overrides ServicesClientConditionPlugin::getDefaultConfiguration
ServicesClientPropertyCondition::getSummary public function Retrieve configuration summary. Overrides ServicesClientConditionInterface::getSummary
ServicesClientPropertyCondition::isEmpty protected function Check if configured property is empty.
ServicesClientPropertyCondition::match public function Match entity with condition. Overrides ServicesClientConditionInterface::match