You are here

fraction.module in Fraction 2.x

Same filename and directory in other branches
  1. 8 fraction.module
  2. 7 fraction.module

Fraction module code.

File

fraction.module
View source
<?php

/**
 * @file
 * Fraction module code.
 */
use Drupal\fraction\Fraction;
use Drupal\Core\Routing\RouteMatchInterface;

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

    // Main module help for the fraction module.
    case 'help.page.fraction':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provides a field for storing decimals as fractions, for maximum precision.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Fraction factory function.
 *
 * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the
 * static \Drupal\fraction\Fraction instead.
 *
 * @param $numerator
 *   The fraction's numerator.
 * @param $denominator
 *   The fraction's denominator.
 *
 * @return \Drupal\fraction\Fraction
 *   Returns a new fraction object.
 */
function fraction($numerator = 0, $denominator = 1) {
  return new Fraction($numerator, $denominator);
}

/**
 * Convert a decimal value into a fraction object.
 *
 * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use the
 * static \Drupal\fraction\Fraction::createFromDecimal() instead.
 *
 * @param $value
 *   The decimal value to be converted.
 *
 * @return \Drupal\fraction\Fraction
 *   Returns a new fraction object.
 */
function fraction_from_decimal($value) {
  return Fraction::createFromDecimal($value);
}

Functions

Namesort descending Description
fraction Deprecated Fraction factory function.
fraction_from_decimal Deprecated Convert a decimal value into a fraction object.
fraction_help Implements hook_help().