Skip to content
Snippets Groups Projects
Commit fa707979 authored by Sven Decabooter's avatar Sven Decabooter
Browse files

Issue #3345494 by svendecabooter: Fix coding style

parent 55dc7c40
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
"homepage": "https://www.drupal.org/project/hms_field",
"support": {
"issues": "https://www.drupal.org/project/issues/hms_field",
"source": "http://cgit.drupalcode.org/hms_field"
"source": "http://cgit.drupalcode.org/hms_field",
},
"license": "GPL-2.0+",
}
......@@ -55,7 +55,7 @@ class HMS extends FormElement {
$form_state->setValueForElement($element, $value);
if ($value !== '' && !\Drupal::service('hms_field.hms')->isValid($value, $element['#format'], $element, $form_state)) {
$form_state->setError($element, t('Please enter a correct hms value in format %format.', ['%format' => $element['#format']]));
$form_state->setError($element, $this->t('Please enter a correct hms value in format %format.', ['%format' => $element['#format']]));
}
else {
// Format given value to seconds if input is valid.
......
......@@ -4,6 +4,7 @@ namespace Drupal\hms_field;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Provides a service to handle various hms related functionality.
......@@ -12,6 +13,8 @@ use Drupal\Core\Form\FormStateInterface;
*/
class HMSService implements HMSServiceInterface {
use StringTranslationTrait;
/**
* The module handler service.
*
......@@ -32,7 +35,7 @@ class HMSService implements HMSServiceInterface {
/**
* {@inheritdoc}
*/
public function formatOptions() {
public function formatOptions(): array {
$format = drupal_static(__FUNCTION__);
if (empty($format)) {
$format = [
......
......@@ -64,16 +64,16 @@ class HMSFormatter extends FormatterBase implements ContainerFactoryPluginInterf
$settings = $this->getSettings();
$elements['format'] = [
'#type' => 'select',
'#title' => t('Display format'),
'#title' => $this->t('Display format'),
'#options' => $this->hms_service->formatOptions(),
'#description' => t('The display format used for this field'),
'#description' => $this->t('The display format used for this field'),
'#default_value' => $settings['format'],
'#required' => TRUE,
];
$elements['leading_zero'] = [
'#type' => 'checkbox',
'#title' => t('Leading zero'),
'#description' => t('Leading zero values will be displayed when this option is checked'),
'#title' => $this->t('Leading zero'),
'#description' => $this->t('Leading zero values will be displayed when this option is checked'),
'#default_value' => $settings['leading_zero'],
];
return $elements;
......@@ -85,8 +85,8 @@ class HMSFormatter extends FormatterBase implements ContainerFactoryPluginInterf
public function settingsSummary() {
$summary = [];
$settings = $this->getSettings();
$summary[] = t('Format: @format', ['@format' => $settings['format']]);
$summary[] = t('Leading zero: @zero', ['@zero' => ($settings['leading_zero'] ? t('On') : t('Off'))]);
$summary[] = $this->t('Format: @format', ['@format' => $settings['format']]);
$summary[] = $this->t('Leading zero: @zero', ['@zero' => ($settings['leading_zero'] ? $this->t('On') : $this->t('Off'))]);
return $summary;
}
......
......@@ -88,7 +88,7 @@ class HMSNaturalLanguageFormatter extends FormatterBase implements ContainerFact
];
$elements['last_separator'] = [
'#type' => 'textfield',
'#title' => t('Last separator'),
'#title' => $this->t('Last separator'),
'#description' => $this->t('Separator used between the last 2 fragments'),
'#default_value' => $this->getSetting('last_separator'),
'#required' => FALSE,
......
......@@ -57,22 +57,22 @@ class HMSFieldWidget extends WidgetBase implements ContainerFactoryPluginInterfa
$elements['format'] = [
'#type' => 'select',
'#title' => t('Input format'),
'#title' => $this->t('Input format'),
'#default_value' => $this->getSetting('format'),
'#options' => $this->hms_service->formatOptions(),
'#description' => t('The input format used for this field.'),
'#description' => $this->t('The input format used for this field.'),
];
$elements['default_placeholder'] = [
'#type' => 'checkbox',
'#title' => t('Default placeholder'),
'#title' => $this->t('Default placeholder'),
'#default_value' => $this->getSetting('default_placeholder'),
'#description' => t('Provide a default placeholder with the format.'),
'#description' => $this->t('Provide a default placeholder with the format.'),
];
$elements['placeholder'] = [
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#title' => $this->t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
'#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
'#states' => [
'invisible' => [
':input[name*="default_placeholder"]' => ['checked' => TRUE],
......@@ -88,8 +88,8 @@ class HMSFieldWidget extends WidgetBase implements ContainerFactoryPluginInterfa
public function settingsSummary() {
$summary = [];
$summary[] = t('Format: @format', ['@format' => $this->getSetting('format')]);
$summary[] = t('Placeholder: @value', ['@value' => ($this->getSetting('default_placeholder') ? $this->getSetting('format') : $this->getSetting('placeholder'))]);
$summary[] = $this->t('Format: @format', ['@format' => $this->getSetting('format')]);
$summary[] = $this->t('Placeholder: @value', ['@value' => ($this->getSetting('default_placeholder') ? $this->getSetting('format') : $this->getSetting('placeholder'))]);
return $summary;
}
......
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