CourseObjectManual.php in Course 8.3
File
modules/course_object_manual/src/Plugin/course/CourseObject/CourseObjectManual.php
View source
<?php
namespace Drupal\course_object_manual\Plugin\course\CourseObject;
use Drupal;
use Drupal\course\Entity\CourseObject;
class CourseObjectManual extends CourseObject {
public function take() {
return [
'#plain_text' => $this
->getStatus(),
];
}
public function getStatus() {
$user = Drupal::currentUser();
$config = $this
->getOptions();
if ($this
->getFulfillment($user)
->isComplete()) {
return t($config['complete_msg']);
}
elseif ($this
->getFulfillment($user)
->getGrade() == '') {
return $config['incomplete_msg'];
}
else {
return $config['failed_msg'];
}
}
public function optionsDefinition() {
$defaults = parent::optionsDefinition();
$defaults['complete_msg'] = 'Your instructor has marked you as passed.';
$defaults['incomplete_msg'] = 'Your instructor has not given you a pass/fail grade yet.';
$defaults['failed_msg'] = 'Your instructor has marked you as failed.';
return $defaults;
}
public function optionsForm(&$form, &$form_state) {
parent::optionsForm($form, $form_state);
$config = $this
->getOptions();
$form['complete_msg'] = array(
'#type' => 'textfield',
'#title' => t('Complete message'),
'#default_value' => $config['complete_msg'],
);
$form['failed_msg'] = array(
'#type' => 'textfield',
'#title' => t('Failed message'),
'#default_value' => $config['failed_msg'],
);
$form['incomplete_msg'] = array(
'#type' => 'textfield',
'#title' => t('Incomplete message'),
'#default_value' => $config['incomplete_msg'],
);
}
}
Classes
Name |
Description |
CourseObjectManual |
Plugin annotation
@CourseObject(
id = "manual",
label = "Manual step",
handlers = {
"fulfillment" = "\Drupal\course\Entity\CourseObjectFulfillment"
}
) |