abstract class GridStackEntityFormatterBase in GridStack 8.2
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php \Drupal\gridstack\Plugin\Field\FieldFormatter\GridStackEntityFormatterBase
Base class for gridstack entity reference formatters without field details.
Hierarchy
- class \Drupal\gridstack\Plugin\Field\FieldFormatter\GridStackEntityFormatterBase extends \Drupal\blazy\Dejavu\BlazyEntityBase uses GridStackFormatterTrait, GridStackFormatterViewTrait
Expanded class hierarchy of GridStackEntityFormatterBase
File
- src/
Plugin/ Field/ FieldFormatter/ GridStackEntityFormatterBase.php, line 13
Namespace
Drupal\gridstack\Plugin\Field\FieldFormatterView source
abstract class GridStackEntityFormatterBase extends BlazyEntityBase {
use GridStackFormatterTrait {
buildSettings as traitBuildSettings;
}
use GridStackFormatterViewTrait;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
return self::injectServices($instance, $container, 'entity');
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
$settings = GridStackDefault::baseSettings();
$settings['view_mode'] = '';
return $settings;
}
/**
* {@inheritdoc}
*/
public function buildElement(array &$build, $entity, $langcode) {
$view_mode = empty($build['settings']['view_mode']) ? 'full' : $build['settings']['view_mode'];
$delta = $build['settings']['delta'];
// Adds element box to contain any entity as expected by GridStackManager.
$build['items'][$delta] = [
'box' => $this
->formatter()
->getEntityTypeManager()
->getViewBuilder($entity
->getEntityTypeId())
->view($entity, $view_mode, $langcode),
];
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$entities = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($entities)) {
return [];
}
return $this
->commonViewElements($items, $langcode, $entities);
}
/**
* Builds the settings.
*/
public function buildSettings() {
return [
'vanilla' => TRUE,
] + $this
->traitBuildSettings();
}
/**
* {@inheritdoc}
*/
public function getScopedFormElements() {
return $this
->getCommonScopedFormElements() + parent::getScopedFormElements();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GridStackEntityFormatterBase:: |
public | function | ||
GridStackEntityFormatterBase:: |
public | function | Builds the settings. | |
GridStackEntityFormatterBase:: |
public static | function | ||
GridStackEntityFormatterBase:: |
public static | function | ||
GridStackEntityFormatterBase:: |
public | function | ||
GridStackEntityFormatterBase:: |
public | function | ||
GridStackFormatterTrait:: |
protected | property | The gridstack field formatter manager. | |
GridStackFormatterTrait:: |
protected | property | The logger factory. | |
GridStackFormatterTrait:: |
protected | property | The gridstack field formatter manager. | |
GridStackFormatterTrait:: |
public | function | Returns the gridstack admin service shortcut. | |
GridStackFormatterTrait:: |
public | function | Overrides the blazy manager. | |
GridStackFormatterTrait:: |
public | function | Builds the settings. Aliased as: traitBuildSettings | |
GridStackFormatterTrait:: |
public | function | Returns the gridstack field formatter service. | |
GridStackFormatterTrait:: |
public | function | Defines the common scope for both front and admin. | |
GridStackFormatterTrait:: |
public | function | Defines the common scope for the form elements. | |
GridStackFormatterTrait:: |
protected static | function | Injects DI services. | |
GridStackFormatterTrait:: |
public static | function | 4 | |
GridStackFormatterTrait:: |
public | function | Returns the gridstack service. | |
GridStackFormatterTrait:: |
public | function | ||
GridStackFormatterViewTrait:: |
public | function | Returns similar view elements. |