class WebformElements in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformElements
- 5.0.x modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformElements
Adapter for Webform elements.
Plugin annotation
@Plugin(
id = "WebformElements",
label = @Translation("Webform elements")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\salesforce_mapping\SalesforceMappingFieldPluginBase implements SalesforceMappingFieldPluginInterface
- class \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformElements
- class \Drupal\salesforce_mapping\SalesforceMappingFieldPluginBase implements SalesforceMappingFieldPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WebformElements
File
- modules/
salesforce_webform/ src/ Plugin/ SalesforceMappingField/ WebformElements.php, line 19
Namespace
Drupal\salesforce_webform\Plugin\SalesforceMappingFieldView source
class WebformElements extends SalesforceMappingFieldPluginBase {
/**
* {@inheritdoc}
*/
public static function isAllowed(SalesforceMappingInterface $mapping) {
return $mapping
->getDrupalEntityType() == 'webform_submission';
}
/**
* {@inheritdoc}
*/
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 webform elements.'),
];
}
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 webform element.'),
];
}
// Just allowed to push.
$pluginForm['direction']['#options'] = [
MappingConstants::SALESFORCE_MAPPING_DIRECTION_DRUPAL_SF => $pluginForm['direction']['#options'][MappingConstants::SALESFORCE_MAPPING_DIRECTION_DRUPAL_SF],
];
$pluginForm['direction']['#default_value'] = MappingConstants::SALESFORCE_MAPPING_DIRECTION_DRUPAL_SF;
return $pluginForm;
}
/**
* {@inheritdoc}
*/
public function value(EntityInterface $entity, SalesforceMappingInterface $mapping) {
$element_parts = explode('__', $this
->config('drupal_field_value'));
$main_element_name = reset($element_parts);
$webform = $this->entityTypeManager
->getStorage('webform')
->load($mapping
->get('drupal_bundle'));
$webform_element = $webform
->getElement($main_element_name);
if (!$webform_element) {
// This reference field does not exist.
return;
}
try {
$describe = $this->salesforceClient
->objectDescribe($mapping
->getSalesforceObjectType());
$field_definition = $describe
->getField($this
->config('salesforce_field'));
if ($field_definition['type'] == 'multipicklist') {
return implode(';', $entity
->getElementData($main_element_name));
}
else {
$value = $entity
->getElementData($main_element_name);
if (isset($element_parts[1])) {
$value = $value[$element_parts[1]];
}
return $value;
}
} catch (\Exception $e) {
return NULL;
}
}
/**
* {@inheritdoc}
*/
public function getPluginDefinition() {
$definition = parent::getPluginDefinition();
$element_parts = explode('__', $this
->config('drupal_field_value'));
$main_element_name = reset($element_parts);
$webform = $this->entityTypeManager
->getStorage('webform')
->load($this->mapping
->get('drupal_bundle'));
// Unfortunately, the best we can do for webform dependencies is a single
// dependency on the top-level webform, which is itself a monolithic config.
// @TODO implement webform-element-changed hook, if that exists.
$definition['config_dependencies']['config'][] = $webform
->getConfigDependencyName();
return $definition;
}
/**
* {@inheritdoc}
*/
public function checkFieldMappingDependency(array $dependencies) {
$definition = $this
->getPluginDefinition();
foreach ($definition['config_dependencies']['config'] as $dependency) {
if (!empty($dependencies['config'][$dependency])) {
return TRUE;
}
}
return FALSE;
}
/**
* Form options helper.
*/
protected function getConfigurationOptions($mapping) {
/** @var \Drupal\webform\Entity\Webform $webform */
$webform = $this->entityTypeManager
->getStorage('webform')
->load($mapping
->get('drupal_bundle'));
$webform_elements = $webform
->getElementsInitializedFlattenedAndHasValue();
if (empty($webform_elements)) {
return;
}
$options = [];
// Loop over every field on the webform.
foreach ($webform_elements as $element_id => $element) {
if ($element['#type'] == 'webform_address') {
$element = $webform
->getElement($element_id, TRUE);
foreach ($element['#webform_composite_elements'] as $sub_element) {
$options[$sub_element['#webform_composite_key']] = $element['#title'] . ': ' . (string) $sub_element['#title'];
}
}
else {
$options[$element_id] = $element['#title'];
}
}
if (empty($options)) {
return;
}
asort($options);
return $options;
}
/**
* {@inheritdoc}
*/
public function pull() {
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Entity field manager service. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Entity type bundle info service. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Entity type manager service. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Event dispatcher service. | |
SalesforceMappingFieldPluginBase:: |
protected | property | The machine name of the mapping. | |
SalesforceMappingFieldPluginBase:: |
protected | property | The label of the mapping. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Storage handler for Mapped Objects. | |
SalesforceMappingFieldPluginBase:: |
protected | property | The mapping to which this instance is attached. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Storage handler for SF mappings. | |
SalesforceMappingFieldPluginBase:: |
protected | property | Salesforce client service. | |
SalesforceMappingFieldPluginBase:: |
protected | function | Helper for buildConfigurationForm() to build a broken field plugin. | |
SalesforceMappingFieldPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
In order to set a config value to null, use setConfiguration() Overrides SalesforceMappingFieldPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
SalesforceMappingFieldPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
Used for returning values by key. Overrides SalesforceMappingFieldPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
SalesforceMappingFieldPluginBase:: |
protected | function | Helper method to get the Field Type of the given Field Data Definition. | 1 |
SalesforceMappingFieldPluginBase:: |
protected | function | Helper method to get the Data Definition for the current field. | 1 |
SalesforceMappingFieldPluginBase:: |
protected | function | Helper to retreive a list of fields for a given object type. | |
SalesforceMappingFieldPluginBase:: |
protected | function | Return TRUE if the given field uses an entity reference handler. | |
SalesforceMappingFieldPluginBase:: |
public | function |
Returns label of the mapping field plugin. Overrides SalesforceMappingFieldPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
Pull callback for field plugins. Overrides SalesforceMappingFieldPluginInterface:: |
4 |
SalesforceMappingFieldPluginBase:: |
public | function |
Whether this plugin supports "push" operations. Overrides SalesforceMappingFieldPluginInterface:: |
1 |
SalesforceMappingFieldPluginBase:: |
public | function |
Munge the value that's being prepared to push to Salesforce. Overrides SalesforceMappingFieldPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
protected | function | Wraper for plugin.manager.entity_reference_selection service. | |
SalesforceMappingFieldPluginBase:: |
public | function |
Used for returning values by key. Overrides SalesforceMappingFieldPluginInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
SalesforceMappingFieldPluginBase:: |
public | function |
Implements PluginFormInterface::submitConfigurationForm(). Overrides PluginFormInterface:: |
1 |
SalesforceMappingFieldPluginBase:: |
public | function |
Implements PluginFormInterface::validateConfigurationForm(). Overrides PluginFormInterface:: |
1 |
SalesforceMappingFieldPluginBase:: |
public | function |
SalesforceMappingFieldPluginBase constructor. Overrides PluginBase:: |
1 |
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. | |
WebformElements:: |
public | function |
Form constructor. Overrides SalesforceMappingFieldPluginBase:: |
|
WebformElements:: |
public | function |
On dependency removal, determine if this plugin needs to be removed. Overrides SalesforceMappingFieldPluginBase:: |
|
WebformElements:: |
protected | function | Form options helper. | |
WebformElements:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginBase:: |
|
WebformElements:: |
public static | function |
Determine whether this plugin is allowed for a given mapping. Overrides SalesforceMappingFieldPluginBase:: |
|
WebformElements:: |
public | function |
Whether this plugin supports "pull" operations. Overrides SalesforceMappingFieldPluginBase:: |
|
WebformElements:: |
public | function |
Given a Drupal entity, return the outbound value. Overrides SalesforceMappingFieldPluginInterface:: |