CourseEnrollmentEntityForm.php in Course 3.x
Namespace
Drupal\course\FormFile
src/Form/CourseEnrollmentEntityForm.phpView source
<?php
namespace Drupal\course\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\ContentEntityForm;
class CourseEnrollmentEntityForm extends ContentEntityForm {
/**
* Update the timestamp on submission by user.
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$account = \Drupal::currentUser();
if ($account
->id() == $this->entity
->getUser()
->id()) {
// Only update start time if this belongs to the current user.
if ($this->entity
->get('timestamp')
->isEmpty()) {
\Drupal::messenger()
->addStatus(t('Your enrollment in this course has been recorded.'));
}
$this->entity
->set('timestamp', \Drupal::time()
->getRequestTime());
}
}
}
Classes
Name | Description |
---|---|
CourseEnrollmentEntityForm |