This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Non-JavaScript callback that returns hello world. | |
*/ | |
function MY_CUSTOM_MODULE_nojs_callback() { | |
return "Hello world"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* AJAX callback that prints hello world underneath our link. | |
*/ | |
function MY_CUSTOM_MODULE_ajax_callback() { | |
// Define a new array to hold our AJAX commands. | |
$ajax_commands = array(); | |
// Create a new AJAX command that replaces the #page text with our own text. | |
$ajax_commands[] = ajax_command_after('#my-special-link', 'Hello world'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function MY_CUSTOM_MODULE_trigger_page() { | |
// Load in Drupal core AJAX library. | |
drupal_add_library('system', 'drupal.ajax'); | |
// Load in our custom JavaScript. | |
drupal_add_js(drupal_get_path('module', 'MY_CUSTOM_MODULE') . '/MY_CUSTOM_MODULE.js'); | |
// Present the user with a link with the id 'my-special-link'. | |
return l('Run my AJAX commands', 'my-custom-path/nojs', array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_menu(). | |
*/ | |
function MY_CUSTOM_MODULE_menu() { | |
// Returns AJAX commands if the user has JavaScript turned on. | |
$items['my-custom-path/ajax'] = array( | |
'title' => 'My custom ajax callback', | |
'page callback' => 'MY_CUSTOM_MODULE_ajax_callback', | |
'access arguments' => array('access content'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change the page title. | |
$site_title = variable_get('site_name'); | |
$page_title = t('My Great Page'); | |
$ajax_commands[] = ajax_command_invoke(NULL, 'changePageTitle', array($page_title . ' - ' . $site_title)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change the page title. | |
$ajax_commands[] = ajax_command_invoke(NULL, 'changePageTitle', array(t('My great page title'))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Changes the page title. Can be called from Drupal AJAX commands using ajax_command_invoke(). | |
*/ | |
(function ($) { | |
$.fn.changePageTitle = function(pageTitle) { | |
document.title = pageTitle; | |
}; | |
})(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_awesome_theme_item_list($variables) { | |
$items = $variables['items']; | |
$title = $variables['title']; | |
$type = $variables['type']; | |
$attributes = $variables['attributes']; | |
// Only output the list container and title, if there are any list items. | |
// Check to see whether the block title exists before adding a header. | |
// Empty headers are not semantic and present accessibility challenges. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_awesome_theme_breadcrumb($variables) { | |
$breadcrumb = $variables['breadcrumb']; | |
if (!empty($breadcrumb)) { | |
// Provide a navigational heading to give context for breadcrumb links to | |
// screen-reader users. Make the heading invisible with .element-invisible. | |
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>'; | |
// Add 'my-awesome-class' to the breadcrumb wrapper and change the separators from '»' to '::'. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This will fail. | |
$this->assertTrue('foo' == 'bar', 'The two strings are equal to eachother.'); | |
// This will pass. | |
$this->assertTrue('foo' == 'foo', 'The two strings are equal to eachother.'); |