You are here

course_poll.module in Course 3.x

File

modules/course_poll/course_poll.module
View source
<?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_course_handlers().
 */
function course_poll_course_handlers() {
  return array(
    'object' => array(
      'poll' => array(
        'name' => t('Poll'),
        'class' => 'Drupal\\course_poll\\Course\\Object\\CourseObjectPoll',
        'fulfillment class' => 'Drupal\\course_poll\\Course\\Object\\CourseObjectPollFulfillment',
        'description' => t('A poll to be used in a course workflow.'),
      ),
    ),
  );
}

/**
 * Implements hook_form_FORMID_alter().
 */
function course_poll_form_poll_view_form_alter(&$form, FormStateInterface $form_state) {
  $form['actions']['vote']['#submit'][] = 'course_poll_fulfill';

  // Unset ajax so that the next step button appears,until we can make a better
  // way of signalling fulfillment completion.
  unset($form['actions']['vote']['#ajax']);
}

/**
 * Fulfill the voting object.
 */
function course_poll_fulfill($form, FormStateInterface $form_state) {
  $account = \Drupal::currentUser();

  // Find the course object associated with this poll.
  if ($courseObject = course_get_course_object('poll', $form['#entity']
    ->id())) {
    $courseObject
      ->getFulfillment($account)
      ->setOption('instance', $form_state
      ->getValue('choice'))
      ->setComplete()
      ->save();
  }
}

Functions

Namesort descending Description
course_poll_course_handlers Implements hook_course_handlers().
course_poll_form_poll_view_form_alter Implements hook_form_FORMID_alter().
course_poll_fulfill Fulfill the voting object.