EntityReferencePathFormatter.php in REST Views 8
Same filename and directory in other branches
File
src/Plugin/Field/FieldFormatter/EntityReferencePathFormatter.phpView source
<?php
namespace Drupal\rest_views\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\link\Plugin\Field\FieldFormatter\LinkFormatter;
use Drupal\rest_views\SerializedData;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'entity_path' formatter.
*
* @FieldFormatter(
* id = "entity_path",
* label = @Translation("Entity path"),
* field_types = {
* "entity_reference"
* }
* )
*/
class EntityReferencePathFormatter extends LinkFormatter {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
/** @var \Drupal\Core\Url $url */
$url = $item->entity
->toUrl();
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create($url
->toString()),
];
}
return $elements;
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [];
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
return [];
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
return [];
}
}
Classes
Name | Description |
---|---|
EntityReferencePathFormatter | Plugin implementation of the 'entity_path' formatter. |