You are here

class LogLocation in farmOS 2.x

Log location logic.

Hierarchy

Expanded class hierarchy of LogLocation

1 string reference to 'LogLocation'
farm_location.services.yml in modules/core/location/farm_location.services.yml
modules/core/location/farm_location.services.yml
1 service uses LogLocation
log.location in modules/core/location/farm_location.services.yml
Drupal\farm_location\LogLocation

File

modules/core/location/src/LogLocation.php, line 10

Namespace

Drupal\farm_location
View source
class LogLocation implements LogLocationInterface {

  /**
   * The name of the log location field.
   *
   * @var string
   */
  const LOG_FIELD_LOCATION = 'location';

  /**
   * The name of the log geometry field.
   *
   * @var string
   */
  const LOG_FIELD_GEOMETRY = 'geometry';

  /**
   * {@inheritdoc}
   */
  public function hasLocation(LogInterface $log) : bool {
    return !$log
      ->get(static::LOG_FIELD_LOCATION)
      ->isEmpty();
  }

  /**
   * {@inheritdoc}
   */
  public function hasGeometry(LogInterface $log) : bool {
    return !$log
      ->get(static::LOG_FIELD_GEOMETRY)
      ->isEmpty();
  }

  /**
   * {@inheritdoc}
   */
  public function getLocation(LogInterface $log) : array {
    return $log->{static::LOG_FIELD_LOCATION}
      ->referencedEntities() ?? [];
  }

  /**
   * {@inheritdoc}
   */
  public function getGeometry(LogInterface $log) : string {
    return $log
      ->get(static::LOG_FIELD_GEOMETRY)->value ?? '';
  }

  /**
   * {@inheritdoc}
   */
  public function setLocation(LogInterface $log, array $assets) : void {
    foreach ($assets as $asset) {
      $log->{static::LOG_FIELD_LOCATION}[] = [
        'target_id' => $asset
          ->id(),
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setGeometry(LogInterface $log, string $wkt) : void {
    $log->{static::LOG_FIELD_GEOMETRY}->value = $wkt;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LogLocation::getGeometry public function Get a log's geometry. Overrides LogLocationInterface::getGeometry
LogLocation::getLocation public function Get location assets referenced by a log. Overrides LogLocationInterface::getLocation
LogLocation::hasGeometry public function Check if a log has geometry. Overrides LogLocationInterface::hasGeometry
LogLocation::hasLocation public function Check if a log references location assets. Overrides LogLocationInterface::hasLocation
LogLocation::LOG_FIELD_GEOMETRY constant The name of the log geometry field.
LogLocation::LOG_FIELD_LOCATION constant The name of the log location field.
LogLocation::setGeometry public function Set a log's geometry. Overrides LogLocationInterface::setGeometry
LogLocation::setLocation public function Set a log's location. Overrides LogLocationInterface::setLocation