summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrigids-PUCC2017-06-21 14:50:13 (GMT)
committerRenato Goncalves de Araujo2017-06-21 14:50:13 (GMT)
commit07bcb2dd635f85a4d718a420c92133b13b0f679d (patch)
tree8bb467a56dcc0e2c4c8d86e5cdfc7dc7b7e81e33
parent17ba110cba8de198dc0f80cf8b458647b645f1eb (diff)
Issue #2888120 by Yago Elias, RenatoG: Coding standards and best practices
-rw-r--r--src/Form/ColorboxSettingsForm.php87
-rw-r--r--src/Plugin/Field/FieldFormatter/ColorboxFormatter.php21
2 files changed, 73 insertions, 35 deletions
diff --git a/src/Form/ColorboxSettingsForm.php b/src/Form/ColorboxSettingsForm.php
index 549a717..ed54747 100644
--- a/src/Form/ColorboxSettingsForm.php
+++ b/src/Form/ColorboxSettingsForm.php
@@ -2,8 +2,11 @@
namespace Drupal\colorbox\Form;
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* General configuration form for controlling the colorbox behaviour..
@@ -21,6 +24,31 @@ class ColorboxSettingsForm extends ConfigFormBase {
const STATE_SLIDESHOW_ENABLED = 1;
/**
+ * Drupal\Core\Extension\ModuleHandlerInterface definition.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ private $moduleHandler;
+
+ /**
+ * Class constructor.
+ */
+ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler) {
+ parent::__construct($config_factory);
+ $this->moduleHandler = $moduleHandler;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('config.factory'),
+ $container->get('module_handler')
+ );
+ }
+
+ /**
* {@inheritdoc}
*/
public function getFormId() {
@@ -296,8 +324,7 @@ class ColorboxSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('advanced.compression_type'),
];
- $moduleHandler = \Drupal::service('module_handler');
- if (!$moduleHandler->moduleExists('colorbox_load') || !$moduleHandler->moduleExists('colorbox_inline')) {
+ if (!$this->moduleHandler->moduleExists('colorbox_load') || !$this->moduleHandler->moduleExists('colorbox_inline')) {
$form['colorbox_extras'] = [
'#type' => 'details',
@@ -323,34 +350,34 @@ class ColorboxSettingsForm extends ConfigFormBase {
$config = $this->configFactory->getEditable('colorbox.settings');
$config
- ->set('custom.style', $form_state->getValue('colorbox_style'))
- ->set('custom.activate', $form_state->getValue('colorbox_custom_settings_activate'))
- ->set('custom.transition_type', $form_state->getValue('colorbox_transition_type'))
- ->set('custom.transition_speed', $form_state->getValue('colorbox_transition_speed'))
- ->set('custom.opacity', $form_state->getValue('colorbox_opacity'))
- ->set('custom.text_current', $form_state->getValue('colorbox_text_current'))
- ->set('custom.text_previous', $form_state->getValue('colorbox_text_previous'))
- ->set('custom.text_next', $form_state->getValue('colorbox_text_next'))
- ->set('custom.text_close', $form_state->getValue('colorbox_text_close'))
- ->set('custom.overlayclose', $form_state->getValue('colorbox_overlayclose'))
- ->set('custom.returnfocus', $form_state->getValue('colorbox_returnfocus'))
- ->set('custom.maxwidth', $form_state->getValue('colorbox_maxwidth'))
- ->set('custom.maxheight', $form_state->getValue('colorbox_maxheight'))
- ->set('custom.initialwidth', $form_state->getValue('colorbox_initialwidth'))
- ->set('custom.initialheight', $form_state->getValue('colorbox_initialheight'))
- ->set('custom.fixed', $form_state->getValue('colorbox_fixed'))
- ->set('custom.scrolling', $form_state->getValue('colorbox_scrolling'))
- ->set('custom.slideshow.slideshow', $form_state->getValue('colorbox_slideshow'))
- ->set('custom.slideshow.auto', $form_state->getValue('colorbox_slideshowauto'))
- ->set('custom.slideshow.speed', $form_state->getValue('colorbox_slideshowspeed'))
- ->set('custom.slideshow.text_start', $form_state->getValue('colorbox_text_start'))
- ->set('custom.slideshow.text_stop', $form_state->getValue('colorbox_text_stop'))
- ->set('advanced.unique_token', $form_state->getValue('colorbox_unique_token'))
- ->set('advanced.mobile_detect', $form_state->getValue('colorbox_mobile_detect'))
- ->set('advanced.mobile_device_width', $form_state->getValue('colorbox_mobile_device_width'))
- ->set('advanced.caption_trim', $form_state->getValue('colorbox_caption_trim'))
- ->set('advanced.caption_trim_length', $form_state->getValue('colorbox_caption_trim_length'))
- ->set('advanced.compression_type', $form_state->getValue('colorbox_compression_type'));
+ ->set('custom.style', $form_state->getValue('colorbox_style'))
+ ->set('custom.activate', $form_state->getValue('colorbox_custom_settings_activate'))
+ ->set('custom.transition_type', $form_state->getValue('colorbox_transition_type'))
+ ->set('custom.transition_speed', $form_state->getValue('colorbox_transition_speed'))
+ ->set('custom.opacity', $form_state->getValue('colorbox_opacity'))
+ ->set('custom.text_current', $form_state->getValue('colorbox_text_current'))
+ ->set('custom.text_previous', $form_state->getValue('colorbox_text_previous'))
+ ->set('custom.text_next', $form_state->getValue('colorbox_text_next'))
+ ->set('custom.text_close', $form_state->getValue('colorbox_text_close'))
+ ->set('custom.overlayclose', $form_state->getValue('colorbox_overlayclose'))
+ ->set('custom.returnfocus', $form_state->getValue('colorbox_returnfocus'))
+ ->set('custom.maxwidth', $form_state->getValue('colorbox_maxwidth'))
+ ->set('custom.maxheight', $form_state->getValue('colorbox_maxheight'))
+ ->set('custom.initialwidth', $form_state->getValue('colorbox_initialwidth'))
+ ->set('custom.initialheight', $form_state->getValue('colorbox_initialheight'))
+ ->set('custom.fixed', $form_state->getValue('colorbox_fixed'))
+ ->set('custom.scrolling', $form_state->getValue('colorbox_scrolling'))
+ ->set('custom.slideshow.slideshow', $form_state->getValue('colorbox_slideshow'))
+ ->set('custom.slideshow.auto', $form_state->getValue('colorbox_slideshowauto'))
+ ->set('custom.slideshow.speed', $form_state->getValue('colorbox_slideshowspeed'))
+ ->set('custom.slideshow.text_start', $form_state->getValue('colorbox_text_start'))
+ ->set('custom.slideshow.text_stop', $form_state->getValue('colorbox_text_stop'))
+ ->set('advanced.unique_token', $form_state->getValue('colorbox_unique_token'))
+ ->set('advanced.mobile_detect', $form_state->getValue('colorbox_mobile_detect'))
+ ->set('advanced.mobile_device_width', $form_state->getValue('colorbox_mobile_device_width'))
+ ->set('advanced.caption_trim', $form_state->getValue('colorbox_caption_trim'))
+ ->set('advanced.caption_trim_length', $form_state->getValue('colorbox_caption_trim_length'))
+ ->set('advanced.compression_type', $form_state->getValue('colorbox_compression_type'));
if ($form_state->getValue('colorbox_image_style')) {
$config->set('insert.image_style', $form_state->getValue('colorbox_image_style'));
diff --git a/src/Plugin/Field/FieldFormatter/ColorboxFormatter.php b/src/Plugin/Field/FieldFormatter/ColorboxFormatter.php
index eec56df..a648d8f 100644
--- a/src/Plugin/Field/FieldFormatter/ColorboxFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/ColorboxFormatter.php
@@ -3,6 +3,7 @@
namespace Drupal\colorbox\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Link;
@@ -45,6 +46,13 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
protected $imageStyleStorage;
/**
+ * Drupal\Core\Extension\ModuleHandlerInterface definition.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ */
+ private $moduleHandler;
+
+ /**
* Constructs an ImageFormatter object.
*
* @param string $plugin_id
@@ -67,12 +75,15 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
* The image style storage.
* @param \Drupal\colorbox\ElementAttachmentInterface $attachment
* Allow the library to be attached to the page.
+ * @param Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
+ * Module handler services.
*/
- 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) {
+ 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) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
$this->imageStyleStorage = $image_style_storage;
$this->attachment = $attachment;
+ $this->moduleHandler = $moduleHandler;
}
/**
@@ -178,10 +189,10 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
],
],
];
- if (\Drupal::moduleHandler()->moduleExists('token')) {
+ if ($this->moduleHandler->moduleExists('token')) {
$element['colorbox_token_gallery'] = [
'#type' => 'fieldset',
- '#title' => t('Replacement patterns'),
+ '#title' => $this->t('Replacement patterns'),
'#theme' => 'token_tree_link',
'#token_types' => [$form['#entity_type'], 'file'],
'#states' => [
@@ -229,10 +240,10 @@ class ColorboxFormatter extends ImageFormatterBase implements ContainerFactoryPl
],
],
];
- if (\Drupal::moduleHandler()->moduleExists('token')) {
+ if ($this->moduleHandler->moduleExists('token')) {
$element['colorbox_token_caption'] = [
'#type' => 'fieldset',
- '#title' => t('Replacement patterns'),
+ '#title' => $this->t('Replacement patterns'),
'#theme' => 'token_tree_link',
'#token_types' => [$form['#entity_type'], 'file'],
'#states' => [