GridStackFormatterTrait.php in GridStack 8.2
File
src/Plugin/Field/FieldFormatter/GridStackFormatterTrait.php
View source
<?php
namespace Drupal\gridstack\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
trait GridStackFormatterTrait {
protected $formatter;
protected $manager;
protected $loggerFactory;
public function formatter() {
return $this->formatter;
}
public function manager() {
return $this->manager;
}
public function blazyManager() {
return $this->formatter;
}
protected static function injectServices($instance, ContainerInterface $container, $type = '') {
$instance->formatter = $instance->blazyManager = $container
->get('gridstack.formatter');
$instance->manager = $container
->get('gridstack.manager');
if ($type == 'image' || $type == 'entity') {
$instance->imageFactory = isset($instance->imageFactory) ? $instance->imageFactory : $container
->get('image.factory');
if ($type == 'entity') {
$instance->loggerFactory = isset($instance->loggerFactory) ? $instance->loggerFactory : $container
->get('logger.factory');
$instance->blazyEntity = isset($instance->blazyEntity) ? $instance->blazyEntity : $container
->get('blazy.entity');
$instance->blazyOembed = isset($instance->blazyOembed) ? $instance->blazyOembed : $instance->blazyEntity
->oembed();
}
}
return $instance;
}
public function admin() {
return \Drupal::service('gridstack.admin');
}
public function settingsSummary() {
return $this
->admin()
->getSettingsSummary($this
->getScopedFormElements());
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return $field_definition
->getFieldStorageDefinition()
->isMultiple();
}
public function buildSettings() {
$settings = array_merge($this
->getCommonFieldDefinition(), $this
->getSettings());
$settings['blazy'] = TRUE;
$settings['third_party'] = $this
->getThirdPartySettings();
return $settings;
}
public function getCommonFieldDefinition() {
$field = $this->fieldDefinition;
return [
'namespace' => 'gridstack',
'current_view_mode' => $this->viewMode,
'field_name' => $field
->getName(),
'field_type' => $field
->getType(),
'entity_type' => $field
->getTargetEntityTypeId(),
'plugin_id' => $this
->getPluginId(),
'target_type' => $this
->getFieldSetting('target_type'),
'style' => FALSE,
'grid_form' => FALSE,
];
}
public function getCommonScopedFormElements() {
return [
'settings' => $this
->getSettings(),
] + $this
->getCommonFieldDefinition();
}
}