function _makemeeting_answer_element in Make Meeting Scheduler 7.2
Helper function to provide an answer form element
Parameters
$form: Form to be modified
$item: Item providing settings for the answer form
$id: Suggestion id
\DateTime $originalDate: Suggestion date
$text: Suggestion text
array $answers: Already submitted answers
null $answer: Answer being edited
1 call to _makemeeting_answer_element()
- makemeeting_answers_form in ./
makemeeting.form.inc - Form callback: enables users to answer a makemeeting poll
File
- ./
makemeeting.form.inc, line 231
Code
function _makemeeting_answer_element(&$form, $item, $id, $originalDate, $text, $answers = [], $answer = NULL) {
$key = $originalDate
->format('d-m-Y') . ':' . $id;
// If the limit is reached for this option, display a markup text
if ($item['limit'] > 0 && isset($answers[$key]) && $answers[$key] >= $item['limit']) {
$form['answers'][$key] = [
'#markup' => t('Unavailable'),
];
}
else {
// Try to convert the hour to convert timezone
$dateToParse = $originalDate
->format('d-m-Y') . ' ' . $text;
$tz = new DateTimeZone($item['timezone']);
$userTz = new DateTimeZone(drupal_get_user_timezone());
if ($date = DateTime::createFromFormat('d-m-Y H\\h', $dateToParse, $tz)) {
$title = $date
->setTimezone($userTz)
->format('l j F Y H\\h');
}
elseif ($date = DateTime::createFromFormat('d-m-Y H:i', $dateToParse, $tz)) {
$title = $date
->setTimezone($userTz)
->format('l j F Y H:i');
}
elseif ($date = DateTime::createFromFormat('d-m-Y H a', $dateToParse, $tz)) {
$title = $date
->setTimezone($userTz)
->format('l j F Y H a');
}
else {
$title = $originalDate
->format('l j F Y') . ' ' . $text;
}
$form['answers'][$key] = [
'#type' => $item['one_option'] ? 'radio' : ($item['yesnomaybe'] ? 'radios' : 'checkbox'),
'#attributes' => [
'title' => check_plain($title),
],
'#parents' => [
'answers',
$key,
],
];
if ($item['one_option']) {
$form['answers'][$key]['#parents'] = [
'answers',
];
$form['answers'][$key]['#return_value'] = $key;
}
else {
$form['answers'][$key]['#options'] = _makemeeting_options($item['yesnomaybe']);
}
if ($item['yesnomaybe']) {
$form['answers'][$key]['#default_value'] = MAKEMEETING_NO;
}
// Display previous choice if answer is being edited
if ($answer && !empty($answer->value[$key])) {
$form['answers'][$key]['#default_value'] = $answer->value[$key];
}
}
}