You are here

protected function MigrateGeolocationFieldHandler::validate in Geolocation Field 7

Validates given geolocation field value item.

Parameters

object $entity: Entity being processed.

array $field_info: Field info.

array $instance: Field instance.

array $item: Field values delta.

Return value

bool TRUE if given item contains valid geolocation field value, FALSE - otherwise.

1 call to MigrateGeolocationFieldHandler::validate()
MigrateGeolocationFieldHandler::prepare in migrate/destinations/geolocation.inc

File

migrate/destinations/geolocation.inc, line 148
Contains geolocation field migration handler.

Class

MigrateGeolocationFieldHandler
Geolocation field migration handler class.

Code

protected function validate($entity, array $field_info, array $instance, array $item) {
  $item_is_valid = TRUE;
  $migration = Migration::currentMigration();
  if ((string) $item['lat'] === '' || (string) $item['lng'] === '') {
    $migration
      ->saveMessage(t('%name: both latitude and longitude values are required.', array(
      '%name' => $instance['label'],
    )), Migration::MESSAGE_ERROR);
    $item_is_valid = FALSE;
  }
  if (!is_numeric($item['lat']) || !is_numeric($item['lng'])) {
    $migration
      ->saveMessage(t('%name: only numeric values are acceptable.', array(
      '%name' => $instance['label'],
    )), Migration::MESSAGE_ERROR);
    $item_is_valid = FALSE;
  }
  if ($item['lat'] < -90 || $item['lat'] > 90 || $item['lng'] < -180 || $item['lng'] > 180) {
    $migration
      ->saveMessage(t('%name: invalid latitude or longitude has been provided.', array(
      '%name' => $instance['label'],
    )), Migration::MESSAGE_ERROR);
    $item_is_valid = FALSE;
  }
  return $item_is_valid;
}