public static function CourseObjectNode::context in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::context()
- 8.2 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 30
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 = 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(),
);
}
}
}
}