You are here

class ServicesClientFieldD6Formatter in Services Client 7.2

D6 and D5 field formatter.

Hierarchy

Expanded class hierarchy of ServicesClientFieldD6Formatter

5 string references to 'ServicesClientFieldD6Formatter'
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 821

View source
class ServicesClientFieldD6Formatter extends ServicesClientFieldFormatter {

  /**
   * Get plugin configuration summary.
   *
   * @return string
   *   Configuration overview string.
   */
  public function getSummary() {
    if (empty($this->config['field'])) {
      return '[FieldD6Formatter - not configured]';
    }
    else {
      $multivalue = $this->config['multivalue'] == 'force_single' ? '0' : '*';
      return "\$object-><b>{$this->config['field']}[{$multivalue}][{$this->config['property']}]</b>";
    }
  }

  /**
   * Retrieve empty value formatting by configuration.
   *
   * @return array|NULL
   *   Formatted empty value.
   */
  protected function formatEmptyValue() {
    if ($this->config['empty'] == 'no_field') {
      return NULL;
    }
    elseif ($this->config['empty'] == 'null_field') {
      return array(
        'key' => $this->config['field'],
        'value' => array(),
      );
    }
    elseif ($this->config['empty'] == 'null_property') {
      return array(
        'key' => $this->config['field'],
        'value' => NULL,
      );
    }
    elseif ($this->config['empty'] == 'default_value') {
      return array(
        'key' => $this->config['field'],
        'value' => array(
          array(
            $this->config['property'] => $this->config['default_value'],
          ),
        ),
      );
    }
  }

  /**
   * Format source value array to field.
   *
   * @param array $values
   *   Source values that should be formatted.
   *
   * @return array
   *   Formatted value in format
   */
  protected function formatArray($values) {

    // Make handy shortcuts
    $field = $this->config['field'];
    $property = $this->config['property'];

    // Build final value
    $out = array();
    foreach ($values as $value) {
      $out[][$property] = $value;
    }

    // Return resulting value.
    return array(
      'key' => $this->config['field'],
      'value' => $out,
    );
  }

  /**
   * Config form.
   */
  public function configForm(&$form, &$form_state) {
    parent::configForm($form, $form_state);
    unset($form['formatter_config']['language']);
  }

  /**
   * Submit config form.
   */
  public function configFormSubmit(&$form, &$form_state) {
    $this->config['field'] = $form_state['values']['formatter_config']['field'];
    $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'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicesClientFieldD6Formatter::configForm public function Config form. Overrides ServicesClientFieldFormatter::configForm
ServicesClientFieldD6Formatter::configFormSubmit public function Submit config form. Overrides ServicesClientFieldFormatter::configFormSubmit
ServicesClientFieldD6Formatter::formatArray protected function Format source value array to field. Overrides ServicesClientFieldFormatter::formatArray
ServicesClientFieldD6Formatter::formatEmptyValue protected function Retrieve empty value formatting by configuration. Overrides ServicesClientFieldFormatter::formatEmptyValue
ServicesClientFieldD6Formatter::getSummary public function Get plugin configuration summary. Overrides ServicesClientFieldFormatter::getSummary
ServicesClientFieldFormatter::format public function Format source value to destination. Overrides ServicesClientMappingFormatterInterface::format
ServicesClientFieldFormatter::getDefaultConfiguration protected function Retrieve default configuration. Overrides ServicesClientMapperPlugin::getDefaultConfiguration
ServicesClientMapperPlugin::configFormValidate public function Validate configuration form. Overrides ServicesClientPlugin::configFormValidate
ServicesClientMapperPlugin::__construct public function Constructor. Overrides ServicesClientPlugin::__construct
ServicesClientPlugin::$config protected property Plugin specific configuration
ServicesClientPlugin::$event protected property Event definition
ServicesClientPlugin::getConfiguration public function Retrieve current plugin configuration. Overrides ServicesClientConfigurableInterface::getConfiguration
ServicesClientPlugin::setConfiguration public function Set configuration of plugin. Overrides ServicesClientConfigurableInterface::setConfiguration