protected function ContactEmails::getEntityReferenceEmailFields in Contact Emails 8
Get contact form fields by type.
Parameters
array $available_fields: The already added available fields.
object $field: The field.
Return value
array The new array of available fields.
1 call to ContactEmails::getEntityReferenceEmailFields()
- ContactEmails::getContactFormFields in src/
ContactEmails.php - Get contact form fields by type.
File
- src/
ContactEmails.php, line 175
Class
- ContactEmails
- Class ContactEmails.
Namespace
Drupal\contact_emailsCode
protected function getEntityReferenceEmailFields(array $available_fields, $field) {
$settings = $field
->getSettings();
// Get all bundles for given target type and filter by selected target
// bundles.
$bundle_info = $this->entityTypeBundleInfo
->getBundleInfo($settings['target_type']);
if (!empty($settings['handler_settings']['target_bundles'])) {
$bundle_info = array_intersect_key($bundle_info, $settings['handler_settings']['target_bundles']);
}
if (!empty($bundle_info)) {
foreach ($bundle_info as $bundle_name => $bundle) {
$bundle_fields = array_filter($this->entityFieldManager
->getFieldDefinitions($settings['target_type'], $bundle_name), function ($field_definition) {
return $field_definition instanceof FieldConfigInterface;
});
if ($bundle_fields) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $bundle_field */
foreach ($bundle_fields as $bundle_field) {
$type = $bundle_field
->getType();
// Allow field type email.
if ($type == 'email') {
$available_fields[$field
->getName() . '.' . $settings['target_type'] . '.' . $bundle_name . '.' . $bundle_field
->getName()] = $bundle['label'] . ': ' . $bundle_field
->getLabel() . ' (' . $bundle_field
->getName() . ')';
}
}
}
}
}
return $available_fields;
}