Adds the basic Tooltip Text Formatter (no javascript).

This commit is contained in:
2021-02-18 09:32:13 +00:00
parent f3452c23a2
commit 3abcb9ccdc
3 changed files with 90 additions and 0 deletions
@@ -0,0 +1,57 @@
<?php
namespace Drupal\cdesai_tff\Plugin\Field\FieldFormatter;
use Drupal\cdesai_tff\DesaiTextFormatterBase;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Implementation of custom Tooltip text formatter.
*
* @FieldFormatter(
* id = "cdesai_tff_tooltip",
* label = @Translation("Custom Tooltip Formatter"),
* field_types = {
* "string",
* "text"
* }
* )
*/
class TooltipTextFormatter extends DesaiTextFormatterBase {
/**
* @inheritDoc
*/
function getCssClassId() {
return 'cdesai-tff-tooltip';
}
/**
* @inheritDoc
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#theme' => 'cdesai_tff_tooltip_formatter',
'#value' => $this->getValue($item),
'#attributes' => [
'class' => [$this->getCssClassId()],
],
];
}
return $elements;
}
/**
* @inheritDoc
*/
function getValue(FieldItemInterface $item) {
return $item->getString();
}
}