You are here

public function GeolocationGpx::getGpxFileFromItem in Geolocation Field 8.3

Get GPX file.

Parameters

\Drupal\Core\Field\FieldItemInterface $fieldItem: Field item.

Return value

\phpGPX\Models\GpxFile|false GPX file or false.

2 calls to GeolocationGpx::getGpxFileFromItem()
GeolocationGpx::getLocationsFromItem in modules/geolocation_gpx/src/Plugin/geolocation/DataProvider/GeolocationGpx.php
Get locations from field item list.
GeolocationGpx::getShapesFromItem in modules/geolocation_gpx/src/Plugin/geolocation/DataProvider/GeolocationGpx.php
Get shapes from field item list.

File

modules/geolocation_gpx/src/Plugin/geolocation/DataProvider/GeolocationGpx.php, line 252

Class

GeolocationGpx
Provides GPX.

Namespace

Drupal\geolocation_gpx\Plugin\geolocation\DataProvider

Code

public function getGpxFileFromItem(FieldItemInterface $fieldItem) {
  if ($fieldItem instanceof GeolocationGpxFile) {
    $target_id = $fieldItem
      ->get('target_id')
      ->getValue();
    if (empty($target_id)) {
      return FALSE;
    }
    $file = File::load($target_id);
    if (empty($file)) {
      return FALSE;
    }
    $filename = $file
      ->getFileUri();
    $gpx = new phpGPX();
    $file = $gpx
      ->load($filename);
    if (empty($file)) {
      return FALSE;
    }
    return $file;
  }
  return FALSE;
}