Skip to content
Snippets Groups Projects

Native preview

Merged oierbravo requested to merge native-preview into 1.1.x
Files
5
@@ -3,6 +3,7 @@
namespace Drupal\static_export_data_resolver_graphql\Plugin\static_export\Data\IncludeLoader;
use Drupal\static_export\Exporter\Data\Includes\Loader\DataIncludeLoaderPluginBase;
use Exception;
/**
* Provides a JSON data include loader for data coming from GraphQL.
@@ -18,6 +19,25 @@ class JsonGraphqlDataIncludeLoader extends DataIncludeLoaderPluginBase {
protected const REGEXP_PATTERN = '/"([^"]*(entity|config|locale|custom))Include":"([^"]+)"/i';
/**
* {@inheritdoc}
*
* Check if data is pretty printed, with multiple line breaks. If true,
* re-encode it without pretty-printing it.
*/
protected function sanitizeData(string $data): string {
if (substr_count($data, "\n") > 1) {
try {
$dataArray = json_decode($data, TRUE, 512, JSON_THROW_ON_ERROR);
$data = json_encode($dataArray, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
catch (Exception $e) {
@trigger_error('Error while sanitizing data in JSON GraphQL data include loader: ' . $e->getMessage(), E_USER_WARNING);
}
}
return $data;
}
/**
* {@inheritdoc}
*/
Loading