public function EventTypeFieldMappingForm::buildForm in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 src/Form/EventTypeFieldMappingForm.php \Drupal\rng\Form\EventTypeFieldMappingForm::buildForm()
- 8 src/Form/EventTypeFieldMappingForm.php \Drupal\rng\Form\EventTypeFieldMappingForm::buildForm()
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 EntityForm::buildForm
File
- src/
Form/ EventTypeFieldMappingForm.php, line 34
Class
- EventTypeFieldMappingForm
- Form for event type field mapping.
Namespace
Drupal\rng\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\rng\Entity\EventTypeInterface $event_type */
$event_type = $this->entity;
$form = parent::buildForm($form, $form_state);
$form['table'] = [
'#type' => 'table',
'#header' => [
$this
->t('Field name'),
$this
->t('Description'),
$this
->t('Field exists'),
$this
->t('Operations'),
],
];
module_load_include('inc', 'rng', 'rng.field.defaults');
foreach ($this->fields as $field_name) {
$row = [];
$definition = rng_event_field_config_definition($field_name);
$row['field_name']['#plain_text'] = $definition['label'];
$row['description']['#plain_text'] = isset($definition['description']) ? $definition['description'] : '';
$exists = FieldConfig::loadByName($event_type
->getEventEntityTypeId(), $event_type
->getEventBundle(), $field_name);
if ($exists) {
$row['exists']['#plain_text'] = $this
->t('Exists');
$row['operations'][] = [];
}
else {
$row['exists']['#plain_text'] = $this
->t('Does not exist');
$row['operations']['create'] = [
'#name' => 'submit-create-' . $field_name,
'#type' => 'submit',
'#rng_field_name' => $field_name,
'#value' => $this
->t('Create'),
'#submit' => [
[
static::class,
'createField',
],
],
];
}
$form['table'][$field_name] = $row;
}
return $form;
}