private static function PcaAddressElementTrait::preparePcaFieldMapping in Loqate 8
Same name and namespace in other branches
- 2.x src/PcaAddressElementTrait.php \Drupal\loqate\PcaAddressElementTrait::preparePcaFieldMapping()
Processes field mapping output.
This method is responsible for:
- Validates field mapping as existing fields
- Sets context for the element attribute selector
- Provides an empty default value for the field attribute
- ...
Parameters
array $element: Element array.
See also
https://www.loqate.com/resources/support/setup-guides/advanced-setup-gui...
1 call to PcaAddressElementTrait::preparePcaFieldMapping()
- PcaAddressElementTrait::processPcaAddress in src/
PcaAddressElementTrait.php - Process the PCA address form element.
File
- src/
PcaAddressElementTrait.php, line 155
Class
- PcaAddressElementTrait
- Class PcaAddressElementTrait.
Namespace
Drupal\loqateCode
private static function preparePcaFieldMapping(array &$element) : void {
// Fallback to settings.
if (empty($element['#pca_fields'])) {
$element['#pca_fields'] = \Drupal::config('loqate.settings')
->get(PcaAddressSettingsForm::PCA_FIELDS);
}
// Start normalising value output.
foreach ($element['#pca_fields'] as $i => $field_mapping) {
// Add context for our element selectors.
if (isset($field_mapping['element']) && !empty($field_mapping['element'])) {
// Prepend id on field map.
$element['#pca_fields'][$i]['element'] = "{$element['#name']}[{$field_mapping['element']}]";
}
// Fallback value.
if (!isset($field_mapping['field']) || empty($field_mapping['field'])) {
$element['#pca_fields'][$i]['field'] = '';
}
}
// Add fields mapping for the nested lookup field element.
$element['#pca_fields'][] = [
'element' => "{$element['#name']}[address_lookup]",
'field' => '',
];
// Expose the field_mapping options to Drupal Settings.
$element['#attached']['drupalSettings']['pca_address']['elements']['#' . $element['#id']]['fields'] = $element['#pca_fields'];
}