First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
20
modules/contextual/contextual-rtl.css
Normal file
20
modules/contextual/contextual-rtl.css
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* @file
|
||||
* Stylesheet specific to right-to-left languages.
|
||||
*/
|
||||
|
||||
div.contextual-links-wrapper {
|
||||
left: 5px;
|
||||
right: auto;
|
||||
}
|
||||
div.contextual-links-wrapper ul.contextual-links {
|
||||
-moz-border-radius: 0 4px 4px 4px;
|
||||
-webkit-border-top-left-radius: 0;
|
||||
-webkit-border-top-right-radius: 4px;
|
||||
border-radius: 0 4px 4px 4px;
|
||||
left: 0;
|
||||
right: auto;
|
||||
}
|
||||
a.contextual-links-trigger {
|
||||
text-indent: -90px;
|
||||
}
|
40
modules/contextual/contextual.api.php
Normal file
40
modules/contextual/contextual.api.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by Contextual module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alter a contextual links element before it is rendered.
|
||||
*
|
||||
* This hook is invoked by contextual_pre_render_links(). The renderable array
|
||||
* of #type 'contextual_links', containing the entire contextual links data that
|
||||
* is passed in by reference. Further links may be added or existing links can
|
||||
* be altered.
|
||||
*
|
||||
* @param $element
|
||||
* A renderable array representing the contextual links.
|
||||
* @param $items
|
||||
* An associative array containing the original contextual link items, as
|
||||
* generated by menu_contextual_links(), which were used to build
|
||||
* $element['#links'].
|
||||
*
|
||||
* @see hook_menu_contextual_links_alter()
|
||||
* @see contextual_pre_render_links()
|
||||
* @see contextual_element_info()
|
||||
*/
|
||||
function hook_contextual_links_view_alter(&$element, $items) {
|
||||
// Add another class to all contextual link lists to facilitate custom
|
||||
// styling.
|
||||
$element['#attributes']['class'][] = 'custom-class';
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
103
modules/contextual/contextual.css
Normal file
103
modules/contextual/contextual.css
Normal file
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
* @file
|
||||
* Stylesheet for the Contextual module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Contextual links regions.
|
||||
*/
|
||||
.contextual-links-region {
|
||||
outline: none;
|
||||
position: relative;
|
||||
}
|
||||
.contextual-links-region-active {
|
||||
outline: #999 dashed 1px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contextual links.
|
||||
*/
|
||||
div.contextual-links-wrapper {
|
||||
display: none;
|
||||
font-size: 90%;
|
||||
position: absolute;
|
||||
right: 5px; /* LTR */
|
||||
top: 2px;
|
||||
z-index: 999;
|
||||
}
|
||||
html.js div.contextual-links-wrapper {
|
||||
display: block;
|
||||
}
|
||||
a.contextual-links-trigger {
|
||||
background: transparent url(images/gear-select.png) no-repeat 2px 0;
|
||||
border: 1px solid transparent;
|
||||
display: none;
|
||||
height: 18px;
|
||||
margin: 0;
|
||||
padding: 0 2px;
|
||||
outline: none;
|
||||
text-indent: 34px; /* LTR */
|
||||
width: 28px;
|
||||
overflow: hidden;
|
||||
-khtml-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
a.contextual-links-trigger:hover,
|
||||
div.contextual-links-active a.contextual-links-trigger {
|
||||
background-position: 2px -18px;
|
||||
}
|
||||
div.contextual-links-active a.contextual-links-trigger {
|
||||
background-color: #fff;
|
||||
border-color: #ccc;
|
||||
border-bottom: none;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
-moz-border-radius: 4px 4px 0 0;
|
||||
-webkit-border-bottom-left-radius: 0;
|
||||
-webkit-border-bottom-right-radius: 0;
|
||||
border-radius: 4px 4px 0 0;
|
||||
}
|
||||
div.contextual-links-wrapper ul.contextual-links {
|
||||
background-color: #fff;
|
||||
border: 1px solid #ccc;
|
||||
display: none;
|
||||
margin: 0;
|
||||
padding: 0.25em 0;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
text-align: left;
|
||||
top: 18px;
|
||||
white-space: nowrap;
|
||||
-moz-border-radius: 4px 0 4px 4px; /* LTR */
|
||||
-webkit-border-bottom-left-radius: 4px;
|
||||
-webkit-border-bottom-right-radius: 4px;
|
||||
-webkit-border-top-right-radius: 0; /* LTR */
|
||||
-webkit-border-top-left-radius: 4px; /* LTR */
|
||||
border-radius: 4px 0 4px 4px; /* LTR */
|
||||
}
|
||||
a.contextual-links-trigger-active,
|
||||
div.contextual-links-active a.contextual-links-trigger,
|
||||
div.contextual-links-active ul.contextual-links {
|
||||
display: block;
|
||||
}
|
||||
ul.contextual-links li {
|
||||
line-height: 100%;
|
||||
list-style: none;
|
||||
list-style-image: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
div.contextual-links-wrapper a {
|
||||
text-decoration: none;
|
||||
}
|
||||
ul.contextual-links li a {
|
||||
color: #333 !important;
|
||||
display: block;
|
||||
margin: 0.25em 0;
|
||||
padding: 0.25em 1em 0.25em 0.5em;
|
||||
}
|
||||
ul.contextual-links li a:hover {
|
||||
background-color: #bfdcee;
|
||||
}
|
12
modules/contextual/contextual.info
Normal file
12
modules/contextual/contextual.info
Normal file
|
@ -0,0 +1,12 @@
|
|||
name = Contextual links
|
||||
description = Provides contextual links to perform actions related to elements on a page.
|
||||
package = Core
|
||||
version = VERSION
|
||||
core = 7.x
|
||||
files[] = contextual.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2017-06-21
|
||||
version = "7.56"
|
||||
project = "drupal"
|
||||
datestamp = "1498069849"
|
||||
|
52
modules/contextual/contextual.js
Normal file
52
modules/contextual/contextual.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @file
|
||||
* Attaches behaviors for the Contextual module.
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.contextualLinks = Drupal.contextualLinks || {};
|
||||
|
||||
/**
|
||||
* Attaches outline behavior for regions associated with contextual links.
|
||||
*/
|
||||
Drupal.behaviors.contextualLinks = {
|
||||
attach: function (context) {
|
||||
$('div.contextual-links-wrapper', context).once('contextual-links', function () {
|
||||
var $wrapper = $(this);
|
||||
var $region = $wrapper.closest('.contextual-links-region');
|
||||
var $links = $wrapper.find('ul.contextual-links');
|
||||
var $trigger = $('<a class="contextual-links-trigger" href="#" />').text(Drupal.t('Configure')).click(
|
||||
function () {
|
||||
$links.stop(true, true).slideToggle(100);
|
||||
$wrapper.toggleClass('contextual-links-active');
|
||||
return false;
|
||||
}
|
||||
);
|
||||
// Attach hover behavior to trigger and ul.contextual-links.
|
||||
$trigger.add($links).hover(
|
||||
function () { $region.addClass('contextual-links-region-active'); },
|
||||
function () { $region.removeClass('contextual-links-region-active'); }
|
||||
);
|
||||
// Hide the contextual links when user clicks a link or rolls out of the .contextual-links-region.
|
||||
$region.bind('mouseleave click', Drupal.contextualLinks.mouseleave);
|
||||
$region.hover(
|
||||
function() { $trigger.addClass('contextual-links-trigger-active'); },
|
||||
function() { $trigger.removeClass('contextual-links-trigger-active'); }
|
||||
);
|
||||
// Prepend the trigger.
|
||||
$wrapper.prepend($trigger);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Disables outline for the region contextual links are associated with.
|
||||
*/
|
||||
Drupal.contextualLinks.mouseleave = function () {
|
||||
$(this)
|
||||
.find('.contextual-links-active').removeClass('contextual-links-active')
|
||||
.find('ul.contextual-links').hide();
|
||||
};
|
||||
|
||||
})(jQuery);
|
169
modules/contextual/contextual.module
Normal file
169
modules/contextual/contextual.module
Normal file
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Adds contextual links to perform actions related to elements on a page.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function contextual_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#contextual':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Contextual links module displays links related to regions of pages on your site to users with <em>access contextual links</em> permission. For more information, see the online handbook entry for <a href="@contextual">Contextual links module</a>.', array('@contextual' => 'http://drupal.org/documentation/modules/contextual')) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Displaying contextual links') . '</dt>';
|
||||
$output .= '<dd>' . t('Contextual links are supplied by modules, to give you quick access to tasks associated with regions of pages on your site. For instance, if you have a custom menu block displayed in a sidebar of your site, the Blocks and Menus modules will supply links to configure the block and edit the menu. The Contextual links module collects these links into a list for display by your theme, and also adds JavaScript code to the page to hide the links initially, and display them when your mouse hovers over the block.') . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function contextual_permission() {
|
||||
return array(
|
||||
'access contextual links' => array(
|
||||
'title' => t('Use contextual links'),
|
||||
'description' => t('Use contextual links to perform actions related to elements on a page.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_library().
|
||||
*/
|
||||
function contextual_library() {
|
||||
$path = drupal_get_path('module', 'contextual');
|
||||
$libraries['contextual-links'] = array(
|
||||
'title' => 'Contextual links',
|
||||
'website' => 'http://drupal.org/node/473268',
|
||||
'version' => '1.0',
|
||||
'js' => array(
|
||||
$path . '/contextual.js' => array(),
|
||||
),
|
||||
'css' => array(
|
||||
$path . '/contextual.css' => array(),
|
||||
),
|
||||
);
|
||||
return $libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_element_info().
|
||||
*/
|
||||
function contextual_element_info() {
|
||||
$types['contextual_links'] = array(
|
||||
'#pre_render' => array('contextual_pre_render_links'),
|
||||
'#theme' => 'links__contextual',
|
||||
'#links' => array(),
|
||||
'#prefix' => '<div class="contextual-links-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#attributes' => array(
|
||||
'class' => array('contextual-links'),
|
||||
),
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
array('contextual', 'contextual-links'),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess().
|
||||
*
|
||||
* @see contextual_pre_render_links()
|
||||
*/
|
||||
function contextual_preprocess(&$variables, $hook) {
|
||||
// Nothing to do here if the user is not permitted to access contextual links.
|
||||
if (!user_access('access contextual links')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hooks = theme_get_registry(FALSE);
|
||||
|
||||
// Determine the primary theme function argument.
|
||||
if (!empty($hooks[$hook]['variables'])) {
|
||||
$keys = array_keys($hooks[$hook]['variables']);
|
||||
$key = $keys[0];
|
||||
}
|
||||
elseif (!empty($hooks[$hook]['render element'])) {
|
||||
$key = $hooks[$hook]['render element'];
|
||||
}
|
||||
if (!empty($key) && isset($variables[$key])) {
|
||||
$element = $variables[$key];
|
||||
}
|
||||
|
||||
if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
|
||||
// Initialize the template variable as a renderable array.
|
||||
$variables['title_suffix']['contextual_links'] = array(
|
||||
'#type' => 'contextual_links',
|
||||
'#contextual_links' => $element['#contextual_links'],
|
||||
'#element' => $element,
|
||||
);
|
||||
// Mark this element as potentially having contextual links attached to it.
|
||||
$variables['classes_array'][] = 'contextual-links-region';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a renderable array for contextual links.
|
||||
*
|
||||
* @param $element
|
||||
* A renderable array containing a #contextual_links property, which is a
|
||||
* keyed array. Each key is the name of the implementing module, and each
|
||||
* value is an array that forms the function arguments for
|
||||
* menu_contextual_links(). For example:
|
||||
* @code
|
||||
* array('#contextual_links' => array(
|
||||
* 'block' => array('admin/structure/block/manage', array('system', 'navigation')),
|
||||
* 'menu' => array('admin/structure/menu/manage', array('navigation')),
|
||||
* ))
|
||||
* @endcode
|
||||
*
|
||||
* @return
|
||||
* A renderable array representing contextual links.
|
||||
*
|
||||
* @see menu_contextual_links()
|
||||
* @see contextual_element_info()
|
||||
*/
|
||||
function contextual_pre_render_links($element) {
|
||||
// Retrieve contextual menu links.
|
||||
$items = array();
|
||||
foreach ($element['#contextual_links'] as $module => $args) {
|
||||
$items += menu_contextual_links($module, $args[0], $args[1]);
|
||||
}
|
||||
|
||||
// Transform contextual links into parameters suitable for theme_link().
|
||||
$links = array();
|
||||
foreach ($items as $class => $item) {
|
||||
$class = drupal_html_class($class);
|
||||
$links[$class] = array(
|
||||
'title' => $item['title'],
|
||||
'href' => $item['href'],
|
||||
);
|
||||
// @todo theme_links() should *really* use the same parameters as l().
|
||||
$item['localized_options'] += array('query' => array());
|
||||
$item['localized_options']['query'] += drupal_get_destination();
|
||||
$links[$class] += $item['localized_options'];
|
||||
}
|
||||
$element['#links'] = $links;
|
||||
|
||||
// Allow modules to alter the renderable contextual links element.
|
||||
drupal_alter('contextual_links_view', $element, $items);
|
||||
|
||||
// If there are no links, tell drupal_render() to abort rendering.
|
||||
if (empty($element['#links'])) {
|
||||
$element['#printed'] = TRUE;
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
49
modules/contextual/contextual.test
Normal file
49
modules/contextual/contextual.test
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for contextual.module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests accessible links after inaccessible links on dynamic context.
|
||||
*/
|
||||
class ContextualDynamicContextTestCase extends DrupalWebTestCase {
|
||||
protected $profile = 'testing';
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Contextual links on node lists',
|
||||
'description' => 'Tests if contextual links are showing on the front page depending on permissions.',
|
||||
'group' => 'Contextual',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp(array('contextual', 'node'));
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$web_user = $this->drupalCreateUser(array('access content', 'access contextual links', 'edit any article content'));
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests contextual links on node lists with different permissions.
|
||||
*/
|
||||
function testNodeLinks() {
|
||||
// Create three nodes in the following order:
|
||||
// - An article, which should be user-editable.
|
||||
// - A page, which should not be user-editable.
|
||||
// - A second article, which should also be user-editable.
|
||||
$node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
||||
$node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
|
||||
$node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
|
||||
|
||||
// Now, on the front page, all article nodes should have contextual edit
|
||||
// links. The page node in between should not.
|
||||
$this->drupalGet('node');
|
||||
$this->assertRaw('node/' . $node1->nid . '/edit', 'Edit link for oldest article node showing.');
|
||||
$this->assertNoRaw('node/' . $node2->nid . '/edit', 'No edit link for page nodes.');
|
||||
$this->assertRaw('node/' . $node3->nid . '/edit', 'Edit link for most recent article node showing.');
|
||||
}
|
||||
}
|
BIN
modules/contextual/images/gear-select.png
Normal file
BIN
modules/contextual/images/gear-select.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 506 B |
Loading…
Add table
Add a link
Reference in a new issue