commit 19b970a2980bfe720d24d5505b605185c4dd7127 Author: Lee Rowlands Date: Sun Feb 17 08:54:34 2013 +1000 Incorporate Wim Leers interdiff from #94 diff --git a/core/modules/tour/css/tour-rtl.css b/core/modules/tour/css/tour-rtl.css new file mode 100644 index 0000000..5e19f7b --- /dev/null +++ b/core/modules/tour/css/tour-rtl.css @@ -0,0 +1,13 @@ +/** + * @file + * RTL styling for tour module. + */ + +.js .toolbar .bar .tour-toolbar-tab.tab { + float: left; +} + +.tour-progress { + right: 0; + left: 15px; +} diff --git a/core/modules/tour/css/tour.css b/core/modules/tour/css/tour.css index 0c0dde5..9f71ccb 100644 --- a/core/modules/tour/css/tour.css +++ b/core/modules/tour/css/tour.css @@ -1,17 +1,36 @@ -.toolbar .icon-help.tour-no-items-hidden { - display: none; -} +/** + * @file + * Styling for tour module. + */ +/* Tab appearance. */ .js .toolbar .bar .tour-toolbar-tab.tab { - float: right; + float: right; /* LTR */ +} +.js .toolbar .bar .tour-toolbar-tab button { + padding-bottom: 1em; + padding-top: 1em; + color: #fff; + font-weight: bold; +} +.js .toolbar .bar .tour-toolbar-tab button.active { + background-image: -webkit-linear-gradient(rgba(255, 255, 255, 0.25) 20%, transparent 200%); + background-image: linear-gradient(rgba(255, 255, 255, 0.25) 20%, transparent 200%); } +/* Joyride tips should always be on top of everything else. */ .joyride-tip-guide { - z-index: 502 + z-index: 999; } +/* Override placement of the tour progress indicator. */ .tour-progress { position: absolute; bottom: 10px; - right: 15px; + right: 15px; /* LTR */ +} + +/* @todo Remove once http://drupal.org/node/1916690 is resolved. */ +.js .toolbar .bar .tour-toolbar-tab.tab.element-hidden { + display: none; } diff --git a/core/modules/tour/js/tour.js b/core/modules/tour/js/tour.js index 70e97f5..975a258 100644 --- a/core/modules/tour/js/tour.js +++ b/core/modules/tour/js/tour.js @@ -1,130 +1,202 @@ -(function ($, Drupal) { - - "use strict"; - - Drupal.behaviors.tour = { - attach: function (context) { - - var toolbar_id = "#toolbar-tab-tour"; - var toolbar_class = "tour-no-items-hidden"; - var tour_items = "#tour-items"; - var overlay_content = "#overlay-content " + tour_items; - - /** - * Initializes the tour. - */ - function setupTour(items, scope) { - var $toolbar = $(toolbar_id, scope); - - if ($(items).length) { - $toolbar.removeClass(toolbar_class); - - // Loop over items and remove missing tour items. - $("li", items).each(function (index) { - var tour_item_id = $(this).data("id"); - var tour_item_class = $(this).data("class"); - if (!$("#" + tour_item_id).length && !$("." + tour_item_class).length) { - $(this).remove(); - } - else { - $(this).data("text", Drupal.t("Next")); - } - }); - - // Update the last item to have "End tour" as the button. - $("li", items).last().data("text", Drupal.t("End tour")); - } - else { - $toolbar.addClass(toolbar_class); - } - $toolbar.bind("click.tour", function() { - if ((Drupal.overlay && Drupal.overlay.isOpen)|| !window) { - return false; - } - if ($(toolbar_id + ".touring", scope).length) { - // Allow other scripts to respond to this event. - $(document).trigger('drupalTourBeforeClose'); - - $(items).prop("hidden", true).joyride("destroy"); - closeTour(scope); - } - else { - // Allow other scripts to respond to this event. - $(document).trigger('drupalTourBeforeOpen'); - - $toolbar.addClass("touring"); - $(items).prop("hidden", false).joyride({ - "postRideCallback": function() { - $toolbar.removeClass("touring"); - $(document).trigger('drupalTourFinished'); - } - }); - } - return false; - }); - } - - /** - * Cleans up the tour. - */ - function closeTour(scope) { - $(toolbar_id, scope).removeClass("touring"); - } - - /** - * Detaches up the tour. - */ - function detachTour(scope) { - closeTour(scope); - $(toolbar_id, scope).unbind("click.tour"); - } - - /** - * Initialize the appropriate tour. - */ - if ($(overlay_content).length) { - $(document).bind('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function() { - // Remove tour events associated with overlay. - detachTour(window.parent.document); - }); - - // Remove tour events associated with overlay. - detachTour(window.parent.document); - // Attach it based on outer content. - setupTour(overlay_content, window.parent.document); - } - else { - $(document).bind("drupalOverlayBeforeClose", function() { - // Remove tour events associated with overlay. - detachTour(window.document); - // Attach it based on outer content. - setupTour(tour_items, window.document); - }); - $(document).bind("drupalOverlayBeforeLoad", function() { - // Remove tour events associated with overlay. - detachTour(window.document); - }); - $(document).bind("drupalOverlayReady", function() { - if ($(tour_items).length) { - $(toolbar_id, window.parent.document).addClass(toolbar_class); - } - else { - $(toolbar_id, window.parent.document).removeClass(toolbar_class); - } - }); - - // Don't run this in overlay. - // This only runs once in the parent. - if (window == window.parent) { - $("body").once("tour", function() { - setupTour(tour_items, window.document); - }); - } - else { - setupTour(tour_items, window.document); +/** + * @file + * Attaches behaviors for the Tour module's toolbar tab. + */ + +(function ($, Backbone, Drupal, document) { + +"use strict"; + +/** + * Attaches the tour's toolbar tab behavior. + */ +Drupal.behaviors.tour = { + attach: function (context) { + var model = new Drupal.tour.models.StateModel(); + var view = new Drupal.tour.views.ToggleTourView({ + el: $(context).find('#toolbar-tab-tour'), + model: model + }); + + // Update the model based on Overlay events. + $(document) + // Overlay is opening: cancel tour if active and mark overlay as open. + .on('drupalOverlayOpen.tour', function () { + model.set({ isActive: false, overlayIsOpen: true }); + }) + // Overlay is loading a new URL: clear tour & cancel if active. + .on('drupalOverlayBeforeLoad.tour', function () { + model.set({ isActive: false, overlayTour: [] }); + }) + // Overlay is closing: clear tour & cancel if active, mark overlay closed. + .on('drupalOverlayClose.tour', function () { + model.set({ isActive: false, overlayIsOpen: false, overlayTour: [] }); + }) + // Overlay has loaded DOM: check whether a tour is available. + .on('drupalOverlayReady.tour', function () { + // We must select the tour in the Overlay's window using the Overlay's + // jQuery, because the joyride plugin only works for the window in which + // it was loaded. + // @todo Make upstream contribution so this can be simplified, which + // should also allow us to *not* load jquery.joyride.js in the Overlay, + // resulting in better front-end performance. + var overlay = Drupal.overlay.iframeWindow; + var $overlayContext = overlay.jQuery(overlay.document); + model.set('overlayTour', $overlayContext.find('#tour')); + }); + + model + // Allow other scripts to respond to tour events. + .on('change:isActive', function (model, isActive) { + $(document).trigger((isActive) ? 'drupalTourStarted' : 'drupalTourStopped'); + }) + // Initialization: check whether a tour is available on the current page. + .set('tour', $(context).find('#tour')); + } +}; + +Drupal.tour = Drupal.tour || { models: {}, views: {}}; + +/** + * Backbone Model for tours. + */ +Drupal.tour.models.StateModel = Backbone.Model.extend({ + defaults: { + // Indicates whether the Drupal root window has a tour. + tour: [], + // Indicates whether the Overlay is open. + overlayIsOpen: false, + // Indicates whether the Overlay window has a tour. + overlayTour: [], + // Indicates whether the tour is currently running. + isActive: false, + // Indicates which tour is the active one (necessary to cleanly stop). + activeTour: [] + } +}); + +/** + * Handles edit mode toggle interactions. + */ +Drupal.tour.views.ToggleTourView = Backbone.View.extend({ + + events: { 'click': 'onClick' }, + + /** + * Implements Backbone Views' initialize(). + */ + initialize: function () { + this.model.on('change:tour change:overlayTour change:overlayIsOpen change:isActive', this.render, this); + this.model.on('change:isActive', this.toggleTour, this); + }, + + /** + * Implements Backbone Views' render(). + */ + render: function () { + // Render the visibility. + this.$el.toggleClass('element-hidden', this._getTour().length === 0); + // Render the state. + var isActive = this.model.get('isActive'); + this.$el.find('button') + .toggleClass('active', isActive) + .attr('aria-pressed', isActive); + return this; + }, + + /** + * Model change handler; starts or stops the tour. + */ + toggleTour: function() { + if (this.model.get('isActive')) { + var $tour = this._getTour(); + this._removeIrrelevantTourItems($tour, this._getDocument()); + var that = this; + $tour.joyride({ + postRideCallback: function () { that.model.set('isActive', false); } + }); + this.model.set({ isActive: true, activeTour: $tour }); + } + else { + this.model.get('activeTour').joyride('destroy'); + this.model.set({ isActive: false, activeTour: [] }); + } + }, + + /** + * Toolbar tab click event handler; toggles isActive. + */ + onClick: function (event) { + this.model.set('isActive', !this.model.get('isActive')); + event.preventDefault(); + event.stopPropagation(); + }, + + /** + * Gets the tour. + * + * @return jQuery + * A jQuery element pointing to a
    containing tour items. + */ + _getTour: function () { + var whichTour = (this.model.get('overlayIsOpen')) ? 'overlayTour' : 'tour'; + return this.model.get(whichTour); + }, + + /** + * Gets the relevant document as a jQuery element. + * + * @return jQuery + * A jQuery element pointing to the document within which a tour would be + * started given the current state. I.e. when the Overlay is open, this will + * point to the HTML document inside the Overlay's iframe, otherwise it will + * point to the Drupal root window. + */ + _getDocument: function () { + return (this.model.get('overlayIsOpen')) ? $(Drupal.overlay.iframeWindow.document) : $(document); + }, + + /** + * Removes tour items for elements that don't exist. + * + * @param jQuery $tour + * A jQuery element pointing to a
      containing tour items. + * @param jQuery $document + * A jQuery element pointing to the document within which the elements + * should be sought. + * + * @see _getDocument() + */ + _removeIrrelevantTourItems: function ($tour, $document) { + var removals = false; + $tour + .find('li') + .each(function () { + var $this = $(this); + var itemId = $this.attr('data-id'); + var itemClass = $this.attr('data-class'); + if ($document.find('#' + itemId + ', .' + itemClass).length === 0) { + removals = true; + $this.remove(); } - } + }); + + // If there were removals, we'll have to do some clean-up. + if (removals) { + var total = $tour.find('li').length; + $tour + .find('li') + // Rebuild the progress data. + .each(function (index) { + var progress = Drupal.t('!tour_item of !total', { '!tour_item': index + 1, '!total': total }); + $(this).find('.tour-progress').text(progress); + }) + // Update the last item to have "End tour" as the button. + .last() + .attr('data-text', Drupal.t('End tour')); } - }; + } + +}); -})(jQuery, Drupal); +})(jQuery, Backbone, Drupal, document); diff --git a/core/modules/tour/tour.info b/core/modules/tour/tour.info index 77abd7b..341cb0d 100644 --- a/core/modules/tour/tour.info +++ b/core/modules/tour/tour.info @@ -1,5 +1,5 @@ name = Tour -description = Provides a guided tour of the Drupal interface. +description = Provides guided tours. package = Core version = VERSION core = 8.x diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index f9b30b6..b20cd0d 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -22,38 +22,46 @@ function tour_permission() { * Implements hook_library_info(). */ function tour_library_info() { - $tour_path = drupal_get_path('module', 'tour'); + $path = drupal_get_path('module', 'tour'); $libraries['tour'] = array( 'title' => 'Tour', - 'website' => '', - 'version' => '', + 'version' => VERSION, 'js' => array( - $tour_path . '/js/tour.js' => array(), + // Add the JavaScript, with a group and weight such that it will run + // before modules/overlay/overlay-parent.js. + $path . '/js/tour.js' => array('group' => JS_LIBRARY, 'weight' => -1), ), - 'css' => array( - $tour_path . '/css/tour.css' => array( - 'media' => 'screen', - ), + 'dependencies' => array( + array('system', 'jquery'), + array('system', 'drupal'), + array('system', 'backbone'), + array('tour', 'jquery.joyride'), + array('tour', 'tour-styling'), ), ); + $libraries['tour-styling'] = array( + 'title' => 'Tour', + 'version' => VERSION, + 'css' => array( + $path . '/css/tour.css' => array('media' => 'screen'), + ) + ); + $libraries['jquery.joyride'] = array( 'title' => 'Joyride', 'website' => 'https://github.com/zurb/joyride', 'version' => '2.0.3', 'js' => array( - $tour_path . '/js/jquery.joyride-2.0.3.js' => array(), + $path . '/js/jquery.joyride-2.0.3.js' => array(), ), 'css' => array( - $tour_path . '/css/joyride-2.0.3.css' => array( - 'media' => 'screen', - ), + $path . '/css/joyride-2.0.3.css' => array('media' => 'screen'), ), 'dependencies' => array( array('system', 'jquery'), array('system', 'jquery.cookie'), - array('tour', 'tour'), ), ); @@ -71,19 +79,18 @@ function tour_toolbar() { $tab['tour'] = array( '#type' => 'toolbar_item', 'tab' => array( - '#type' => 'link', - '#title' => t('Tour'), - '#href' => '', - '#options' => array( - 'html' => FALSE, - 'attributes' => array( - 'class' => array('icon', 'icon-help', 'tour-no-items-hidden'), - 'id' => 'toolbar-tab-tour', - ), + '#type' => 'html_tag', + '#tag' => 'button', + '#value' => t('Tour'), + '#attributes' => array( + 'class' => array('icon', 'icon-help'), + 'role' => 'button', + 'aria-pressed' => 'false', ), ), '#wrapper_attributes' => array( - 'class' => array('tour-toolbar-tab'), + 'class' => array('tour-toolbar-tab', 'element-hidden'), + 'id' => 'toolbar-tab-tour', ), '#attached' => array( 'library' => array( @@ -170,15 +177,25 @@ function tour_preprocess_page(&$variables) { '#items' => $list_items, '#type' => 'ol', '#attributes' => array( - 'id' => 'tour-items', + 'id' => 'tour', 'class' => array( 'element-hidden', ), - 'hidden' => TRUE, ), '#attached' => array( 'library' => array( + // We must also attach the jquery.joyride library here, because it only + // works within the window within which it is loaded. This means that if + // we want the Tour module to work inside the Overlay, we must ensure + // that jquery.joyride also is loaded there. (And since the Toolbar does + // not get loaded inside the Overlay, we cannot rely on it being loaded + // that way.) + // If this a non-overlay page, then Drupal's dependency checking will + // ensure this gets loaded only once. array('tour', 'jquery.joyride'), + // Similarly, we must load tour's CSS, in order to style the tour tips + // in the desired way inside the Overlay. + array('tour', 'tour-styling'), ), ), ); commit 25c12c7a42da5c39e68162b83cc33a07a45169fd Author: Lee Rowlands Date: Sun Feb 17 08:46:01 2013 +1000 Move tour/tour to tour/tip, added extra api doc, added processdecorator and fixed plugin test, cleanup comments in tests diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php similarity index 98% rename from core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php rename to core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php index 1edb11f..c492d8e 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php @@ -5,7 +5,7 @@ * Contains \Drupal\tour\TipPluginText. */ -namespace Drupal\tour\Plugin\tour\tour; +namespace Drupal\tour\Plugin\tour\tip; use Drupal\Core\Annotation\Plugin; use Drupal\tour\TipPluginBase; diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php index 8256eed..188e83c 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php @@ -28,6 +28,9 @@ class TourPluginTest extends DrupalUnitTestBase { */ protected $pluginManager; + /** + * Defines test info. + */ public static function getInfo() { return array( 'name' => 'Tour plugin tests', @@ -36,6 +39,9 @@ public static function getInfo() { ); } + /** + * Sets up the test. + */ protected function setUp() { parent::setUp(); diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index 5b8f87a..e8b97f5 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -40,18 +40,14 @@ protected function setUp() { * Test tour functionality. */ public function testTourFunctionality() { - - /** - * Navigate to tour-test-1 and verify the tour_test_1 tip is found. - */ - + // Navigate to tour-test-1 and verify the tour_test_1 tip is found. $this->drupalGet('tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-test-1', ':text' => 'The first tip' )); $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); - + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-test-2', ':text' => 'The quick brown fox' @@ -64,16 +60,10 @@ public function testTourFunctionality() { )); $this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.'); - /** - * Ensure that plugin's work. - */ - + // Ensure that plugin's work. $this->assertRaw('img src="http://local/image.png"', 'Image plugin tip found.'); - /** - * Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. - */ - + // Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. $this->drupalGet('tour-test-2/subpath'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-test-2', @@ -87,11 +77,8 @@ public function testTourFunctionality() { )); $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); - /** - * Enable Italian language and navigate to it/tour-test1 and verify italian - * version of tip is found. - */ - + // Enable Italian language and navigate to it/tour-test1 and verify italian + // version of tip is found. language_save(new Language(array('langcode' => 'it'))); $this->drupalGet('it/tour-test-1'); @@ -109,11 +96,7 @@ public function testTourFunctionality() { language_save(new Language(array('langcode' => 'en'))); - - /** - * Programmatically create a tour for use through the remainder of the test. - */ - + // Programmatically create a tour for use through the remainder of the test. entity_create('tour', array( 'id' => 'tour-entity-create-test-en', 'label' => 'Tour test english', @@ -144,10 +127,7 @@ public function testTourFunctionality() { // Verify that hook_ENTITY_TYPE_presave() integration worked. $this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); - /** - * Navigate to tour-test-1 and verify the new tip is found. - */ - + // Navigate to tour-test-1 and verify the new tip is found. $this->drupalGet('tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-code-test-1', @@ -155,21 +135,15 @@ public function testTourFunctionality() { )); $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); - /** - * Verify that the weight sorting works by ensuring the lower weight item - * (tip 4) has the close button. - */ - + // Verify that the weight sorting works by ensuring the lower weight item + // (tip 4) has the close button. $elements = $this->xpath('//li[@data-id=:data_id and ./div[contains(., :text)]]', array( ':data_id' => 'tour-code-test-1', ':text' => '3 of 3' )); $this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "3 of 3".'); - /** - * Test hook_tour_alter(). - */ - + // Test hook_tour_alter(). $this->assertText('Altered by hook_tour_tips_alter'); } } diff --git a/core/modules/tour/lib/Drupal/tour/TourManager.php b/core/modules/tour/lib/Drupal/tour/TourManager.php index 26d278c..633006d 100644 --- a/core/modules/tour/lib/Drupal/tour/TourManager.php +++ b/core/modules/tour/lib/Drupal/tour/TourManager.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\Component\Plugin\Discovery\ProcessDecorator; /** * Configurable text tour manager. @@ -21,7 +22,8 @@ class TourManager extends PluginManagerBase { * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). */ public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('tour', 'tour'); + $this->discovery = new AnnotatedClassDiscovery('tour', 'tip'); + $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new CacheDecorator($this->discovery, 'tour'); $this->factory = new DefaultFactory($this->discovery); } @@ -33,4 +35,17 @@ public function createInstance($plugin_id, array $configuration = array(), TipsB $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this->discovery); return new $plugin_class($configuration, $plugin_id, $this->discovery, $bag); } + + /** + * Overrides \Drupal\Component\Plugin\PluginManagerBase::processDefinition(). + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + // @todo Remove this check once http://drupal.org/node/1780396 is resolved. + if (!module_exists($definition['module'])) { + $definition = NULL; + return; + } + } } diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php index d0f1b0b..af280a3 100644 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php @@ -15,7 +15,7 @@ * * @Plugin( * id = "image", - * module = "tour" + * module = "tour_test" * ) */ class TipPluginImage extends TipPluginBase { @@ -37,7 +37,7 @@ class TipPluginImage extends TipPluginBase { protected $alt; /** - * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getOutput(); + * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getOutput(). */ public function getOutput() { return array( diff --git a/core/modules/tour/tests/tour_test/tour_test.module b/core/modules/tour/tests/tour_test/tour_test.module index ffef6df..a2b7bda 100644 --- a/core/modules/tour/tests/tour_test/tour_test.module +++ b/core/modules/tour/tests/tour_test/tour_test.module @@ -27,7 +27,7 @@ function tour_test_menu() { */ function tour_test_tour_load($entities) { if (isset($entities['tour-entity-create-test-en'])) { - $entities['tour-entity-create-test-en']->loaded = 'load hooks work'; + $entities['tour-entity-create-test-en']->loaded = 'Load hooks work'; } } diff --git a/core/modules/tour/tour.api.php b/core/modules/tour/tour.api.php index a5e819d..a3672b3 100644 --- a/core/modules/tour/tour.api.php +++ b/core/modules/tour/tour.api.php @@ -9,14 +9,65 @@ * Allow modules to alter tour items before render. * * @param array $tour_items - * Array of tour items. + * Array of \Drupal\tour\TipPluginInterface items. * @param string $path * The path for which the tour is valid. */ -function tour_test_tour_tips_alter(array &$tour_tips, $path) { +function hook_tour_tips_alter(array &$tour_tips, $path) { foreach ($tour_tips as $tour_tip) { if ($tour_tip->get('id') == 'tour-code-test-1') { $tour_tip->set('body', 'Altered by hook_tour_tips_alter'); } } } + +/** + * Act on tour objects when loaded. + * + * @param array $entities + * An array of \Drupal\tour\Plugin\Core\Entity\Tour objects, indexed by id. + */ +function hook_tour_load($entities) { + if (isset($entities['tour-entity-create-test-en'])) { + $entities['tour-entity-create-test-en']->loaded = 'Load hooks work'; + } +} + +/** + * Act on a tour being inserted or updated. + * + * This hook is invoked before the tour object is saved to configuration. + * + * @param \Drupal\tour\Plugin\Core\Entity\Tour $entity + * The tour object. + * + * @see hook_tour_insert() + * @see hook_tour_update() + */ +function hook_tour_presave($entity) { + if ($entity->id() == 'tour-entity-create-test-en') { + $entity->set('label', $entity->label() . ' alter'); + } +} + +/** + * Respond to creation of a new tour. + * + * @param \Drupal\tour\Plugin\Core\Entity\Tour $entity + * The tour object being inserted. + */ +function hook_tour_insert($entity) { + drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); + cache('cache_tour')->deleteTags(array('tour_items')); +} + +/** + * Respond to updates to a tour object. + * + * @param \Drupal\tour\Plugin\Core\Entity\Tour $entity + * The tour object being updated. + */ +function hook_tour_update($entity) { + drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); + cache('cache_tour')->deleteTags(array('tour_items')); +} diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index 852e639..f9b30b6 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -138,10 +138,6 @@ function tour_preprocess_page(&$variables) { return; } - if (empty($tour_items)) { - return; - } - // Sort by weight. uasort($tour_items, function ($a, $b) { if ($a->getWeight() == $b->getWeight()) { @@ -191,7 +187,7 @@ function tour_preprocess_page(&$variables) { /** * Implements hook_tour_tour_insert(). */ -function tour_tour_insert($entities) { +function tour_tour_insert($entity) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour_items')); } @@ -199,7 +195,7 @@ function tour_tour_insert($entities) { /** * Implements hook_tour_tour_update(). */ -function tour_tour_update($entities) { +function tour_tour_update($entity) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour_items')); } commit 6483a020bc4e1783dabb88bab531ed93fa4bc579 Author: Lee Rowlands Date: Sat Feb 16 18:34:06 2013 +1000 Revert "Duplicate definition" This reverts commit 7f7516682f1b1d8a9833ee5620415ba9238f4d32. diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index df34eb2..852e639 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -138,6 +138,10 @@ function tour_preprocess_page(&$variables) { return; } + if (empty($tour_items)) { + return; + } + // Sort by weight. uasort($tour_items, function ($a, $b) { if ($a->getWeight() == $b->getWeight()) { commit e4c51fcf72e09365ea53db1c048ac2b1662d9dcd Author: Lee Rowlands Date: Sat Feb 16 18:33:03 2013 +1000 Duplicate definition diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index 852e639..df34eb2 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -138,10 +138,6 @@ function tour_preprocess_page(&$variables) { return; } - if (empty($tour_items)) { - return; - } - // Sort by weight. uasort($tour_items, function ($a, $b) { if ($a->getWeight() == $b->getWeight()) { commit 1a1aaa4383a53f76a6b272298d446cc0c1247083 Author: Nick Schuch Date: Sat Feb 16 05:56:52 2013 -0800 Fixed up plugin system. diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php similarity index 98% rename from core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php rename to core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php index c492d8e..1edb11f 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php @@ -5,7 +5,7 @@ * Contains \Drupal\tour\TipPluginText. */ -namespace Drupal\tour\Plugin\tour\tip; +namespace Drupal\tour\Plugin\tour\tour; use Drupal\Core\Annotation\Plugin; use Drupal\tour\TipPluginBase; diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php index f81528a..3f376ef 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php @@ -10,7 +10,7 @@ /** * Defines an interface for tour items. */ -interface TourPluginInterface { +interface TipPluginInterface { /** * Returns label of the tip. @@ -45,7 +45,7 @@ public function getAttributes(); * @return string * Value of the key. */ - public function get(); + public function get($key); /** * Used for returning values by key. @@ -56,7 +56,7 @@ public function get(); * @var string * Value of the key. */ - public function set(); + public function set($key, $value); /** * Returns a renderable array. commit 32326e2f044da17bee850c2f07fa7a822600f94c Merge: 67776ca 65642a1 Author: Nick Schuch Date: Sat Feb 16 05:29:26 2013 -0800 Merge branch 'tour' of git.drupal.org:sandbox/larowlan/1790736 into tour commit 67776cacd5342b1b69109b186c304394dc75a6f7 Author: Nick Schuch Date: Sat Feb 16 05:29:00 2013 -0800 Makes the tests pass! diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index d4e1bd0..5b8f87a 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -64,6 +64,11 @@ public function testTourFunctionality() { )); $this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.'); + /** + * Ensure that plugin's work. + */ + + $this->assertRaw('img src="http://local/image.png"', 'Image plugin tip found.'); /** * Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. @@ -106,10 +111,9 @@ public function testTourFunctionality() { /** - * Programmatically create a tour. + * Programmatically create a tour for use through the remainder of the test. */ - // Create a new tour (tour-code-test-1) visible on tour-test-1 with low weight. entity_create('tour', array( 'id' => 'tour-entity-create-test-en', 'label' => 'Tour test english', @@ -123,7 +127,7 @@ public function testTourFunctionality() { 'plugin' => 'text', 'label' => 'The rain in spain', 'body' => 'Falls mostly on the plain.', - 'weight' => '-100', + 'weight' => '100', 'attributes' => array( 'data-id' => 'tour-code-test-1', ), @@ -131,18 +135,19 @@ public function testTourFunctionality() { ), ))->save(); - // Load it back from the database and verify storage worked. $this->drupalGet('tour-test-1'); // Load it back from the database and verify storage worked. $entity_save_tip = entity_load('tour', 'tour-entity-create-test-en'); - // Verify that hook_ENTITY_TYPE_load() integration worked. - $this->assertEqual($entity_save_tip->loaded, 'load hooks work'); + $this->assertEqual($entity_save_tip->loaded, 'Load hooks work'); // Verify that hook_ENTITY_TYPE_presave() integration worked. $this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); - // Navigate to tour-test-1 and verify the new tip is found. + /** + * Navigate to tour-test-1 and verify the new tip is found. + */ + $this->drupalGet('tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-code-test-1', @@ -150,21 +155,21 @@ public function testTourFunctionality() { )); $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); - // Verify that the weight sorting works by ensuring the lower weight item - // (tip 4) has the close button. - $elements = $this->xpath('//li[@data-id=:data_id and @data-text=:text]', array( + /** + * Verify that the weight sorting works by ensuring the lower weight item + * (tip 4) has the close button. + */ + + $elements = $this->xpath('//li[@data-id=:data_id and ./div[contains(., :text)]]', array( ':data_id' => 'tour-code-test-1', - ':text' => 'End tour' + ':text' => '3 of 3' )); - $this->assertEqual(count($elements), 1, 'Found tip 4 was weighted last and had "End tour" button'); + $this->assertEqual(count($elements), 1, 'Found code tip was weighted last and had "3 of 3".'); - // Test hook_tour_alter(). - $this->assertText('Altered by hook_tour_items_alter'); + /** + * Test hook_tour_alter(). + */ - // Navigate to tour-test-3 and verify the TestTour plugin provides expected - // markup. - $this->drupalGet('tour-test-3'); - $this->assertText('This is the output of TourTest plugin'); + $this->assertText('Altered by hook_tour_tips_alter'); } - } diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-2-en.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-2-en.yml new file mode 100644 index 0000000..6816aa7 --- /dev/null +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-2-en.yml @@ -0,0 +1,14 @@ +id: tour-test-2-en +label: Tour test english +langcode: en +paths: + - tour-test-2/* +tips: + tour-test-2: + id: tour-test-2-en + plugin: text + label: The quick brown fox + body: Per lo più in pianura. + weight: "2" + attributes: + data-id: tour-test-2 diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml index c0b96dc..5271213 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml @@ -12,14 +12,6 @@ tips: weight: "1" attributes: data-id: tour-test-1 - tour-test-2: - id: tour-test-2-en - plugin: text - label: The quick brown fox - body: Per lo più in pianura. - weight: "2" - attributes: - data-id: tour-test-2 tour-test-3: id: tour-test-3-en plugin: image diff --git a/core/modules/tour/tests/tour_test/tour_test.module b/core/modules/tour/tests/tour_test/tour_test.module index e13a307..ffef6df 100644 --- a/core/modules/tour/tests/tour_test/tour_test.module +++ b/core/modules/tour/tests/tour_test/tour_test.module @@ -19,11 +19,6 @@ function tour_test_menu() { 'access callback' => TRUE, 'title' => 'Tour test 2' ); - $items['tour-test-3'] = array( - 'page callback' => 'tour_test_3', - 'access callback' => TRUE, - 'title' => 'Tour test 3' - ); return $items; } @@ -81,23 +76,12 @@ function tour_test_2() { } /** - * Page callback: output some content for testing tours. - */ -function tour_test_3() { - return array( - '#type' => 'container', - '#attributes' => array( - 'id' => 'tour-test-3', - ), - '#children' => t('Third test'), - ); -} - -/** * Implements hook_tour_alter(). */ -function tour_test_tour_alter(array &$tour_items, $path) { - if (!empty($tour_items['tour-entity-create-test-en'])) { - $tour_items['tour-entity-create-test-en']->entity->set('body', t('Altered by hook_tour_items_alter')); +function tour_test_tour_tips_alter(array &$tour_tips, $path) { + foreach ($tour_tips as $tour_tip) { + if ($tour_tip->get('id') == 'tour-code-test-1') { + $tour_tip->set('body', 'Altered by hook_tour_tips_alter'); + } } } diff --git a/core/modules/tour/tour.api.php b/core/modules/tour/tour.api.php index df430e0..a5e819d 100644 --- a/core/modules/tour/tour.api.php +++ b/core/modules/tour/tour.api.php @@ -13,8 +13,10 @@ * @param string $path * The path for which the tour is valid. */ -function hook_tour_items_alter(array &$tour_items, $path) { - if (!empty($tour_items['tour-entity-create-test-en'])) { - $tour_items['tour-entity-create-test-en']->entity->set('label', t('Search')); +function tour_test_tour_tips_alter(array &$tour_tips, $path) { + foreach ($tour_tips as $tour_tip) { + if ($tour_tip->get('id') == 'tour-code-test-1') { + $tour_tip->set('body', 'Altered by hook_tour_tips_alter'); + } } } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index fd540cf..852e639 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -126,6 +126,10 @@ function tour_preprocess_page(&$variables) { } } } + + // Allow other modules to alter. + drupal_container()->get('module_handler')->alter('tour_tips', $tour_items, $path); + // Cache for future requests. cache('cache_tour')->set($cid, $tour_items, CacheBackendInterface::CACHE_PERMANENT, array('tour_items')); } commit 65642a17e4876d5d1db1d314e43e4b750e194b1c Author: Lee Rowlands Date: Sat Feb 16 17:40:27 2013 +1000 Refactoring namespaces diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php similarity index 89% rename from core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php rename to core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php index 780ad00..c492d8e 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tip/TipPluginText.php @@ -5,10 +5,10 @@ * Contains \Drupal\tour\TipPluginText. */ -namespace Drupal\tour\Plugin\tour\tour; +namespace Drupal\tour\Plugin\tour\tip; use Drupal\Core\Annotation\Plugin; -use Drupal\tour\Plugin\tour\tour\TipPluginBase; +use Drupal\tour\TipPluginBase; /** * Displays some text as a tip. @@ -37,13 +37,17 @@ class TipPluginText extends TipPluginBase { protected $location; /** - * Returns a ID that is guaranteed uniqueness. + * Returns a ID that is guaranteed uniqueness. * * @return string * A unique string. */ public function getAriaId() { - return drupal_html_id($this->get('id')); + static $id; + if (!isset($id)) { + $id = drupal_html_id($this->get('id')); + } + return $id; } /** diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php index 63f8d57..8256eed 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourPluginTest.php @@ -47,8 +47,7 @@ protected function setUp() { * Test tour plugins. */ public function testTourPlugins() { - $this->assertIdentical(count($this->pluginManager->getDefinitions()), 2, 'Only tour plugins for the enabled modules were returned.'); + $this->assertIdentical(count($this->pluginManager->getDefinitions()), 1, 'Only tour plugins for the enabled modules were returned.'); } } - diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php b/core/modules/tour/lib/Drupal/tour/TipPluginBase.php similarity index 91% rename from core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php rename to core/modules/tour/lib/Drupal/tour/TipPluginBase.php index 4b9978d..4779061 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginBase.php @@ -2,18 +2,19 @@ /** * @file - * Contains \Drupal\tour\Plugin\tour\tour\TipPluginBase. + * Contains \Drupal\tour\TipPluginBase. */ -namespace Drupal\tour\Plugin\tour\tour; +namespace Drupal\tour; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\Discovery\CacheDecorator; +use Drupal\tour\TipPluginInterface; /** * Defines a base tour implementation. */ -abstract class TipPluginBase extends PluginBase { +abstract class TipPluginBase extends PluginBase implements TipPluginInterface { /** * The label which is used for render of this tip. diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php similarity index 91% rename from core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php rename to core/modules/tour/lib/Drupal/tour/TipPluginInterface.php index 4263894..f81528a 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php @@ -2,16 +2,16 @@ /** * @file - * Contains \Drupal\tour\TourInterface. + * Contains \Drupal\tour\TipPluginInterface. */ -namespace Drupal\tour\Plugin\tour\tour; +namespace Drupal\tour; /** * Defines an interface for tour items. */ interface TourPluginInterface { - + /** * Returns label of the tip. * @@ -30,7 +30,7 @@ public function getWeight(); /** * Returns an array of attributes for the tip wrapper. - * + * * @return array * An array of classes and values. */ diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php similarity index 91% rename from core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php rename to core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php index e49bcfb..d0f1b0b 100644 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tip/TipPluginImage.php @@ -5,10 +5,10 @@ * Contains \Drupal\tour_test\Plugin\tour\tour\TipPluginImage. */ -namespace Drupal\tour_test\Plugin\tour\tour; +namespace Drupal\tour_test\Plugin\tour\tip; use Drupal\Core\Annotation\Plugin; -use Drupal\tour\Plugin\tour\tour\TipPluginBase; +use Drupal\tour\TipPluginBase; /** * Displays an image as a tip. commit 168f069236808c71c8d2a1d01166c153b9d5037e Author: Lee Rowlands Date: Sat Feb 16 17:26:14 2013 +1000 Some errant mentions of filter in tipbag diff --git a/core/modules/tour/lib/Drupal/tour/TipsBag.php b/core/modules/tour/lib/Drupal/tour/TipsBag.php index 5c14284..99c2ecf 100644 --- a/core/modules/tour/lib/Drupal/tour/TipsBag.php +++ b/core/modules/tour/lib/Drupal/tour/TipsBag.php @@ -13,7 +13,7 @@ use Drupal\Component\Utility\NestedArray; /** - * A collection of filters. + * A collection of tips. */ class TipsBag extends PluginBag { /** @@ -54,7 +54,7 @@ public function __construct(PluginManagerInterface $manager, array $configuratio * Overrides \Drupal\Component\Plugin\PluginBag::initializePlugin(). */ protected function initializePlugin($instance_id) { - // If the filter was initialized before, just return. + // If the tip was initialized before, just return. if (isset($this->pluginInstances[$instance_id])) { return; } commit 4946981ff064d06aa2852dfe4b34ba5ed62baf77 Author: Lee Rowlands Date: Sat Feb 16 17:25:18 2013 +1000 Path matching with PluginBags diff --git a/core/modules/tour/lib/Drupal/tour/TourManager.php b/core/modules/tour/lib/Drupal/tour/TourManager.php index a02312f..26d278c 100644 --- a/core/modules/tour/lib/Drupal/tour/TourManager.php +++ b/core/modules/tour/lib/Drupal/tour/TourManager.php @@ -11,7 +11,6 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; -use Drupal\Core\Cache\CacheBackendInterface; /** * Configurable text tour manager. diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index 9de4515..fd540cf 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -4,6 +4,7 @@ * @file * Main functions of the module. */ +use Drupal\Core\Cache\CacheBackendInterface; /** * Implements hook_permission(). @@ -98,17 +99,40 @@ function tour_toolbar() { * Implements hook_preprocess_HOOK() for page.tpl.php. */ function tour_preprocess_page(&$variables) { + $path = current_path(); $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; - $tour_ids = entity_query('tour')->condition('langcode', $langcode)->execute(); - $tour_tips = entity_load_multiple('tour', array_keys($tour_ids)); - - foreach ($tour_tips as $tour_tip) { - foreach ($tour_tip->getTipList() as $id) { - $tour_items[] = $tour_tip->getTip($id); + $cid = $path . ':' . $langcode; + $cache = cache('cache_tour')->get($cid); + $tour_items = array(); + if ($cache) { + // Cache hit. + $tour_items = $cache->data; + } + else { + // Load all of the items and match on path. + $tour_ids = entity_query('tour') + ->condition('langcode', $langcode) + ->execute(); + $tours = entity_load_multiple('tour', $tour_ids); + + $path_alias = drupal_strtolower(drupal_container()->get('path.alias_manager')->getPathAlias($path)); + foreach ($tours as $tour) { + // @todo replace this with an entity_query() that does path matching when + // http://drupal.org/node/1918768 lands. + $pages = implode("\n", $tour->getPaths()); + if (drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages))) { + foreach ($tour->getTipList() as $id) { + $tour_items[] = $tour->getTip($id); + } + } } + // Cache for future requests. + cache('cache_tour')->set($cid, $tour_items, CacheBackendInterface::CACHE_PERMANENT, array('tour_items')); } - // Filter by path. + if (empty($tour_items)) { + return; + } if (empty($tour_items)) { return; @@ -165,7 +189,7 @@ function tour_preprocess_page(&$variables) { */ function tour_tour_insert($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); - cache('cache_tour')->deleteTags(array('tour')); + cache('cache_tour')->deleteTags(array('tour_items')); } /** @@ -173,5 +197,5 @@ function tour_tour_insert($entities) { */ function tour_tour_update($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); - cache('cache_tour')->deleteTags(array('tour')); + cache('cache_tour')->deleteTags(array('tour_items')); } commit ad1308cfc78d5388e21c26bb6b7650dbfebdcf72 Author: Nick Schuch Date: Fri Feb 15 23:11:06 2013 -0800 Update of tips and moving check of tour items before the sort diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index 51d3b6e..d4e1bd0 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -135,37 +135,25 @@ public function testTourFunctionality() { $this->drupalGet('tour-test-1'); // Load it back from the database and verify storage worked. - //$entity_save_tip = entity_load('tour', 'tour-entity-create-test-en'); + $entity_save_tip = entity_load('tour', 'tour-entity-create-test-en'); // Verify that hook_ENTITY_TYPE_load() integration worked. - //$this->assertEqual($entity_save_tip->loaded, 'load hooks work'); + $this->assertEqual($entity_save_tip->loaded, 'load hooks work'); // Verify that hook_ENTITY_TYPE_presave() integration worked. - //$this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); + $this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); // Navigate to tour-test-1 and verify the new tip is found. $this->drupalGet('tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( - ':data_id' => 'tour-test-4', - ':text' => 'Tip 4 alter' + ':data_id' => 'tour-code-test-1', + ':text' => 'The rain in spain' )); - $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); - // Change the name of tip 4 and verify new value found. - // Note that tour_test_tour_presave() will rewrite this to add alter - // again. - //$entity_save_tip->save(); - $this->drupalGet('tour-test-1'); - $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( - ':data_id' => 'tour-test-4', - ':text' => 'Tip 4 alter alter' - )); - $this->assertEqual(count($elements), 1, 'Found the new tip markup for tip 4'); - // Verify that the weight sorting works by ensuring the lower weight item // (tip 4) has the close button. $elements = $this->xpath('//li[@data-id=:data_id and @data-text=:text]', array( - ':data_id' => 'tour-test-4', + ':data_id' => 'tour-code-test-1', ':text' => 'End tour' )); $this->assertEqual(count($elements), 1, 'Found tip 4 was weighted last and had "End tour" button'); diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml index 660e834..86f0a25 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml @@ -1,6 +1,6 @@ id: tour-test-it label: Tour test italian -langcode: en +langcode: it paths: - tour-test-1 tips: diff --git a/core/modules/tour/tests/tour_test/tour_test.module b/core/modules/tour/tests/tour_test/tour_test.module index c340683..e13a307 100644 --- a/core/modules/tour/tests/tour_test/tour_test.module +++ b/core/modules/tour/tests/tour_test/tour_test.module @@ -94,9 +94,9 @@ function tour_test_3() { } /** - * Implements hook_tour_items_alter(). + * Implements hook_tour_alter(). */ -function tour_tour_items_alter(array &$tour_items, $path) { +function tour_test_tour_alter(array &$tour_items, $path) { if (!empty($tour_items['tour-entity-create-test-en'])) { $tour_items['tour-entity-create-test-en']->entity->set('body', t('Altered by hook_tour_items_alter')); } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index cbb5b24..9de4515 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -98,7 +98,9 @@ function tour_toolbar() { * Implements hook_preprocess_HOOK() for page.tpl.php. */ function tour_preprocess_page(&$variables) { - $tour_tips = entity_load_multiple('tour'); + $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + $tour_ids = entity_query('tour')->condition('langcode', $langcode)->execute(); + $tour_tips = entity_load_multiple('tour', array_keys($tour_ids)); foreach ($tour_tips as $tour_tip) { foreach ($tour_tip->getTipList() as $id) { @@ -108,6 +110,10 @@ function tour_preprocess_page(&$variables) { // Filter by path. + if (empty($tour_items)) { + return; + } + // Sort by weight. uasort($tour_items, function ($a, $b) { if ($a->getWeight() == $b->getWeight()) { @@ -116,10 +122,6 @@ function tour_preprocess_page(&$variables) { return ($a->getWeight() < $b->getWeight()) ? -1 : 1; }); - if (empty($tour_items)) { - return; - } - $index = 1; $count = count($tour_items); foreach ($tour_items as $tour_item) { commit 93f95760d5b0cdfaaa5b95de22080915ccb96335 Author: Nick Schuch Date: Fri Feb 15 06:23:32 2013 -0800 Removal of the rest of the tooltip refs. diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index 37dd107..51d3b6e 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -25,7 +25,7 @@ class TourTest extends WebTestBase { public static function getInfo() { return array( 'name' => 'Tour tests', - 'description' => 'Test the functionality of tour tooltips.', + 'description' => 'Test the functionality of tour tips.', 'group' => 'Tour', ); } @@ -152,7 +152,7 @@ public function testTourFunctionality() { $this->assertEqual(count($elements), 1, 'Found the required tip markup for tip 4'); // Change the name of tip 4 and verify new value found. - // Note that tour_test_tour_tooltip_presave() will rewrite this to add alter + // Note that tour_test_tour_presave() will rewrite this to add alter // again. //$entity_save_tip->save(); $this->drupalGet('tour-test-1'); diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php index 8f75fbb..e49bcfb 100644 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php @@ -41,8 +41,8 @@ class TipPluginImage extends TipPluginBase { */ public function getOutput() { return array( - '#markup' => '

      ' . check_plain($this->get('label')) . '

      -

      ' . theme('image', array('uri' => $this->get('url'), 'alt' => $this->get('alt'))) . '

      ' + '#markup' => '

      ' . check_plain($this->get('label')) . '

      +

      ' . theme('image', array('uri' => $this->get('url'), 'alt' => $this->get('alt'))) . '

      ' ); } } diff --git a/core/modules/tour/tests/tour_test/tour_test.module b/core/modules/tour/tests/tour_test/tour_test.module index 08ee2ee..c340683 100644 --- a/core/modules/tour/tests/tour_test/tour_test.module +++ b/core/modules/tour/tests/tour_test/tour_test.module @@ -28,7 +28,7 @@ function tour_test_menu() { } /** - * Implements hook_ENTITY_TYPE_load() for tour_tooltip. + * Implements hook_ENTITY_TYPE_load() for tour. */ function tour_test_tour_load($entities) { if (isset($entities['tour-entity-create-test-en'])) { @@ -37,7 +37,7 @@ function tour_test_tour_load($entities) { } /** - * Implements hook_ENTITY_TYPE_presave() for tour_tooltip. + * Implements hook_ENTITY_TYPE_presave() for tour. */ function tour_test_tour_presave($entity) { if ($entity->id() == 'tour-entity-create-test-en') { @@ -97,7 +97,7 @@ function tour_test_3() { * Implements hook_tour_items_alter(). */ function tour_tour_items_alter(array &$tour_items, $path) { - if (!empty($tour_items['tooltip:tip4'])) { - $tour_items['tooltip:tip4']->entity->set('body', t('Altered by hook_tour_items_alter')); + if (!empty($tour_items['tour-entity-create-test-en'])) { + $tour_items['tour-entity-create-test-en']->entity->set('body', t('Altered by hook_tour_items_alter')); } } diff --git a/core/modules/tour/tour.api.php b/core/modules/tour/tour.api.php index 8a8fda2..df430e0 100644 --- a/core/modules/tour/tour.api.php +++ b/core/modules/tour/tour.api.php @@ -14,7 +14,7 @@ * The path for which the tour is valid. */ function hook_tour_items_alter(array &$tour_items, $path) { - if (!empty($tour_items['tooltip:search-en'])) { - $tour_items['tooltip:search-en']->entity->set('label', t('Search')); + if (!empty($tour_items['tour-entity-create-test-en'])) { + $tour_items['tour-entity-create-test-en']->entity->set('label', t('Search')); } } commit ddd84d01400ffb6f8e1ae0eb591d66a068d18323 Author: Nick Schuch Date: Fri Feb 15 06:08:09 2013 -0800 Resolved half of the tests, updated yml files and removed unnecessary items in the yml files. diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php index 834ecc6..71ce552 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php @@ -78,6 +78,26 @@ public function __construct(array $values, $entity_type) { } /** + * Returns label of tour. + * + * @return string + * The label of the tour. + */ + public function getLabel() { + return $this->label; + } + + /** + * The paths that this tour will appear on. + * + * @return array + * Returns array of paths for the tour. + */ + public function getPaths() { + return $this->paths; + } + + /** * Returns tip plugin. * * @return string diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php index a0a82b0..4b9978d 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php @@ -49,6 +49,20 @@ public function __construct(array $configuration, $plugin_id, CacheDecorator $di } /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getLabel(). + */ + public function getLabel() { + return $this->get('label'); + } + + /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getWeight(). + */ + public function getWeight() { + return $this->get('weight'); + } + + /** * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getAttributes(). */ public function getAttributes() { diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php index c94f907..4263894 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php @@ -13,6 +13,22 @@ interface TourPluginInterface { /** + * Returns label of the tip. + * + * @return string + * The label of the tip. + */ + public function getLabel(); + + /** + * Returns weight of the tip. + * + * @return string + * The weight of the tip. + */ + public function getWeight(); + + /** * Returns an array of attributes for the tip wrapper. * * @return array diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php index 441e52a..780ad00 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php @@ -47,10 +47,30 @@ public function getAriaId() { } /** + * Returns body of the text tip. + * + * @return string + * The body of the text tip. + */ + public function getBody() { + return $this->get('body'); + } + + /** + * Returns location of the text tip. + * + * @return string + * The location (left|right|top|bottom) of the text tip. + */ + public function getLocation() { + return $this->get('location'); + } + + /** * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getAttributes(); */ public function getAttributes() { - $attributes = $this->get('attributes'); + $attributes = parent::getAttributes(); $attributes['data-aria-describedby'] = 'tour-tip-' . $this->getAriaId() . '-contents'; $attributes['data-aria-labelledby'] = 'tour-tip-' . $this->getAriaId() . '-label'; if ($location = $this->get('location')) { @@ -64,8 +84,8 @@ public function getAttributes() { */ public function getOutput() { return array( - '#markup' => '

      ' . check_plain($this->get('label')) . '

      -

      ' . filter_xss_admin($this->get('body')) . '

      ' + '#markup' => '

      ' . check_plain($this->getLabel()) . '

      +

      ' . filter_xss_admin($this->getBody()) . '

      ' ); } } diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php index 989f87e..37dd107 100644 --- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php +++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php @@ -40,72 +40,107 @@ protected function setUp() { * Test tour functionality. */ public function testTourFunctionality() { - // Navigate to tour-test-1 and verify the tour_test_1 tip is found. + + /** + * Navigate to tour-test-1 and verify the tour_test_1 tip is found. + */ + $this->drupalGet('tour-test-1'); - $this->assertRaw('data-id="tour-test-1" data-text="End tour" class="custom'); + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-1', + ':text' => 'The first tip' + )); + $this->assertEqual(count($elements), 1, 'Found English variant of tip 1.'); + + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-2', + ':text' => 'The quick brown fox' + )); + $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 2.'); + + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-1', + ':text' => 'La pioggia cade in spagna' + )); + $this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.'); - // Verify Italian variant is not found. - $this->assertNoText('La pioggia cade in spagna'); - // Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. + /** + * Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found. + */ + $this->drupalGet('tour-test-2/subpath'); - $this->assertRaw('data-id="tour-test-2" data-text="End tour" class="custom'); + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-2', + ':text' => 'The quick brown fox' + )); + $this->assertEqual(count($elements), 1, 'Found English variant of tip 2.'); - // Enable Italian language and navigate to it/tour-test1 and verify italian - // version of tip is found. - language_save(new Language(array('langcode' => 'it'))); + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-1', + ':text' => 'The first tip' + )); + $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); + + /** + * Enable Italian language and navigate to it/tour-test1 and verify italian + * version of tip is found. + */ + language_save(new Language(array('langcode' => 'it'))); $this->drupalGet('it/tour-test-1'); - $this->assertText('La pioggia cade in spagna'); - // Verify English version is not found. - $this->assertNoText('Falls mostly on the plain'); + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-1', + ':text' => 'La pioggia cade in spagna' + )); + $this->assertEqual(count($elements), 1, 'Found Italian variant of tip 1.'); + + $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( + ':data_id' => 'tour-test-1', + ':text' => 'The first tip' + )); + $this->assertNotEqual(count($elements), 1, 'Did not find English variant of tip 1.'); - // Revert back to english. language_save(new Language(array('langcode' => 'en'))); - // Create a new tip (tip-3) visible on tour-test-1 with low weight. - entity_create('tour_tooltip', array( - 'id' => 'tour-code-test-1', - 'label' => 'The rain in spain', + + /** + * Programmatically create a tour. + */ + + // Create a new tour (tour-code-test-1) visible on tour-test-1 with low weight. + entity_create('tour', array( + 'id' => 'tour-entity-create-test-en', + 'label' => 'Tour test english', 'langcode' => 'en', - 'body' => 'Falls mostly on the plain.', - 'weight' => '-100', 'paths' => array( 'tour-test-1', ), - 'attributes' => array( - 'data-id' => 'tour-code-test-1', - 'data-text' => 'Next', - 'class' => 'custom', + 'tips' => array( + 'tour-test-1' => array( + 'id' => 'tour-code-test-1', + 'plugin' => 'text', + 'label' => 'The rain in spain', + 'body' => 'Falls mostly on the plain.', + 'weight' => '-100', + 'attributes' => array( + 'data-id' => 'tour-code-test-1', + ), + ), ), - )); + ))->save(); // Load it back from the database and verify storage worked. $this->drupalGet('tour-test-1'); - // Create a new tip (tip-4) visible on tour-test-1 with low weight. - entity_create('tour_tooltip', array( - 'id' => 'tip4', - 'label' => 'Tip 4', - 'langcode' => 'en', - 'weight' => 100, - 'body' => 'Body of tip 4', - 'paths' => array('tour-test-1'), - 'attributes' => array( - 'data-id' => 'tour-test-4', - 'data-text' => 'Next', - 'class' => array('custom'), - ) - ))->save(); - // Load it back from the database and verify storage worked. - $tip4_loaded = entity_load('tour_tooltip', 'tip4'); + //$entity_save_tip = entity_load('tour', 'tour-entity-create-test-en'); // Verify that hook_ENTITY_TYPE_load() integration worked. - $this->assertEqual($tip4_loaded->loaded, 'load hooks work'); + //$this->assertEqual($entity_save_tip->loaded, 'load hooks work'); // Verify that hook_ENTITY_TYPE_presave() integration worked. - $this->assertEqual($tip4_loaded->label(), 'Tip 4 alter'); + //$this->assertEqual($entity_save_tip->label(), 'Tour test english alter'); // Navigate to tour-test-1 and verify the new tip is found. $this->drupalGet('tour-test-1'); @@ -119,7 +154,7 @@ public function testTourFunctionality() { // Change the name of tip 4 and verify new value found. // Note that tour_test_tour_tooltip_presave() will rewrite this to add alter // again. - $tip4_loaded->save(); + //$entity_save_tip->save(); $this->drupalGet('tour-test-1'); $elements = $this->xpath('//li[@data-id=:data_id and ./h2[contains(., :text)]]', array( ':data_id' => 'tour-test-4', diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml index ca735bc..c0b96dc 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml @@ -7,14 +7,11 @@ tips: tour-test-1: id: tour-test-1-en plugin: text - label: La pioggia cade in spagna - body: Per lo più in pianura. + label: The first tip + body: Is always the best dressed. weight: "1" attributes: data-id: tour-test-1 - data-text: Next - class: - - custom tour-test-2: id: tour-test-2-en plugin: text @@ -23,9 +20,6 @@ tips: weight: "2" attributes: data-id: tour-test-2 - data-text: Next - class: - - custom tour-test-3: id: tour-test-3-en plugin: image @@ -33,7 +27,4 @@ tips: url: http://local/image.png weight: "1" attributes: - data-id: tour-test-1 - data-text: Next - class: - - custom + data-id: tour-test-3 diff --git a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml similarity index 83% rename from core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml rename to core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml index 7d06752..660e834 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-it.yml @@ -12,6 +12,3 @@ tips: weight: "1" attributes: data-id: tour-test-1 - data-text: Next - class: - - custom diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php index 5526854..8f75fbb 100644 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php @@ -2,10 +2,10 @@ /** * @file - * Contains \Drupal\tour\TipPluginImage. + * Contains \Drupal\tour_test\Plugin\tour\tour\TipPluginImage. */ -namespace Drupal\tour\Plugin\tour\tour; +namespace Drupal\tour_test\Plugin\tour\tour; use Drupal\Core\Annotation\Plugin; use Drupal\tour\Plugin\tour\tour\TipPluginBase; @@ -21,7 +21,7 @@ class TipPluginImage extends TipPluginBase { /** - * The image url which is used for render of this Text Tip. + * The url which is used for the image in this Tip. * * @var string * A url used for the image. @@ -29,12 +29,20 @@ class TipPluginImage extends TipPluginBase { protected $url; /** + * The alt text which is used for the image in this Tip. + * + * @var string + * A alt text used for the image. + */ + protected $alt; + + /** * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getOutput(); */ public function getOutput() { return array( '#markup' => '

      ' . check_plain($this->get('label')) . '

      -

      ' . theme('image', array('uri' => $this->get('url'))) . '

      ' +

      ' . theme('image', array('uri' => $this->get('url'), 'alt' => $this->get('alt'))) . '

      ' ); } } diff --git a/core/modules/tour/tests/tour_test/tour_test.module b/core/modules/tour/tests/tour_test/tour_test.module index cddca99..08ee2ee 100644 --- a/core/modules/tour/tests/tour_test/tour_test.module +++ b/core/modules/tour/tests/tour_test/tour_test.module @@ -30,17 +30,17 @@ function tour_test_menu() { /** * Implements hook_ENTITY_TYPE_load() for tour_tooltip. */ -function tour_test_tour_tooltip_load($entities) { - if (isset($entities['tip4'])) { - $entities['tip4']->loaded = 'load hooks work'; +function tour_test_tour_load($entities) { + if (isset($entities['tour-entity-create-test-en'])) { + $entities['tour-entity-create-test-en']->loaded = 'load hooks work'; } } /** * Implements hook_ENTITY_TYPE_presave() for tour_tooltip. */ -function tour_test_tour_tooltip_presave($entity) { - if ($entity->id() == 'tip4') { +function tour_test_tour_presave($entity) { + if ($entity->id() == 'tour-entity-create-test-en') { $entity->set('label', $entity->label() . ' alter'); } } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index aa60c59..cbb5b24 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -110,10 +110,10 @@ function tour_preprocess_page(&$variables) { // Sort by weight. uasort($tour_items, function ($a, $b) { - if ($a->get('weight') == $b->get('weight')) { + if ($a->getWeight() == $b->getWeight()) { return 0; } - return ($a->get('weight') < $b->get('weight')) ? -1 : 1; + return ($a->getWeight() < $b->getWeight()) ? -1 : 1; }); if (empty($tour_items)) { @@ -161,7 +161,7 @@ function tour_preprocess_page(&$variables) { /** * Implements hook_tour_tour_insert(). */ -function tour_tour_tour_insert($entities) { +function tour_tour_insert($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour')); } @@ -169,7 +169,7 @@ function tour_tour_tour_insert($entities) { /** * Implements hook_tour_tour_update(). */ -function tour_tour_tour_update($entities) { +function tour_tour_update($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour')); } diff --git a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml index a6d1ca6..0e80903 100644 --- a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml +++ b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml @@ -12,8 +12,6 @@ tips: weight: "2" attributes: data-class: views-display-top li.active - class: - - custom views-ui-displays-en: id: views-ui-displays-en plugin: text @@ -22,8 +20,6 @@ tips: weight: "1" attributes: data-id: views-display-top - class: - - custom views-ui-fields-en: id: views-ui-fields-en plugin: text @@ -32,8 +28,6 @@ tips: weight: "5" attributes: data-class: views-ui-display-tab-bucket.fields - class: - - custom views-ui-filter-en: id: views-ui-filter-en plugin: text @@ -42,8 +36,6 @@ tips: weight: "6" attributes: data-class: views-ui-display-tab-bucket.filter-criteria - class: - - custom views-ui-filter-operations-en: id: views-ui-filter-operations-en plugin: text @@ -52,8 +44,6 @@ tips: weight: "7" attributes: data-class: views-ui-display-tab-bucket.filter-criteria .dropbutton-widget - class: - - custom views-ui-format-en: id: views-ui-format-en plugin: text @@ -62,8 +52,6 @@ tips: weight: "4" attributes: data-class: views-ui-display-tab-bucket.format - class: - - custom views-ui-preview-en: id: views-ui-preview-en plugin: text @@ -72,8 +60,6 @@ tips: weight: "10" attributes: data-id: preview-submit - class: - - custom views-ui-sorts-en: id: views-ui-sorts-en plugin: text @@ -82,8 +68,6 @@ tips: weight: "8" attributes: data-class: views-ui-display-tab-bucket.sort-criteria - class: - - custom views-ui-sorts-operations-en: id: views-ui-sorts-operations-en plugin: text @@ -92,8 +76,6 @@ tips: weight: "9" attributes: data-class: views-ui-display-tab-bucket.sort-criteria .dropbutton-widget - class: - - custom views-ui-view-admin-en: id: views-ui-view-admin-en plugin: text @@ -103,5 +85,3 @@ tips: location: left attributes: data-id: views-display-extra-actions - class: - - custom commit e13eab60b9791de226dc0325a63615191422bb1b Author: Nick Schuch Date: Fri Feb 15 04:22:28 2013 -0800 Aria, export, position support, .element-hidden for tour items and renaming of tooltip to tip. diff --git a/core/modules/tour/css/tour.css b/core/modules/tour/css/tour.css index 9125c61..0c0dde5 100644 --- a/core/modules/tour/css/tour.css +++ b/core/modules/tour/css/tour.css @@ -1,7 +1,3 @@ -#tour-items { - display: none; -} - .toolbar .icon-help.tour-no-items-hidden { display: none; } diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php index d569acb..834ecc6 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php @@ -69,6 +69,15 @@ class Tour extends ConfigEntityBase { protected $tips; /** + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct(); + */ + public function __construct(array $values, $entity_type) { + parent::__construct($values, $entity_type); + + $this->tipsBag = new TipsBag(drupal_container()->get('plugin.manager.tour'), $this->tips); + } + + /** * Returns tip plugin. * * @return string @@ -89,12 +98,19 @@ public function getTipList() { } /** - * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct(); + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); */ - public function __construct(array $values, $entity_type) { - parent::__construct($values, $entity_type); - - $this->tipsBag = new TipsBag(drupal_container()->get('plugin.manager.tour'), $this->tips); + public function getExportProperties() { + $properties = parent::getExportProperties(); + $names = array( + 'id', + 'label', + 'paths', + 'tips', + ); + foreach ($names as $name) { + $properties[$name] = $this->get($name); + } + return $properties; } - } diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php index 2cfe99b..a0a82b0 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php @@ -49,6 +49,13 @@ public function __construct(array $configuration, $plugin_id, CacheDecorator $di } /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getAttributes(). + */ + public function getAttributes() { + return $this->get('attributes'); + } + + /** * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::get(). */ public function get($key) { diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php index 3e3e693..c94f907 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php @@ -13,6 +13,14 @@ interface TourPluginInterface { /** + * Returns an array of attributes for the tip wrapper. + * + * @return array + * An array of classes and values. + */ + public function getAttributes(); + + /** * Used for returning values by key. * * @var string diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php index d4ebfb3..441e52a 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginText.php @@ -29,12 +29,43 @@ class TipPluginText extends TipPluginBase { protected $body; /** + * The forced position of where the tip will be located. + * + * @var string + * A string of left|right|top|bottom. + */ + protected $location; + + /** + * Returns a ID that is guaranteed uniqueness. + * + * @return string + * A unique string. + */ + public function getAriaId() { + return drupal_html_id($this->get('id')); + } + + /** + * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getAttributes(); + */ + public function getAttributes() { + $attributes = $this->get('attributes'); + $attributes['data-aria-describedby'] = 'tour-tip-' . $this->getAriaId() . '-contents'; + $attributes['data-aria-labelledby'] = 'tour-tip-' . $this->getAriaId() . '-label'; + if ($location = $this->get('location')) { + $attributes['data-options'] = 'tipLocation:' . $location; + } + return $attributes; + } + + /** * Overrides \Drupal\tour\Plugin\tour\tour\TipPluginInterface::getOutput(); */ public function getOutput() { return array( - '#markup' => '

      ' . check_plain($this->get('label')) . '

      -

      ' . filter_xss_admin($this->get('body')) . '

      ' + '#markup' => '

      ' . check_plain($this->get('label')) . '

      +

      ' . filter_xss_admin($this->get('body')) . '

      ' ); } } diff --git a/core/modules/tour/tour.install b/core/modules/tour/tour.install index de5cc44..e22be72 100644 --- a/core/modules/tour/tour.install +++ b/core/modules/tour/tour.install @@ -11,6 +11,6 @@ function tour_schema() { $schema = array(); $schema['cache_tour'] = drupal_get_schema_unprocessed('system', 'cache'); - $schema['cache_tour']['description'] = 'Cache table for the Tour module to store tooltips by path.'; + $schema['cache_tour']['description'] = 'Cache table for the Tour module.'; return $schema; } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index dceec24..aa60c59 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -134,7 +134,7 @@ function tour_preprocess_page(&$variables) { ), '#children' => t('!tour_item of !total', array('!tour_item' => $index, '!total' => $count)), ), - '#wrapper_attributes' => $tour_item->get('attributes'), + '#wrapper_attributes' => $tour_item->getAttributes(), ); $index++; } @@ -145,6 +145,9 @@ function tour_preprocess_page(&$variables) { '#type' => 'ol', '#attributes' => array( 'id' => 'tour-items', + 'class' => array( + 'element-hidden', + ), 'hidden' => TRUE, ), '#attached' => array( @@ -156,17 +159,17 @@ function tour_preprocess_page(&$variables) { } /** - * Implements hook_tour_tooltip_insert(). + * Implements hook_tour_tour_insert(). */ -function tour_tour_tooltip_insert($entities) { +function tour_tour_tour_insert($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour')); } /** - * Implements hook_tour_tooltip_update(). + * Implements hook_tour_tour_update(). */ -function tour_tour_tooltip_update($entities) { +function tour_tour_tour_update($entities) { drupal_container()->get('plugin.manager.tour')->clearCachedDefinitions(); cache('cache_tour')->deleteTags(array('tour')); } diff --git a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml index 75a0a8e..a6d1ca6 100644 --- a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml +++ b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml @@ -12,7 +12,6 @@ tips: weight: "2" attributes: data-class: views-display-top li.active - data-text: Next class: - custom views-ui-displays-en: @@ -23,7 +22,6 @@ tips: weight: "1" attributes: data-id: views-display-top - data-text: Next class: - custom views-ui-fields-en: @@ -34,7 +32,6 @@ tips: weight: "5" attributes: data-class: views-ui-display-tab-bucket.fields - data-text: Next class: - custom views-ui-filter-en: @@ -45,7 +42,6 @@ tips: weight: "6" attributes: data-class: views-ui-display-tab-bucket.filter-criteria - data-text: Next class: - custom views-ui-filter-operations-en: @@ -56,7 +52,6 @@ tips: weight: "7" attributes: data-class: views-ui-display-tab-bucket.filter-criteria .dropbutton-widget - data-text: Next class: - custom views-ui-format-en: @@ -67,7 +62,6 @@ tips: weight: "4" attributes: data-class: views-ui-display-tab-bucket.format - data-text: Next class: - custom views-ui-preview-en: @@ -78,7 +72,6 @@ tips: weight: "10" attributes: data-id: preview-submit - data-text: Next class: - custom views-ui-sorts-en: @@ -89,7 +82,6 @@ tips: weight: "8" attributes: data-class: views-ui-display-tab-bucket.sort-criteria - data-text: Next class: - custom views-ui-sorts-operations-en: @@ -100,7 +92,6 @@ tips: weight: "9" attributes: data-class: views-ui-display-tab-bucket.sort-criteria .dropbutton-widget - data-text: Next class: - custom views-ui-view-admin-en: @@ -112,6 +103,5 @@ tips: location: left attributes: data-id: views-display-extra-actions - data-text: Next class: - custom commit cbe257fa0b707afedea19bba8105559d9b91aea9 Author: Nick Schuch Date: Fri Feb 15 02:20:05 2013 -0800 Moved from tip to tour diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php index c12b2e7..d569acb 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php @@ -47,6 +47,14 @@ class Tour extends ConfigEntityBase { public $label; /** + * The paths in which this tip can be displayed. + * + * @var array + * An array of paths. + */ + protected $paths; + + /** * Holds the collection of tips that are attached to this tour. * * @var \Drupal\tour\TipsBag diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php index bd091c8..2cfe99b 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginBase.php @@ -24,14 +24,6 @@ protected $label; /** - * The paths in which this tip can be displayed. - * - * @var array - * An array of paths. - */ - protected $paths; - - /** * Allows tips to take more priority that others. * * @var string diff --git a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml index e477651..7d06752 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml @@ -1,14 +1,14 @@ id: tour-test-it label: Tour test italian langcode: en +paths: + - tour-test-1 tips: tour-test-1-it: id: tour-test-1-it plugin: text label: La pioggia cade in spagna body: Per lo più in pianura. - paths: - - tour-test-1 weight: "1" attributes: data-id: tour-test-1 diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml index 48daa80..ca735bc 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml @@ -1,14 +1,14 @@ id: tour-test-en label: Tour test english langcode: en +paths: + - tour-test-1 tips: tour-test-1: id: tour-test-1-en plugin: text label: La pioggia cade in spagna body: Per lo più in pianura. - paths: - - tour-test-1 weight: "1" attributes: data-id: tour-test-1 @@ -20,8 +20,6 @@ tips: plugin: text label: The quick brown fox body: Per lo più in pianura. - paths: - - tour-test-2/* weight: "2" attributes: data-id: tour-test-2 @@ -33,8 +31,6 @@ tips: plugin: image label: The awesome image url: http://local/image.png - paths: - - tour-test-1 weight: "1" attributes: data-id: tour-test-1 diff --git a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml index 2373e07..75a0a8e 100644 --- a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml +++ b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml @@ -1,14 +1,14 @@ id: views-ui-en label: Views ui langcode: en +paths: + - admin/structure/views/view/*/edit tips: views-ui-active-display-en: id: views-ui-active-display-en plugin: text label: Active display body: This is the active display in the view. When there are multiple displays, one link for each display is shown and you can switch displays simply by clicking on the display link. - paths: - - admin/structure/views/view/*/edit weight: "2" attributes: data-class: views-display-top li.active @@ -20,8 +20,6 @@ tips: plugin: text label: Displays in this view body: A view can consist of multiple displays. A display is a way of outputting the results E.g. as a page or in a block. The available displays in your view are show here. - paths: - - admin/structure/views/view/*/edit weight: "1" attributes: data-id: views-display-top @@ -33,8 +31,6 @@ tips: plugin: text label: Fields body: This section shows the fields output for each result. Depending on the format selected for the view, you may not see anything listed here. If the format of your view uses fields, you can click on each field displayed to configure it. - paths: - - admin/structure/views/view/*/edit weight: "5" attributes: data-class: views-ui-display-tab-bucket.fields @@ -46,8 +42,6 @@ tips: plugin: text label: Filter your view body: This section displays the filters you have active in your view. A filter is used to limit the results available in the output. E.g. to only show content that was published, you would add a filter for Published and select Yes. - paths: - - admin/structure/views/view/*/edit weight: "6" attributes: data-class: views-ui-display-tab-bucket.filter-criteria @@ -59,8 +53,6 @@ tips: plugin: text label: Filter actions body: Use this drop-button to add and re-arrange filters - paths: - - admin/structure/views/view/*/edit weight: "7" attributes: data-class: views-ui-display-tab-bucket.filter-criteria .dropbutton-widget @@ -72,8 +64,6 @@ tips: plugin: text label: Output format body: Use this section to manage the format of the output results. You can choose different ways in which the matching results are output. E.g. Choose Content to output each item completely, using your configured display settings. Other options include Fields which allows you to output only specific fields on each matching result. Additional formats can be added by installing additional module to extend Drupal's base functionality. - paths: - - admin/structure/views/view/*/edit weight: "4" attributes: data-class: views-ui-display-tab-bucket.format @@ -85,8 +75,6 @@ tips: plugin: text label: Preview body: Use this button to show a preview of the view output - paths: - - admin/structure/views/view/*/edit weight: "10" attributes: data-id: preview-submit @@ -98,8 +86,6 @@ tips: plugin: text label: Sort Criteria body: This section shows the enabled sorting criteria for the view. Sorting criteria are used to control the order in which the results are output. Clicking on any of the active sorting criteria shown in this section enables you to configure it. - paths: - - admin/structure/views/view/*/edit weight: "8" attributes: data-class: views-ui-display-tab-bucket.sort-criteria @@ -111,8 +97,6 @@ tips: plugin: text label: Sort actions body: Use this drop-button to add and re-arrange the sorting criteria. - paths: - - admin/structure/views/view/*/edit weight: "9" attributes: data-class: views-ui-display-tab-bucket.sort-criteria .dropbutton-widget @@ -124,8 +108,6 @@ tips: plugin: text label: View administration body: Use this drop-button to perform administrative tasks on the view, including adding a description and creating a clone. Click the drop button to view the available options. - paths: - - admin/structure/views/view/*/edit weight: "3" location: left attributes: commit a28b8649a7911be675ed1d4416951bb0d9c511ee Author: Nick Schuch Date: Thu Feb 14 23:27:32 2013 -0800 Update of tour_test yml files and addition of TipPluginImage diff --git a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml index 9dc1029..e477651 100644 --- a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml +++ b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1-it.yml @@ -1,12 +1,17 @@ -id: tour-test-1-it -label: La pioggia cade in spagna -langcode: it -weight: "1" -body: Per lo più in pianura. -paths: - - tour-test-1 -attributes: - data-id: tour-test-1 - data-text: Next - class: - - custom +id: tour-test-it +label: Tour test italian +langcode: en +tips: + tour-test-1-it: + id: tour-test-1-it + plugin: text + label: La pioggia cade in spagna + body: Per lo più in pianura. + paths: + - tour-test-1 + weight: "1" + attributes: + data-id: tour-test-1 + data-text: Next + class: + - custom diff --git a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1.yml b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1.yml deleted file mode 100644 index 1036606..0000000 --- a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-1.yml +++ /dev/null @@ -1,12 +0,0 @@ -id: tour-test-1 -label: The rain in spain -langcode: en -body: Falls mostly on the plain. -weight: "1" -paths: - - tour-test-1 -attributes: - data-id: tour-test-1 - data-text: Next - class: - - custom diff --git a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-2.yml b/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-2.yml deleted file mode 100644 index d5056c4..0000000 --- a/core/modules/tour/tests/tour_test/config/tour.tooltip.tour-test-2.yml +++ /dev/null @@ -1,12 +0,0 @@ -id: tour-test-2 -label: The quick brown fox -langcode: en -body: Jumps over the lazy dog. -weight: "2" -paths: - - tour-test-2/* -attributes: - data-id: tour-test-2 - data-text: Next - class: - - custom diff --git a/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml new file mode 100644 index 0000000..48daa80 --- /dev/null +++ b/core/modules/tour/tests/tour_test/config/tour.tour.tour-test-en.yml @@ -0,0 +1,43 @@ +id: tour-test-en +label: Tour test english +langcode: en +tips: + tour-test-1: + id: tour-test-1-en + plugin: text + label: La pioggia cade in spagna + body: Per lo più in pianura. + paths: + - tour-test-1 + weight: "1" + attributes: + data-id: tour-test-1 + data-text: Next + class: + - custom + tour-test-2: + id: tour-test-2-en + plugin: text + label: The quick brown fox + body: Per lo più in pianura. + paths: + - tour-test-2/* + weight: "2" + attributes: + data-id: tour-test-2 + data-text: Next + class: + - custom + tour-test-3: + id: tour-test-3-en + plugin: image + label: The awesome image + url: http://local/image.png + paths: + - tour-test-1 + weight: "1" + attributes: + data-id: tour-test-1 + data-text: Next + class: + - custom diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TestTour.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TestTour.php deleted file mode 100644 index f0a041f..0000000 --- a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TestTour.php +++ /dev/null @@ -1,62 +0,0 @@ - 'tour-test-3', - 'data-options' => 'tipLocation:top', - 'data-text' => 'Next', - 'class' => array('custom'), - ); - - /** - * Set the language of this tour. - * - * @var string - */ - public $langcode = 'en'; - - /** - * Implements \Drupal\tour\TourInterface::getOutput(). - */ - public function getOutput() { - return array( - '#markup' => t('This is the output of TourTest plugin'), - ); - } - -} diff --git a/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php new file mode 100644 index 0000000..5526854 --- /dev/null +++ b/core/modules/tour/tests/tour_test/lib/Drupal/tour_test/Plugin/tour/tour/TipPluginImage.php @@ -0,0 +1,40 @@ + '

      ' . check_plain($this->get('label')) . '

      +

      ' . theme('image', array('uri' => $this->get('url'))) . '

      ' + ); + } +} commit 2750853d5357c1c19d98c2d3a387c183443abcf8 Author: Nick Schuch Date: Thu Feb 14 22:37:13 2013 -0800 Remove the cruff diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index 57fcb0f..dceec24 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -139,8 +139,6 @@ function tour_preprocess_page(&$variables) { $index++; } - dsm($list_items); - $variables['page']['help']['tour'] = array( '#theme' => 'item_list', '#items' => $list_items, diff --git a/core/profiles/standard/standard.info b/core/profiles/standard/standard.info index 9e1fb14..ad9a398 100644 --- a/core/profiles/standard/standard.info +++ b/core/profiles/standard/standard.info @@ -31,4 +31,3 @@ dependencies[] = rdf dependencies[] = views dependencies[] = views_ui dependencies[] = tour -dependencies[] = devel commit c5a42f4c26919711c074894dbe5b0c4b184d7a8e Author: Nick Schuch Date: Thu Feb 14 22:30:11 2013 -0800 The tidy up diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php index b9e4da2..c12b2e7 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/Core/Entity/Tour.php @@ -31,38 +31,10 @@ class Tour extends ConfigEntityBase { /** - * Holds the collection of filters that are attached to this format. - * - * @var \Drupal\filter\FilterBag - */ - protected $tipBag; - - /** - * The array of plugin config, only used for export and to populate the $tipBag. - */ - protected $tips; - - public function getTip($id) { - return $this->tipBag->get($id); - } - - public function getTipList() { - return array_keys($this->tips); - } - - /** - * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct(); - */ - public function __construct(array $values, $entity_type) { - parent::__construct($values, $entity_type); - - $this->tipBag = new TipsBag(drupal_container()->get('plugin.manager.tour'), $this->tips); - } - - /** * The name (plugin ID) of the tour. * * @var string + * Unique identifier for this tour. */ public $id; @@ -70,50 +42,51 @@ public function __construct(array $values, $entity_type) { * The label of the tour. * * @var string + * A human readable name for this tour. */ public $label; /** - * The UUID of the tour. + * Holds the collection of tips that are attached to this tour. * - * @var string + * @var \Drupal\tour\TipsBag */ - public $uuid; + protected $tipsBag; /** - * The array of settings for the tour. + * The array of plugin config, only used for export and to populate the $tipsBag. * * @var array */ - protected $settings = array(); + protected $tips; /** - * The module for the tour. + * Returns tip plugin. * - * @var string + * @return string + * The identifier of the tip. */ - protected $module; + public function getTip($id) { + return $this->tipsBag->get($id); + } - public function tours($instance_id = NULL) { - if (isset($instance_id)) { - return $this->tipsBag->get($instance_id); - } - return $this->tipsBag; + /** + * Returns a list of tips. + * + * @return array + * A list of tips. + */ + public function getTipList() { + return array_keys($this->tips); } /** - * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::__construct(); */ - public function getExportProperties() { - $properties = parent::getExportProperties(); - $names = array( - 'tips', - 'module', - ); - foreach ($names as $name) { - $properties[$name] = $this->get($name); - } - return $properties; + public function __construct(array $values, $entity_type) { + parent::__construct($values, $entity_type); + + $this->tipsBag = new TipsBag(drupal_container()->get('plugin.manager.tour'), $this->tips); } } diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php deleted file mode 100644 index ea90ab2..0000000 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php +++ /dev/null @@ -1,27 +0,0 @@ -definition = $this->discovery->getDefinition($plugin_id); + $this->module = $this->definition['module']; + } + + /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::get(). + */ + public function get($key) { + if (!empty($this->configuration[$key])) { + return $this->configuration[$key]; + } + } + + /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::set(). + */ + public function set($key, $value) { + $this->configuration[$key] = $value; + } +} diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php new file mode 100644 index 0000000..3e3e693 --- /dev/null +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TipPluginInterface.php @@ -0,0 +1,44 @@ + '

      ' . check_plain($this->get('label')) . '

      +

      ' . filter_xss_admin($this->get('body')) . '

      ' + ); + } +} diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/Tooltip.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/Tooltip.php deleted file mode 100644 index a207ce2..0000000 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/Tooltip.php +++ /dev/null @@ -1,66 +0,0 @@ -entity = entity_load('tour', $configuration['id']); - } - - /** - * Implements \Drupal\tour\TourInterface::getOutput(). - */ - public function getOutput() { - return array( - '#theme' => 'tour_tooltip', - '#tooltip' => $this->entity, - ); - } - - /** - * Implements \Drupal\tour\TourInterface::getAttributes(). - */ - public function getAttributes() { - $attributes = $this->entity->get('attributes'); - if ($location = $this->entity->get('location')) { - $attributes['data-options'] = 'tipLocation:' . $location; - } - // Add aria support. - $this->entity->ariaId = drupal_html_id($this->entity->id()); - $attributes['data-aria-describedby'] = 'tour-tooltip-' . $this->entity->ariaId . '-contents'; - $attributes['data-aria-labelledby'] = 'tour-tooltip-' . $this->entity->ariaId . '-label'; - return $attributes; - } - - /** - * Implements \Drupal\tour\TourInterface::label(). - */ - public function label() { - return $this->entity->label(); - } - -} diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php b/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php deleted file mode 100644 index 06c7486..0000000 --- a/core/modules/tour/lib/Drupal/tour/TipPluginInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -manager = $manager; @@ -59,18 +59,11 @@ protected function initializePlugin($instance_id) { return; } - // Filters have a 1:1 relationship to text formats and can be added and - // instantiated at any time. $type = $this->configurations[$instance_id]['plugin']; $definition = $this->manager->getDefinition($type); if (isset($definition)) { $this->addInstanceID($instance_id); - // $configuration is the whole filter plugin instance configuration, as - // contained in the text format configuration. The default configuration - // is the filter plugin definition. - // @todo Configuration should not be contained in definitions. Move into a - // FilterBase::init() method. $configuration = $definition; // Merge the actual configuration into the default configuration. @@ -80,49 +73,7 @@ protected function initializePlugin($instance_id) { $this->pluginInstances[$instance_id] = $this->manager->createInstance($type, $configuration, $this); } else { - throw new PluginException(format_string("Unknown filter plugin ID '@filter'.", array('@filter' => $instance_id))); + throw new PluginException(format_string("Unknown tip plugin ID '@tip'.", array('@tip' => $instance_id))); } } - - /** - * Sorts all filter plugin instances in this bag. - * - * @return \Drupal\filter\FilterBag - */ - public function sort() { - uasort($this->pluginInstances, array($this, 'sortHelper')); - return $this; - } - - /** - * uasort() callback to sort tours by weight, module, and name. - * - * @see \Drupal\filter\FilterFormatStorageController::preSave() - */ - public function sortHelper($a, $b) { - if ($a->weight != $b->weight) { - return ($a->weight < $b->weight) ? -1 : 1; - } - elseif ($a->module != $b->module) { - return strnatcasecmp($a->module, $b->module); - } - return strnatcasecmp($a->getPluginId(), $b->getPluginId()); - } - - /** - * Returns the current configuration of all filters in this bag. - * - * @return array - * An associative array keyed by filter plugin instance ID, whose values - * are filter configurations. - * - * @see \Drupal\filter\Plugin\filter\filter\FilterInterface::export() - */ - public function export() { - $filters = array(); - foreach ($this->pluginInstances as $instance_id => $instance) { - $filters[$instance_id] = $instance->export(); - } - return $filters; - } } diff --git a/core/modules/tour/lib/Drupal/tour/TourBase.php b/core/modules/tour/lib/Drupal/tour/TourBase.php deleted file mode 100644 index b98c0d1..0000000 --- a/core/modules/tour/lib/Drupal/tour/TourBase.php +++ /dev/null @@ -1,94 +0,0 @@ -configuration['label']; - } - - /** - * A collection of all tous this tour participates in. - * - * @var \Drupal\filter\TipsBag - */ - protected $bag; - - /** - * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). - */ - public function __construct(array $configuration, $plugin_id, CacheDecorator $discovery, TipsBag $bag) { - parent::__construct($configuration, $plugin_id, $discovery); - $this->definition = $this->discovery->getDefinition($plugin_id); - $this->module = $this->definition['module']; - $this->setPluginConfiguration($configuration); - $this->bag = $bag; - } - - /** - * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::setPluginConfiguration(). - */ - public function setPluginConfiguration(array $configuration) { - if (isset($configuration['label'])) { - $this->label = (bool) $configuration['label']; - } - if (isset($configuration['tips'])) { - $this->tips = (int) $configuration['tips']; - } - return $this; - } - - /** - * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getOutput(). - */ - public function getOutput() { - return theme('tour_tooltip', array('tooltip' => $this)); - } - - /** - * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getAttributes(). - */ - public function getAttributes() { - return $this->configuration['attributes']; - } - - /** - * Magic getter. - */ - public function get($key) { - if (!empty($this->configuration[$key])) { - return $this->configuration[$key]; - } - } - - /** - * Magic getter. - */ - public function set($key, $value) { - $this->configuration[$key] = $value; - } -} diff --git a/core/modules/tour/lib/Drupal/tour/TourBundle.php b/core/modules/tour/lib/Drupal/tour/TourBundle.php index 6a8c901..337a672 100644 --- a/core/modules/tour/lib/Drupal/tour/TourBundle.php +++ b/core/modules/tour/lib/Drupal/tour/TourBundle.php @@ -23,5 +23,4 @@ public function build(ContainerBuilder $container) { // injection container. $container->register('plugin.manager.tour', 'Drupal\tour\TourManager'); } - } diff --git a/core/modules/tour/lib/Drupal/tour/TourInterface.php b/core/modules/tour/lib/Drupal/tour/TourInterface.php deleted file mode 100644 index fbd70f6..0000000 --- a/core/modules/tour/lib/Drupal/tour/TourInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - array( - 'variables' => array('tooltip' => NULL), - ), - ); -} - -/** - * Default implementation of theme_tour_tooltip(). - */ -function theme_tour_tooltip($vars) { - $tooltip = $vars['tooltip']; - return array( - '#markup' => '

      ' . check_plain($tooltip->label()) . '

      -

      ' . filter_xss_admin($tooltip->get('body')) . '

      ' - ); -} - -/** * Implements hook_preprocess_HOOK() for page.tpl.php. */ function tour_preprocess_page(&$variables) { $tour_tips = entity_load_multiple('tour'); foreach ($tour_tips as $tour_tip) { - //$list = $tip->getTipsList(); foreach ($tour_tip->getTipList() as $id) { $tour_items[] = $tour_tip->getTip($id); } } - //$tour_items = drupal_container()->get('plugin.manager.tour')->getByPath(current_path()); + // Filter by path. + + // Sort by weight. + uasort($tour_items, function ($a, $b) { + if ($a->get('weight') == $b->get('weight')) { + return 0; + } + return ($a->get('weight') < $b->get('weight')) ? -1 : 1; + }); + if (empty($tour_items)) { return; } @@ -148,11 +134,13 @@ function tour_preprocess_page(&$variables) { ), '#children' => t('!tour_item of !total', array('!tour_item' => $index, '!total' => $count)), ), - '#wrapper_attributes' => $tour_item->getAttributes(), + '#wrapper_attributes' => $tour_item->get('attributes'), ); $index++; } + dsm($list_items); + $variables['page']['help']['tour'] = array( '#theme' => 'item_list', '#items' => $list_items, diff --git a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml index 6328c97..2373e07 100644 --- a/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml +++ b/core/modules/views/views_ui/config/tour.tour.views-ui-en.yml @@ -1,11 +1,11 @@ id: views-ui-en label: Views ui +langcode: en tips: views-ui-active-display-en: id: views-ui-active-display-en plugin: text label: Active display - langcode: en body: This is the active display in the view. When there are multiple displays, one link for each display is shown and you can switch displays simply by clicking on the display link. paths: - admin/structure/views/view/*/edit @@ -19,7 +19,6 @@ tips: id: views-ui-displays-en plugin: text label: Displays in this view - langcode: en body: A view can consist of multiple displays. A display is a way of outputting the results E.g. as a page or in a block. The available displays in your view are show here. paths: - admin/structure/views/view/*/edit @@ -33,7 +32,6 @@ tips: id: views-ui-fields-en plugin: text label: Fields - langcode: en body: This section shows the fields output for each result. Depending on the format selected for the view, you may not see anything listed here. If the format of your view uses fields, you can click on each field displayed to configure it. paths: - admin/structure/views/view/*/edit @@ -47,7 +45,6 @@ tips: id: views-ui-filter-en plugin: text label: Filter your view - langcode: en body: This section displays the filters you have active in your view. A filter is used to limit the results available in the output. E.g. to only show content that was published, you would add a filter for Published and select Yes. paths: - admin/structure/views/view/*/edit @@ -61,7 +58,6 @@ tips: id: views-ui-filter-operations-en plugin: text label: Filter actions - langcode: en body: Use this drop-button to add and re-arrange filters paths: - admin/structure/views/view/*/edit @@ -75,7 +71,6 @@ tips: id: views-ui-format-en plugin: text label: Output format - langcode: en body: Use this section to manage the format of the output results. You can choose different ways in which the matching results are output. E.g. Choose Content to output each item completely, using your configured display settings. Other options include Fields which allows you to output only specific fields on each matching result. Additional formats can be added by installing additional module to extend Drupal's base functionality. paths: - admin/structure/views/view/*/edit @@ -89,7 +84,6 @@ tips: id: views-ui-preview-en plugin: text label: Preview - langcode: en body: Use this button to show a preview of the view output paths: - admin/structure/views/view/*/edit @@ -103,7 +97,6 @@ tips: id: views-ui-sorts-en plugin: text label: Sort Criteria - langcode: en body: This section shows the enabled sorting criteria for the view. Sorting criteria are used to control the order in which the results are output. Clicking on any of the active sorting criteria shown in this section enables you to configure it. paths: - admin/structure/views/view/*/edit @@ -117,7 +110,6 @@ tips: id: views-ui-sorts-operations-en plugin: text label: Sort actions - langcode: en body: Use this drop-button to add and re-arrange the sorting criteria. paths: - admin/structure/views/view/*/edit @@ -131,7 +123,6 @@ tips: id: views-ui-view-admin-en plugin: text label: View administration - langcode: en body: Use this drop-button to perform administrative tasks on the view, including adding a description and creating a clone. Click the drop button to view the available options. paths: - admin/structure/views/view/*/edit commit bb24163a311c613955c69aa302daee71f6352e88 Author: Lee Rowlands Date: Fri Feb 15 14:37:08 2013 +1000 Tip bags ahoy diff --git a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php index 70a970e..ea90ab2 100644 --- a/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php +++ b/core/modules/tour/lib/Drupal/tour/Plugin/tour/tour/TextTip.php @@ -7,8 +7,8 @@ namespace Drupal\tour\Plugin\tour\tour; -use Drupal\tour\TipPluginInterface; use Drupal\Core\Annotation\Plugin; +use Drupal\tour\TourBase; /** * Displays some text as a tip. @@ -18,7 +18,7 @@ * module = "tour" * ) */ -class TextTip implements TipPluginInterface { +class TextTip extends TourBase { protected $label; protected $langcode; protected $body; diff --git a/core/modules/tour/lib/Drupal/tour/TourBase.php b/core/modules/tour/lib/Drupal/tour/TourBase.php index 5194c05..b98c0d1 100644 --- a/core/modules/tour/lib/Drupal/tour/TourBase.php +++ b/core/modules/tour/lib/Drupal/tour/TourBase.php @@ -8,7 +8,9 @@ namespace Drupal\tour; use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\tour\TourInterface; +use Drupal\tour\TipsBag; /** * Defines a base tour implementation. @@ -26,7 +28,7 @@ * Implements \Drupal\tour\TourInterface::label(). */ public function label() { - return $this->label; + return $this->configuration['label']; } /** @@ -39,7 +41,7 @@ public function label() { /** * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery, TipsBag $bag) { + public function __construct(array $configuration, $plugin_id, CacheDecorator $discovery, TipsBag $bag) { parent::__construct($configuration, $plugin_id, $discovery); $this->definition = $this->discovery->getDefinition($plugin_id); $this->module = $this->definition['module']; @@ -59,4 +61,34 @@ public function setPluginConfiguration(array $configuration) { } return $this; } + + /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getOutput(). + */ + public function getOutput() { + return theme('tour_tooltip', array('tooltip' => $this)); + } + + /** + * Implements \Drupal\tour\Plugin\tour\tour\TourInterface::getAttributes(). + */ + public function getAttributes() { + return $this->configuration['attributes']; + } + + /** + * Magic getter. + */ + public function get($key) { + if (!empty($this->configuration[$key])) { + return $this->configuration[$key]; + } + } + + /** + * Magic getter. + */ + public function set($key, $value) { + $this->configuration[$key] = $value; + } } diff --git a/core/modules/tour/lib/Drupal/tour/TourInterface.php b/core/modules/tour/lib/Drupal/tour/TourInterface.php index 993dde1..fbd70f6 100644 --- a/core/modules/tour/lib/Drupal/tour/TourInterface.php +++ b/core/modules/tour/lib/Drupal/tour/TourInterface.php @@ -21,19 +21,18 @@ public function getOutput(); /** - * Returns the tour label. + * Returns a attributes for the tour element. * - * @return string - * The label of the tour. + * @return array + * Array of attributes. */ - public function label(); + public function getAttributes(); /** * Returns the tour label. * - * @return array - * A list of tips for this particular tour. + * @return string + * The label of the tour. */ - public function tips(); - + public function label(); } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index db6a54f..e7af33f 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -110,41 +110,30 @@ function tour_theme($existing, $type, $theme, $path) { */ function theme_tour_tooltip($vars) { $tooltip = $vars['tooltip']; - return '

      ' . check_plain($tooltip->label()) . '

      -

      ' . filter_xss_admin($tooltip->get('body')) . '

      '; + return array( + '#markup' => '

      ' . check_plain($tooltip->label()) . '

      +

      ' . filter_xss_admin($tooltip->get('body')) . '

      ' + ); } /** * Implements hook_preprocess_HOOK() for page.tpl.php. */ function tour_preprocess_page(&$variables) { - $tour_ids = entity_query('tour')->execute(); - $tour_tips = entity_load_multiple('tour', $tour_ids); + $tour_tips = entity_load_multiple('tour'); foreach ($tour_tips as $tour_tip) { //$list = $tip->getTipsList(); foreach ($tour_tip->getTipList() as $id) { - $tip = $tour_tip->getTip($id); + $tour_items[] = $tour_tip->getTip($id); } } - return; - //$tour_items = drupal_container()->get('plugin.manager.tour')->getByPath(current_path()); if (empty($tour_items)) { return; } - // Sort and set the last tooltip to show "End tour". - uasort($tour_items, function ($a, $b) { - if ($a->weight == $b->weight) { - return 0; - } - return ($a->weight < $b->weight) ? -1 : 1; - }); - $last = end($tour_items); - $last->setAttribute('data-text', t('End tour')); - $index = 1; $count = count($tour_items); foreach ($tour_items as $tour_item) {