You are here

public static function ImageStyles::create in Consumer Image Styles 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php \Drupal\consumer_image_styles\Plugin\jsonapi\FieldEnhancer\ImageStyles::create()

Creates an instance of the plugin.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container to pull out services used in the plugin.

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin ID for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Return value

static Returns an instance of this plugin.

Overrides ContainerFactoryPluginInterface::create

File

src/Plugin/jsonapi/FieldEnhancer/ImageStyles.php, line 56

Class

ImageStyles
Perform additional manipulations to timestamp fields.

Namespace

Drupal\consumer_image_styles\Plugin\jsonapi\FieldEnhancer

Code

public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
  $image_styles_provider = $container
    ->get('consumer_image_styles.image_styles_provider');
  $entity_type_manager = $container
    ->get('entity_type.manager');
  $configuration['consumer_image_style_ids'] = [];
  $request = $container
    ->get('request_stack')
    ->getCurrentRequest();
  $consumer = $container
    ->get('consumer.negotiator')
    ->negotiateFromRequest($request);
  if ($consumer) {
    $styles = $image_styles_provider
      ->loadStyles($consumer);
    $configuration['consumer_image_style_ids'] = array_keys($styles);
  }
  return new static($configuration, $plugin_id, $plugin_definition, $image_styles_provider, $entity_type_manager);
}