Commit 05460f77 authored by catch's avatar catch
Browse files

fix: #3557135 Calling...

fix: #3557135 Calling \Drupal\Core\Entity\EntityTypeBundleInfo::getBundleInfo() with a NULL causes a deprecation in PHP 8.5

By: @alexpott
By: @smustgrave
(cherry picked from commit 8443c9a5)
parent 06d7aaad
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -76,7 +76,11 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Lan
  /**
   * {@inheritdoc}
   */
  public function getBundleInfo($entity_type_id) {
  public function getBundleInfo(/* string */ $entity_type_id) {
    if (!is_string($entity_type_id)) {
      @trigger_error('Calling ' . __CLASS__ . '::getBundleInfo() with a non-string $entity_type_id is deprecated in drupal:11.3.0 and throws an exception in drupal:12.0.0. See https://www.drupal.org/node/3557136', E_USER_DEPRECATED);
      return [];
    }
    $bundle_info = $this->getAllBundleInfo();
    return $bundle_info[$entity_type_id] ?? [];
  }
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public function getAllBundleInfo();
   *   The inner arrays are associative arrays of bundle information, such as
   *   the label for the bundle.
   */
  public function getBundleInfo($entity_type_id);
  public function getBundleInfo(/* string */ $entity_type_id);

  /**
   * Gets an array of bundle labels for an entity type.
+1 −1
Original line number Diff line number Diff line
@@ -637,7 +637,7 @@ protected function rowStyleOptions() {
  protected function buildFilters(&$form, FormStateInterface $form_state) {
    \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');

    $bundles = $this->bundleInfoService->getBundleInfo($this->entityTypeId);
    $bundles = isset($this->entityTypeId) ? $this->bundleInfoService->getBundleInfo($this->entityTypeId) : [];
    // If the current base table support bundles and has more than one (like
    // user).
    if (!empty($bundles) && $this->entityType && $this->entityType->hasKey('bundle')) {
+13 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -343,6 +344,18 @@ public function testGetBundleLabels(string $entity_type_id, array $expected): vo
    $this->assertSame($expected, $this->entityTypeBundleInfo->getBundleLabels($entity_type_id));
  }

  /**
   * Tests calling getBundleInfo() method with a NULL.
   *
   * @legacy-covers ::getBundleInfo
   */
  #[IgnoreDeprecations]
  public function testGetBundleInfoWithNull(): void {
    $this->expectDeprecation('Calling Drupal\Core\Entity\EntityTypeBundleInfo::getBundleInfo() with a non-string $entity_type_id is deprecated in drupal:11.3.0 and throws an exception in drupal:12.0.0. See https://www.drupal.org/node/3557136');
    $bundle_info = $this->entityTypeBundleInfo->getBundleInfo(NULL);
    $this->assertSame([], $bundle_info);
  }

  /**
   * Provides test data for testGetBundleLabels().
   *