You are here

protected function RelatedProperties::getConfigurationOptions in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php \Drupal\salesforce_mapping\Plugin\SalesforceMappingField\RelatedProperties::getConfigurationOptions()
  2. 5.0.x modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php \Drupal\salesforce_mapping\Plugin\SalesforceMappingField\RelatedProperties::getConfigurationOptions()

Form options helper.

1 call to RelatedProperties::getConfigurationOptions()
RelatedProperties::buildConfigurationForm in modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php
Form constructor.

File

modules/salesforce_mapping/src/Plugin/SalesforceMappingField/RelatedProperties.php, line 97

Class

RelatedProperties
Adapter for entity Reference and fields.

Namespace

Drupal\salesforce_mapping\Plugin\SalesforceMappingField

Code

protected function getConfigurationOptions($mapping) {
  $instances = $this->entityFieldManager
    ->getFieldDefinitions($mapping
    ->get('drupal_entity_type'), $mapping
    ->get('drupal_bundle'));
  if (empty($instances)) {
    return;
  }
  $options = [];

  // Loop over every field on the mapped entity. For reference fields, expose
  // all properties of the referenced entity.
  foreach ($instances as $instance) {
    if (!$this
      ->instanceOfEntityReference($instance)) {
      continue;
    }
    $settings = $this
      ->selectionPluginManager()
      ->getSelectionHandler($instance)
      ->getConfiguration();
    $entity_type = $settings['target_type'];
    $properties = [];

    // If handler is default and allowed bundles are set, include all fields
    // from all allowed bundles.
    try {
      if (!empty($settings['handler_settings']['target_bundles'])) {
        foreach ($settings['handler_settings']['target_bundles'] as $bundle) {
          $properties += $this->entityFieldManager
            ->getFieldDefinitions($entity_type, $bundle);
        }
      }
      else {
        $properties += $this->entityFieldManager
          ->getBaseFieldDefinitions($entity_type);
        $bundles = array_keys($this->entityTypeBundleInfo
          ->getBundleInfo($entity_type));
        foreach ($bundles as $bundle) {
          $properties += $this->entityFieldManager
            ->getFieldDefinitions($entity_type, $bundle);
        }
      }
    } catch (\Exception $e) {

      // @TODO is there a better way to exclude non-fieldables?
      continue;
    }
    foreach ($properties as $key => $property) {
      $options[(string) $instance
        ->getLabel()][$instance
        ->getName() . ':' . $key] = $property
        ->getLabel();
    }
  }
  if (empty($options)) {
    return;
  }

  // Alphabetize options for UI.
  foreach ($options as $group => &$option_set) {
    asort($option_set);
  }
  asort($options);
  return $options;
}