You are here

abstract class FieldMappingBase in Webform Content Creator 3.x

Base for a field mapping plugin.

Hierarchy

Expanded class hierarchy of FieldMappingBase

10 files declare their use of FieldMappingBase
AddressFieldMapping.php in src/Plugin/WebformContentCreator/FieldMapping/AddressFieldMapping.php
BooleanFieldMapping.php in src/Plugin/WebformContentCreator/FieldMapping/BooleanFieldMapping.php
DateTimeFieldMapping.php in src/Plugin/WebformContentCreator/FieldMapping/DateTimeFieldMapping.php
DefaultFieldMapping.php in src/Plugin/WebformContentCreator/FieldMapping/DefaultFieldMapping.php
EmailFieldMapping.php in src/Plugin/WebformContentCreator/FieldMapping/EmailFieldMapping.php

... See full list

File

src/Plugin/FieldMappingBase.php, line 13

Namespace

Drupal\webform_content_creator\Plugin
View source
abstract class FieldMappingBase extends PluginBase implements FieldMappingInterface {

  /**
   * Return the plugin.
   */
  public function getPlugin() {
    return $this;
  }

  /**
   * Get the plugin ID.
   */
  public function getId() {
    return $this->pluginDefinition['id'];
  }

  /**
   * Get the plugin label.
   */
  public function getLabel() {
    return $this->pluginDefinition['label'];
  }

  /**
   * Get the plugin weight.
   */
  public function getWeight() {
    return $this->pluginDefinition['weight'];
  }

  /**
   * Get the field types this plugin is available for.
   */
  public function getFieldTypes() {
    return $this->pluginDefinition['field_types'];
  }

  /**
   * Is this a generic (non-element specific) plugin.
   */
  public function isGeneric() {
    return empty($this->pluginDefinition['field_types']) ? TRUE : FALSE;
  }
  public function supportsCustomFields() {
    return TRUE;
  }
  public function getEntityComponentFields(FieldDefinitionInterface $field_definition) {
    return [];
  }
  public function getSupportedWebformFields($webform_id) {
    return WebformContentCreatorUtilities::getWebformElements($webform_id);
  }

  /**
   * Use a single mapping to set an entity field value.
   */
  public function mapEntityField(ContentEntityInterface &$content, array $webform_element, array $data = [], FieldDefinitionInterface $field_definition) {
    $field_id = $field_definition
      ->getName();
    $field_value = $data[$field_id];
    $content
      ->set($field_id, $field_value);
  }
  protected function filterWebformFields($webform_id, array $supported_types, array $available_fields = NULL) {
    if (!isset($available_fields)) {
      $available_fields = WebformContentCreatorUtilities::getWebformElements($webform_id);
    }
    $webform_field_types = WebformContentCreatorUtilities::getWebformElementsTypes($webform_id);
    $allowed_fields = [];
    foreach ($available_fields as $key => $available_field) {
      $key_parts = explode(',', $key);
      if (sizeOf($key_parts) > 1) {
        $element_type = $webform_field_types[$key_parts[1]];

        //Webform field vs user added fields
        if ($key_parts[0] == "1") {
          $element_type = $element_type['type'];
        }
        if (in_array($element_type, $supported_types)) {
          $allowed_fields[$key] = $available_field;
        }
      }
      else {

        //We're dealing with an option group, so recursive call to process the sub fields
        $retval = $this
          ->filterWebformFields($webform_id, $supported_types, $available_field);
        if (!empty($retval)) {
          $allowed_fields[$key] = $retval;
        }
      }
    }
    return $allowed_fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldMappingBase::filterWebformFields protected function
FieldMappingBase::getEntityComponentFields public function Returns the entity component fields. Overrides FieldMappingInterface::getEntityComponentFields 1
FieldMappingBase::getFieldTypes public function Get the field types this plugin is available for.
FieldMappingBase::getId public function Get the plugin ID.
FieldMappingBase::getLabel public function Get the plugin label.
FieldMappingBase::getPlugin public function Return the plugin.
FieldMappingBase::getSupportedWebformFields public function Overrides FieldMappingInterface::getSupportedWebformFields 9
FieldMappingBase::getWeight public function Get the plugin weight.
FieldMappingBase::isGeneric public function Is this a generic (non-element specific) plugin.
FieldMappingBase::mapEntityField public function Use a single mapping to set an entity field value. Overrides FieldMappingInterface::mapEntityField 10
FieldMappingBase::supportsCustomFields public function Returns whether the mapper supports custom field text Overrides FieldMappingInterface::supportsCustomFields 2
FieldMappingInterface::WEBFORM_ENTIY_REFERENCE_ELEMENTS constant
FieldMappingInterface::WEBFORM_OPTIONS_ELEMENTS constant
FieldMappingInterface::WEBFORM_TEXT_ELEMENTS constant
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 2
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 98