LogLocation.php in farmOS 2.x
File
modules/core/location/src/LogLocation.php
View source
<?php
namespace Drupal\farm_location;
use Drupal\log\Entity\LogInterface;
class LogLocation implements LogLocationInterface {
const LOG_FIELD_LOCATION = 'location';
const LOG_FIELD_GEOMETRY = 'geometry';
public function hasLocation(LogInterface $log) : bool {
return !$log
->get(static::LOG_FIELD_LOCATION)
->isEmpty();
}
public function hasGeometry(LogInterface $log) : bool {
return !$log
->get(static::LOG_FIELD_GEOMETRY)
->isEmpty();
}
public function getLocation(LogInterface $log) : array {
return $log->{static::LOG_FIELD_LOCATION}
->referencedEntities() ?? [];
}
public function getGeometry(LogInterface $log) : string {
return $log
->get(static::LOG_FIELD_GEOMETRY)->value ?? '';
}
public function setLocation(LogInterface $log, array $assets) : void {
foreach ($assets as $asset) {
$log->{static::LOG_FIELD_LOCATION}[] = [
'target_id' => $asset
->id(),
];
}
}
public function setGeometry(LogInterface $log, string $wkt) : void {
$log->{static::LOG_FIELD_GEOMETRY}->value = $wkt;
}
}