Commit aa23f12d authored by NickWilde's avatar NickWilde

Task: Issue #2824470: Short Array Syntax

parent c22bb26d
......@@ -16,10 +16,10 @@ function views_slideshow_cycle_help($route_name, RouteMatchInterface $route_matc
switch ($route_name) {
case 'help.page.views_slideshow_cycle':
if (\Drupal::moduleHandler()->moduleExists('advanced_help')) {
$output = '<p>' . Link::fromTextAndUrl('Click here to view the documentation for Views Slideshow Cycle.', Url::fromRoute('advanced_help.module_index', array('module' => 'views_slideshow_cycle'))->toString()) . '</p>';
$output = '<p>' . Link::fromTextAndUrl('Click here to view the documentation for Views Slideshow Cycle.', Url::fromRoute('advanced_help.module_index', ['module' => 'views_slideshow_cycle'])->toString()) . '</p>';
}
else {
$output = '<p>' . t('Views Slideshow Cycle help can be found by installing and enabling the !advanced_help', array('!advanced_help' => Link::fromTextAndUrl(t('Advanced Help module'), Url::fromUri('http://drupal.org/project/advanced_help'))->toString())) . '</p>';
$output = '<p>' . t('Views Slideshow Cycle help can be found by installing and enabling the !advanced_help', ['!advanced_help' => Link::fromTextAndUrl(t('Advanced Help module'), Url::fromUri('http://drupal.org/project/advanced_help'))->toString()]) . '</p>';
}
return $output;
}
......@@ -29,53 +29,53 @@ function views_slideshow_cycle_help($route_name, RouteMatchInterface $route_matc
* Implements hook_theme().
*/
function views_slideshow_cycle_theme($existing, $type, $theme, $path) {
return array(
'views_slideshow_cycle' => array(
'variables' => array(
return [
'views_slideshow_cycle' => [
'variables' => [
'view' => NULL,
'settings' => array(),
'rows' => array(),
'settings' => [],
'rows' => [],
'title' => '',
),
],
'template' => 'views-slideshow-cycle',
'file' => 'views_slideshow_cycle.theme.inc',
//'pattern' => 'views_slideshow_cycle__',
),
'views_slideshow_cycle_main_frame' => array(
'variables' => array(
],
'views_slideshow_cycle_main_frame' => [
'variables' => [
'vss_id' => NULL,
'view' => NULL,
'settings' => NULL,
'rows' => NULL,
),
],
'template' => 'views-slideshow-cycle-main-frame',
'file' => 'views_slideshow_cycle.theme.inc',
//'pattern' => 'views_slideshow_cycle_main_frame__',
),
'views_slideshow_cycle_main_frame_row' => array(
'variables' => array(
],
'views_slideshow_cycle_main_frame_row' => [
'variables' => [
'vss_id' => NULL,
'items' => NULL,
'count' => NULL,
'view' => NULL,
),
],
'template' => 'views-slideshow-cycle-main-frame-row',
'file' => 'views_slideshow_cycle.theme.inc',
//'pattern' => 'views_slideshow_cycle_main_frame_row__',
),
'views_slideshow_cycle_main_frame_row_item' => array(
'variables' => array(
],
'views_slideshow_cycle_main_frame_row_item' => [
'variables' => [
'item' => NULL,
'item_count' => NULL,
'count' => NULL,
'view' => NULL,
'length' => NULL,
),
],
'template' => 'views-slideshow-cycle-main-frame-row-item',
'file' => 'views_slideshow_cycle.theme.inc',
//'pattern' => 'views_slideshow_cycle_main_frame_row_item__',
),
);
],
];
}
/**
......
......@@ -18,7 +18,7 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$vss_id = $vars['vss_id'];
// Cast the strings into int or bool as necessary.
$new_settings = array();
$new_settings = [];
foreach ($settings as $key => $value) {
if (is_string($value)) {
$value = str_replace("\n", ' ', $value);
......@@ -40,12 +40,12 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
}
$settings = array_merge(
array(
[
'num_divs' => count($rows),
'id_prefix' => '#views_slideshow_cycle_main_',
'div_prefix' => '#views_slideshow_cycle_div_',
'vss_id' => $vss_id,
),
],
$new_settings
);
......@@ -96,21 +96,21 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) {
$vars['items_per_slide'] = $settings['items_per_slide'];
$items = array();
$items = [];
$index = 0;
$vars['rendered_rows'] = '';
foreach ($rows as $count => $item) {
$items[] = $item;
if (count($items) == $settings['items_per_slide'] || $count == (count($rows) - 1)) {
$vars['rendered_rows'][] = array(
$vars['rendered_rows'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'),
'#vss_id' => $vss_id,
'#items' => $items,
'#count' => $index,
'#view' => $vars['view'],
);
];
$items = array();
$items = [];
$index++;
}
}
......@@ -133,14 +133,14 @@ function template_preprocess_views_slideshow_cycle_main_frame_row(&$vars) {
$vars['rendered_items'] = '';
foreach ($vars['items'] as $item_count => $item) {
$vars['rendered_items'][] = array(
$vars['rendered_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row_item'),
'#item' => $item,
'#item_count' => $item_count,
'#count' => $vars['count'],
'#view' => $vars['view'],
'#length' => count($vars['view']->result),
);
];
}
}
......@@ -184,23 +184,23 @@ function _views_slideshow_cycle_preprocess_views_slideshow_pager_fields(&$vars)
$rendered_fields = '';
foreach ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_fields'] as $field => $use) {
if ($use !== 0 && is_object($vars['view']->field[$field])) {
$rendered_fields[] = array(
$rendered_fields[] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_field'),
'#view' => $vars['view'],
'#label' => $vars['view']->field[$field]->options['label'],
'#output' => $vars['view']->style_plugin->getField($count, $field),
'#css_identifier' => Html::cleanCssIdentifier($vars['view']->field[$field]->field),
);
];
}
}
$vars['rendered_field_items'][] = array(
$vars['rendered_field_items'][] = [
'#theme' => $vars['view']->buildThemeFunctions('views_slideshow_pager_field_item'),
'#vss_id' => $vars['vss_id'],
'#item' => $rendered_fields,
'#count' => $count,
'#location' => $vars['location'],
);
];
}
}
}
......
......@@ -21,8 +21,8 @@ class PagerFields extends ViewsSlideshowWidgetBase {
*/
public function defaultConfiguration() {
return [
'views_slideshow_pager_fields_fields' => array('default' => array()),
'views_slideshow_pager_fields_hover' => array('default' => 0),
'views_slideshow_pager_fields_fields' => ['default' => []],
'views_slideshow_pager_fields_hover' => ['default' => 0],
];
}
......@@ -31,7 +31,7 @@ class PagerFields extends ViewsSlideshowWidgetBase {
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Settings for fields pager.
$options = array();
$options = [];
// Get each field and it's name.
foreach ($this->getConfiguration()['view']->display_handler->getHandlers('field') as $field_name => $field) {
......@@ -39,42 +39,43 @@ class PagerFields extends ViewsSlideshowWidgetBase {
}
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_fields_wrapper'] = array(
$form['views_slideshow_pager_fields_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
);
];
// Add ability to choose which fields to show in the pager.
$form['views_slideshow_pager_fields_fields'] = array(
$form['views_slideshow_pager_fields_fields'] = [
'#type' => 'checkboxes',
'#title' => t('Pager fields'),
'#options' => $options,
'#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_fields'],
'#description' => t('Choose the fields that will appear in the pager.'),
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
],
],
];
// Add field to see if they would like to activate slide and pause on pager
// hover.
$form['views_slideshow_pager_fields_hover'] = array(
$form['views_slideshow_pager_fields_hover'] = [
'#type' => 'checkbox',
'#title' => t('Activate Slide and Pause on Pager Hover'),
'#default_value' => $this->getConfiguration()['views_slideshow_pager_fields_hover'],
'#description' => t('Should the slide be activated and paused when hovering over a pager item.'),
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => array('value' => 'views_slideshow_pager_fields'),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
':input[name="' . $this->getConfiguration()['dependency'] . '[type]"]' => ['value' => 'views_slideshow_pager_fields'],
],
],
];
$form['views_slideshow_pager_fields_wrapper_close'] = array(
$form['views_slideshow_pager_fields_wrapper_close'] = [
'#markup' => '</div>',
);
];
return $form;
}
......
......@@ -22,8 +22,8 @@ class Controls extends ViewsSlideshowWidgetTypeBase {
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'hide_on_single_slide' => array('default' => 0),
'type' => array('default' => 0),
'hide_on_single_slide' => ['default' => 0],
'type' => ['default' => 0],
];
}
......@@ -37,43 +37,43 @@ class Controls extends ViewsSlideshowWidgetTypeBase {
$widgets = $widgetManager->getDefinitions($this->getPluginId());
if (!empty($widgets)) {
$options = array();
$options = [];
foreach ($widgets as $widgetId => $widgetInfo) {
$options[$widgetId] = $widgetInfo['label'];
}
// Need to wrap this so it indents correctly.
$form['views_slideshow_controls_wrapper'] = array(
$form['views_slideshow_controls_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
);
];
// Add field to see if they would like to hide controls if there is only
// one slide.
$form['hide_on_single_slide'] = array(
$form['hide_on_single_slide'] = [
'#type' => 'checkbox',
'#title' => t('Hide controls if there is only one slide'),
'#default_value' => $this->getConfiguration()['hide_on_single_slide'],
'#description' => t('Should the controls be hidden if there is only one slide.'),
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
// Create the widget type field.
$form['type'] = array(
$form['type'] = [
'#type' => 'select',
'#title' => t('Controls Type'),
'#description' => t('Style of the controls'),
'#default_value' => $this->getConfiguration()['type'],
'#options' => $options,
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
foreach ($widgets as $widget_id => $widget_info) {
// Get the current configuration of this widget.
......@@ -89,14 +89,14 @@ class Controls extends ViewsSlideshowWidgetTypeBase {
$form[$widget_id] = $instance->buildConfigurationForm($form[$widget_id], $form_state);
}
$form['controls_wrapper_close'] = array(
$form['controls_wrapper_close'] = [
'#markup' => '</div>',
);
];
}
else {
$form['enable_controls'] = array(
$form['enable_controls'] = [
'#markup' => 'There are no controls available.',
);
];
}
return $form;
......
......@@ -27,12 +27,12 @@ class Pager extends ViewsSlideshowWidgetTypeBase {
*/
public function defaultConfiguration() {
$options = parent::defaultConfiguration() + [
'hide_on_single_slide' => array('default' => 0),
'type' => array('default' => 0),
'views_slideshow_pager_numbered_hover' => array('default' => 0),
'views_slideshow_pager_numbered_click_to_page' => array('default' => 0),
'views_slideshow_pager_thumbnails_hover' => array('default' => 0),
'views_slideshow_pager_thumbnails_click_to_page' => array('default' => 0),
'hide_on_single_slide' => ['default' => 0],
'type' => ['default' => 0],
'views_slideshow_pager_numbered_hover' => ['default' => 0],
'views_slideshow_pager_numbered_click_to_page' => ['default' => 0],
'views_slideshow_pager_thumbnails_hover' => ['default' => 0],
'views_slideshow_pager_thumbnails_click_to_page' => ['default' => 0],
];
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
......@@ -66,37 +66,37 @@ class Pager extends ViewsSlideshowWidgetTypeBase {
if (!empty($widgets)) {
// Need to wrap this so it indents correctly.
$form['views_slideshow_pager_wrapper'] = array(
$form['views_slideshow_pager_wrapper'] = [
'#markup' => '<div class="vs-dependent">',
);
];
// Add field to see if they would like to hide pager if there is only one
// slide.
$form['hide_on_single_slide'] = array(
$form['hide_on_single_slide'] = [
'#type' => 'checkbox',
'#title' => t('Hide pager if there is only one slide'),
'#default_value' => $this->getConfiguration()['hide_on_single_slide'],
'#description' => t('Should the pager be hidden if there is only one slide.'),
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
// Create the widget type field.
$form['type'] = array(
$form['type'] = [
'#type' => 'select',
'#title' => t('Pager Type'),
'#description' => t('Style of the pager'),
'#default_value' => $this->getConfiguration()['type'],
'#options' => $widgets,
'#states' => array(
'visible' => array(
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="' . $this->getConfiguration()['dependency'] . '[enable]"]' => ['checked' => TRUE],
],
],
];
foreach ($widgetManager->getDefinitions() as $widget_id => $widget_info) {
// Get the current configuration of this widget.
......@@ -113,14 +113,14 @@ class Pager extends ViewsSlideshowWidgetTypeBase {
$form[$widget_id] = $instance->buildConfigurationForm($form[$widget_id], $form_state);
}
$form['views_slideshow_pager_wrapper_close'] = array(
$form['views_slideshow_pager_wrapper_close'] = [
'#markup' => '</div>',
);
];
}
else {
$form['enable_pager'] = array(
$form['enable_pager'] = [
'#markup' => 'There are no pagers available.',
);
];
}
return $form;
......
......@@ -58,10 +58,10 @@ class Slideshow extends StylePluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['row_class_custom'] = array('default' => '');
$options['row_class_default'] = array('default' => TRUE);
$options['slideshow_type'] = array('default' => 'views_slideshow_cycle');
$options['slideshow_skin'] = array('default' => 'default');
$options['row_class_custom'] = ['default' => ''];
$options['row_class_default'] = ['default' => TRUE];
$options['slideshow_type'] = ['default' => 'views_slideshow_cycle'];
$options['slideshow_skin'] = ['default' => 'default'];
$typeManager = \Drupal::service('plugin.manager.views_slideshow.slideshow_type');
foreach ($typeManager->getDefinitions() as $id => $definition) {
......@@ -71,7 +71,7 @@ class Slideshow extends StylePluginBase {
$widgetTypeManager = \Drupal::service('plugin.manager.views_slideshow.widget_type');
$widgetTypes = $widgetTypeManager->getDefinitions();
foreach (array('top', 'bottom') as $location) {
foreach (['top', 'bottom'] as $location) {
foreach ($widgetTypes as $widgetTypeId => $widgetTypeDefinition) {
$options['widgets']['contains'][$location]['contains'][$widgetTypeId]['contains'] = $widgetTypeManager->createInstance($widgetTypeId, [])->defaultConfiguration();
}
......@@ -87,14 +87,14 @@ class Slideshow extends StylePluginBase {
parent::buildOptionsForm($form, $form_state);
// Wrap all the form elements to help style the form.
$form['views_slideshow_wrapper'] = array(
$form['views_slideshow_wrapper'] = [
'#markup' => '<div id="views-slideshow-form-wrapper">',
);
];
// Skins.
$form['slideshow_skin_header'] = array(
$form['slideshow_skin_header'] = [
'#markup' => '<h2>' . t('Style') . '</h2>',
);
];
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
$skinManager = \Drupal::service('plugin.manager.views_slideshow.slideshow_skin');
......@@ -107,18 +107,18 @@ class Slideshow extends StylePluginBase {
asort($skins);
// Create the drop down box so users can choose an available skin.
$form['slideshow_skin'] = array(
$form['slideshow_skin'] = [
'#type' => 'select',
'#title' => t('Skin'),
'#options' => $skins,
'#default_value' => $this->options['slideshow_skin'],
'#description' => t('Select the skin to use for this display. Skins allow for easily swappable layouts of things like next/prev links and thumbnails. Note that not all skins support all widgets, so a combination of skins and widgets may lead to unpredictable results in layout.'),
);
];
// Slides.
$form['slides_header'] = array(
$form['slides_header'] = [
'#markup' => '<h2>' . t('Slides') . '</h2>',
);
];
// Get all slideshow types.
$typeManager = \Drupal::service('plugin.manager.views_slideshow.slideshow_type');
......@@ -127,17 +127,17 @@ class Slideshow extends StylePluginBase {
if ($types) {
// Build our slideshow options for the form.
$slideshow_options = array();
$slideshow_options = [];
foreach ($types as $id => $definition) {
$slideshow_options[$id] = $definition['label'];
}
$form['slideshow_type'] = array(
$form['slideshow_type'] = [
'#type' => 'select',
'#title' => t('Slideshow Type'),
'#options' => $slideshow_options,
'#default_value' => $this->options['slideshow_type'],
);
];
// @todo: check if default values are properly passed to the buildConfigurationForm().
foreach ($types as $id => $definition) {
......@@ -147,41 +147,41 @@ class Slideshow extends StylePluginBase {
}
$instance = $typeManager->createInstance($id, $configuration);
$form[$id] = array(
$form[$id] = [
'#type' => 'fieldset',
'#title' => t('@module options', array('@module' => $definition['label'])),
'#title' => t('@module options', ['@module' => $definition['label']]),
'#collapsible' => TRUE,
'#attributes' => array('class' => array($id)),
'#states' => array(
'visible' => array(
':input[name="style_options[slideshow_type]"]' => array('value' => $id),
),
),
);
'#attributes' => ['class' => [$id]],
'#states' => [
'visible' => [
':input[name="style_options[slideshow_type]"]' => ['value' => $id],
],
],
];
$form = $instance->buildConfigurationForm($form, $form_state);
}
}
else {
$form['enable_module'] = array(
'#markup' => t('There is no Views Slideshow plugin enabled. Go to the @modules and enable a Views Slideshow plugin module. For example Views Slideshow Singleframe.', array('@modules' => Link::fromTextAndUrl(t('Modules Page'), Url::fromRoute('system.modules_list'))->toString())),
);
$form['enable_module'] = [
'#markup' => t('There is no Views Slideshow plugin enabled. Go to the @modules and enable a Views Slideshow plugin module. For example Views Slideshow Singleframe.', ['@modules' => Link::fromTextAndUrl(t('Modules Page'), Url::fromRoute('system.modules_list'))->toString()]),
];
}
// Widgets.
// @todo: Improve the UX by using Ajax.
$form['widgets_header'] = array(
$form['widgets_header'] = [
'#markup' => '<h2>' . t('Widgets') . '</h2>',
);
];
// Define the available locations.
$location = array('top' => t('Top'), 'bottom' => t('Bottom'));
$location = ['top' => t('Top'), 'bottom' => t('Bottom')];
// Loop through all locations so we can add header for each location.
foreach ($location as $location_id => $location_name) {
$form['widgets'][$location_id]['header'] = array(
'#markup' => '<h3>' . t('@location Widgets', array('@location' => $location_name)) . '</h3>',
);
$form['widgets'][$location_id]['header'] = [
'#markup' => '<h3>' . t('@location Widgets', ['@location' => $location_name]) . '</h3>',
];
}
/* @var \Drupal\Component\Plugin\PluginManagerInterface */
......@@ -214,15 +214,15 @@ class Slideshow extends StylePluginBase {
if (!empty($compatible_slideshows)) {
foreach ($location as $location_id => $location_name) {
// Use Widget Checkbox.
$form['widgets'][$location_id][$widget_id]['enable'] = array(
$form['widgets'][$location_id][$widget_id]['enable'] = [
'#type' => 'checkbox',
'#title' => $widget_info['label'],
'#default_value' => $this->options['widgets'][$location_id][$widget_id]['enable'],
'#description' => t('Should @name be rendered at the @location of the slides.', array('@name' => $widget_info['label'], '@location' => $location_name)),
'#dependency' => array(
'#description' => t('Should @name be rendered at the @location of the slides.', ['@name' => $widget_info['label'], '@location' => $location_name]),
'#dependency' => [
'edit-style-options-slideshow-type' => $compatible_slideshows,
),
);
],
];
// Need to wrap this so it indents correctly.
$form['widgets'][$location_id][$widget_id]['wrapper'] = [
......
......@@ -38,16 +38,16 @@ abstract class ViewsSlideshowTypeBase extends PluginBase implements ViewsSlidesh
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return array(
return [
'id' => $this->getPluginId(),
) + $this->configuration;
] + $this->configuration;
}
/**
......@@ -62,7 +62,7 @@ abstract class ViewsSlideshowTypeBase extends PluginBase implements ViewsSlidesh
* {@inheritdoc}
*/
public function calculateDependencies() {
return array();
return [];
}
/**
......
......@@ -32,7 +32,7 @@ abstract class ViewsSlideshowWidgetBase extends PluginBase implements ViewsSlide
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return array();
return [];
}
/**
......@@ -45,16 +45,16 @@ abstract class ViewsSlideshowWidgetBase extends PluginBase implements ViewsSlide
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return array(
return [
'id' => $this->getPluginId(),
) + $this->configuration;
] + $this->configuration;
}
/**
......@@ -75,7 +75,7 @@ abstract class ViewsSlideshowWidgetBase extends PluginBase implements ViewsSlide
* {@inheritdoc}
*/
public function calculateDependencies() {
return array();
return [];
}
/**
......
......@@ -45,19 +45,19 @@ abstract class ViewsSlideshowWidgetTypeBase extends PluginBase implements ViewsS
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'enable' => array('default' => 0),
'weight' => array('default' => 1),
);
return [
'enable' => ['default' => 0],
'weight' => ['default' => 1],
];
}
/**
* {@inheritdoc}
*/