learnosity-1.0.x-dev/learnosity.module

learnosity.module
<?php

use Drupal\Core\Form\FormStateInterface;
use Drupal\learnosity\Form\LearnosityNodeTypeForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\learnosity\LearnosityItemsInlineHandler;

/**
 * @file
 * Contains learnosity.module.
 */

/**
 * Implements hook_theme().
 */
function learnosity_theme() {
  return [
    'learnosity_assessment_item' => [
      'render element' => 'element',
    ],
    'learnosity_activity_editor' => [
      'render element' => 'element',
    ],
    'learnosity_reports_item' => [
      'render element' => 'element',
    ],
  ];
}

/**
 * Implements hook_library_info_build().
 */
function learnosity_library_info_build() {
  // This registers learnosity library items based on the endpoints defined in
  // learnosity.services.yml.
  $libraries = [];
  $sdk = \Drupal::service('learnosity.sdk');
  $endpoints = $sdk->getApiLibraries();
  foreach ($endpoints as $key => $url) {
    $libraries['api.' . $key] = [
      'js' => [
        $url . '/?' . $sdk->getApiVersion() => [
          'type' => 'external',
          'attributes' => ['async' => TRUE],
        ],
      ],
    ];
  }

  return $libraries;
}

/**
 * Implements hook_form_FORM_ID_alter() for node_type_form().
 */
function learnosity_form_node_type_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  return \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(LearnosityNodeTypeForm::class)
    ->formAlter($form, $form_state);
}

/**
 * Implements hook_node_view_alter().
 */
function learnosity_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
  return \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(LearnosityItemsInlineHandler::class)
    ->nodeViewAlter($build, $node, $display);
}

/**
 * Implements hook_cron().
 */
function learnosity_cron() {
  // Prune expired sessions.
  \Drupal::service('learnosity.session_handler')->prune();
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc