abstract class GridStackEntityFormatterBase in GridStack 8
Same name and namespace in other branches
- 8.2 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 implements ContainerFactoryPluginInterface uses GridStackFormatterTrait
Expanded class hierarchy of GridStackEntityFormatterBase
File
- src/
Plugin/ Field/ FieldFormatter/ GridStackEntityFormatterBase.php, line 18
Namespace
Drupal\gridstack\Plugin\Field\FieldFormatterView source
abstract class GridStackEntityFormatterBase extends BlazyEntityBase implements ContainerFactoryPluginInterface {
use GridStackFormatterTrait;
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* Constructs a GridStackMediaFormatter instance.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory, GridStackFormatterInterface $formatter, GridStackManagerInterface $manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->loggerFactory = $logger_factory;
$this->formatter = $formatter;
$this->manager = $manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container
->get('logger.factory'), $container
->get('gridstack.formatter'), $container
->get('gridstack.manager'));
}
/**
* Returns the blazy manager.
*/
public function blazyManager() {
return $this->formatter;
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
$settings = GridStackDefault::baseSettings();
$settings['view_mode'] = '';
return $settings;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$entities = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($entities)) {
return [];
}
// Collects specific settings to this formatter.
$settings = $this
->buildSettings();
$build = [
'settings' => $settings,
];
$this->formatter
->buildSettings($build, $items);
// Build the elements.
$this
->buildElements($build, $entities, $langcode);
return $this
->manager()
->build($build);
}
/**
* Builds the settings.
*/
public function buildSettings() {
$settings = $this
->getSettings();
$settings['blazy'] = TRUE;
$settings['lazy'] = 'blazy';
$settings['namespace'] = $settings['item_id'] = 'gridstack';
$settings['plugin_id'] = $this
->getPluginId();
$settings['vanilla'] = TRUE;
return $settings;
}
/**
* {@inheritdoc}
*/
public function getScopedFormElements() {
return [
'namespace' => 'gridstack',
] + parent::getScopedFormElements();
}
}