FeedsItemGuidFormatter.php in Feeds 8.3
File
src/Plugin/Field/FieldFormatter/FeedsItemGuidFormatter.php
View source
<?php
namespace Drupal\feeds\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Url;
use InvalidArgumentException;
class FeedsItemGuidFormatter extends FeedsItemFormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = [];
foreach ($items as $delta => $item) {
if ($this
->valueIsUrl($item->guid)) {
try {
$url = Url::fromUri($item->guid);
$element[$delta] = $this
->generateLink($url);
} catch (InvalidArgumentException $e) {
$element[$delta] = [
'#plain_text' => $item->guid,
];
}
}
elseif (strlen($item->guid)) {
$element[$delta] = [
'#plain_text' => $item->guid,
];
}
}
return $element;
}
}