You are here

protected function DateRangeDurationWidgetTest::getFormDisplay in Datetime Extras 8

Gets an entity form display via the correct method based on core version.

The entity_get_form_display() procedural function is the only way prior to drupal:8.8.0, but that method is deprecated in 8.8.0 and above.

@todo In https://www.drupal.org/node/3129008 remove this technical debt once we drop support for Drupal core version 8.7.x.

Parameters

string $entity_type_id: The entity type ID.

string $bundle_id: The entity bundle ID.

string $form_mode: Which form mode to load.

Return value

\Drupal\Core\Entity\Display\EntityFormDisplayInterface The entity form display associated with the given form mode.

File

tests/src/Functional/DateRangeDurationWidgetTest.php, line 66

Class

DateRangeDurationWidgetTest
Test the DateRangeDurationWidget for datetime_range fields.

Namespace

Drupal\Tests\datetime_extras\Functional

Code

protected function getFormDisplay($entity_type_id, $bundle_id, $form_mode) {
  if (floatval(\Drupal::VERSION) >= 8.800000000000001) {
    return \Drupal::service('entity_display.repository')
      ->getFormDisplay($entity_type_id, $bundle_id, $form_mode);
  }

  // This is fallback code for 8.7.x and below. It's not called on later
  // versions, so we don't nee to "fix" it for upgrade_status.
  // The @noRector *needs* to be in /** */ to work, but our code sniffer
  // configuration flags that as an error, so we ignore the next line. ;)
  // @codingStandardsIgnoreLine

  /** @noRector \DrupalRector\Rector\Deprecation\EntityGetFormDisplayRector */

  // @phpstan-ignore-next-line
  return entity_get_form_display($entity_type_id, $bundle_id, $form_mode);
}