Skip to content
Snippets Groups Projects
Commit ce7c8d58 authored by erutan's avatar erutan
Browse files

update for code review comment #20

parent c2dcc5db
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ class SubstrFormatter extends FormatterBase {
*/
public static function defaultSettings() {
return [
'trim_start' => t('2'),
'trim_start' => 2,
'trim_length' => NULL,
] + parent::defaultSettings();
}
......@@ -41,14 +41,14 @@ class SubstrFormatter extends FormatterBase {
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['trim_start'] = [
'#type' => 'textfield',
'#title' => $this->t('Trim Start Position:'),
'#title' => $this->t('Trim Start Position'),
'#description' => $this->t('A negative value will trim all characters from the start of the string until the specified character count from the end of the string (trimming from the left), a positive value will do the opposite and trim from the right. For the string 12345678, -3 would output 678 and 3 would output 123.'),
'#default_value' => $this->getSetting('trim_start'),
];
$element['trim_length'] = [
'#type' => 'textfield',
'#title' => $this->t('Trimmed String Length (Optional):'),
'#title' => $this->t('Trimmed String Length (Optional)'),
'#description' => $this->t('Sets the string length to a fixed number of characters. For the string 12345678, with a start position of -3, a trim length of 2 would output 67.'),
'#default_value' => $this->getSetting('trim_length'),
];
......@@ -64,16 +64,17 @@ class SubstrFormatter extends FormatterBase {
$settings = $this->getSettings();
if (!empty($settings['trim_start']) and !empty($settings['trim_length'])) {
$summary[] = $this->t(
'Display only @trim_length character(s) from the start position of @trim_start in the string.',
['@trim_start' => $settings['trim_start'], '@trim_length' => $settings['trim_length']],
);
$summary[] = $this->formatPlural($settings['trim_length'],
'Display only @trim_length character from the start position of @trim_start in the string.',
'Display only @trim_length characters from the start position of @trim_start in the string.',
['@trim_start' => $settings['trim_start'], '@trim_length' => $settings['trim_length']],
);
}
elseif (!empty($settings['trim_start']) and empty($settings['trim_length'])) {
$summary[] = $this->t(
'Display all character(s) from the start position of @trim_start in the string.',
'Display all characters from the start position of @trim_start in the string.',
['@trim_start' => $settings['trim_start']],
);
);
}
else {
$summary[] = $this->t('No trimming will occur.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment