class ImageStyleguide in Style Guide 8
Same name and namespace in other branches
- 2.x src/Plugin/Styleguide/ImageStyleguide.php \Drupal\styleguide\Plugin\Styleguide\ImageStyleguide
Image styles Styleguide items implementation.
Plugin annotation
@Plugin(
id = "image_styleguide",
label = @Translation("Image styles Styleguide elements")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\styleguide\Plugin\StyleguidePluginBase implements ContainerFactoryPluginInterface, StyleguideInterface
- class \Drupal\styleguide\Plugin\Styleguide\ImageStyleguide
- class \Drupal\styleguide\Plugin\StyleguidePluginBase implements ContainerFactoryPluginInterface, StyleguideInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ImageStyleguide
File
- src/
Plugin/ Styleguide/ ImageStyleguide.php, line 21
Namespace
Drupal\styleguide\Plugin\StyleguideView source
class ImageStyleguide extends StyleguidePluginBase {
/**
* The styleguide generator service.
*
* @var \Drupal\styleguide\Generator
*/
protected $generator;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Constructs a new imageStyleguide.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\styleguide\GeneratorInterface $styleguide_generator
* The styleguide generator service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, GeneratorInterface $styleguide_generator, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->generator = $styleguide_generator;
$this->moduleHandler = $module_handler;
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('styleguide.generator'), $container
->get('module_handler'), $container
->get('file_system'));
}
/**
* {@inheritdoc}
*/
public function items() {
$items = [];
if ($this->moduleHandler
->moduleExists('image')) {
// Get the sample file provided by the module.
$preview_img_path = 'public://styleguide-preview.jpg';
if ($this->fileSystem
->getDestinationFilename($preview_img_path, FileSystemInterface::EXISTS_ERROR) !== FALSE) {
// Move the image so that styles may be applied.
$this->fileSystem
->copy($this->generator
->image('vertical'), $preview_img_path, FileSystemInterface::EXISTS_ERROR);
}
// Iterate through the image styles on the site.
foreach (ImageStyle::loadMultiple() as $stylename => $style) {
$details = [];
foreach ($style
->getEffects() as $effect) {
$summary = $effect
->getSummary();
$summary = render($summary);
$label = $effect
->label();
if ($summary) {
$details[] = new FormattableMarkup('%label: @summary', [
'%label' => $label,
'@summary' => $summary,
]);
}
else {
$details[] = new FormattableMarkup('%label', [
'%label' => $label,
]);
}
}
$title = $this
->t('Image style, @stylename', [
'@stylename' => $style
->get('label'),
]);
$items['image_' . $stylename] = [
'title' => $title,
'description' => [
'#theme' => 'item_list',
'#items' => $details,
],
'content' => [
'#theme' => 'image_style',
'#uri' => $preview_img_path,
'#style_name' => $stylename,
'#alt' => $title,
'#title' => $title,
],
'group' => $this
->t('Media'),
];
}
}
return $items;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
ImageStyleguide:: |
protected | property | The file system service. | |
ImageStyleguide:: |
protected | property | The styleguide generator service. | |
ImageStyleguide:: |
protected | property | The module handler service. | |
ImageStyleguide:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ImageStyleguide:: |
public | function |
Styleguide elements implementation. Overrides StyleguideInterface:: |
|
ImageStyleguide:: |
public | function |
Constructs a new imageStyleguide. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
StyleguidePluginBase:: |
public | function | Build a link. | |
StyleguidePluginBase:: |
public | function | Build a link from a given route name and parameters. |