public static function CourseObjectNode::context in Course 8.2
Same name and namespace in other branches
- 8.3 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::context()
- 3.x modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::context()
Course context handler callback.
Overrides CourseObject::context
File
- modules/
course_content/ src/ Course/ Object/ CourseObjectNode.php, line 26
Class
- CourseObjectNode
- A course object that uses a node as a base.
Namespace
Drupal\course_content\Course\ObjectCode
public static function context() {
$route_match = Drupal::routeMatch();
if ($route_match
->getRouteName() == 'entity.node.canonical') {
$node = $route_match
->getParameter('node');
$type = NodeType::load($node
->bundle());
if ($type
->getThirdPartySetting('course_content', 'use')) {
if ($courseObject = course_get_course_object('content', $node
->id())) {
return array(
'object_type' => 'content',
'instance' => $node
->id(),
);
}
}
// This node might not be in a course, so let's check for related nodes.
$instances = static::getNodeInstances($node);
if (!empty($instances)) {
$node = \Drupal\node\Entity\Node::load($instances[0]);
// @todo this breaks 'content', need to figure this out
if ($courseObject = course_get_course_object($node
->bundle(), $node
->id())) {
return array(
'object_type' => $node
->bundle(),
'instance' => $node
->id(),
);
}
}
}
}