class CourseEnrollmentCreateAction in Course 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/Action/CourseEnrollmentCreateAction.php \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction
- 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
- class \Drupal\course\Plugin\Action\CourseEnrollmentCreateAction extends \Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase uses StringTranslationTrait
Expanded class hierarchy of CourseEnrollmentCreateAction
File
- src/
Plugin/ Action/ CourseEnrollmentCreateAction.php, line 20
Namespace
Drupal\course\Plugin\ActionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseEnrollmentCreateAction:: |
public | function | ||
CourseEnrollmentCreateAction:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |