public function MeetingForm::buildForm in Opigno Moxtra 3.x
Same name and namespace in other branches
- 8 src/Form/MeetingForm.php \Drupal\opigno_moxtra\Form\MeetingForm::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/ MeetingForm.php, line 83
Class
- MeetingForm
- Provides a form for creating/editing a opigno_moxtra_meeting entity.
Namespace
Drupal\opigno_moxtra\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
/** @var \Drupal\opigno_moxtra\MeetingInterface $entity */
$entity = $this->entity;
$owner_id = $entity
->getOwnerId();
$session_key = $entity
->getSessionKey();
if (!empty($session_key)) {
$info = $this->moxtraService
->getMeetingInfo($owner_id, $session_key);
$status = !empty($info['data']) ? $info['data']['status'] : FALSE;
if (!empty($status) && $status !== 'SESSION_SCHEDULED') {
$form[] = [
'#markup' => $this
->t('You can edit only a scheduled live meeting.'),
];
return $form;
}
}
if ($entity
->getTraining() === NULL) {
$group = $this
->getRequest()
->get('group');
if ($group !== NULL) {
$group_type = $group
->getGroupType()
->id();
if ($group_type === 'learning_path') {
// If creating entity on a group page, set that group as a related.
$entity
->setTraining($group);
}
}
}
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#default_value' => $entity
->label(),
'#required' => TRUE,
];
$date_field_def = $entity
->getFieldDefinition('date');
$date_field_item_list = $entity
->get('date');
$date_range_plugin_id = 'opigno_daterange';
$date_range = new OpignoDateRangeWidget($date_range_plugin_id, $this->pluginManager
->getDefinition($date_range_plugin_id), $date_field_def, array_merge(OpignoDateRangeWidget::defaultSettings(), [
'value_format' => 'Y-m-d H:i:s',
'value_timezone' => date_default_timezone_get(),
]), [], $this->entityTypeManager
->getStorage('date_format'));
$form['date'] = $date_range
->form($date_field_item_list, $form, $form_state);
$training = $entity
->getTraining();
if ($training !== NULL) {
$options = [];
$members = $entity
->getMembers();
foreach ($members as $member) {
$options['user_' . $member
->id()] = $this
->t("@name (User #@id)", [
'@name' => $member
->getDisplayName(),
'@id' => $member
->id(),
]);
}
$form['members'] = [
'#title' => $this
->t('Members restriction'),
'#type' => 'entity_selector',
'#attributes' => [
'id' => 'meeting_members',
'class' => [
'row',
],
],
'#default_value' => array_keys($options),
'#entity_selector_option' => '\\Drupal\\opigno_moxtra\\Controller\\MeetingController::membersAutocompleteSelect',
'#entity_selector_parameters' => [
'group' => $training,
],
'#multiple' => TRUE,
'#data_type' => 'key',
'#options' => [],
'#show_exists' => TRUE,
'#validated' => TRUE,
];
}
else {
$form['members'] = [
'#markup' => $this
->t('Live Meeting should have a related training to add a members restriction.'),
];
}
$form['status_messages'] = [
'#type' => 'status_messages',
];
// $form['#attached']['library'][] = 'multiselect/drupal.multiselect';
$form['#attached']['library'][] = 'opigno_moxtra/meeting_form';
return $form;
}