From 0238fb5ebe559737459aecaca27cdf9eea3c2feb Mon Sep 17 00:00:00 2001
From: Cedric Lenders <61348-CedricL@users.noreply.drupalcode.org>
Date: Thu, 13 Mar 2025 09:17:53 +0000
Subject: [PATCH] PHP 8.4 Support: Nullable types must be explicit

---
 languagefield.module                        |  2 +-
 src/Plugin/Field/FieldType/LanguageItem.php | 10 +++++-----
 src/Plugin/Tamper/LanguageToCode.php        |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/languagefield.module b/languagefield.module
index 9439ea0..0773b89 100644
--- a/languagefield.module
+++ b/languagefield.module
@@ -33,7 +33,7 @@ function languagefield_field_formatter_info_alter(array &$info): void {
  * @see callback_allowed_values_function()
  * @see options_allowed_values()
  */
-function languagefield_allowed_values(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = TRUE): array {
+function languagefield_allowed_values(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL, &$cacheable = TRUE): array {
   $valueOptions = CustomLanguageManager::allowedValues($definition->getSettings());
   return $valueOptions;
 }
diff --git a/src/Plugin/Field/FieldType/LanguageItem.php b/src/Plugin/Field/FieldType/LanguageItem.php
index 16ae844..5d31592 100644
--- a/src/Plugin/Field/FieldType/LanguageItem.php
+++ b/src/Plugin/Field/FieldType/LanguageItem.php
@@ -297,13 +297,13 @@ class LanguageItem extends LanguageItemBase implements OptionsProviderInterface
   /**
    * {@inheritdoc}
    *
-   * @param \Drupal\Core\Session\AccountInterface $account
+   * @param \Drupal\Core\Session\AccountInterface|null $account
    *   (optional) The user account for which to filter the possible options.
    *   If omitted, all possible options are returned.
    * @param string $format
    *   Extra parameter for formatting options.
    */
-  public function getPossibleOptions(AccountInterface $account = NULL, string $format = 'en'): array {
+  public function getPossibleOptions(?AccountInterface $account = NULL, string $format = 'en'): array {
     // Caching as per https://www.drupal.org/node/2661204
     static $possible_options = [];
 
@@ -349,7 +349,7 @@ class LanguageItem extends LanguageItemBase implements OptionsProviderInterface
   /**
    * {@inheritdoc}
    */
-  public function getPossibleValues(AccountInterface $account = NULL): array {
+  public function getPossibleValues(?AccountInterface $account = NULL): array {
     $options = $this->getPossibleOptions($account);
     return array_keys($options);
   }
@@ -357,7 +357,7 @@ class LanguageItem extends LanguageItemBase implements OptionsProviderInterface
   /**
    * {@inheritdoc}
    */
-  public function getSettableValues(AccountInterface $account = NULL): array {
+  public function getSettableValues(?AccountInterface $account = NULL): array {
     $options = $this->getSettableOptions($account);
     // Remove groups from Settable Options.
     $options = OptGroup::flattenOptions($options);
@@ -367,7 +367,7 @@ class LanguageItem extends LanguageItemBase implements OptionsProviderInterface
   /**
    * {@inheritdoc}
    */
-  public function getSettableOptions(AccountInterface $account = NULL): array {
+  public function getSettableOptions(?AccountInterface $account = NULL): array {
     // Caching as per https://www.drupal.org/node/2661204
     static $settable_options;
 
diff --git a/src/Plugin/Tamper/LanguageToCode.php b/src/Plugin/Tamper/LanguageToCode.php
index c2a91fa..5122a33 100644
--- a/src/Plugin/Tamper/LanguageToCode.php
+++ b/src/Plugin/Tamper/LanguageToCode.php
@@ -41,7 +41,7 @@ class LanguageToCode extends TamperBase implements ContainerFactoryPluginInterfa
   /**
    * {@inheritdoc}
    */
-  public function tamper($data, TamperableItemInterface $item = NULL): array {
+  public function tamper($data, ?TamperableItemInterface $item = NULL): array {
     if (!is_string($data)) {
       throw new TamperException('Input should be a string.');
     }
-- 
GitLab