Adds the basic Tooltip Text Formatter (no javascript).
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user