protected function EmailOverrideForm::getPossibleMappings in Easy Email 8
Same name and namespace in other branches
- 2.0.x modules/easy_email_override/src/Form/EmailOverrideForm.php \Drupal\easy_email_override\Form\EmailOverrideForm::getPossibleMappings()
1 call to EmailOverrideForm::getPossibleMappings()
- EmailOverrideForm::form in modules/
easy_email_override/ src/ Form/ EmailOverrideForm.php - Gets the actual form array to be built.
File
- modules/
easy_email_override/ src/ Form/ EmailOverrideForm.php, line 101
Class
- EmailOverrideForm
- Class EmailOverrideForm.
Namespace
Drupal\easy_email_override\FormCode
protected function getPossibleMappings($email_id, $easy_email_type) {
$possible_mappings = [];
$easy_email_fields = [];
$field_definitions = $this->entityFieldManager
->getFieldDefinitions('easy_email', $easy_email_type);
foreach ($field_definitions as $field_name => $definition) {
$field_info = [
'label' => $definition
->getLabel(),
'type' => $definition
->getType(),
];
if ($field_info['type'] === 'entity_reference') {
$field_info['type'] = 'entity:' . $definition
->getSetting('target_type');
}
elseif (in_array($field_info['type'], [
'string',
'string_long',
])) {
$field_info['type'] = 'string';
}
elseif (in_array($field_info['type'], [
'text',
'text_long',
])) {
$field_info['type'] = 'text';
}
$easy_email_fields[$field_name] = $field_info;
}
$email_definition = $this->emailManager
->getDefinition($email_id);
foreach ($email_definition['params'] as $id => $param_info) {
$param_possible_matches = [];
foreach ($easy_email_fields as $field_name => $field_info) {
if ($field_info['type'] === $param_info['type']) {
$param_possible_matches[$field_name] = $field_info['label'];
}
}
if (!empty($param_possible_matches)) {
$possible_mappings[$id] = [
'label' => $param_info['label'],
'options' => $param_possible_matches,
];
}
}
return $possible_mappings;
}