Commit e4c86f3f authored by jurgenhaas's avatar jurgenhaas

Rewrite for short array notation

parent c03f9c70
......@@ -30,7 +30,7 @@ class ColorboxFieldFormatter extends FormatterBase {
*/
public static function defaultSettings() {
$config = \Drupal::config('colorbox.settings');
return array(
return [
'style' => $config->get('custom.style'),
'link_type' => 'content',
'link' => '',
......@@ -41,7 +41,7 @@ class ColorboxFieldFormatter extends FormatterBase {
'anchor' => '',
'class' => '',
'rel' => '',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
......@@ -50,100 +50,100 @@ class ColorboxFieldFormatter extends FormatterBase {
public function settingsForm(array $form, FormStateInterface $form_state) {
$form += parent::settingsForm($form, $form_state);
$form['style'] = array(
$form['style'] = [
'#title' => $this->t('Style of colorbox'),
'#type' => 'select',
'#default_value' => $this->getSetting('style'),
'#options' => $this->getStyles(),
'#attributes' => array(
'class' => array('colorbox-field-formatter-style'),
),
);
'#attributes' => [
'class' => ['colorbox-field-formatter-style'],
],
];
$form['link_wrapper'] = array(
$form['link_wrapper'] = [
'#type' => 'container',
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-style' => array('value' => 'default'),
),
),
);
$form['link_wrapper']['link_type'] = array(
'#states' => [
'visible' => [
'select.colorbox-field-formatter-style' => ['value' => 'default'],
],
],
];
$form['link_wrapper']['link_type'] = [
'#title' => $this->t('Link colorbox to'),
'#type' => 'select',
'#default_value' => $this->getSetting('link_type'),
'#options' => $this->getLinkTypes(),
'#attributes' => array(
'class' => array('colorbox-field-formatter-link-type'),
),
);
$form['link_wrapper']['link'] = array(
'#attributes' => [
'class' => ['colorbox-field-formatter-link-type'],
],
];
$form['link_wrapper']['link'] = [
'#title' => $this->t('URI'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('link'),
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-link-type' => array('value' => 'manual'),
),
),
);
'#states' => [
'visible' => [
'select.colorbox-field-formatter-link-type' => ['value' => 'manual'],
],
],
];
if (\Drupal::moduleHandler()->moduleExists('token') && isset($form['#entity_type'])) {
$form['link_wrapper']['token_help_wrapper'] = array(
$form['link_wrapper']['token_help_wrapper'] = [
'#type' => 'container',
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-link-type' => array('value' => 'manual'),
),
),
);
$form['link_wrapper']['token_help_wrapper']['token_help'] = array(
'#states' => [
'visible' => [
'select.colorbox-field-formatter-link-type' => ['value' => 'manual'],
],
],
];
$form['link_wrapper']['token_help_wrapper']['token_help'] = [
'#theme' => 'token_tree',
'#token_types' => array('entity' => $form['#entity_type']),
'#token_types' => ['entity' => $form['#entity_type']],
'#global_types' => FALSE,
);
];
}
$form['inline_selector'] = array(
$form['inline_selector'] = [
'#title' => $this->t('Inline selector'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('inline_selector'),
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-style' => array('value' => 'colorbox-inline'),
),
),
);
'#states' => [
'visible' => [
'select.colorbox-field-formatter-style' => ['value' => 'colorbox-inline'],
],
],
];
$form['width'] = array(
$form['width'] = [
'#title' => $this->t('Width'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('width'),
);
$form['height'] = array(
];
$form['height'] = [
'#title' => $this->t('Height'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('height'),
);
$form['iframe'] = array(
];
$form['iframe'] = [
'#title' => $this->t('iFrame Mode'),
'#type' => 'checkbox',
'#default_value' => $this->getSetting('iframe'),
);
$form['anchor'] = array(
];
$form['anchor'] = [
'#title' => $this->t('Anchor'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('anchor'),
);
$form['class'] = array(
];
$form['class'] = [
'#title' => $this->t('Class'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('class'),
);
$form['rel'] = array(
];
$form['rel'] = [
'#title' => $this->t('Rel'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('rel'),
'#description' => $this->t('This can be used to identify a group for Colorbox to cycle through.'),
);
];
return $form;
}
......@@ -152,7 +152,7 @@ class ColorboxFieldFormatter extends FormatterBase {
* @inheritdoc
*/
public function settingsSummary() {
$summary = array();
$summary = [];
$styles = $this->getStyles();
$summary[] = $this->t('Style: @style', ['@style' => $styles[$this->getSetting('style')],]);
......@@ -193,21 +193,21 @@ class ColorboxFieldFormatter extends FormatterBase {
* @inheritdoc
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = array();
$element = [];
foreach ($items as $delta => $item) {
$output = $this->viewValue($item);
$url = $this->getUrl($item);
$options = array(
$options = [
'html' => TRUE,
'attributes' => array(
'class' => array('colorbox', $this->getSetting('style')),
),
'query' => array(
'attributes' => [
'class' => ['colorbox', $this->getSetting('style')],
],
'query' => [
'width' => $this->getSetting('width'),
'height' => $this->getSetting('height'),
),
);
],
];
if ($this->getSetting('iframe')) {
$options['query']['iframe'] = 'true';
}
......@@ -270,7 +270,7 @@ class ColorboxFieldFormatter extends FormatterBase {
$link = $this->getSetting('link');
if (\Drupal::moduleHandler()->moduleExists('token')) {
$token_service = \Drupal::token();
$link = $token_service->replace($this->getSetting('link'), array($entity->bundle() => $entity), array('clear' => TRUE));
$link = $token_service->replace($this->getSetting('link'), [$entity->bundle() => $entity], ['clear' => TRUE]);
}
return Url::fromUri($link);
}
......@@ -282,9 +282,9 @@ class ColorboxFieldFormatter extends FormatterBase {
* @return array
*/
private function getStyles() {
$styles = array(
$styles = [
'default' => $this->t('Default'),
);
];
if (\Drupal::moduleHandler()->moduleExists('colorbox_inline')) {
$styles['colorbox-inline'] = $this->t('Colorbox inline');
}
......@@ -301,10 +301,10 @@ class ColorboxFieldFormatter extends FormatterBase {
* @return array
*/
private function getLinkTypes() {
return array(
return [
'content' => $this->t('Content'),
'manual' => $this->t('Manually provide a link'),
);
];
}
}
......@@ -21,9 +21,9 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
* @inheritdoc
*/
public static function defaultSettings() {
return array(
return [
'image_style' => 'original',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
......@@ -32,14 +32,14 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
public function settingsForm(array $form, FormStateInterface $form_state) {
$image_styles = image_style_options(FALSE);
$image_styles['hide'] = t('Hide (do not display image)');
$form['image_style'] = array(
$form['image_style'] = [
'#title' => $this->t('Content image style'),
'#type' => 'select',
'#default_value' => $this->getSetting('image_style'),
'#empty_option' => $this->t('None (original image)'),
'#options' => $image_styles,
'#description' => $this->t('Image style to use in the content.'),
);
];
return parent::settingsForm($form, $form_state);
}
......@@ -60,9 +60,9 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
else {
$style = $this->t('Original image');
}
return array(
return [
$this->t('Content image style: @style', ['@style' => $style]),
) + parent::settingsSummary();
] + parent::settingsSummary();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment