You are here

opigno_course.module in Opigno course 3.x

Same filename and directory in other branches
  1. 8 opigno_course.module

File

opigno_course.module
View source
<?php

/**
 * @file
 * Contains opigno_course.module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function opigno_course_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the opigno_course module.
    case 'help.page.opigno_course':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Adds course feature to your Opigno instance.') . '</p>';
      return $output;
    default:
      return '';
  }
}

/**
 * Implements hook_form_alter().
 */
function opigno_course_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (in_array($form_id, [
    'group_opigno_course_edit_form',
    'group_opigno_course_add_form',
  ])) {
    unset($form['badge_criteria']['widget']['#options']['_none']);
    if (\Drupal::moduleHandler()
      ->moduleExists('opigno_module')) {
      $form['#attached']['library'][] = 'opigno_module/opigno_badges';
    }
  }
  $destination = \Drupal::request()
    ->get('destination', FALSE);
  if ($destination === FALSE || substr($destination, -14) != 'course-content') {
    return;
  }
  $destination_parts = explode('/', $destination);
  $destination_id = $destination_parts[3];
  if (!is_numeric($destination_id)) {
    return;
  }
}

/**
 * Implements hook_views_view_field().
 */
function opigno_course_preprocess_views_view_field(&$variables) {
  if ($variables['view']
    ->id() == 'media_browser_images_png' && $variables['field']->options['id'] == 'name') {
    $variables['bundle'] = $variables['view']->field['bundle']->original_value
      ->jsonSerialize();
  }
}

Functions

Namesort descending Description
opigno_course_form_alter Implements hook_form_alter().
opigno_course_help Implements hook_help().
opigno_course_preprocess_views_view_field Implements hook_views_view_field().