LegacyWrapper.php in Mini site 8
File
src/LegacyWrapper.php
View source
<?php
namespace Drupal\minisite;
use Drupal\Core\File\FileSystem;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
class LegacyWrapper {
public static function scanDirectory($dir, $mask, array $options = []) {
if (method_exists(FileSystem::class, 'scanDirectory')) {
$fs = \Drupal::service('file_system');
return $fs
->scanDirectory($dir, $mask, $options);
}
if (function_exists('file_scan_directory')) {
return file_scan_directory($dir, $mask, $options);
}
throw new \RuntimeException('Unable to find compatible function');
}
public static function isValidUri($uri) {
if (method_exists(StreamWrapperManager::class, 'isValidUri')) {
return \Drupal::service('stream_wrapper_manager')
->isValidUri($uri);
}
if (function_exists('file_valid_uri')) {
return file_valid_uri($uri);
}
throw new \RuntimeException('Unable to find compatible function');
}
public static function getViewDisplay($entity_type, $bundle, $view_mode) {
$dr = \Drupal::service('entity_display.repository');
if (method_exists(get_class($dr), 'getViewDisplay')) {
return $dr
->getViewDisplay($entity_type, $bundle, $view_mode);
}
if (function_exists('entity_get_display')) {
return entity_get_display($entity_type, $bundle, $view_mode);
}
throw new \RuntimeException('Unable to find compatible function');
}
public static function getFormDisplay($entity_type, $bundle, $form_mode) {
$dr = \Drupal::service('entity_display.repository');
if (method_exists(get_class($dr), 'getFormDisplay')) {
return $dr
->getFormDisplay($entity_type, $bundle, $form_mode);
}
if (function_exists('entity_get_display')) {
return entity_get_form_display($entity_type, $bundle, $form_mode);
}
throw new \RuntimeException('Unable to find compatible function');
}
public static function getTarget($uri) {
if (is_callable(StreamWrapperManager::class, 'getTarget')) {
return StreamWrapperManager::getTarget($uri);
}
if (function_exists('file_uri_target')) {
return file_uri_target($uri);
}
throw new \RuntimeException('Unable to find compatible function');
}
}