-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for geometry fields in CSV exports
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
modules/core/csv/src/Normalizer/GeofieldItemNormalizer.php
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,39 @@ | ||
<?php | ||
|
||
namespace Drupal\farm_csv\Normalizer; | ||
|
||
use Drupal\geofield\Plugin\Field\FieldType\GeofieldItem; | ||
use Drupal\serialization\Normalizer\FieldItemNormalizer; | ||
|
||
/** | ||
* Normalizes Geofields for farmOS CSV exports. | ||
*/ | ||
class GeofieldItemNormalizer extends FieldItemNormalizer { | ||
|
||
/** | ||
* The supported format. | ||
*/ | ||
const FORMAT = 'csv'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL { | ||
$data = parent::normalize($object, $format, $context); | ||
|
||
// Return the WKT value, if desired. | ||
if (isset($context['wkt']) && $context['wkt'] === TRUE) { | ||
return $data['value']; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsNormalization($data, ?string $format = NULL, array $context = []): bool { | ||
return $data instanceof GeofieldItem && $format == static::FORMAT; | ||
} | ||
|
||
} |
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