public function OpignoGroupManagerController::getItemForm in Opigno group manager 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoGroupManagerController.php \Drupal\opigno_group_manager\Controller\OpignoGroupManagerController::getItemForm()
Method called when the LP manager needs a create or edit form.
1 string reference to 'OpignoGroupManagerController::getItemForm'
File
- src/
Controller/ OpignoGroupManagerController.php, line 162
Class
- OpignoGroupManagerController
- Controller for all the actions of the Opigno group manager app.
Namespace
Drupal\opigno_group_manager\ControllerCode
public function getItemForm(Group $group, $type = NULL, $item = 0) {
// Get the good form from the corresponding content type.
$content_type = $this->content_types_manager
->createInstance($type);
$form = $content_type
->getFormObject($item);
if ($type === 'ContentTypeModule' && $item !== NULL && ($module = OpignoModule::load($item)) !== NULL) {
/** @var \Drupal\opigno_module\Entity\OpignoModuleInterface $module */
if (!$module
->access('update')) {
throw new AccessDeniedHttpException();
}
}
elseif ($type === 'ContentTypeCourse' && $item !== NULL && ($group = Group::load($item)) !== NULL) {
/** @var \Drupal\group\Entity\GroupInterface $group */
if (!$group
->access('update')) {
throw new AccessDeniedHttpException();
}
}
// Add parent learning path id to the form
// in the case if current group is a course.
$keys = \Drupal::request()->query
->keys();
if ($keys && in_array('learning_path', $keys)) {
$learning_path = \Drupal::request()->query
->get('learning_path');
}
// Adds some information used
// in the method opigno_learning_path_form_alter().
$form_build = \Drupal::formBuilder()
->getForm($form, [
'opigno_group_info' => [
'group_id' => $group ? $group
->id() : NULL,
'opigno_group_content_type' => $type,
'learning_path' => isset($learning_path) ? $learning_path : NULL,
],
]);
// Returns the form.
return $form_build;
}