You are here

public function OpignoModuleManagerController::getItemForm in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Controller/OpignoModuleManagerController.php \Drupal\opigno_module\Controller\OpignoModuleManagerController::getItemForm()

Method called when the manager needs a create or edit form.

1 string reference to 'OpignoModuleManagerController::getItemForm'
opigno_module.routing.yml in ./opigno_module.routing.yml
opigno_module.routing.yml

File

src/Controller/OpignoModuleManagerController.php, line 71

Class

OpignoModuleManagerController
Controller for all the actions of the Opigno module manager.

Namespace

Drupal\opigno_module\Controller

Code

public function getItemForm(OpignoModuleInterface $opigno_module, $type = NULL, $item = 0) {

  // Get the good form from the corresponding content type.
  if ($item > 0) {
    $entity = OpignoActivity::load($item);
    if (!$entity
      ->access('update')) {
      throw new AccessDeniedHttpException();
    }
  }
  else {
    $entity = OpignoActivity::create([
      'type' => $type,
    ]);
  }

  /** @var \Drupal\Core\Entity\EntityFormBuilder $form_builder */
  $form_builder = \Drupal::service('entity.form_builder');
  $form_build = $form_builder
    ->getForm($entity, 'default');
  $form_build['#attached']['library'][] = 'opigno_module/ajax_form';

  // Returns the form.
  return $form_build;
}