You are here

protected static function GridStackFormatterTrait::injectServices in GridStack 8.2

Injects DI services.

4 calls to GridStackFormatterTrait::injectServices()
GridStackEntityFormatterBase::create in src/Plugin/Field/FieldFormatter/GridStackEntityFormatterBase.php
GridStackFileFormatter::create in src/Plugin/Field/FieldFormatter/GridStackFileFormatter.php
GridStackFileFormatterBase::create in src/Plugin/Field/FieldFormatter/GridStackFileFormatterBase.php
GridStackMediaFormatter::create in src/Plugin/Field/FieldFormatter/GridStackMediaFormatter.php
Creates an instance of the plugin.

File

src/Plugin/Field/FieldFormatter/GridStackFormatterTrait.php, line 58

Class

GridStackFormatterTrait
A Trait common for gridstack formatters.

Namespace

Drupal\gridstack\Plugin\Field\FieldFormatter

Code

protected static function injectServices($instance, ContainerInterface $container, $type = '') {
  $instance->formatter = $instance->blazyManager = $container
    ->get('gridstack.formatter');
  $instance->manager = $container
    ->get('gridstack.manager');

  // Blazy:2.x+ might already set these, provides a failsafe.
  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;
}