public function EmailField::buildConfigurationForm in Workbench Email 8
Same name and namespace in other branches
- 2.x src/Plugin/RecipientType/EmailField.php \Drupal\workbench_email\Plugin\RecipientType\EmailField::buildConfigurationForm()
Generates a recipient types's settings form.
Parameters
array $form: A minimally prepopulated form array.
\Drupal\Core\Form\FormStateInterface $form_state: The state of the (entire) configuration form.
Return value
array The $form array with additional form elements for the settings of this recipient type. The submitted form values should match $this->settings.
Overrides RecipientTypeBase::buildConfigurationForm
1 method overrides EmailField::buildConfigurationForm()
- EntityReferenceUser::buildConfigurationForm in src/
Plugin/ RecipientType/ EntityReferenceUser.php - Generates a recipient types's settings form.
File
- src/
Plugin/ RecipientType/ EmailField.php, line 94
Class
- EmailField
- Provides a recipient type of an email field.
Namespace
Drupal\workbench_email\Plugin\RecipientTypeCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Add the fields.
$fields = $this->entityFieldManager
->getFieldMapByFieldType('email');
$field_options = [];
foreach ($fields as $entity_type_id => $entity_type_fields) {
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
if (!$this
->isModeratableEntityType($entity_type)) {
// These fields are irrelevant, the entity type isn't moderated.
continue;
}
$base = $this->entityFieldManager
->getBaseFieldDefinitions($entity_type_id);
foreach ($entity_type_fields as $field_name => $field_detail) {
if (in_array($field_name, array_keys($base), TRUE)) {
continue;
}
$sample_bundle = reset($field_detail['bundles']);
$sample_field = $this->entityTypeManager
->getStorage('field_config')
->load($entity_type_id . '.' . $sample_bundle . '.' . $field_name);
if ($sample_field) {
$field_options[$entity_type_id . ':' . $field_name] = $sample_field
->label() . ' (' . $entity_type
->getLabel() . ')';
}
}
}
return [
'fields' => [
'#type' => 'checkboxes',
'#title' => $this
->t('Email Fields'),
'#description' => $this
->t('Send to mail address found in the selected fields'),
'#options' => $field_options,
'#default_value' => $this
->getFields(),
],
];
}