function advpoll_modules_installed in Advanced Poll 8
Implements hook_modules_installed().
File
- ./
advpoll.module, line 10
Code
function advpoll_modules_installed($modules) {
// Necessary to do this since it can't be done in config and field config needs to have been installed first.
// using https://www.drupal.org/docs/8/api/update-api/updating-entities-and-fields-in-drupal-8 example as guide
$form_display_storage = \Drupal::entityTypeManager()
->getStorage('entity_form_display');
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = $form_display_storage
->load('poll.poll.default');
if (empty($form_display)) {
$form_display = $form_display_storage
->create([
'targetEntityType' => 'poll',
'bundle' => 'poll',
'mode' => 'default',
'status' => TRUE,
]);
}
$form_display
->setComponent('field_poll_type', [
'type' => 'options_select',
'weight' => 1,
'region' => 'content',
]);
$form_display
->save();
$form_display
->setComponent('field_writein', [
'type' => 'boolean_checkbox',
'weight' => 2,
'settings' => [
'display_label' => TRUE,
],
'region' => 'content',
]);
$form_display
->save();
$form_display
->setComponent('field_writein_multiple', [
'type' => 'boolean_checkbox',
'weight' => 2,
'settings' => [
'display_label' => TRUE,
],
'region' => 'content',
]);
$form_display
->save();
$form_display
->setComponent('field_number_of_votes', [
'type' => 'number',
'weight' => 3,
'region' => 'content',
]);
$form_display
->save();
$form_display
->setComponent('field_start_date', [
'type' => 'datetime_default',
'weight' => 4,
'region' => 'content',
]);
$form_display
->save();
}