function advpoll_form_poll_edit_form_alter in Advanced Poll 8
Implements hook_form_FORM_ID_alter().
File
- ./
advpoll.module, line 90
Code
function advpoll_form_poll_edit_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\poll\Entity\Poll $poll */
$poll = $form_state
->getFormObject()
->getEntity();
// Dynamic form for different poll types.
if (!empty($form['field_poll_type']['widget'])) {
// State for max number.
if (!empty($form['field_number_of_votes']['widget'][0]['value'])) {
$form['field_number_of_votes']['widget'][0]['value']['#states']['invisible'][] = [
':input[name="field_poll_type"]' => [
'value' => '_none',
],
];
if (empty($form['field_number_of_votes']['widget'][0]['value']['#default_value'])) {
$form['field_number_of_votes']['widget'][0]['value']['#default_value'] = 1;
}
}
// Validator and cleaner for hidden elements.
$form['#validate'][] = 'advpoll_form_poll_edit_form_validate';
}
}