Skip to content
Snippets Groups Projects
Commit 5b01f9a1 authored by Sidharth Soman's avatar Sidharth Soman Committed by Jeffrey Fortune
Browse files

Fixed phpcs issues.

parent e4f58be8
No related branches found
No related tags found
1 merge request!2Fixed phpcs issues.
......@@ -6,8 +6,6 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\bg_img_field\Component\Render\CSSSnippet;
......@@ -18,6 +16,8 @@ use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Url;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Image\ImageFactory;
/**
* Plugin implementation of the 'image' formatter.
......@@ -35,9 +35,26 @@ use Drupal\Core\Url;
*/
class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerFactoryPluginInterface {
// @var Drupal\Core\Logger\LoggerChannelTrait
/**
* Logger channel trait.
*
* @var Drupal\Core\Logger\LoggerChannelTrait */
use LoggerChannelTrait;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* The image factory service.
*
* @var \Drupal\Core\Image\ImageFactory
*/
protected $imageFactory;
/**
* Constructor for the Background Image Formatter.
*
......@@ -64,6 +81,10 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
* Help generate links.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\File\FileSystemInterface $fileSystem
* The file system.
* @param \Drupal\Core\Image\ImageFactory $imageFactory
* The image factory.
*/
public function __construct(
$plugin_id,
......@@ -76,7 +97,9 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
EntityStorageInterface $responsive_image_style_storage,
EntityStorageInterface $image_style_storage,
LinkGeneratorInterface $link_generator,
AccountInterface $current_user
AccountInterface $current_user,
FileSystemInterface $fileSystem,
ImageFactory $imageFactory,
) {
parent::__construct(
$plugin_id,
......@@ -93,6 +116,8 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
);
$this->logger = $this->getLogger('bg_img_field');
$this->fileSystem = $fileSystem;
$this->imageFactory = $imageFactory;
}
/**
......@@ -162,7 +187,7 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
$files = [];
foreach ($items->getValue() as $item) {
$files[] = [
'file' => File::load($item['target_id']),
'file' => $this->fileSystem->load($item['target_id']),
'item' => $item,
];
}
......@@ -226,8 +251,8 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
// Attach to head on element to create style tag in the html head.
if (!empty($css)) {
$current_path = \Drupal::request()->getRequestUri();
if(preg_match('/node\/(\d+)\/layout/', $current_path, $matches)) {
$current_path = \Drupal::request()->getRequestUri();
if (preg_match('/node\/(\d+)\/layout/', $current_path, $matches)) {
$elements = [
'#theme' => 'background_style',
'#css' => $css,
......@@ -236,7 +261,8 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
'contexts' => $cache_contexts,
],
];
} else {
}
else {
// Use the selector in the id to avoid collisions with multiple
// background formatters on the same page.
$id = 'picture-background-formatter-' . $selector;
......@@ -247,7 +273,8 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
'tags' => $cache_tags,
'contexts' => $cache_contexts,
],
], $id];
], $id,
];
}
}
}
......@@ -318,7 +345,7 @@ class BgImgFieldFormatter extends ResponsiveImageFormatter implements ContainerF
$url = \Drupal::service('file_url_generator')->generateAbsoluteString($image->getFileUri());
}
else {
$url = ImageStyle::load($mapping['image_mapping'])->buildUrl($image->getFileUri());
$url = $this->imageFactory->load($mapping['image_mapping'])->buildUrl($image->getFileUri());
}
if ($multiplier != 1) {
......
......@@ -6,7 +6,6 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\image\Plugin\Field\FieldType\ImageItem;
use Robo\State\Data;
/**
* Plugin implementation of the 'bg_img_field' field type.
......
......@@ -4,6 +4,7 @@ namespace Drupal\bg_img_field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\image\Plugin\Field\FieldWidget\ImageWidget;
/**
......@@ -19,6 +20,8 @@ use Drupal\image\Plugin\Field\FieldWidget\ImageWidget;
*/
class BgImageFieldWidget extends ImageWidget {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
......@@ -42,9 +45,9 @@ class BgImageFieldWidget extends ImageWidget {
$item = $items[$delta]->getFieldDefinition()->getSettings();
// set the form state with values of css_settings and hide_css_settings
// Set the form state with values of css_settings and hide_css_settings
// to be used by the process method.
$form_state->set('css_values',$item['css_settings'] );
$form_state->set('css_values', $item['css_settings']);
$form_state->set('hide_css_settings', $this->getSetting('hide_css_settings'));
$elements['#upload_validators']['file_validate_extensions'][0] =
......@@ -83,8 +86,10 @@ class BgImageFieldWidget extends ImageWidget {
'#title' => t('CSS Settings'),
'#description' => t('Set default CSS properties for the background image.'),
'#open' => FALSE,
'#attributes' => $form_state->get('hide_css_settings') ? ['class' =>
['visually-hidden']] : ['class' => ['visually-shown']],
'#attributes' => $form_state->get('hide_css_settings') ? [
'class' =>
['visually-hidden'],
] : ['class' => ['visually-shown']],
];
$token_types = [];
......@@ -176,13 +181,16 @@ class BgImageFieldWidget extends ImageWidget {
return $elements;
}
/**
* The settings form.
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element['hide_css_settings'] = [
'#type' => 'checkbox',
'#title' => t("Hide CSS Settings"),
'#description' => t("Do not show CSS settings when creating content
'#title' => $this->t("Hide CSS Settings"),
'#description' => $this->t("Do not show CSS settings when creating content
on nodes, blocks, custom entities, media, and paragraph items"),
'#default_value' => $this->getSetting('hide_css_settings'),
];
......
<?php
namespace Drupal\bg_img_field\Plugin\media\Source;
use Drupal\media\Plugin\media\Source\Image;
......@@ -19,4 +20,4 @@ use Drupal\media\Plugin\media\Source\Image;
*/
class BackgroundImageMedia extends Image {
}
\ No newline at end of file
}
<style>
{{ css }}
</style>
\ No newline at end of file
</style>
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