You are here

class RestResponseDescribe in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 src/Rest/RestResponseDescribe.php \Drupal\salesforce\Rest\RestResponseDescribe
  2. 5.0.x src/Rest/RestResponseDescribe.php \Drupal\salesforce\Rest\RestResponseDescribe

Class RestResponseDescribe.

@package Drupal\salesforce\Rest

Hierarchy

Expanded class hierarchy of RestResponseDescribe

2 files declare their use of RestResponseDescribe
RestClientTest.php in tests/src/Unit/RestClientTest.php
TestRestClient.php in src/Tests/TestRestClient.php

File

src/Rest/RestResponseDescribe.php, line 10

Namespace

Drupal\salesforce\Rest
View source
class RestResponseDescribe extends RestResponse {

  /**
   * Array of field definitions for this SObject type, indexed by machine name.
   *
   * @var array
   */
  protected $fields;

  /**
   * The name of this SObject type, e.g. "Contact", "Account", "Opportunity".
   *
   * @var string
   */
  protected $name;

  /**
   * Flattened fields mapping field name => field label.
   *
   * @var array
   */
  private $fieldOptions;

  /**
   * See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_describe.htm.
   *
   * @param \Drupal\salesforce\Rest\RestResponse $response
   *   The Response.
   */
  public function __construct(RestResponse $response) {
    parent::__construct($response->response);
    $this->name = $response->data['name'];
    $this->fields = [];

    // Index fields by machine name, so we don't have to search every time.
    foreach ($response->data['fields'] as $field) {
      $this->fields[$field['name']] = $field;
    }
    foreach ($response->data as $key => $value) {
      if ($key == 'fields') {
        continue;
      }
      $this->{$key} = $value;
    }
    $this->data = $response->data;
  }

  /**
   * Getter for name.
   *
   * @return string
   *   The object name.
   */
  public function getName() {
    return $this->name;
  }

  /**
   * Getter.
   *
   * @return array
   *   The fields.
   */
  public function getFields() {
    return $this->fields;
  }

  /**
   * Return a field definition for the given field name.
   *
   * A single Salesforce field may contain the following keys:
   *    aggregatable
   *    autoNumber
   *    byteLength
   *    calculated
   *    calculatedFormula
   *    cascadeDelete
   *    caseSensitive
   *    controllerName
   *    createable
   *    custom
   *    defaultValue
   *    defaultValueFormula
   *    defaultedOnCreate
   *    dependentPicklist
   *    deprecatedAndHidden
   *    digits
   *    displayLocationInDecimal
   *    encrypted
   *    externalId
   *    extraTypeInfo
   *    filterable
   *    filteredLookupInfo
   *    groupable
   *    highScaleNumber
   *    htmlFormatted
   *    idLookup
   *    inlineHelpText
   *    label
   *    length
   *    mask
   *    maskType
   *    name
   *    nameField
   *    namePointing
   *    nillable
   *    permissionable
   *    picklistValues
   *    precision
   *    queryByDistance
   *    referenceTargetField
   *    referenceTo
   *    relationshipName
   *    relationshipOrder
   *    restrictedDelete
   *    restrictedPicklist
   *    scale
   *    soapType
   *    sortable
   *    type
   *    unique
   *    updateable
   *    writeRequiresMasterRead.
   *
   * For more information @see https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_fields_describe.htm.
   *
   * @param string $field_name
   *   A field name.
   *
   * @return array
   *   The field definition.
   *
   * @throws \Exception
   *   If field_name is not defined for this SObject type.
   */
  public function getField($field_name) {
    if (empty($this->fields[$field_name])) {
      throw new \Exception("No field {$field_name}");
    }
    return $this->fields[$field_name];
  }

  /**
   * Return a one-dimensional array of field names => field labels.
   *
   * @return array
   *   The field options.
   */
  public function getFieldOptions() {
    if (!isset($this->fieldOptions)) {
      $this->fieldOptions = array_column($this->fields, 'label', 'name');
      asort($this->fieldOptions);
    }
    return $this->fieldOptions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestResponse::$data protected property The json-decoded response body.
RestResponse::$response protected property The original Response used to build this object.
RestResponse::handleJsonResponse private function Helper function to eliminate repetitive json parsing.
RestResponse::__get public function Magic getter method to return the given property.
RestResponseDescribe::$fieldOptions private property Flattened fields mapping field name => field label.
RestResponseDescribe::$fields protected property Array of field definitions for this SObject type, indexed by machine name.
RestResponseDescribe::$name protected property The name of this SObject type, e.g. "Contact", "Account", "Opportunity".
RestResponseDescribe::getField public function Return a field definition for the given field name.
RestResponseDescribe::getFieldOptions public function Return a one-dimensional array of field names => field labels.
RestResponseDescribe::getFields public function Getter.
RestResponseDescribe::getName public function Getter for name.
RestResponseDescribe::__construct public function See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest.... Overrides RestResponse::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.