ClipboardJs.php in Clipboard.js 8
File
src/Plugin/Field/FieldFormatter/ClipboardJs.php
View source
<?php
namespace Drupal\clipboardjs\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;
class ClipboardJs extends FormatterBase {
public static function defaultSettings() {
return [] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
return [] + parent::settingsForm($form, $form_state);
}
public function settingsSummary() {
$summary = [];
return $summary;
}
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'clipboardjs',
'#text' => $this
->viewValue($item),
];
}
return $elements;
}
protected function viewValue(FieldItemInterface $item) {
return nl2br(Html::escape($item->value));
}
}
Classes
Name |
Description |
ClipboardJs |
Plugin implementation of the 'clipboard' formatter. |