class SlickTextFormatter in Slick Carousel 7.3
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/SlickTextFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickTextFormatter
- 8 src/Plugin/Field/FieldFormatter/SlickTextFormatter.php \Drupal\slick\Plugin\Field\FieldFormatter\SlickTextFormatter
Plugin implementation of the 'Slick Text' formatter.
Hierarchy
- class \Drupal\blazy\Plugin\Field\FieldFormatter\FormatterBase implements FormatterInterface
- class \Drupal\slick\Plugin\Field\FieldFormatter\SlickTextFormatter uses SlickFormatterTrait
Expanded class hierarchy of SlickTextFormatter
File
- src/
Plugin/ Field/ FieldFormatter/ SlickTextFormatter.php, line 13
Namespace
Drupal\slick\Plugin\Field\FieldFormatterView source
class SlickTextFormatter extends FormatterBase {
use SlickFormatterTrait;
/**
* Constructs a SlickTextFormatter instance.
*/
public function __construct($plugin_id, $field, $instance, SlickFormatterInterface $formatter, SlickManagerInterface $manager) {
parent::__construct($plugin_id, $field, $instance);
$this->formatter = $formatter;
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return SlickDefault::baseSettings() + SlickDefault::gridSettings();
}
/**
* {@inheritdoc}
*/
public function getRequiredForms() {
return [
'grid' => $this->isMultiple,
];
}
/**
* {@inheritdoc}
*/
public function viewElements($items, $entity) {
$settings = $this
->buildSettings();
// Hand over to default formatter if not multiple.
// @todo figure out to disable formatter like isApplicable() at D8 in the
// first place, and remove this.
if (!$this->isMultiple) {
$types = field_info_field_types($this->fieldDefinition['type']);
$display['type'] = isset($types['default_formatter']) ? $types['default_formatter'] : '';
if ($fallback = text_field_formatter_view($settings['entity_type_id'], $entity, $this->fieldDefinition, $this->fieldInstance, $this->langcode, $items, $display)) {
return $fallback;
}
}
$settings['vanilla'] = TRUE;
// Build the settings.
$build = [
'settings' => $settings,
];
// Modifies settings before building elements.
$this
->formatter()
->preBuildElements($build, $items, $entity);
// Build the elements.
$this
->buildElements($build, $items);
// If using 0, or directly passed like D8, taken over by theme_field().
$element = $this
->manager()
->build($build);
return $element;
}
/**
* Build the slick carousel elements.
*/
public function buildElements(array &$build, $items) {
$settings = $build['settings'];
// The ProcessedText element already handles cache context & tag bubbling.
// @see \Drupal\filter\Element\ProcessedText::preRenderText()
foreach ($items as $item) {
$text = _text_sanitize($this->fieldInstance, $settings['langcode'], $item, 'value');
$build['items'][] = [
'#markup' => $text,
];
unset($text);
}
}
/**
* {@inheritdoc}
*/
public function settingsForm($form, &$form_state, $definition) {
$element = [];
// @todo remove once D8-like isApplicable() for cardinality - 1 is working.
if (!$this->isMultiple) {
return $element;
}
$this
->admin()
->buildSettingsForm($element, $definition);
return $element;
}
/**
* Defines the scope for the form elements.
*/
public function getScopedFormElements() {
return [
'no_image_style' => TRUE,
'no_layouts' => TRUE,
'responsive_image' => FALSE,
'style' => TRUE,
] + parent::getScopedFormElements();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazyFormatterTrait:: |
protected | property | The blazy-related formatter service. | |
BlazyFormatterTrait:: |
protected | property | The blazy field formatter manager. | |
BlazyFormatterTrait:: |
public | function | Returns the blazy-related formatter. | |
BlazyFormatterTrait:: |
public | function | Returns the blazy service. | |
BlazyFormatterTrait:: |
public | function | ||
FormatterBase:: |
protected | property | The blazy-related admin formatter service. | |
FormatterBase:: |
protected | property | Whether default settings have been merged into the current $settings. | |
FormatterBase:: |
protected | property | The field definition. | |
FormatterBase:: |
protected | property | The field display. | |
FormatterBase:: |
protected | property | The field instance. | |
FormatterBase:: |
protected | property | The form settings. | |
FormatterBase:: |
protected | property | True if the field cardinality equals -1. | |
FormatterBase:: |
protected | property | The known hard-coded entities. | |
FormatterBase:: |
protected | property | The langcode. | |
FormatterBase:: |
protected | property | The blazy formatter plugin id. | |
FormatterBase:: |
protected | property | The formatter settings. | |
FormatterBase:: |
protected | property | The view mode. | |
FormatterBase:: |
public | function | Builds the settings. | 1 |
FormatterBase:: |
public | function | Implements hook_field_formatter_settings_form(). | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Gets html settings. | |
FormatterBase:: |
public | function | Gets formatter plugin id. | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Gets formatter settings. | |
FormatterBase:: |
protected | function | Merges default settings values into $settings. | |
FormatterBase:: |
public | function | Sets html settings. | |
FormatterBase:: |
public | function | ||
FormatterBase:: |
public | function | Sets formatter settings. | |
FormatterBase:: |
protected | function | Setup common variables across different hooks. | |
FormatterBase:: |
public | function | Implements hook_field_formatter_view(). | |
SlickFormatterTrait:: |
public | function | Returns the slick admin service. | |
SlickTextFormatter:: |
public | function | Build the slick carousel elements. | |
SlickTextFormatter:: |
public static | function |
Returns default settings. Overrides FormatterBase:: |
|
SlickTextFormatter:: |
public | function |
Returns required form elements for the current formatter. Overrides FormatterBase:: |
|
SlickTextFormatter:: |
public | function |
Defines the scope for the form elements. Overrides FormatterBase:: |
|
SlickTextFormatter:: |
public | function |
Implements hook_field_formatter_settings_form(). Overrides FormatterBase:: |
|
SlickTextFormatter:: |
public | function |
Implements hook_field_formatter_view(). Overrides SlickFormatterTrait:: |
|
SlickTextFormatter:: |
public | function |
Constructs a SlickTextFormatter instance. Overrides FormatterBase:: |