You are here

AdminHelper.php in moderated content bulk publish 8

Same filename and directory in other branches
  1. 2.0.x src/AdminHelper.php
  2. 1.0.x src/AdminHelper.php

File

src/AdminHelper.php
View source
<?php

namespace Drupal\moderated_content_bulk_publish;

class AdminHelper {
  public static function addMessage($message) {
    \Drupal::messenger()
      ->addMessage($message);
  }
  public static function addToLog($message, $DEBUG = FALSE) {

    //$DEBUG = TRUE;
    if ($DEBUG) {
      \Drupal::logger('moderated_content_bulk_publish')
        ->notice($message);
    }
  }

  /**
   * Helper function to get all enabled languages, excluding current language.
   */
  public static function getOtherEnabledLanguages() {

    // Get the list of all languages
    $language = \Drupal::languageManager()
      ->getCurrentLanguage();
    $languages = \Drupal::languageManager()
      ->getLanguages();
    $other_languages = array();

    // Add each enabled language, aside from the current language to an array.
    foreach ($languages as $field_language_code => $field_language) {
      if ($field_language_code != $language
        ->getId()) {
        $other_languages[$field_language_code] = $field_language
          ->getName();
      }
    }
    return $other_languages;
  }

  /**
   * Helper function get current language.
   */
  public static function getDefaultLangcode() {
    $language = \Drupal::languageManager()
      ->getDefaultLanguage();
    return $language
      ->getId();
  }

  /**
   * Helper function to get all enabled languages, including the current language.
   */
  public static function getAllEnabledLanguages() {

    // Get the list of all languages
    $language = \Drupal::languageManager()
      ->getCurrentLanguage();
    $languages = \Drupal::languageManager()
      ->getLanguages();
    $other_languages = array();

    // Add each enabled language, aside from the current language to an array.
    foreach ($languages as $field_language_code => $field_language) {
      $other_languages[$field_language_code] = $field_language
        ->getName();
    }
    return $other_languages;
  }

}

Classes

Namesort descending Description
AdminHelper