View source
<?php
namespace Drupal\slick\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\slick\SlickDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SlickTextFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
use SlickFormatterViewTrait;
use SlickFormatterTrait {
buildSettings as traitBuildSettings;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings']);
return self::injectServices($instance, $container, 'text');
}
public static function defaultSettings() {
return SlickDefault::baseSettings() + SlickDefault::gridSettings();
}
public function viewElements(FieldItemListInterface $items, $langcode) {
return $this
->commonViewElements($items, $langcode);
}
public function buildElements(array &$build, $items) {
foreach ($items as $key => $item) {
if (empty($item->value)) {
continue;
}
$element = [
'#type' => 'processed_text',
'#text' => $item->value,
'#format' => $item->format,
'#langcode' => $item
->getLangcode(),
];
$build['items'][$key] = $element;
unset($element);
}
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$definition = $this
->getScopedFormElements();
$this
->admin()
->buildSettingsForm($element, $definition);
return $element;
}
public function buildSettings() {
return [
'vanilla' => TRUE,
] + $this
->traitBuildSettings();
}
public function getScopedFormElements() {
return [
'grid_form' => TRUE,
'no_image_style' => TRUE,
'no_layouts' => TRUE,
'responsive_image' => FALSE,
'style' => TRUE,
] + $this
->getCommonScopedFormElements();
}
}