trait ElementEntityClassTrait in Element Class Formatter 8
The ElementEntityClassTrait is used for adding classes to the #item_attributes of fields that display other entities.
@package Drupal\element_class_formatter\Plugin\Field\FieldFormatter
Hierarchy
- trait \Drupal\element_class_formatter\Plugin\Field\FieldFormatter\ElementEntityClassTrait uses ElementClassTrait
1 file declares its use of ElementEntityClassTrait
- ResponsiveImageClassFormatter.php in modules/
element_class_formatter_responsive_image/ src/ Plugin/ Field/ FieldFormatter/ ResponsiveImageClassFormatter.php
File
- src/
Plugin/ Field/ FieldFormatter/ ElementEntityClassTrait.php, line 14
Namespace
Drupal\element_class_formatter\Plugin\Field\FieldFormatterView source
trait ElementEntityClassTrait {
use ElementClassTrait;
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return ElementClassTrait::elementClassDefaultSettings(parent::defaultSettings());
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$class = $this
->getSetting('class');
return $this
->elementClassSettingsForm($elements, $class);
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = parent::settingsSummary();
$class = $this
->getSetting('class');
return $this
->elementClassSettingsSummary($summary, $class);
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
$entities = $this
->getEntitiesToView($items, $langcode);
$class = $this
->getSetting('class');
return $this
->setEntityClass($elements, $class, $entities);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ElementClassTrait:: |
public static | function | Default class value. | |
ElementClassTrait:: |
public | function | Setting form to collect class value. | |
ElementClassTrait:: |
public | function | Text for settings summary. | |
ElementClassTrait:: |
public | function | Set the class on the element. | |
ElementClassTrait:: |
public | function | Set the class on the entity. | |
ElementEntityClassTrait:: |
public static | function | ||
ElementEntityClassTrait:: |
public | function | ||
ElementEntityClassTrait:: |
public | function | ||
ElementEntityClassTrait:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |