Skip to content
Snippets Groups Projects
Commit ab7cd99e authored by Pavlo Tyshchenko's avatar Pavlo Tyshchenko
Browse files

Issue #2789807 by azovsky: Coding standards

parent 9c871f57
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ class AdvancedTextFormatter extends FormatterBase {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'trim_length' => 600,
'ellipsis' => 1,
'word_boundary' => 1,
......@@ -47,7 +47,7 @@ class AdvancedTextFormatter extends FormatterBase {
'allowed_html' => '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>',
'autop' => 0,
'use_summary' => 0,
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
......@@ -57,7 +57,7 @@ class AdvancedTextFormatter extends FormatterBase {
$elTrimLengthId = Html::getUniqueId('advanced_text_formatter_trim');
$elFilterId = Html::getUniqueId('advanced_text_formatter_filter');
$element['trim_length'] = array(
$element['trim_length'] = [
'#id' => $elTrimLengthId,
'#type' => 'number',
'#title' => $this->t('Trim length'),
......@@ -65,75 +65,75 @@ class AdvancedTextFormatter extends FormatterBase {
'#size' => 10,
'#default_value' => $this->getSetting('trim_length'),
'#required' => TRUE,
);
];
$element['ellipsis'] = array(
$element['ellipsis'] = [
'#type' => 'checkbox',
'#title' => $this->t('Ellipsis'),
'#description' => $this->t('If checked, a "..." will be added if a field was trimmed.'),
'#default_value' => $this->getSetting('ellipsis'),
'#states' => array(
'visible' => array(
'#' . $elTrimLengthId => array('!value' => '0'),
),
),
);
$element['word_boundary'] = array(
'#states' => [
'visible' => [
'#' . $elTrimLengthId => ['!value' => '0'],
],
],
];
$element['word_boundary'] = [
'#type' => 'checkbox',
'#title' => $this->t('Word Boundary'),
'#description' => $this->t('If checked, this field be trimmed only on a word boundary.'),
'#default_value' => $this->getSetting('word_boundary'),
'#states' => array(
'visible' => array(
'#' . $elTrimLengthId => array('!value' => '0'),
),
),
);
$element['use_summary'] = array(
'#states' => [
'visible' => [
'#' . $elTrimLengthId => ['!value' => '0'],
],
],
];
$element['use_summary'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use Summary'),
'#description' => $this->t('If a summary exists, use it.'),
'#default_value' => $this->getSetting('use_summary'),
);
];
$token_link = _advanced_text_formatter_browse_tokens($this->fieldDefinition->getTargetEntityTypeId());
$element['token_replace'] = array(
$element['token_replace'] = [
'#type' => 'checkbox',
'#description' => $this->t('Replace text pattern. e.g %node-title-token or %node-author-name-token, by token values.', array(
'#description' => $this->t('Replace text pattern. e.g %node-title-token or %node-author-name-token, by token values.', [
'%node-title-token' => '[node:title]',
'%node-author-name-token' => '[node:author:name]',
)) . ' ' /*. $token_link*/,
]) . ' ' /*. $token_link*/,
'#title' => $this->t('Token Replace'),
'#default_value' => $this->getSetting('token_replace'),
);
];
$element['filter'] = array(
$element['filter'] = [
'#id' => $elFilterId,
'#title' => $this->t('Filter'),
'#type' => 'select',
'#options' => array(
'#options' => [
static::FORMAT_NONE => $this->t('None'),
static::FORMAT_INPUT => $this->t('Selected Text Format'),
static::FORMAT_PHP => $this->t('Limit allowed HTML tags'),
static::FORMAT_DRUPAL => $this->t('Drupal'),
),
],
'#default_value' => $this->getSetting('filter'),
);
];
$element['format'] = array(
$element['format'] = [
'#title' => $this->t('Format'),
'#type' => 'select',
'#options' => array(),
'#options' => [],
'#default_value' => $this->getSetting('format'),
'#states' => array(
'visible' => array(
'#' . $elFilterId => array('value' => 'drupal'),
),
),
);
'#states' => [
'visible' => [
'#' . $elFilterId => ['value' => 'drupal'],
],
],
];
$formats = filter_formats();
......@@ -153,34 +153,34 @@ class AdvancedTextFormatter extends FormatterBase {
$tags = '<' . implode('> <', $allowedHtml) . '>';
}
$element['allowed_html'] = array(
$element['allowed_html'] = [
'#type' => 'textfield',
'#title' => $this->t('Allowed HTML tags'),
'#description' => $this->t('See <a href="@link" target="_blank">filter_xss()</a> for more information', array(
'#description' => $this->t('See <a href="@link" target="_blank">filter_xss()</a> for more information', [
'@link' => 'http://api.drupal.org/api/drupal/core%21includes%21common.inc/function/filter_xss/8',
)),
]),
'#default_value' => $tags,
'#element_validate' => array('_advanced_text_formatter_validate_allowed_html'),
'#states' => array(
'visible' => array(
'#' . $elFilterId => array('value' => 'php'),
),
),
);
$element['autop'] = array(
'#element_validate' => ['_advanced_text_formatter_validate_allowed_html'],
'#states' => [
'visible' => [
'#' . $elFilterId => ['value' => 'php'],
],
],
];
$element['autop'] = [
'#title' => $this->t('Converts line breaks into HTML (i.e. &lt;br&gt; and &lt;p&gt;) tags.'),
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => $this->getSetting('autop'),
'#states' => array(
'invisible' => array(
'#' . $elFilterId => array('!value' => 'php'),
),
),
);
'#states' => [
'invisible' => [
'#' . $elFilterId => ['!value' => 'php'],
],
],
];
$element['br'] = array('#markup' => '<br/>');
$element['br'] = ['#markup' => '<br/>'];
return $element;
}
......@@ -189,18 +189,18 @@ class AdvancedTextFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary = [];
$yes = $this->t('Yes');
$no = $this->t('No');
if ($this->getSetting('trim_length') > 0) {
$summary[] = $this->t('Trim length') . ': ' . $this->getSetting('trim_length');
$summary[] = $this->t('Ellipsis') . ': ' . ($this->getSetting('ellipsis') ? $yes : $no);
$summary[] = $this->t('Word Boundary') . ': ' . ($this->getSetting('word_boundary') ? $yes : $no);
$summary[] = $this->t('Use Summary') . ': ' . ($this->getSetting('use_summary') ? $yes : $no);
$summary[] = $this->t('Trim length: @length', ['@length' => $this->getSetting('trim_length')]);
$summary[] = $this->t('Ellipsis: @ellipsis', ['@ellipsis' => $this->getSetting('ellipsis') ? $yes : $no]);
$summary[] = $this->t('Word Boundary: @word', ['@word' => $this->getSetting('word_boundary') ? $yes : $no]);
$summary[] = $this->t('Use Summary: @summary', ['@summary' => $this->getSetting('use_summary') ? $yes : $no]);
}
$summary[] = $this->t('Token Replace') . ': ' . ($this->getSetting('token_replace') ? $yes : $no);
$summary[] = $this->t('Token Replace: @token', ['@token' => $this->getSetting('token_replace') ? $yes : $no]);
switch ($this->getSetting('filter')) {
case static::FORMAT_DRUPAL:
......@@ -208,13 +208,13 @@ class AdvancedTextFormatter extends FormatterBase {
$format = $this->getSetting('format');
$format = isset($formats[$format]) ? $formats[$format]->get('name') : $this->t('Unknown');
$summary[] = $this->t('Filter: @filter', array('@filter' => $this->t('Drupal')));
$summary[] = $this->t('Format: @format', array('@format' => $format));
$summary[] = $this->t('Filter: @filter', ['@filter' => $this->t('Drupal')]);
$summary[] = $this->t('Format: @format', ['@format' => $format]);
break;
case static::FORMAT_PHP:
$text = array();
$text = [];
$tags = $this->getSetting('allowed_html');
$autop = $this->getSetting('autop');
......@@ -226,24 +226,24 @@ class AdvancedTextFormatter extends FormatterBase {
$text[] = $this->t('Remove all HTML tags.');
}
else {
$text[] = $this->t('Limit allowed HTML tags: @tags.', array('@tags' => $tags));
$text[] = $this->t('Limit allowed HTML tags: @tags.', ['@tags' => $tags]);
}
if (!empty($autop)) {
$text[] = $this->t('Convert line breaks into HTML.');
}
$summary[] = $this->t('Filter: @filter', array('@filter' => implode(' ', $text)));
$summary[] = $this->t('Filter: @filter', ['@filter' => implode(' ', $text)]);
break;
case static::FORMAT_INPUT:
$summary[] = $this->t('Filter: @filter', array('@filter' => $this->t('Selected Text Format')));
$summary[] = $this->t('Filter: @filter', ['@filter' => $this->t('Selected Text Format')]);
break;
default:
$summary[] = $this->t('Filter: @filter', array('@filter' => $this->t('None')));
$summary[] = $this->t('Filter: @filter', ['@filter' => $this->t('None')]);
break;
}
......@@ -257,11 +257,11 @@ class AdvancedTextFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$token_data = array(
$elements = [];
$token_data = [
'user' => \Drupal::currentUser(),
$items->getEntity()->getEntityTypeId() => $items->getEntity(),
);
];
foreach ($items as $delta => $item) {
if ($this->getSetting('use_summary') && !empty($item->summary)) {
......@@ -297,21 +297,22 @@ class AdvancedTextFormatter extends FormatterBase {
}
if ($this->getSetting('trim_length') > 0) {
$options = array(
$options = [
'word_boundary' => $this->getSetting('word_boundary'),
'max_length' => $this->getSetting('trim_length'),
'ellipsis' => $this->getSetting('ellipsis'),
);
];
$output = advanced_text_formatter_trim_text($output, $options);
}
$elements[$delta] = array(
'#markup' => $output
$elements[$delta] = [
'#markup' => $output,
'#langcode' => $item->getLangcode(),
);
];
}
return $elements;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment