public function RngContactSettingsForm::buildForm in RNG Contact 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ RngContactSettingsForm.php, line 66
Class
- RngContactSettingsForm
- Configure RNG Contact settings.
Namespace
Drupal\rng_contact\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['table_help'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this
->t('Select email fields Courier should use when communicating with contacts.'),
];
$form['table'] = [
'#type' => 'table',
'#header' => [
$this
->t('Contact type'),
$this
->t('Email field'),
],
'#empty' => $this
->t('There are no people types available.'),
];
foreach (RngContactType::loadMultiple() as $contact_type) {
$row = [];
$row['label'] = [
'#markup' => $contact_type
->label(),
];
/** @var \Drupal\rng_contact\Entity\RngContactTypeInterface $contact_type */
$field_definitions = $this->entityFieldManager
->getFieldDefinitions('rng_contact', $contact_type
->id());
$field_options = [];
foreach ($field_definitions as $field_definition) {
$field_type = $field_definition
->getType();
if ($field_type == 'email') {
$field_options[$field_definition
->getName()] = $field_definition
->getLabel();
}
}
$row['email_field'] = [
'#type' => 'select',
'#title_display' => 'invisible',
'#empty_option' => $this
->t('- Disable -'),
'#empty_value' => NULL,
'#options' => $field_options,
'#default_value' => $contact_type
->getCourierEmailField(),
];
$form['table'][$contact_type
->id()] = $row;
}
return $form;
}