You are here

public function ContentTypeCourse::getFormObject in Opigno course 8

Same name and namespace in other branches
  1. 3.x src/Plugin/OpignoGroupManagerContentType/ContentTypeCourse.php \Drupal\opigno_course\Plugin\OpignoGroupManagerContentType\ContentTypeCourse::getFormObject()

Get the form object based on the entity ID.

If no entity given in parameter, return the entity creation form object.

Parameters

int $entity_id: The entity ID.

Return value

\Drupal\Core\Entity\EntityFormInterface Form.

Overrides ContentTypeInterface::getFormObject

File

src/Plugin/OpignoGroupManagerContentType/ContentTypeCourse.php, line 294

Class

ContentTypeCourse
Class ContentTypeCourse.

Namespace

Drupal\opigno_course\Plugin\OpignoGroupManagerContentType

Code

public function getFormObject($entity_id = NULL) {
  if (empty($entity_id)) {
    $form = \Drupal::entityTypeManager()
      ->getFormObject($this
      ->getEntityType(), 'add');
    $entity = Group::create([
      'type' => 'opigno_course',
    ]);
  }
  else {
    $form = \Drupal::entityTypeManager()
      ->getFormObject($this
      ->getEntityType(), 'edit');
    $entity = Group::load($entity_id);
  }
  $form
    ->setEntity($entity);
  return $form;
}