Skip to content
Snippets Groups Projects
Commit 00ece8b7 authored by Dominique CLAUSE's avatar Dominique CLAUSE
Browse files

Issue #3354825 by Dom., dineshkumarbollu: Coding standards

parent 671e4bef
Branches
Tags
No related merge requests found
......@@ -18,14 +18,16 @@ Composer dependencies installation
2- Install wikimedia/composer-merge-plugin :
composer require wikimedia/composer-merge-plugin
3- Edit your "merge-plugin" section under "extra" in your *root* composer.json so it looks like :
3- Edit your "merge-plugin" section under "extra" in your *root* composer.json
so it looks like :
"extra": {
"merge-plugin": {
"include": [
"modules/contrib/masonry/composer.libraries.json"
],
Beware to change the path to your contrib module folder if under web or docroot for instance
Beware to change the path to your contrib module folder if under web or docroot
for instance.
3- Run a locked update:
composer update --lock
......@@ -55,4 +57,3 @@ Download and unzip imagesloaded from http://imagesloaded.desandro.com/
and place it into /libraries folder so the following path exists:
/libraries/imagesloaded/imagesloaded.pkgd.min.js
......@@ -4,32 +4,34 @@
* @file
* Hooks provided by Masonry.
*
* Sponsored by: www.freelance-drupal.com
* Sponsored by: www.freelance-drupal.com.
*/
/**
* Alter Masonry's default options.
*
* @param $options
* @param array $options
* An associative array of option names and their default values.
*/
function hook_masonry_default_options_alter(&$options) {
// Add default value for easing option
function hook_masonry_default_options_alter(array &$options) {
// Add default value for easing option.
$options['masonry_animation_easing'] = 'swing';
}
/**
* Alter the Masonry options form.
*
* This allows you to define UI configuration for a custom configuration.
* @see hook_masonry_default_options_alter().
*
* @param $form
* @param array $form
* A form array.
* @param $default_values
* @param array $default_values
* An array of default form values.
*
* @see hook_masonry_default_options_alter()
*/
function hook_masonry_options_form_alter(&$form, $default_values) {
// Add form item for easing option
function hook_masonry_options_form_alter(array &$form, array $default_values) {
// Add form item for easing option.
$form['layoutAnimationEasing'] = [
'#type' => 'select',
'#title' => t('Animation easing'),
......@@ -51,26 +53,25 @@ function hook_masonry_options_form_alter(&$form, $default_values) {
/**
* Alter the Masonry script.
*
* @param $masonry
* @param array $masonry
* An array of Masonry options to send to the script file.
* @param $context
* @param array $context
* An associative array of additional variables.
* Contains:
* - container: The CSS selector of the container element to apply Masonry to.
* - options: An associative array of Masonry options. See masonry_apply().
*/
function hook_masonry_script_alter(&$masonry, $context) {
function hook_masonry_script_alter(array &$masonry, array $context) {
$container = $context['container'];
$options = $context['options'];
// Send easing option to the script file
// Note: this new option has to be introduce via hook_masonry_options_form_alter()
// otherwise use extra_options.
// Note: this new option has to be introduced via
// hook_masonry_options_form_alter() otherwise use extra_options.
$masonry['masonry'][$container]['animation_easing'] = $options['layoutAnimationEasing'];
// Set the option "horizontalOrder" to true.
// Note that this option is not included into the predefined options
// Note that this option is not included into the predefined options.
// @see MasonryService::getMasonryDefaultOptions
$masonry['masonry'][$container]['extra_options']['horizontalOrder'] = TRUE;
}
......@@ -33,7 +33,6 @@ function masonry_libraries_info() {
'download url' => 'http://desandro.github.io/imagesloaded/imagesloaded.pkgd.min.js',
'version arguments' => [
'file' => 'imagesloaded.pkgd.min.js',
// imagesLoaded 3.x
'pattern' => '/imagesLoaded\s+PACKAGED\s+v?([0-9\.]+)/',
'lines' => 2,
'cols' => 35,
......@@ -48,20 +47,6 @@ function masonry_libraries_info() {
return $libraries;
}
/**
* Check if the Masonry and imagesLoaded libraries have been loaded.
*
* @return
* A boolean indicating the loaded status.
*
* @deprecated
* Use \Drupal::service('masonry.service')->isMasonryInstalled() and
* \Drupal::service('masonry.service')->isImagesloadedInstalled() instead.
*/
function masonry_loaded() {
return (\Drupal::service('masonry.service')->isMasonryInstalled() && \Drupal::service('masonry.service')->isImagesloadedInstalled());
}
/**
* Implements hook_library_info_alter().
*
......@@ -77,15 +62,14 @@ function masonry_library_info_alter(&$libraries, $extension) {
if ($masonryPath = $masonryService->isMasonryInstalled()) {
$libraries['masonry']['js'] = [
"/$masonryPath" => ['minified' => true]
"/$masonryPath" => ['minified' => TRUE],
];
}
if ($imagesLoaded = $masonryService->isImagesloadedInstalled()) {
$libraries['imagesloaded']['js'] = [
"/$imagesLoaded" => ['minified' => true]
$libraries['imagesloaded']['js'] = [
"/$imagesLoaded" => ['minified' => TRUE],
];
}
}
}
<?php
/**
* @file
* Masonry service file.
*
* Sponsored by: www.freelance-drupal.com
*/
namespace Drupal\masonry\Services;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Theme\ThemeManagerInterface;
/**
* Wrapper methods for Masonry API methods.
*
*
* @ingroup masonry
*/
class MasonryService {
use StringTranslationTrait;
/**
* The module handler service.
......@@ -38,14 +32,14 @@ class MasonryService {
protected $themeManager;
/**
* The language manager service
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The config factory service
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
......@@ -63,7 +57,7 @@ class MasonryService {
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, LanguageManager $language_manager, ConfigFactoryInterface $config_factory) {
public function __construct(ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) {
$this->moduleHandler = $module_handler;
$this->themeManager = $theme_manager;
$this->languageManager = $language_manager;
......@@ -152,15 +146,17 @@ class MasonryService {
* - masonry_resizable: Automatically rearrange items when the container is
* resized.
* - masonry_animated: Animate item rearrangements.
* - masonry_animation_duration: The duration of animations in milliseconds.
* - masonry_animation_duration: The duration of animations in milliseconds.
* - masonry_fit_width: Sets the width of the container to the nearest
* column.
* Ideal for centering Masonry layouts.
* Ideal for centering Masonry layouts.
* - masonry_rtl: Display items from right-to-left.
* - masonry_images_first: Load all images first before triggering Masonry.
* @param string[] $masonry_ids
* Some optional IDs to target this particular display in
* hook_masonry_script_alter().
*/
public function applyMasonryDisplay(&$form, $container, $item_selector, $options = [], $masonry_ids = ['masonry_default']) {
public function applyMasonryDisplay(array &$form, string $container, string $item_selector, array $options = [], array $masonry_ids = ['masonry_default']) {
if (!empty($container)) {
// For any options not specified, use default options.
......@@ -216,13 +212,13 @@ class MasonryService {
/**
* Build the masonry setting configuration form.
*
* @param array (optional)
* The default values for the form.
* @param array $default_values
* (optional) The default values for the form.
*
* @return array
* The form
* The form.
*/
public function buildSettingsForm($default_values = []) {
public function buildSettingsForm(array $default_values = []) {
// Load module default values if empty.
if (empty($default_values)) {
......@@ -231,43 +227,43 @@ class MasonryService {
$form['layoutColumnWidth'] = [
'#type' => 'textfield',
'#title' => t('Column width'),
'#description' => t("The width of each column, enter pixels, percentage, or string of css selector"),
'#title' => $this->t('Column width'),
'#description' => $this->t("The width of each column, enter pixels, percentage, or string of css selector"),
'#default_value' => $default_values['layoutColumnWidth'],
];
$form['layoutColumnWidthUnit'] = [
'#type' => 'radios',
'#title' => t('Column width units'),
'#description' => t("The units to use for the column width."),
'#title' => $this->t('Column width units'),
'#description' => $this->t("The units to use for the column width."),
'#options' => [
'px' => t("Pixels"),
'%' => t("Percentage (of container's width)"),
'css' => t("CSS selector (you must configure your css to set widths for .masonry-item)"),
'px' => $this->t("Pixels"),
'%' => $this->t("Percentage (of container's width)"),
'css' => $this->t("CSS selector (you must configure your css to set widths for .masonry-item)"),
],
'#default_value' => $default_values['layoutColumnWidthUnit'],
];
$form['gutterWidth'] = [
'#type' => 'textfield',
'#title' => t('Gutter width'),
'#description' => t("The spacing between each column, enter pixels, or string of css selector"),
'#title' => $this->t('Gutter width'),
'#description' => $this->t("The spacing between each column, enter pixels, or string of css selector"),
'#default_value' => $default_values['gutterWidth'],
];
$form['stampSelector'] = [
'#type' => 'textfield',
'#title' => t('Stamp Selector'),
'#description' => t("Specifies which elements are stamped within the layout using css selector"),
'#title' => $this->t('Stamp Selector'),
'#description' => $this->t("Specifies which elements are stamped within the layout using css selector"),
'#default_value' => $default_values['stampSelector'],
];
$form['isLayoutResizable'] = [
'#type' => 'checkbox',
'#title' => t('Resizable'),
'#description' => t("Automatically rearrange items when the container is resized."),
'#title' => $this->t('Resizable'),
'#description' => $this->t("Automatically rearrange items when the container is resized."),
'#default_value' => $default_values['isLayoutResizable'],
];
$form['isLayoutAnimated'] = [
'#type' => 'checkbox',
'#title' => t('Animated'),
'#description' => t("Animate item rearrangements."),
'#title' => $this->t('Animated'),
'#description' => $this->t("Animate item rearrangements."),
'#default_value' => $default_values['isLayoutAnimated'],
'#states' => [
'visible' => [
......@@ -277,12 +273,12 @@ class MasonryService {
];
$form['layoutAnimationDuration'] = [
'#type' => 'textfield',
'#title' => t('Animation duration'),
'#description' => t("The duration of animations (1000 ms = 1 sec)."),
'#title' => $this->t('Animation duration'),
'#description' => $this->t("The duration of animations (1000 ms = 1 sec)."),
'#default_value' => $default_values['layoutAnimationDuration'],
'#size' => 5,
'#maxlength' => 4,
'#field_suffix' => t('ms'),
'#field_suffix' => $this->t('ms'),
'#states' => [
'visible' => [
'input.form-checkbox[name*="isLayoutResizable"]' => ['checked' => TRUE],
......@@ -292,26 +288,26 @@ class MasonryService {
];
$form['isLayoutFitsWidth'] = [
'#type' => 'checkbox',
'#title' => t('Fit width'),
'#description' => t("Sets the width of the container to the nearest column. Ideal for centering Masonry layouts. See the <a href='http://masonry.desandro.com/demos/centered.html'>'Centered' demo</a> for more information."),
'#title' => $this->t('Fit width'),
'#description' => $this->t("Sets the width of the container to the nearest column. Ideal for centering Masonry layouts. See the <a href='http://masonry.desandro.com/demos/centered.html'>'Centered' demo</a> for more information."),
'#default_value' => $default_values['isLayoutFitsWidth'],
];
$form['isLayoutImagesLoadedFirst'] = [
'#type' => 'checkbox',
'#title' => t('Load images first'),
'#description' => t("Load all images first before triggering Masonry."),
'#title' => $this->t('Load images first'),
'#description' => $this->t("Load all images first before triggering Masonry."),
'#default_value' => $default_values['isLayoutImagesLoadedFirst'],
];
$form['isLayoutImagesLazyLoaded'] = [
'#type' => 'checkbox',
'#title' => t('Add listener for lazy loaded images.'),
'#description' => t("If using the lazysizes library, you should probably activate this option."),
'#title' => $this->t('Add listener for lazy loaded images.'),
'#description' => $this->t("If using the lazysizes library, you should probably activate this option."),
'#default_value' => $default_values['isLayoutImagesLazyLoaded'],
];
$form['isItemsPositionInPercent'] = [
'#type' => 'checkbox',
'#title' => t('Percent position'),
'#description' => t("Sets item positions in percent values, rather than pixel values. Checking this will works well with percent-width items, as items will not transition their position on resize. See the <a href='http://masonry.desandro.com/options.html#percentposition'>masonry doc</a> for more information."),
'#title' => $this->t('Percent position'),
'#description' => $this->t("Sets item positions in percent values, rather than pixel values. Checking this will works well with percent-width items, as items will not transition their position on resize. See the <a href='http://masonry.desandro.com/options.html#percentposition'>masonry doc</a> for more information."),
'#default_value' => $default_values['isItemsPositionInPercent'],
];
......@@ -325,7 +321,7 @@ class MasonryService {
/**
* Check if the Masonry library is installed.
*
* @return string|NULL
* @return string|null
* The masonry library install path.
*/
public function isMasonryInstalled() {
......@@ -346,7 +342,7 @@ class MasonryService {
/**
* Check if the ImagesLoaded library is installed.
*
* @return string|NULL
* @return string|null
* The imagesloaded library install path.
*/
public function isImagesloadedInstalled() {
......@@ -363,4 +359,5 @@ class MasonryService {
return file_exists($library_path) ? $library_path : NULL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment