public function FeedImportSimpleXPathReader::map in Feed Import 8
Returns a value mapped from obj by path.
Parameters
mixed $obj Variable to search:
mixed $path Path to value:
Return value
mixed Mapped value
Overrides FeedImportReader::map
File
- feed_import_base/
src/ FeedImportSimpleXPathReader.php, line 12
Class
- FeedImportSimpleXPathReader
- This class is a helper for xpath readers using SimpleXMLElement.
Namespace
Drupal\feed_import_baseCode
public function map(&$item, &$xpath) {
// Get values and handle xpath exceptions.
try {
$values = $item
->xpath($xpath);
} catch (Exception $e) {
return NULL;
}
// Xpath gave no values return null.
if (!$values) {
return NULL;
}
// Get the number of values.
$count = count($values);
$i = -1;
while (++$i < $count) {
// Get each value.
$values[$i] = (string) $values[$i][0];
}
// Return values.
return $count == 1 ? $values[0] : $values;
}