Use GeometryWrapper as type when normalizing to geometry_kml format
This commit is contained in:
parent
8f2efe2724
commit
94c9fe9ed0
|
@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\farm_geo\GeometryWrapper;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
|
@ -148,7 +149,7 @@ class KmlImporter extends FormBase {
|
|||
|
||||
// Deserialize the KML placemarks into WKT geometry.
|
||||
/** @var \Drupal\farm_geo\GeometryWrapper[] $geometries */
|
||||
$geometries = $this->serializer->deserialize($data, 'geometry_wrapper', 'geometry_kml');
|
||||
$geometries = $this->serializer->deserialize($data, GeometryWrapper::class, 'geometry_kml');
|
||||
|
||||
// Bail if no geometries were found.
|
||||
if (empty($geometries)) {
|
||||
|
|
|
@ -22,7 +22,7 @@ class KmlNormalizer implements NormalizerInterface, DenormalizerInterface {
|
|||
/**
|
||||
* The supported type to denormalize to.
|
||||
*/
|
||||
const TYPE = 'geometry_wrapper';
|
||||
const TYPE = GeometryWrapper::class;
|
||||
|
||||
/**
|
||||
* The GeoPHP service.
|
||||
|
@ -84,22 +84,7 @@ class KmlNormalizer implements NormalizerInterface, DenormalizerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = NULL) {
|
||||
|
||||
// First check if the format is supported.
|
||||
if ($format !== static::FORMAT) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Change data to an array.
|
||||
if (!is_array($data)) {
|
||||
$data = [$data];
|
||||
}
|
||||
|
||||
// Ensure all items are GeometryWrappers.
|
||||
$invalid_count = count(array_filter($data, function ($object) {
|
||||
return !$object instanceof GeometryWrapper;
|
||||
}));
|
||||
return $invalid_count === 0;
|
||||
return $data instanceof GeometryWrapper && $format == static::FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +153,7 @@ class KmlNormalizer implements NormalizerInterface, DenormalizerInterface {
|
|||
*/
|
||||
public function getSupportedTypes(?string $format): array {
|
||||
return [
|
||||
GeometryWrapper::class => TRUE,
|
||||
static::TYPE => TRUE,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue