Skip to content
Snippets Groups Projects
Commit 036e3351 authored by David Suissa's avatar David Suissa
Browse files

Issue #3459188 by DYdave: PHPCS on GitlabCI: Fixed all validation errors such...

Issue #3459188 by DYdave: PHPCS on GitlabCI: Fixed all validation errors such dependency injection, code formatting, use states ordering and any other issues reported. Required 'phpcs' and 'phpstan' jobs to pass.
parent 475a6e5d
No related branches found
No related tags found
1 merge request!40Issue #3459188 by DYdave: PHPCS on GitlabCI: Fixed all validation errors such...
......@@ -59,48 +59,16 @@ include:
# OPT_IN_TEST_NEXT_MAJOR: '1'
# _CURL_TEMPLATES_REF: 'main'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
# PHPCS overrides and configuration.
#
###################################################################################
phpcs:
# Require phpcs to pass.
allow_failure: false
#
# PHPSTAN overrides and configuration.
#
phpstan:
# Require phpstan to pass.
allow_failure: false
......@@ -5,8 +5,8 @@
* Post-update functions for Colorbox.
*/
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
* Saves the image style dependencies into form and view display entities.
......
......@@ -6,9 +6,9 @@
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Xss;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\Component\Utility\Xss;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
/**
......@@ -137,7 +137,8 @@ function template_preprocess_colorbox_formatter(&$variables) {
$variables['url'] = $file_url_generator->generateAbsoluteString($image_uri);
}
$unique_id = 'colorbox-' . Crypt::randomBytesBase64(8);
$variables['attributes']['title'] = _colorbox_formatter_get_caption($variables);;
$variables['attributes']['title'] = _colorbox_formatter_get_caption($variables);
;
$variables['attributes']['data-colorbox-gallery'] = $gallery_id;
$variables['attributes']['class'] = $classes_array;
$variables['attributes']['aria-controls'] = $unique_id;
......@@ -164,7 +165,7 @@ function template_preprocess_colorbox_responsive_formatter(array &$variables) {
$colorbox_inline = \Drupal::moduleHandler()->moduleExists('colorbox_inline');
$item = $variables['item'];
$item_attributes = isset($variables['item_attributes']) ? $variables['item_attributes'] : [];
$item_attributes = $variables['item_attributes'] ?? [];
$entity = $variables['entity'];
$entity_bundle = $entity->bundle();
$id = $entity->id();
......@@ -271,6 +272,7 @@ function template_preprocess_colorbox_responsive_formatter(array &$variables) {
* - settings: Formatter settings array.
*
* @return string
* The caption text of the image parameter.
*/
function _colorbox_formatter_get_caption(&$variables) {
$item = $variables['item'];
......
......@@ -2,8 +2,8 @@
namespace Drupal\colorbox;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......
......@@ -5,11 +5,11 @@ namespace Drupal\colorbox\Form;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Extension\ModuleExtensionList;
/**
* General configuration form for controlling the colorbox behaviour..
......@@ -52,6 +52,8 @@ class ColorboxSettingsForm extends ConfigFormBase {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The Configuration Factory.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
* The typed configuration manager service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler service.
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module
......@@ -59,11 +61,13 @@ class ColorboxSettingsForm extends ConfigFormBase {
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $libraryDiscovery
* The library discovery service.
*/
public function __construct(ConfigFactoryInterface $config_factory,
TypedConfigManagerInterface $typedConfigManager,
ModuleHandlerInterface $moduleHandler,
ModuleExtensionList $extension_list_module,
LibraryDiscoveryInterface $libraryDiscovery) {
public function __construct(
ConfigFactoryInterface $config_factory,
TypedConfigManagerInterface $typedConfigManager,
ModuleHandlerInterface $moduleHandler,
ModuleExtensionList $extension_list_module,
LibraryDiscoveryInterface $libraryDiscovery,
) {
parent::__construct($config_factory, $typedConfigManager);
$this->moduleHandler = $moduleHandler;
$this->extensionListModule = $extension_list_module;
......
......@@ -2,21 +2,20 @@
namespace Drupal\colorbox\Plugin\Field\FieldFormatter;
use Drupal\colorbox\ElementAttachmentInterface;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\image\Entity\ImageStyle;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
use Drupal\colorbox\ElementAttachmentInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Plugin implementation of the 'colorbox' formatter.
......@@ -95,18 +94,20 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $libraryDiscovery
* Library discovery service.
*/
public function __construct($plugin_id,
$plugin_definition,
FieldDefinitionInterface $field_definition,
array $settings,
$label,
$view_mode,
array $third_party_settings,
AccountInterface $current_user,
EntityStorageInterface $image_style_storage,
ElementAttachmentInterface $attachment,
ModuleHandlerInterface $moduleHandler,
LibraryDiscoveryInterface $libraryDiscovery) {
public function __construct(
$plugin_id,
$plugin_definition,
FieldDefinitionInterface $field_definition,
array $settings,
$label,
$view_mode,
array $third_party_settings,
AccountInterface $current_user,
EntityStorageInterface $image_style_storage,
ElementAttachmentInterface $attachment,
ModuleHandlerInterface $moduleHandler,
LibraryDiscoveryInterface $libraryDiscovery,
) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
$this->imageStyleStorage = $image_style_storage;
......@@ -460,7 +461,7 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
$style_ids[] = $this->getSetting('colorbox_image_style');
foreach ($style_ids as $style_id) {
/** @var \Drupal\image\ImageStyleInterface $style */
if ($style_id && $style = ImageStyle::load($style_id)) {
if ($style_id && $style = $this->imageStyleStorage->load($style_id)) {
// If this formatter uses a valid image style to display the image, add
// the image style configuration entity as dependency of this formatter.
$dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
......@@ -482,14 +483,14 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
$style_ids['colorbox_image_style'] = $this->getSetting('colorbox_image_style');
foreach ($style_ids as $name => $style_id) {
/** @var \Drupal\image\ImageStyleInterface $style */
if ($style_id && $style = ImageStyle::load($style_id)) {
if ($style_id && $style = $this->imageStyleStorage->load($style_id)) {
if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) {
$replacement_id = $this->imageStyleStorage->getReplacementId($style_id);
// If a valid replacement has been provided in the storage,
// replace the image style with the replacement and signal
// that the formatter plugin.
// Settings were updated.
if ($replacement_id && ImageStyle::load($replacement_id)) {
if ($replacement_id && $this->imageStyleStorage->load($replacement_id)) {
$this->setSetting($name, $replacement_id);
$changed = TRUE;
}
......
......@@ -2,20 +2,20 @@
namespace Drupal\colorbox\Plugin\Field\FieldFormatter;
use Drupal\colorbox\ElementAttachmentInterface;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
use Drupal\colorbox\ElementAttachmentInterface;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Plugin for responsive image formatter.
......@@ -103,14 +103,21 @@ class ColorboxResponsiveFormatter extends ImageFormatterBase implements Containe
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $libraryDiscovery
* Library discovery service.
*/
public function __construct($plugin_id, $plugin_definition,
FieldDefinitionInterface $field_definition, array $settings, $label,
$view_mode, array $third_party_settings, AccountInterface $current_user,
EntityStorageInterface $responsive_image_style_storage,
EntityStorageInterface $image_style_storage,
ElementAttachmentInterface $attachment,
ModuleHandlerInterface $moduleHandler,
LibraryDiscoveryInterface $libraryDiscovery) {
public function __construct(
$plugin_id,
$plugin_definition,
FieldDefinitionInterface $field_definition,
array $settings,
$label,
$view_mode,
array $third_party_settings,
AccountInterface $current_user,
EntityStorageInterface $responsive_image_style_storage,
EntityStorageInterface $image_style_storage,
ElementAttachmentInterface $attachment,
ModuleHandlerInterface $moduleHandler,
LibraryDiscoveryInterface $libraryDiscovery,
) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
$this->responsiveImageStyleStorage = $responsive_image_style_storage;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment