You are here

protected function XmlParser::executeSourceExpression in Feeds extensible parsers 8

Executes a single source expression.

Parameters

string $machine_name: The source machine name being executed.

string $expression: The expression to execute.

mixed $row: The row to execute on.

Return value

scalar|[]scalar Either a scalar, or a list of scalars. If null, the value will be ignored.

Overrides ParserBase::executeSourceExpression

1 method overrides XmlParser::executeSourceExpression()
QueryPathXmlParser::executeSourceExpression in src/Feeds/Parser/QueryPathXmlParser.php
Executes a single source expression.

File

src/Feeds/Parser/XmlParser.php, line 135

Class

XmlParser
Defines a XML parser using XPath.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

protected function executeSourceExpression($machine_name, $expression, $row) {
  $result = $this->xpath
    ->evaluate($expression, $row);
  if (!$result instanceof DOMNodeList) {
    return $result;
  }
  if ($result->length == 0) {
    return;
  }
  $return = [];
  if (!empty($this->configuration['sources'][$machine_name]['inner'])) {
    foreach ($result as $node) {
      $return[] = $this
        ->getInnerXml($node);
    }
  }
  elseif (!empty($this->configuration['sources'][$machine_name]['raw'])) {
    foreach ($result as $node) {
      $return[] = $this
        ->getRaw($node);
    }
  }
  else {
    foreach ($result as $node) {
      $return[] = $node->nodeValue;
    }
  }

  // Return a single value if there's only one value.
  return count($return) === 1 ? reset($return) : $return;
}