You are here

function legal_version in Legal 8

Same name and namespace in other branches
  1. 6.8 legal.admin.inc \legal_version()
  2. 7.2 legal.admin.inc \legal_version()
  3. 7 legal.admin.inc \legal_version()
  4. 2.0.x legal.module \legal_version()

Determine version ID of next T&C.

Parameters

string $version_handling: Specify if a new 'version' or 'revision' ID should be returned.

string $language: Language of T&C.

Return value

array Array with next 'version' and 'revision'.

2 calls to legal_version()
LegalAdminTermsForm::submitForm in src/Form/LegalAdminTermsForm.php
Form submission handler.
LegalTestBase::setUp in tests/src/Functional/LegalTestBase.php

File

./legal.module, line 808
Module file for Legal.

Code

function legal_version($version_handling, $language) {
  $versioning = NULL;
  $version = (int) \Drupal::database()
    ->select('legal_conditions', 'lc')
    ->fields('lc', [
    'version',
  ])
    ->orderBy('version', 'desc')
    ->range(0, 1)
    ->execute()
    ->fetchField();

  // Make new version.
  if ($version_handling == 'version') {
    $versioning['version'] = empty($version) ? 1 : $version + 1;
    $versioning['revision'] = 1;
  }

  // Make new revision.
  if ($version_handling == 'revision') {
    $revision = \Drupal::database()
      ->select('legal_conditions', 'lc')
      ->fields('lc', [
      'revision',
    ])
      ->condition('version', $version)
      ->condition('language', $language)
      ->orderBy('revision', 'DESC')
      ->execute()
      ->fetchField();
    $versioning['version'] = empty($version) ? 1 : $version;
    $versioning['revision'] = empty($revision) ? 1 : $revision + 1;
  }
  return $versioning;
}