public static function EventTypeFieldMappingForm::createField in RNG - Events and Registrations 8.2
Same name and namespace in other branches
- 8 src/Form/EventTypeFieldMappingForm.php \Drupal\rng\Form\EventTypeFieldMappingForm::createField()
- 3.x src/Form/EventTypeFieldMappingForm.php \Drupal\rng\Form\EventTypeFieldMappingForm::createField()
Form submission function to respond to the create field button.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- src/
Form/ EventTypeFieldMappingForm.php, line 88
Class
- EventTypeFieldMappingForm
- Form for event type field mapping.
Namespace
Drupal\rng\FormCode
public static function createField(array $form, FormStateInterface $form_state) {
/** @var \Drupal\rng\Entity\EventTypeInterface $event_type */
$event_type = $form_state
->getFormObject()
->getEntity();
$trigger = $form_state
->getTriggeringElement();
$field_name = $trigger['#rng_field_name'];
$entity_type = $event_type
->getEventEntityTypeId();
$bundle = $event_type
->getEventBundle();
// Create the field.
rng_add_event_field_storage($field_name, $entity_type);
$field_config = rng_add_event_field_config($field_name, $entity_type, $bundle);
drupal_set_message(t('Field %field_name added.', [
'%field_name' => $field_config
->label(),
]));
// Make the field visible on the edit form.
$display = entity_get_form_display($entity_type, $bundle, 'rng_event');
rng_add_event_form_display_defaults($display, $field_name);
$component = $display
->getComponent($field_name);
$component['weight'] = 9999;
$display
->setComponent($field_name, $component);
$display
->save();
}