public static function PathMapping::parsePathMapping in Gatsby Live Preview & Incremental Builds 8
Same name and namespace in other branches
- 2.0.x src/PathMapping.php \Drupal\gatsby\PathMapping::parsePathMapping()
Function to parse path mapping.
Parameters
string $path_mapping: Path mapping as a string. Each line is a mapping in format like so: {drupal_path}|{gatsby_path} e.g. /home|/.
Return value
array Array of Gatsby paths keyed by Drupal path.
4 calls to PathMapping::parsePathMapping()
- GatsbyAdminForm::validateForm in src/
Form/ GatsbyAdminForm.php - Form validation handler.
- PathMapping::getPathMapping in src/
PathMapping.php - PathMappingTest::testParsePathMapping in tests/
src/ Unit/ PathMappingTest.php - Tests GatsbyPathMapping::parsePathMapping.
- _gatsby_get_path_mapping in ./
gatsby.module - Gets an array of Gatsby Preview path mappings.
File
- src/
PathMapping.php, line 51
Class
- PathMapping
- Defines a class for mapping paths between Drupal and Gatsby.
Namespace
Drupal\gatsbyCode
public static function parsePathMapping(string $path_mapping) {
$map = [];
if (empty($path_mapping)) {
return $map;
}
$paths = explode(PHP_EOL, $path_mapping);
foreach ($paths as $path) {
if ($split = stripos($path, '|')) {
$drupal_path = substr($path, 0, $split);
$gatsby_path = substr($path, $split + 1);
if (empty($drupal_path) || empty($gatsby_path)) {
return $map;
}
if (!str_starts_with($drupal_path, '/') || !str_starts_with($gatsby_path, '/')) {
return $map;
}
$map[$drupal_path] = $gatsby_path;
}
}
return $map;
}