DrupalConstant.php in Salesforce Suite 8.4
File
modules/salesforce_mapping/src/Plugin/SalesforceMappingField/DrupalConstant.php
View source
<?php
namespace Drupal\salesforce_mapping\Plugin\SalesforceMappingField;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\salesforce_mapping\SalesforceMappingFieldPluginBase;
use Drupal\salesforce_mapping\Entity\SalesforceMappingInterface;
use Drupal\salesforce_mapping\MappingConstants;
use Drupal\salesforce\SObject;
class DrupalConstant extends SalesforceMappingFieldPluginBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$pluginForm = parent::buildConfigurationForm($form, $form_state);
$options = $this
->getConfigurationOptions($form['#entity']);
if (empty($options)) {
$pluginForm['drupal_field_value'] = [
'#markup' => $this
->t('No available properties.'),
];
}
else {
$pluginForm['drupal_field_value'] += [
'#type' => 'select',
'#options' => $options,
'#empty_option' => $this
->t('- Select -'),
'#default_value' => $this
->config('drupal_field_value'),
'#description' => $this
->t('Select a Drupal field or property to map to a constant.'),
];
}
$pluginForm['drupal_constant'] = [
'#type' => 'textfield',
'#default_value' => $this
->config('drupal_constant'),
'#description' => $this
->t('Enter a constant value to map to a Drupal field.'),
];
unset($pluginForm['salesforce_field']);
$pluginForm['direction']['#options'] = [
MappingConstants::SALESFORCE_MAPPING_DIRECTION_SF_DRUPAL => $pluginForm['direction']['#options'][MappingConstants::SALESFORCE_MAPPING_DIRECTION_SF_DRUPAL],
];
$pluginForm['direction']['#default_value'] = MappingConstants::SALESFORCE_MAPPING_DIRECTION_SF_DRUPAL;
return $pluginForm;
}
private function getConfigurationOptions(SalesforceMappingInterface $mapping) {
$instances = $this->entityFieldManager
->getFieldDefinitions($mapping
->get('drupal_entity_type'), $mapping
->get('drupal_bundle'));
$options = [];
foreach ($instances as $key => $instance) {
if ($this
->instanceOfEntityReference($instance)) {
continue;
}
$options[$key] = $instance
->getLabel();
}
asort($options);
return $options;
}
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
}
public function pullValue(SObject $sf_object, EntityInterface $entity, SalesforceMappingInterface $mapping) {
return $this
->config('drupal_constant');
}
public function push() {
return FALSE;
}
}