From 80e6454ddff29e96f66034b7ddac1eb7452171bb Mon Sep 17 00:00:00 2001 From: vbouchet Date: Mon, 14 Sep 2015 16:40:40 +0200 Subject: [PATCH 1/3] Create a dedicated service to formataddonsnames --- src/FormatAddonsName.php | 27 +++++++++++++++++++++++++++ src/FormatAddonsNameInterface.php | 20 ++++++++++++++++++++ src/Plugin/views/style/Slideshow.php | 11 ----------- views_slideshow.services.yml | 5 ++++- views_slideshow.theme.inc | 8 ++++---- 5 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 src/FormatAddonsName.php create mode 100644 src/FormatAddonsNameInterface.php diff --git a/src/FormatAddonsName.php b/src/FormatAddonsName.php new file mode 100644 index 0000000..9a3b54c --- /dev/null +++ b/src/FormatAddonsName.php @@ -0,0 +1,27 @@ + $addon_info) { foreach ($addon_info['accepts'] as $imp_key => $imp_value) { if (is_array($imp_value)) { - $methods[$imp_key][] = \Drupal::service('plugin.manager.views_slideshow.slideshow_type')->formatAddonName($addon_id); + $methods[$imp_key][] = \Drupal::service('views_slideshow.format_addons_name')->format($addon_id); } else { - $methods[$imp_value][] = \Drupal::service('plugin.manager.views_slideshow.slideshow_type')->formatAddonName($addon_id); + $methods[$imp_value][] = \Drupal::service('views_slideshow.format_addons_name')->format($addon_id); } } } @@ -183,7 +183,7 @@ function template_preprocess_views_slideshow_pager_widget_render(&$vars) { $vars['#attached']['library'][] = 'views_slideshow/widget_info'; $vars['#attached']['drupalSettings']['viewsSlideshowPager'][$vars['vss_id']] = array( $vars['location'] => array( - 'type' => \Drupal::service('plugin.manager.views_slideshow.slideshow_type')->formatAddonName($vars['settings']['type']), + 'type' => \Drupal::service('views_slideshow.format_addons_name')->format($vars['settings']['type']), ), ); @@ -284,7 +284,7 @@ function template_preprocess_views_slideshow_controls_widget_render(&$vars) { $vars['#attached']['library'][] = 'views_slideshow/widget_info'; $vars['#attached']['drupalSettings']['viewsSlideshowControls'][$vars['vss_id']] = array( $vars['location'] => array( - 'type' => \Drupal::service('plugin.manager.views_slideshow.slideshow_type')->formatAddonName($vars['settings']['type']), + 'type' => \Drupal::service('views_slideshow.format_addons_name')->format($vars['settings']['type']), ), ); From 668bd4fd63097d000e80355212481d0b7decac94 Mon Sep 17 00:00:00 2001 From: vbouchet Date: Tue, 15 Sep 2015 17:49:01 +0200 Subject: [PATCH 2/3] Upgrade how we add optional libraries --- .../views_slideshow_cycle.theme.inc | 20 ++++--------------- views_slideshow.theme.inc | 6 +----- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc b/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc index 9e4c083..5ffc8d6 100644 --- a/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc +++ b/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc @@ -70,19 +70,11 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) { } // Load the json2 library. - // @todo Check if there is a better way to detect optional libraries. - $json2 = \Drupal::service('library.discovery')->getLibraryByName('views_slideshow_cycle', 'json2'); - if (isset($json2['js'][0]['data']) && file_exists($json2['js'][0]['data'])) { - $vars['#attached']['library'][] = 'views_slideshow_cycle/json2'; - } + $vars['#attached']['library'][] = 'views_slideshow_cycle/json2'; - // Load the pause library - // @todo Check if there is a better way to detect optional libraries. + // Load the pause library. if (!empty($settings['pause_in_middle'])) { - $pause = \Drupal::service('library.discovery')->getLibraryByName('views_slideshow_cycle', 'jquery_pause'); - if (isset($pause['js'][0]['data']) && file_exists($pause['js'][0]['data'])) { - $vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_pause'; - } + $vars['#attached']['library'][] = 'views_slideshow_cycle/jquery_pause'; } // Load jQuery Cycle library. @@ -95,12 +87,8 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) { $processedCycles['#views_slideshow_cycle_main_' . $vss_id] = '#views_slideshow_cycle_main_' . $vss_id; // Add hover intent library. - // @todo Check if there is a better way to detect optional libraries. if ($settings['pause']) { - $hoverIntent = \Drupal::service('library.discovery')->getLibraryByName('views_slideshow', 'jquery_hoverIntent'); - if (isset($hoverIntent['js'][0]['data']) && file_exists($hoverIntent['js'][0]['data'])) { - $vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent'; - } + $vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent'; } // Add the slideshow elements. diff --git a/views_slideshow.theme.inc b/views_slideshow.theme.inc index d29611d..c254461 100644 --- a/views_slideshow.theme.inc +++ b/views_slideshow.theme.inc @@ -216,12 +216,8 @@ function template_preprocess_views_slideshow_pager_fields(&$vars) { ); // Add hover intent library. - // @todo Check if there is a better way to detect optional libraries. if ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_hover']) { - $hoverIntent = \Drupal::service('library.discovery')->getLibraryByName('views_slideshow', 'jquery_hoverIntent'); - if (isset($hoverIntent['js'][0]['data']) && file_exists($hoverIntent['js'][0]['data'])) { - $vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent'; - } + $vars['#attached']['library'][] = 'views_slideshow/jquery_hoverIntent'; } $vars['widget_id'] = $vars['attributes']['id']; From 7c1e59abbf93ab35a58901e8b80674231cf7dfa8 Mon Sep 17 00:00:00 2001 From: vbouchet Date: Wed, 16 Sep 2015 15:53:48 +0200 Subject: [PATCH 3/3] Fix warnings --- .../views_slideshow_cycle.theme.inc | 25 ++----------------- views_slideshow.theme.inc | 3 ++- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc b/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc index 5ffc8d6..116dd24 100644 --- a/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc +++ b/modules/views_slideshow_cycle/views_slideshow_cycle.theme.inc @@ -94,35 +94,14 @@ function template_preprocess_views_slideshow_cycle_main_frame(&$vars) { // Add the slideshow elements. $vars['attributes']['class'][] = 'views_slideshow_cycle_teaser_section'; - $styles = ''; - if (isset($view->display_handler->display->display_options['style_options']['views_slideshow_cycle'])) { - $styles = $view->display_handler->display->display_options['style_options']['views_slideshow_cycle']; - } - - $styles_default = ''; - if (isset($view->display['default']->display_options['style_options']['views_slideshow_cycle'])) { - $styles_default = $view->display['default']->display_options['style_options']['views_slideshow_cycle']; - } - - // Retrieve the number of items per frame. - if (isset($styles['items_per_slide']) && $styles['items_per_slide'] > 0) { - $items_per_slide = $styles['items_per_slide']; - } - elseif (isset($styles_default['items_per_slide']) && $styles_default['items_per_slide'] > 0) { - $items_per_slide = $styles_default['items_per_slide']; - } - else { - $items_per_slide = 1; - } - - $vars['items_per_slide'] = $items_per_slide; + $vars['items_per_slide'] = $settings['items_per_slide']; $items = array(); $index = 0; $vars['rendered_rows'] = ''; foreach ($rows as $count => $item) { $items[] = $item; - if (count($items) == $items_per_slide || $count == (count($rows) - 1)) { + if (count($items) == $settings['items_per_slide'] || $count == (count($rows) - 1)) { $vars['rendered_rows'][] = array( '#theme' => $vars['view']->buildThemeFunctions('views_slideshow_cycle_main_frame_row'), '#vss_id' => $vss_id, diff --git a/views_slideshow.theme.inc b/views_slideshow.theme.inc index c254461..313edfe 100644 --- a/views_slideshow.theme.inc +++ b/views_slideshow.theme.inc @@ -50,6 +50,7 @@ function _views_slideshow_preprocess_views_view_slideshow(&$vars) { $view = $vars['view']; $rows = $vars['rows']; $num_divs = count($rows); + // @todo: This #name element is not available of Views edit page. $vss_id = $view->element['#name'] . '-' . $view->current_display; // Give each slideshow a unique id if there are more than one on the page. @@ -227,7 +228,7 @@ function template_preprocess_views_slideshow_pager_fields(&$vars) { // Render all the fields unless there is only 1 slide and the user specified // to hide them when there is only one slide. $vars['rendered_field_items'] = ''; - if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $vars['view']->style_options['views_slideshow_cycle']['items_per_slide']) { + if (empty($vars['settings']['hide_on_single_slide']) || count($vars['view']->result) > $vars['view']->style_plugin->options['views_slideshow_cycle']['items_per_slide']) { foreach ($vars['view']->result as $count => $node) { $rendered_fields = ''; foreach ($vars['settings']['views_slideshow_pager_fields']['views_slideshow_pager_fields_fields'] as $field => $use) {