Skip to content
Snippets Groups Projects
Commit 7dc18eca authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Documentation standards updates

parent edbc9d51
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
exit;
// @codingStandardsIgnoreStart
// Include the exception class:
use Drupal\salesforce\Rest\RestException;
......@@ -23,8 +24,8 @@ $returnObject = FALSE;
// Uncomment the following line to get Drupal\salesforce\Rest\RestResponse object instead of json-decoded value:
// $returnObject = TRUE;.
// Instantiate the client so we can reference the response later if necessary:
/**
* @var Drupal\salesforce\Rest\RestClient **/
/** @var \Drupal\salesforce\Rest\RestClientInterface $client */
$client = \Drupal::service('salesforce.client');
$method = 'POST';
......@@ -67,5 +68,5 @@ catch (\Exception $e) {
// see GuzzleHttp\Client.
}
```
// @codingStandardsIgnoreEnd
......@@ -30,8 +30,6 @@ function salesforce_example_help($route_name, RouteMatchInterface $route_match)
*
* For this example we are simply calling a "manage" function and passing a
* parameter to indicate what type of operaiton is taking place.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function salesforce_example_entity_insert(EntityInterface $entity) {
_salesforce_example_entity_manage($entity, 'insert');
......@@ -42,8 +40,6 @@ function salesforce_example_entity_insert(EntityInterface $entity) {
*
* For this example we are simply calling a "manage" function and passing a
* parameter to indicate what type of operaiton is taking place.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function salesforce_example_entity_update(EntityInterface $entity) {
_salesforce_example_entity_manage($entity, 'update');
......@@ -54,14 +50,14 @@ function salesforce_example_entity_update(EntityInterface $entity) {
*
* For this example we are simply calling a "manage" function and passing a
* parameter to indicate what type of operaiton is taking place.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*/
function salesforce_example_entity_delete(EntityInterface $entity) {
_salesforce_example_entity_manage($entity, 'delete');
}
/**
* Handler for entity operations.
*
* This function is called by the three hook_entity_OPERATION functions
* - salesforce_example_entity_insert (hook_entity_insert)
* - salesforce_example_entity_update (hook_entity_update)
......@@ -75,9 +71,6 @@ function salesforce_example_entity_delete(EntityInterface $entity) {
* So if you have a Drupal T-Shirt in sizes S,M,L,XL, the Product is "Drupal T-Shirt" and you
* will have four Product Variations, one for each size. The Product object will have entity references
* to each Product Variation.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* @param $op
*/
function _salesforce_example_entity_manage(EntityInterface &$entity, $op) {
......@@ -89,12 +82,10 @@ function _salesforce_example_entity_manage(EntityInterface &$entity, $op) {
->getStorage('salesforce_mapped_object');
}
/**
* We're performing a check to see if we're dealing with a Salesforce Mapped Object. The reason
* we do this instead of just checking to see if we're dealing with a Commerce Product Variation is that
* we could very well have product variations that are not being managed by the SFDC integration.
* If this is the case, we do not want to be programmatically manipulating these objects.
*/
// We're performing a check to see if we're dealing with a Salesforce Mapped Object. The reason
// we do this instead of just checking to see if we're dealing with a Commerce Product Variation is that
// we could very well have product variations that are not being managed by the SFDC integration.
// If this is the case, we do not want to be programmatically manipulating these objects.
if ($entity->getEntityTypeId() == 'salesforce_mapped_object') {
/** @var \Drupal\salesforce_mapping\Entity\MappedObject $entity */
......@@ -102,20 +93,18 @@ function _salesforce_example_entity_manage(EntityInterface &$entity, $op) {
if (!$mapped_entity) {
return;
}
/**
* Here we check to see if the entity that the SFDC Mapping Object dealt with was a Commerce Product
* Variation.
*/
// Here we check to see if the entity that the SFDC Mapping Object dealt with was a Commerce Product
// Variation.
if ($mapped_entity->getEntityTypeId() == 'commerce_product_variation') {
/** @var \Drupal\salesforce\SObject $sf */
$sf = $entity->getSalesforceRecord();
if ($sf != NULL) {
/**
* We are operating under the assumption that the parent Commerce Product object is also being
* managed by the SFDC integration. Therefore we will be able to load the object by leveraging
* the Salesforce Modules storage service and using the SDFC ID as the key.
*/
// We are operating under the assumption that the parent Commerce Product object is also being
// managed by the SFDC integration. Therefore we will be able to load the object by leveraging
// the Salesforce Modules storage service and using the SDFC ID as the key.
// Get the SFDC ID for the parent Product (the Product -> Product Variation already exists in SFDC,
// conveniently mirroring the Drupal Commerce model)
......@@ -129,7 +118,7 @@ function _salesforce_example_entity_manage(EntityInterface &$entity, $op) {
if (is_array($mapped_objects)) {
// We are lazily assuming that there will only be one corresponding prodctu object
// We are lazily assuming that there will only be one corresponding prodct object
// and that it will be the first item in the returned array.
$mapped_object = current($mapped_objects);
......@@ -141,23 +130,18 @@ function _salesforce_example_entity_manage(EntityInterface &$entity, $op) {
/** @var \Drupal\commerce_product\Entity\Product $product */
$product = $mgr->load($course->id());
/**
* If this is a deletion of a Product Variation, we need to remove the reference to the variation
* from the Commerce Product
*/
// If this is a deletion of a Product Variation, we need to remove the reference to the variation
// from the Commerce Product.
if ($op == 'delete') {
$product->removeVariation($mapped_entity);
}
/**
* Otherwise we need to add the reference to the Product Variation that was just inserted or updated
*/
// Otherwise we need to add the reference to the Product Variation that was just inserted or updated.
else {
$product->addVariation($mapped_entity);
}
/**
* Finally we save the Commerce Product that we've manipulated
*/
// Finally we save the Commerce Product that we've manipulated.
$product->save();
}
}
......
......@@ -12,6 +12,7 @@ use Drupal\salesforce_mapping\Event\SalesforceQueryEvent;
/**
* Class SalesforceExampleSubscriber.
*
* Trivial example of subscribing to salesforce.push_params event to set a
* constant value for Contact.FirstName.
*
......@@ -20,7 +21,10 @@ use Drupal\salesforce_mapping\Event\SalesforceQueryEvent;
class SalesforceExampleSubscriber implements EventSubscriberInterface {
/**
* SalesforcePushAllowedEvent callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushAllowedEvent $event
* The push allowed event.
*/
public function pushAllowed(SalesforcePushAllowedEvent $event) {
/** @var \Drupal\Core\Entity\Entity $entity */
......@@ -31,7 +35,10 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
}
/**
* SalesforcePushParamsEvent callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushParamsEvent $event
* The event.
*/
public function pushParamsAlter(SalesforcePushParamsEvent $event) {
$mapping = $event->getMapping();
......@@ -53,7 +60,10 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
}
/**
* SalesforcePushParamsEvent push success callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushParamsEvent $event
* The event.
*/
public function pushSuccess(SalesforcePushParamsEvent $event) {
switch ($event->getMappedObject()->getMapping()->id()) {
......@@ -69,14 +79,20 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
}
/**
* SalesforcePushParamsEvent push fail callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePushOpEvent $event
* The event.
*/
public function pushFail(SalesforcePushOpEvent $event) {
drupal_set_message('push fail example: ' . $event->getMappedObject()->id());
}
/**
* SalesforceQueryEvent pull query alter event callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforceQueryEvent $event
* The event.
*/
public function pullQueryAlter(SalesforceQueryEvent $event) {
$mapping = $event->getMapping();
......@@ -97,7 +113,10 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
}
/**
* Pull presave event callback.
*
* @param \Drupal\salesforce_mapping\Event\SalesforcePullEvent $event
* The event.
*/
public function pullPresave(SalesforcePullEvent $event) {
$mapping = $event->getMapping();
......@@ -132,7 +151,7 @@ class SalesforceExampleSubscriber implements EventSubscriberInterface {
}
catch (\Exception $e) {
// Unable to fetch file data from SF.
\Drupal::logger('db')->error(t('failed to fetch attachment for user ' . $account->id()));
\Drupal::logger('db')->error(t('failed to fetch attachment for user @user', ['@user' => $account->id()]));
return;
}
......
......@@ -19,7 +19,7 @@ use Drupal\salesforce_mapping\MappingConstants;
class Hardcoded extends SalesforceMappingFieldPluginBase {
/**
*
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$pluginForm = parent::buildConfigurationForm($form, $form_state);
......@@ -43,19 +43,17 @@ class Hardcoded extends SalesforceMappingFieldPluginBase {
}
/**
*
* {@inheritdoc}
*/
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
return 'Hardcoded value';
}
/**
*
* {@inheritdoc}
*/
public function pull() {
return FALSE;
}
// @TODO add validation handler (?)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment