class RestResponseDescribe in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 src/Rest/RestResponseDescribe.php \Drupal\salesforce\Rest\RestResponseDescribe
- 5.0.x src/Rest/RestResponseDescribe.php \Drupal\salesforce\Rest\RestResponseDescribe
Class RestResponseDescribe.
@package Drupal\salesforce\Rest
Hierarchy
- class \Drupal\salesforce\Rest\RestResponse extends \GuzzleHttp\Psr7\Response uses StringTranslationTrait
- class \Drupal\salesforce\Rest\RestResponseDescribe
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\RestView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RestResponse:: |
protected | property | The json-decoded response body. | |
RestResponse:: |
protected | property | The original Response used to build this object. | |
RestResponse:: |
private | function | Helper function to eliminate repetitive json parsing. | |
RestResponse:: |
public | function | Magic getter method to return the given property. | |
RestResponseDescribe:: |
private | property | Flattened fields mapping field name => field label. | |
RestResponseDescribe:: |
protected | property | Array of field definitions for this SObject type, indexed by machine name. | |
RestResponseDescribe:: |
protected | property | The name of this SObject type, e.g. "Contact", "Account", "Opportunity". | |
RestResponseDescribe:: |
public | function | Return a field definition for the given field name. | |
RestResponseDescribe:: |
public | function | Return a one-dimensional array of field names => field labels. | |
RestResponseDescribe:: |
public | function | Getter. | |
RestResponseDescribe:: |
public | function | Getter for name. | |
RestResponseDescribe:: |
public | function |
See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest.... Overrides RestResponse:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |