You are here

class WebformEntityElements in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformEntityElements.php \Drupal\salesforce_webform\Plugin\SalesforceMappingField\WebformEntityElements

Adapter for Webform elements.

Plugin annotation


@Plugin(
  id = "WebformEntityElements",
  label = @Translation("Webform Entity Elements")
)

Hierarchy

Expanded class hierarchy of WebformEntityElements

File

modules/salesforce_webform/src/Plugin/SalesforceMappingField/WebformEntityElements.php, line 19

Namespace

Drupal\salesforce_webform\Plugin\SalesforceMappingField
View source
class WebformEntityElements extends SalesforceMappingFieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getDependencies(SalesforceMappingInterface $mapping) {
    return [
      'module' => [
        'webform',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function isAllowed(SalesforceMappingInterface $mapping) {
    return \Drupal::service('module_handler')
      ->moduleExists('webform');
  }

  /**
   * {@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 entity reference 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 entity reference 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 {
      $value = $entity
        ->getElementData($main_element_name);
      $mappedObjects = $this->mappedObjectStorage
        ->loadByDrupal($webform_element['#target_type'], $value);
      if (!empty($mappedObjects)) {
        $mappedObject = reset($mappedObjects);
        return $mappedObject
          ->sfid();
      }
    } catch (\Exception $e) {
      return NULL;
    }
  }

  /**
   * 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 = [];
    foreach ($webform_elements as $element_id => $element) {

      // All webform elements that are entity references are named in the form:
      // webform_entity_[elementtype]. Except autocomplete which is missing
      // "webform".
      if (stripos($element['#type'], 'webform_entity') !== FALSE || $element['#type'] == 'entity_autocomplete') {
        $options[$element_id] = $element['#title'];
      }
    }
    if (empty($options)) {
      return;
    }
    asort($options);
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function pull() {
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SalesforceMappingFieldPluginBase::$entityFieldManager protected property Entity field manager service.
SalesforceMappingFieldPluginBase::$entityTypeBundleInfo protected property Entity type bundle info service.
SalesforceMappingFieldPluginBase::$entityTypeManager protected property Entity type manager service.
SalesforceMappingFieldPluginBase::$eventDispatcher protected property Event dispatcher service.
SalesforceMappingFieldPluginBase::$id protected property The machine name of the mapping.
SalesforceMappingFieldPluginBase::$label protected property The label of the mapping.
SalesforceMappingFieldPluginBase::$mappedObjectStorage protected property Storage handler for Mapped Objects.
SalesforceMappingFieldPluginBase::$mapping protected property The mapping to which this instance is attached.
SalesforceMappingFieldPluginBase::$mappingStorage protected property Storage handler for SF mappings.
SalesforceMappingFieldPluginBase::$salesforceClient protected property Salesforce client service.
SalesforceMappingFieldPluginBase::buildBrokenConfigurationForm protected function Helper for buildConfigurationForm() to build a broken field plugin.
SalesforceMappingFieldPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
SalesforceMappingFieldPluginBase::checkFieldMappingDependency public function On dependency removal, determine if this plugin needs to be removed. Overrides SalesforceMappingFieldPluginInterface::checkFieldMappingDependency 5
SalesforceMappingFieldPluginBase::config public function In order to set a config value to null, use setConfiguration() Overrides SalesforceMappingFieldPluginInterface::config
SalesforceMappingFieldPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 2
SalesforceMappingFieldPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
SalesforceMappingFieldPluginBase::get public function Used for returning values by key. Overrides SalesforceMappingFieldPluginInterface::get
SalesforceMappingFieldPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
SalesforceMappingFieldPluginBase::getDrupalFieldType protected function Helper method to get the Field Type of the given Field Data Definition. 1
SalesforceMappingFieldPluginBase::getFieldDataDefinition protected function Helper method to get the Data Definition for the current field. 1
SalesforceMappingFieldPluginBase::getSalesforceFieldOptions protected function Helper to retreive a list of fields for a given object type.
SalesforceMappingFieldPluginBase::instanceOfEntityReference protected function Return TRUE if the given field uses an entity reference handler.
SalesforceMappingFieldPluginBase::label public function Returns label of the mapping field plugin. Overrides SalesforceMappingFieldPluginInterface::label
SalesforceMappingFieldPluginBase::pullValue public function Pull callback for field plugins. Overrides SalesforceMappingFieldPluginInterface::pullValue 4
SalesforceMappingFieldPluginBase::push public function Whether this plugin supports "push" operations. Overrides SalesforceMappingFieldPluginInterface::push 1
SalesforceMappingFieldPluginBase::pushValue public function Munge the value that's being prepared to push to Salesforce. Overrides SalesforceMappingFieldPluginInterface::pushValue
SalesforceMappingFieldPluginBase::selectionPluginManager protected function Wraper for plugin.manager.entity_reference_selection service.
SalesforceMappingFieldPluginBase::set public function Used for returning values by key. Overrides SalesforceMappingFieldPluginInterface::set
SalesforceMappingFieldPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
SalesforceMappingFieldPluginBase::submitConfigurationForm public function Implements PluginFormInterface::submitConfigurationForm(). Overrides PluginFormInterface::submitConfigurationForm 1
SalesforceMappingFieldPluginBase::validateConfigurationForm public function Implements PluginFormInterface::validateConfigurationForm(). Overrides PluginFormInterface::validateConfigurationForm 1
SalesforceMappingFieldPluginBase::__construct public function SalesforceMappingFieldPluginBase constructor. Overrides PluginBase::__construct 1
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.
WebformEntityElements::buildConfigurationForm public function Form constructor. Overrides SalesforceMappingFieldPluginBase::buildConfigurationForm
WebformEntityElements::getConfigurationOptions protected function Form options helper.
WebformEntityElements::getDependencies public function
WebformEntityElements::isAllowed public static function Determine whether this plugin is allowed for a given mapping. Overrides SalesforceMappingFieldPluginBase::isAllowed
WebformEntityElements::pull public function Whether this plugin supports "pull" operations. Overrides SalesforceMappingFieldPluginBase::pull
WebformEntityElements::value public function Given a Drupal entity, return the outbound value. Overrides SalesforceMappingFieldPluginInterface::value