You are here

class CourseEnrollmentCreateAction in Course 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Action/CourseEnrollmentCreateAction.php \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction
  2. 3.x src/Plugin/Action/CourseEnrollmentCreateAction.php \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction

Action description.

Plugin annotation


@Action(
  id = "course_add_enrollment_action",
  label = @Translation("Enroll user"),
  type = ""
)

Hierarchy

Expanded class hierarchy of CourseEnrollmentCreateAction

File

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

Namespace

Drupal\course\Plugin\Action
View source
class CourseEnrollmentCreateAction extends ViewsBulkOperationsActionBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  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);
    return $this
      ->t('Enrolled user.');
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    if ($object
      ->getEntityType() === 'user') {
      $access = $object
        ->access('update', $account, TRUE)
        ->andIf($object->status
        ->access('edit', $account, TRUE));
      return $return_as_object ? $access : $access
        ->isAllowed();
    }

    // Other entity types may have different
    // access methods and properties.
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CourseEnrollmentCreateAction::access public function
CourseEnrollmentCreateAction::execute public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.