-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for legacy deprecations. (#12)
- Loading branch information
Alex Skrypnyk
authored
Dec 6, 2019
1 parent
6c80287
commit b4f353e
Showing
9 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Drupal\minisite; | ||
|
||
use Drupal\Core\File\FileSystem; | ||
use Drupal\Core\StreamWrapper\StreamWrapperManager; | ||
|
||
/** | ||
* Class LegacyWrapper. | ||
* | ||
* Helper class to resolve compatibility between Drupal core versions. | ||
* | ||
* @todo: Remove this file once 8.7.x is no longer supported. | ||
* | ||
* @package Drupal\minisite | ||
*/ | ||
class LegacyWrapper { | ||
|
||
/** | ||
* Finds all files that match a given mask in a given directory. | ||
* | ||
* @throws \RuntimeException | ||
* If compatible function is not found. | ||
*/ | ||
public static function scanDirectory($dir, $mask, array $options = []) { | ||
if (method_exists(FileSystem::class, 'scanDirectory')) { | ||
/** @var \Drupal\Core\File\FileSystemInterface $fs */ | ||
$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'); | ||
} | ||
|
||
/** | ||
* Determines whether the URI has a valid scheme for file API operations. | ||
* | ||
* @throws \RuntimeException | ||
* If compatible function is not found. | ||
*/ | ||
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'); | ||
} | ||
|
||
/** | ||
* Returns the entity view display associated with a bundle and view mode. | ||
* | ||
* @throws \RuntimeException | ||
* If compatible function is not found. | ||
*/ | ||
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'); | ||
} | ||
|
||
/** | ||
* Returns the entity form display associated with a bundle and form mode. | ||
* | ||
* @throws \RuntimeException | ||
* If compatible function is not found. | ||
*/ | ||
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters