LinkExportFormatter.php in REST Views 2.0.x
File
src/Plugin/Field/FieldFormatter/LinkExportFormatter.php
View source
<?php
namespace Drupal\rest_views\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\link\Plugin\Field\FieldFormatter\LinkFormatter;
use Drupal\rest_views\SerializedData;
class LinkExportFormatter extends LinkFormatter {
public function viewElements(FieldItemListInterface $items, $langcode) : array {
$elements = parent::viewElements($items, $langcode);
foreach ($elements as $delta => $element) {
$url = $element['#url'];
$data = [
'url' => $url
->toString(),
'text' => $element['#title'],
];
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create($data),
];
}
return $elements;
}
public static function defaultSettings() : array {
return [];
}
public function settingsForm(array $form, FormStateInterface $form_state) : array {
return [];
}
public function settingsSummary() : array {
return [];
}
}