visualn-8.x-1.x-dev/modules/visualn_dataset/src/Plugin/Field/FieldFormatter/VisualNResourceProviderFormatter.php
modules/visualn_dataset/src/Plugin/Field/FieldFormatter/VisualNResourceProviderFormatter.php
<?php
namespace Drupal\visualn_dataset\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Plugin implementation of the 'visualn_resource_provider' formatter.
*
* @FieldFormatter(
* id = "visualn_resource_provider",
* label = @Translation("VisualN resource provider"),
* field_types = {
* "visualn_resource_provider"
* }
* )
*/
class VisualNResourceProviderFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
// Implement default settings.
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
return [
// Implement settings form.
] + parent::settingsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
// Implement settings summary.
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = ['#markup' => $this->viewValue($item)];
}
return $elements;
}
/**
* Generate the output appropriate for one field item.
*
* @param \Drupal\Core\Field\FieldItemInterface $item
* One field item.
*
* @return string
* The textual output generated.
*/
protected function viewValue(FieldItemInterface $item) {
$output = '';
$resource_provider_plugin = $item->getResourceProviderPlugin();
if (!is_null($resource_provider_plugin)) {
//$output = $resource_provider_plugin->label();
$output = print_r($resource_provider_plugin->getConfiguration(), 1);
}
// @todo:
return '<pre>' . $output . '</pre>';
}
}
