public function OpignoLearningPathTakeLink::render in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/Plugin/views/field/OpignoLearningPathTakeLink.php \Drupal\opigno_learning_path\Plugin\views\field\OpignoLearningPathTakeLink::render()
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
File
- src/
Plugin/ views/ field/ OpignoLearningPathTakeLink.php, line 29
Class
- OpignoLearningPathTakeLink
- Field handler to output boolean indication of current user membership.
Namespace
Drupal\opigno_learning_path\Plugin\views\fieldCode
public function render(ResultRow $values) {
$account = \Drupal::currentUser();
// Get an entity object.
$learnign_path = $values->_entity;
$bundle = $learnign_path
->getGroupType()
->id();
$group_progress = LPResult::learningPathUserProgress($learnign_path, $account
->id());
if ($group_progress > 0) {
$link_text = $this
->t('Continue');
}
else {
$link_text = $this
->t('Start');
}
// Take the bundle and build the take link.
if ($bundle == 'learning_path') {
return Link::createFromRoute($link_text, 'opigno_learning_path.steps.start', [
'group' => $learnign_path
->id(),
], [
'attributes' => [
'class' => [
'use-ajax',
],
],
])
->toString();
}
else {
return '';
}
}