You are here

public function CourseEnrollmentCreateAction::execute in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Action/CourseEnrollmentCreateAction.php \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction::execute()
  2. 8.2 src/Plugin/Action/CourseEnrollmentCreateAction.php \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction::execute()

Executes the plugin.

Overrides ExecutableInterface::execute

File

src/Plugin/Action/CourseEnrollmentCreateAction.php, line 28

Class

CourseEnrollmentCreateAction
Action description.

Namespace

Drupal\course\Plugin\Action

Code

public function execute($entity = NULL) {

  /* @var $url Drupal\Core\Url */
  $url = $this->context['redirect_url'];
  $cid = $url
    ->getRouteParameters()['course'];
  $course = Course::load($cid);
  $course
    ->enroll($entity, [
    'enrollmenttype' => 'bulk',
  ]);
  $username = Markup::create($entity
    ->label());
  $course_title = Markup::create($course
    ->label());
  return $this
    ->t('Enrolled @name in @course.', [
    '@name' => $username,
    '@course' => $course_title,
  ]);
}