[UTIL][FormFields] Allow specifying a null actor in the language field, for when there isn't a logged in user

This commit is contained in:
Hugo Sales 2021-12-11 22:18:31 +00:00
parent 6b38972cca
commit e62896b84e
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 6 additions and 3 deletions

View File

@ -150,9 +150,12 @@ class Language extends Entity
* Get all the available languages as well as the languages $actor * Get all the available languages as well as the languages $actor
* prefers and are appropriate for posting in/to $context_actor * prefers and are appropriate for posting in/to $context_actor
*/ */
public static function getSortedLanguageChoices(Actor $actor, ?Actor $context_actor, ?bool $use_short_display): array public static function getSortedLanguageChoices(?Actor $actor, ?Actor $context_actor, ?bool $use_short_display): array
{ {
$language_choices = self::getLanguageChoices(); $language_choices = self::getLanguageChoices();
if (\is_null($actor)) {
return [$language_choices, []];
}
$preferred_language_choices = $actor->getPreferredLanguageChoices($context_actor); $preferred_language_choices = $actor->getPreferredLanguageChoices($context_actor);
ksort($language_choices); ksort($language_choices);
if ($use_short_display ?? Common::config('posting', 'use_short_language_display')) { if ($use_short_display ?? Common::config('posting', 'use_short_language_display')) {

View File

@ -80,7 +80,7 @@ abstract class FormFields
/** /**
* Create a from field for `select`ing a language for $actor, in reply or related to $context_actor * Create a from field for `select`ing a language for $actor, in reply or related to $context_actor
*/ */
public static function language(Actor $actor, ?Actor $context_actor, string $label, ?string $help = null, bool $multiple = false, bool $required = true, ?bool $use_short_display = null, ?string $form_id = null, bool $use_no_selection = false): array public static function language(?Actor $actor, ?Actor $context_actor, string $label, ?string $help = null, bool $multiple = false, bool $required = true, ?bool $use_short_display = null, ?string $form_id = null, bool $use_no_selection = false): array
{ {
[$language_choices, $preferred_language_choices] = Language::getSortedLanguageChoices($actor, $context_actor, use_short_display: $use_short_display); [$language_choices, $preferred_language_choices] = Language::getSortedLanguageChoices($actor, $context_actor, use_short_display: $use_short_display);
if ($use_no_selection) { if ($use_no_selection) {