SelectLanguage.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class SelectLanguage
  5. * A dropdownlist with all languages to use with QuickForm.
  6. */
  7. class SelectLanguage extends HTML_QuickForm_select
  8. {
  9. /**
  10. * Class constructor.
  11. */
  12. public function __construct(
  13. $elementName = null,
  14. $elementLabel = null,
  15. $options = [],
  16. $attributes = []
  17. ) {
  18. parent::__construct($elementName, $elementLabel, $options, $attributes);
  19. $default = isset($attributes['set_custom_default']) ? $attributes['set_custom_default'] : false;
  20. // Get all languages
  21. $languages = api_get_languages();
  22. foreach ($languages['name'] as $index => $name) {
  23. if (!empty($default)) {
  24. $defaultValue = $default;
  25. } else {
  26. $defaultValue = api_get_setting('platformLanguage');
  27. }
  28. if ($languages['folder'][$index] == $defaultValue) {
  29. $this->addOption($name, $languages['folder'][$index], ['selected' => 'selected']);
  30. } else {
  31. $this->addOption($name, $languages['folder'][$index]);
  32. }
  33. }
  34. }
  35. }