SlideShare a Scribd company logo
1 of 57
Download to read offline
Demystifying Drupal
AJAX Callback Commands
http://nyccamp.org/node/287
NYC CAMP 2015
#NYCcamp
Goals of this Session
Explain what AJAX callback commands are
Demonstrate how to use AJAX callback commands
Outline how to create AJAX callback commands
Michael Miles
From: Boston, MA USA
Work:   @WeAreGenuine(.com)Genuine
Exp: Working with Drupal since 2008.
Acquia Certified.  2014 Acquia MVP.
Twitter: @mikemiles86 Drupal.org: mikemiles86 
All the Places: mikemiles86
Warning About Example Code
There is example code
Some coding standards ignored for presentation purposes
Drupal 8 code still subject to change
What Commands Are
From a High Level
The response of AJAX request
PHP code to instruct JavaScript functions
A JavaScript function attached to an object
Defined by Drupal core or modules
17 AJAX callback commands in Drupal 7
Example: The "Remove" Command
Using the "examples" module (available on Drupal.org), showing using the 'remove' AJAX Callback
command. The checkbox is checked, which makes an AJAX request, which returns the command to
remove the element with the sample text.
On the Client Side [D7]
A function on the 'Drupal.ajax.prototype.commands' object
Receives 'ajax', 'response' and 'status' arguments
A wrapper for additional javascript
// Provide a series of commands that the server can request the client perform.
Drupal.ajax.prototype.commands = {
//...
/**
* Command to remove a chunk from the page.
*/
remove: function (ajax, response, status) {
var settings = response.settings || ajax.settings || Drupal.settings;
Drupal.detachBehaviors($(response.selector), settings);
$(response.selector).remove();
},
//...
}
misc/ajax.js
On the Server Side [D7]
A PHP function which returns an associative array
Array must have an element with key of 'command'
The value is the name of a JavaScript function
Additional array elements set as response data
/**
* Creates a Drupal Ajax 'remove' command.
*/
function ajax_command_remove($selector) {
return array(
'command' => 'remove',
'selector' => $selector,
);
}
includes/ajax.inc
How to Use Commands
Example Scenario
 As a user
When I navigate to the 'my-messages' page
Then I see a list of my unread messages
And I see a list of my read messages
When I click on an unread message
Then the full messaged is retrieved from the server
And I see the content of my message
And the message is removed from the unread messages list
And the message is added to the read messages list
Example Scenario. Have a page that lists messages to read. When a message subject is clicked, an AJAX
request is made to retrieve the message. The server returns an array of commands to run, which
updates the page with the selected message.
To Use Commands...
1.  Include Drupal AJAX JavaScript library
2.  Attach AJAX to page elements
3.  Define a callback path and function
Returns a render array of commands [D7]
1. Include Drupal AJAX library
// Render a page of messages.
function mymodule_messages_page() {
// Include AJAX library.
drupal_add_library('system', 'drupal.ajax');
// Create inital page content.
$content = theme_item_list(array(
'title' => t('Unread Messages'),
'type' => 'ul',
'attributes' => array( 'id' => 'unread-msgs'),
'items' => mymodule_messages_list(mymodule_get_unread_messages()),
));
$content .= '<div id="current-msg"><h2></h2><p></p></div>';
$content .= theme_item_list(array(
'title' => t('Read Messages'),
'type' => 'ul',
'attributes' => array('id' => 'read-msgs'),
'items' => mymodule_messages_list(mymodule_get_read_messages(), FALSE),
));
return $content;
}
mymodule/mymodule.module
Function to build a page of messages. On line #4, using the drupal_add_librry() function to include the
AJAX library on the page.
2. Attach AJAX to page elements
// Return array of message titles for use in a list.
function mymodule_messages_list($messages, $display_link = TRUE) {
$list_items = array();
foreach ($messages as $mid => $msg) {
// Build link to AJAX callback to load message.
$link = l($msg->subject, 'read-message-callback/nojs/' . $mid, array(
// Add class to link so Drupal knows to use AJAX.
'attributes' => array('class' => array('use-ajax')),
));
// Create list item for message.
$list_items[] = array(
'id' => 'msg-' . $mid,
// Set data to read message link or just message subject.
'data' => $display_link ? $link : $msg->subject,
);
}
return $list_items;
}
mymodule/mymodule.module
Function to build a list of messages. On line #6, creating a link element which links to our callback path.
On line #8, adding the class 'use­ajax' so AJAX framework knows to serve link with an AJAX request.
3.a Define a callback path
// Implements hook_menu().
function mymodule_menu() {
$items = array();
//.. Other menu items.
// None JS callback, for graceful degredation.
$items['read-message-callback/nojs/%'] = array(
'title' => 'AJAX Callback to Read Message',
'access arguments' => array('access content'),
'page callback' => 'mymodule_read_message_callback',
'page arguments' => array(1,2),
'type' => MENU_CALLBACK,
);
// Create AJAX callback. Add ajax_delivery callback.
$items['read-message-callback/ajax/%'] = array(
'delivery callback' => 'ajax_deliver',
) + $items['read-message-callback/nojs/%'];
return $items;
}
mymodule/mymodule.module
Creating two menu items for callback functions. The first is for handling graceful degredation when
reached outside an AJAX Request. The second is the AJAX callback, which add a delivery callback of
"ajax_callback" so Drupal know to return an AJAX Response object.
3.b Return array of commands using a render array [D7]
// AJAX Callback to read a message.
function mymodule_read_message_callback($method, $mid) {
$message = mymodule_load_message($mid);
// @TODO: Graceful degredation if not from ajax method or if no message.
$commands = array(
// Replace content of current message subject.
ajax_command_html('#current-msg h2', $message->subject),
// Replace content of current message body.
ajax_command_html('#current-msg p', $message->content),
// Remove message from unread list.
ajax_command_remove('#msg-' . $mid),
// Add message to read list
ajax_command_append('#read-msgs', '<li>' . $message->subject . '</li>'),
);
// Return an AJAX render array.
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
mymodule/mymodule.module
Lines #5 thru #14, building an array of Core AJAX Callback commands. Each mapps to a javascript
function. Line #16 building a render array of type 'ajax'. Drupal will package into JSON and send back to
the client.
Creating Custom Commands
To Create a Command...
1.  Add a function to the Drupal ajax command JavaScript object
2.  Write PHP code that returns an associative array.
Must have an element with key of 'command'
Value is name of the JavaScript function
Additional elements for response data
That's it.
A Custom Command in Drupal 7
1.  Add a function to 'Drupal.ajax.prototype.commands'
2.  Define a PHP function to return an array
1. Add a function to 'Drupal.ajax.prototype.commands'
(function($, Drupal) {
// Add new command for reading a message.
Drupal.ajax.prototype.commands.readMessage = function(ajax, response, status){
// Place content in current-msg div.
$('#current-msg h2').html(response.subject);
$('#current-msg p').html(response.content);
// Remove from unread list.
$('#msg-' + response.mid).remove();
// Add message to read list.
$('#read-msgs').append('<li>' + response.subject + '</li>');
}
})(jQuery, Drupal);
mymodule/js/commands.js
Attach a new 'readMessage' command to the Drupal AJAX Commands JavaScript object. Function takes
in the 3 arguments "ajax", "response" & "status". Wraps jQuery functions to display a message on the
page.
2. Define a PHP function to return an associative array
/**
* AJAX command to read a message.
*/
function mymodule_command_read_message($message) {
return array(
'command' => 'readMessage',
'mid' => $message->mid,
'subject' => $message->subject,
'content' => $message->content,
);
}
mymodule/mymodule.module
PHP function that mapps to the new JavaScript 'readMessage' array. Returns an associative array, with
an element that has a key of 'command' and value of the JavaScript function name 'readMessage'. Then
additional elements to be sent as request data.
Using a custom command...
1.  Tell Drupal to include custom JavaScript
2.  Return custom command in callback function
Again...that's it.
Using a Custom Command in Drupal 7
1.  Use drupal_add_js() to include custom JavaScript on page
2.  Add command to render array returned by callback
1. Use drupal_add_js() to include custom JavaScript on page
// Render a page of my messages
function mymodule_messages_page() {
// Include AJAX library.
drupal_add_library('system', 'drupal.ajax');
// Include custom JavaScript.
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/commands.js');
// .. Build $content.
return $content;
}
mymodule/mymodule.module
The example function for creating the messages page. In addition to adding the Drupal AJAX library on
line #4 also using drupal_add_js() to include custom javascript file on line #6.
2. Add command to render array returned by callback
// AJAX Callback to read a message.
function mymodule_read_message_callback($method, $mid) {
$message = mymodule_load_message($mid);
// @TODO: Graceful degredation if not from ajax method or if no message.
$commands = array(
// Call the readMessage javascript function.
mymodule_command_read_message($message),
);
// Return an AJAX render array.
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
mymodule/mymodule.module
The example callback function that returns an AJAX render array. Commands array on lines #5 thru #8,
only returns a single command. The new custom command that was created.
AJAX Commands in Drupal 8
Changes to AJAX Commands
22 AJAX callback commands in Drupal 8
JavaScript attatches to 'Drupal.AjaxCommands.prototype' object
A PHP object that implements CommandInterface
Must implement 'render' method
Example: The "Remove" Command
Using the "examples" module (available on Drupal.org), showing using the 'remove' AJAX Callback
command. The checkbox is checked, which makes an AJAX request, which returns the command to
remove the element with the sample text.
A function on the 'Drupal.AjaxCommands.prototype' object
/**
* Provide a series of commands that the client will perform.
*/
Drupal.AjaxCommands.prototype = {
//...
/**
* Command to remove a chunk from the page.
*/
remove: function (ajax, response, status) {
var settings = response.settings || ajax.settings || drupalSettings;
$(response.selector).each(function () {
Drupal.detachBehaviors(this, settings);
}).remove();
},
//...
}
misc/ajax.js
An object that implements CommandInterface
Must implement 'render' method
namespace DrupalCoreAjax;
use DrupalCoreAjaxCommandInterface;
// AJAX command for calling the jQuery remove() method.
class RemoveCommand Implements CommandInterface {
protected $selector;
// Constructs a RemoveCommand object.
public function __construct($selector) {
$this->selector = $selector;
}
// Implements DrupalCoreAjaxCommandInterface:render().
public function render() {
return array(
'command' => 'remove',
'selector' => $this->selector,
);
}
}
core/lib/Drupal/Core/Ajax/RemoveCommand.php
To Use Commands in Drupal 8
1.  Include Drupal AJAX JavaScript library
Must attach to a render array
2.  Attach AJAX to page elements
3.  Define a callback path and function
Returns an AjaxResponse object
Example Scenario. Have a page that lists messages to read. When a message subject is clicked, an AJAX
request is made to retrieve the message. The server returns an array of commands to run, which
updates the page with the selected message.
Attach library to a render array
// Render a page of my messages
function mymodule_messages_page() {
// .. build $content
// Create render array.
$page[] = array(
'#type' => 'markup',
'#markup' => $content,
);
// Attach JavaScript library.
$page['#attached']['library'][] = 'core/drupal.ajax';
return Drupal::service('renderer')->render($page);
}
mymodule/mymodule.module
Function for building messages page is now using a render array. to the '#attached', 'library' array of
that render array, declaring the drupal.ajax library to be included.
Callback returns commands using an AJAXResponse() [D8]
// AJAX Callback to read a message.
function mymodule_read_message_callback($method, $mid) {
$message = mymodule_load_message($mid);
// @TODO: Graceful degredation if not from ajax method or if no message.
// Create AJAX Response object.
$response = new AjaxResponse();
// Replace content of current message subject.
$response->addCommand(new HtmlCommand('#current-msg h2', $message->subject));
// Replace content of current message body.
$response->addCommand(new HtmlCommand('#current-msg p', $message->content));
// Remove message from unread list.
$response->addCommand(new RemoveCommand('#msg-' . $mid));
// Add message to read list.
$item = '<li>' . $message->subject . '</li>';
$response->addCommand(new AppendCommand('#read-msgs', $item));
);
// Return ajax response.
return $response;
}
mymodule/mymodule.module
Returning an AjaxResponse object instead of a render array like in Drupal 7. AjaxResponse has an
'addCommand' method, which takes the argument of a command object.
Custom Commands in Drupal 8
1.  Add function to 'Drupal.AjaxCommands.prototype'
2.  Define a command object that implements CommandInterface
1. Add function to 'Drupal.AjaxCommands.prototype'
(function($, Drupal) {
/**
* Add new command for reading a message.
*/
Drupal.AjaxCommands.prototype.readMessage = function(ajax, response, status){
// Place content in current-msg div.
$('#current-msg h2').html(response.subject);
$('#current-msg p').html(response.content);
// Remove from unread list.
$('#msg-' + response.mid).remove();
// Add message to read list.
$('#read-msgs').append('<li>' + response.subject + '</li>');
}
})(jQuery, Drupal);
mymodule/js/commands.js
Adding the custom 'readMessage' function to the Drupal 8 JavaScript AJAX Commands object. Still takes
the same three arguments as in Drupal 7.
2. Define command object that implements CommandInterface
namespace DrupalmymoduleAjax;
use DrupalCoreAjaxCommandInterface;
class ReadMessageCommand implements CommandInterface {
protected $message;
// Constructs a ReadMessageCommand object.
public function __construct($message) {
$this->message = $message;
}
// Implements DrupalCoreAjaxCommandInterface:render().
public function render() {
return array(
'command' => 'readMessage',
'mid' => $this->message->mid,
'subject' => $this->message->subject,
'content' => $this->message->content,
);
}
}
mymodule/src/Ajax/ReadMessageCommand.php
Creating a Command object which implements the CommandInterface. Must declare a 'render' method,
which will return an associative array. This associative array must have an element with the key of
'command' and value of the JavaScript function to run.
Using a Custom Command in Drupal 8
1.  Tell Drupal about custom JavaScript library
2.  Attach library to a render array
3.  Add command to AjaxResponse object in callback
1. Tell Drupal about custom JavaScript library
mymodule.commands:
version: VERSION
js:
js/commands.js: {}
dependencies:
- core/drupal.ajax
mymodule/mymodule.libraries.yml
Must tell Drupal about custom library with a libraries.yml file. Provide an Asset library name, lists all the
js files needed, and any dependencies on other libraries.
2. Attach library to a render array
// Render a page of my messages
function mymodule_messages_page() {
// .. build $content
// Create render array.
$page[] = array(
'#type' => 'markup',
'#markup' => $content,
);
// Attach JavaScript library.
$page['#attached']['library'][] = 'mymodule/mymodule.commands';
return Drupal::service('renderer')->render($page);
}
mymodule/mymodule.module
Function for building messages page is now using a render array. to the '#attached', 'library' array of
that render array, including the custom library. No longer including the AJAX library, as Drupal will know
to include it from the libraries.yml file.
3. Add command to AjaxResponse object in callback
// AJAX Callback to read a message.
function mymodule_read_message_callback($method, $mid) {
$message = mymodule_load_message($mid);
// @TODO: Graceful degredation if not from ajax method or if no message.
// Create AJAX Response object.
$response = new AjaxResponse();
// Call the readMessage javascript function.
$response->addCommand( new ReadMessageCommand($message));
);
// Return ajax response.
return $response;
}
mymodule/mymodule.module
Returning an AjaxResponse object instead of adding the core commands, just adding the new custom
command using the 'addCommand' method.
Let's Review
AJAX Callback Commands Are...
Returned by all AJAX Framework requests
PHP abstraction for JavaScript functions
Defined by core and modules
To Use AJAX Callback Commands...
Include Drupal AJAX JavaScript library
Attach AJAX to page elements
Have server side callback return array of commands
To Create AJAX Callback Commands...
Add function to Drupal ajax command JavaScript object.
Write PHP code to return associative array with a 'command' key
To Use Custom AJAX Callback
Commands...
Include custom JavaScript
Include custom command in callback function
Resources
Drupal AJAX Framework: bit.ly/DrupalAJAX
Examples Module: bit.ly/DrupalExMod
Drupal 7 Commands: bit.ly/D7ajaxCMD
Drupal 8 Commands: bit.ly/D8ajaxCMD
This Presentation: bit.ly/NYCcampAJAX
Presentation Slides: bit.ly/NYCcampAJAXSlides
Example Code: bit.ly/NYCcampAJAXEx
Send me feedback!
@mikemiles86
#NYCcamp
 #NYCcamp  @WeAreGenuineAJAX Callback Commands /  @mikemiles86
Thank You!
Questions?

More Related Content

What's hot

Using the Features API
Using the Features APIUsing the Features API
Using the Features APIcgmonroe
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...Atlassian
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceIvan Chepurnyi
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016John Napiorkowski
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shintutorialsruby
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With PythonLuca Mearelli
 
To Batch Or Not To Batch
To Batch Or Not To BatchTo Batch Or Not To Batch
To Batch Or Not To BatchLuca Mearelli
 
Raybiztech Guide To Backbone Javascript Library
Raybiztech Guide To Backbone Javascript LibraryRaybiztech Guide To Backbone Javascript Library
Raybiztech Guide To Backbone Javascript Libraryray biztech
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
An Introduction to Ruby on Rails
An Introduction to Ruby on RailsAn Introduction to Ruby on Rails
An Introduction to Ruby on RailsJoe Fiorini
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rulesSrijan Technologies
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading DataIvan Chepurnyi
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 

What's hot (20)

Using the Features API
Using the Features APIUsing the Features API
Using the Features API
 
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With Python
 
To Batch Or Not To Batch
To Batch Or Not To BatchTo Batch Or Not To Batch
To Batch Or Not To Batch
 
Raybiztech Guide To Backbone Javascript Library
Raybiztech Guide To Backbone Javascript LibraryRaybiztech Guide To Backbone Javascript Library
Raybiztech Guide To Backbone Javascript Library
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
 
An Introduction to Ruby on Rails
An Introduction to Ruby on RailsAn Introduction to Ruby on Rails
An Introduction to Ruby on Rails
 
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
[Srijan Wednesday Webinars] Ruling Drupal 8 with #d8rules
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 

Similar to NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands

Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zLEDC 2016
 
How to Create and Load Model in Laravel
How to Create and Load Model in LaravelHow to Create and Load Model in Laravel
How to Create and Load Model in LaravelYogesh singh
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Nicolás Bouhid
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascriptAlmog Baku
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinNida Ismail Shah
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sqlsalissal
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleKaty Slemon
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4JoeDinaso
 
Modular javascript
Modular javascriptModular javascript
Modular javascriptZain Shaikh
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Siva Epari
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmersAlexander Varwijk
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes ramakesavan
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8Logan Farr
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access RunbookTaha Shakeel
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 

Similar to NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands (20)

Анатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to zАнатолий Поляков - Drupal.ajax framework from a to z
Анатолий Поляков - Drupal.ajax framework from a to z
 
How to Create and Load Model in Laravel
How to Create and Load Model in LaravelHow to Create and Load Model in Laravel
How to Create and Load Model in Laravel
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Using php with my sql
Using php with my sqlUsing php with my sql
Using php with my sql
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
Modular javascript
Modular javascriptModular javascript
Modular javascript
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
PHP and Mysql
PHP and MysqlPHP and Mysql
PHP and Mysql
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 

More from Michael Miles

Inclusive Design: Thinking beyond accessibility
Inclusive Design: Thinking beyond accessibilityInclusive Design: Thinking beyond accessibility
Inclusive Design: Thinking beyond accessibilityMichael Miles
 
How to Foster Team Success
How to Foster Team SuccessHow to Foster Team Success
How to Foster Team SuccessMichael Miles
 
How to Foster Team Success | Drupalcon 2017
How to Foster Team Success | Drupalcon 2017How to Foster Team Success | Drupalcon 2017
How to Foster Team Success | Drupalcon 2017Michael Miles
 
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017Michael Miles
 
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017Inclusive Design: Thinking Beyond Accessibility | DCNL 2017
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017Michael Miles
 
The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017Michael Miles
 
INCLUSIVE DESIGN: Going beyond Accessibility
INCLUSIVE DESIGN: Going beyond AccessibilityINCLUSIVE DESIGN: Going beyond Accessibility
INCLUSIVE DESIGN: Going beyond AccessibilityMichael Miles
 
The Flexibility of Drupal 8
The Flexibility of Drupal 8The Flexibility of Drupal 8
The Flexibility of Drupal 8Michael Miles
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of DrupalMichael Miles
 
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right Modules
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right ModulesBadcamp 2015 - R.E.A.D: Four Steps for Selecting The Right Modules
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right ModulesMichael Miles
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of DrupalMichael Miles
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of DrupalMichael Miles
 
Flcamp2015 - R.E.A.D: Four steps for selecting the right modules
Flcamp2015 - R.E.A.D: Four steps for selecting the right modulesFlcamp2015 - R.E.A.D: Four steps for selecting the right modules
Flcamp2015 - R.E.A.D: Four steps for selecting the right modulesMichael Miles
 
R.E.A.D: Four steps for selecting the right modules Midcamp 2015
R.E.A.D: Four steps for selecting the right modules Midcamp 2015R.E.A.D: Four steps for selecting the right modules Midcamp 2015
R.E.A.D: Four steps for selecting the right modules Midcamp 2015Michael Miles
 
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014Michael Miles
 
To Patch or Custom: How to decide when to patch a contrib module or go custom...
To Patch or Custom: How to decide when to patch a contrib module or go custom...To Patch or Custom: How to decide when to patch a contrib module or go custom...
To Patch or Custom: How to decide when to patch a contrib module or go custom...Michael Miles
 

More from Michael Miles (17)

Inclusive Design: Thinking beyond accessibility
Inclusive Design: Thinking beyond accessibilityInclusive Design: Thinking beyond accessibility
Inclusive Design: Thinking beyond accessibility
 
How to Foster Team Success
How to Foster Team SuccessHow to Foster Team Success
How to Foster Team Success
 
How to Foster Team Success | Drupalcon 2017
How to Foster Team Success | Drupalcon 2017How to Foster Team Success | Drupalcon 2017
How to Foster Team Success | Drupalcon 2017
 
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017
Inclusive Design: Thinking Beyond Accessibility | NERDSummit 2017
 
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017Inclusive Design: Thinking Beyond Accessibility | DCNL 2017
Inclusive Design: Thinking Beyond Accessibility | DCNL 2017
 
The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017The Flexibility of Drupal 8 | DCNLights 2017
The Flexibility of Drupal 8 | DCNLights 2017
 
INCLUSIVE DESIGN: Going beyond Accessibility
INCLUSIVE DESIGN: Going beyond AccessibilityINCLUSIVE DESIGN: Going beyond Accessibility
INCLUSIVE DESIGN: Going beyond Accessibility
 
Inclusive Design
Inclusive DesignInclusive Design
Inclusive Design
 
The Flexibility of Drupal 8
The Flexibility of Drupal 8The Flexibility of Drupal 8
The Flexibility of Drupal 8
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of Drupal
 
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right Modules
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right ModulesBadcamp 2015 - R.E.A.D: Four Steps for Selecting The Right Modules
Badcamp 2015 - R.E.A.D: Four Steps for Selecting The Right Modules
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of Drupal
 
The Flexibility of Drupal
The Flexibility of DrupalThe Flexibility of Drupal
The Flexibility of Drupal
 
Flcamp2015 - R.E.A.D: Four steps for selecting the right modules
Flcamp2015 - R.E.A.D: Four steps for selecting the right modulesFlcamp2015 - R.E.A.D: Four steps for selecting the right modules
Flcamp2015 - R.E.A.D: Four steps for selecting the right modules
 
R.E.A.D: Four steps for selecting the right modules Midcamp 2015
R.E.A.D: Four steps for selecting the right modules Midcamp 2015R.E.A.D: Four steps for selecting the right modules Midcamp 2015
R.E.A.D: Four steps for selecting the right modules Midcamp 2015
 
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
How to R.E.A.D: Steps for how to select the correct module @NEWDCamp 2014
 
To Patch or Custom: How to decide when to patch a contrib module or go custom...
To Patch or Custom: How to decide when to patch a contrib module or go custom...To Patch or Custom: How to decide when to patch a contrib module or go custom...
To Patch or Custom: How to decide when to patch a contrib module or go custom...
 

Recently uploaded

horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goahorny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goasexy call girls service in goa
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistKHM Anwar
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 

Recently uploaded (20)

Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goahorny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization Specialist
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 

NYCCAMP 2015 Demystifying Drupal AJAX Callback Commands

  • 1. Demystifying Drupal AJAX Callback Commands http://nyccamp.org/node/287 NYC CAMP 2015 #NYCcamp
  • 2. Goals of this Session Explain what AJAX callback commands are Demonstrate how to use AJAX callback commands Outline how to create AJAX callback commands
  • 3. Michael Miles From: Boston, MA USA Work:   @WeAreGenuine(.com)Genuine Exp: Working with Drupal since 2008. Acquia Certified.  2014 Acquia MVP. Twitter: @mikemiles86 Drupal.org: mikemiles86  All the Places: mikemiles86
  • 4. Warning About Example Code There is example code Some coding standards ignored for presentation purposes Drupal 8 code still subject to change
  • 6. From a High Level The response of AJAX request PHP code to instruct JavaScript functions A JavaScript function attached to an object Defined by Drupal core or modules 17 AJAX callback commands in Drupal 7
  • 7. Example: The "Remove" Command Using the "examples" module (available on Drupal.org), showing using the 'remove' AJAX Callback command. The checkbox is checked, which makes an AJAX request, which returns the command to remove the element with the sample text.
  • 8. On the Client Side [D7] A function on the 'Drupal.ajax.prototype.commands' object Receives 'ajax', 'response' and 'status' arguments A wrapper for additional javascript // Provide a series of commands that the server can request the client perform. Drupal.ajax.prototype.commands = { //... /** * Command to remove a chunk from the page. */ remove: function (ajax, response, status) { var settings = response.settings || ajax.settings || Drupal.settings; Drupal.detachBehaviors($(response.selector), settings); $(response.selector).remove(); }, //... } misc/ajax.js
  • 9. On the Server Side [D7] A PHP function which returns an associative array Array must have an element with key of 'command' The value is the name of a JavaScript function Additional array elements set as response data /** * Creates a Drupal Ajax 'remove' command. */ function ajax_command_remove($selector) { return array( 'command' => 'remove', 'selector' => $selector, ); } includes/ajax.inc
  • 10.
  • 11. How to Use Commands
  • 12. Example Scenario  As a user When I navigate to the 'my-messages' page Then I see a list of my unread messages And I see a list of my read messages When I click on an unread message Then the full messaged is retrieved from the server And I see the content of my message And the message is removed from the unread messages list And the message is added to the read messages list
  • 14. To Use Commands... 1.  Include Drupal AJAX JavaScript library 2.  Attach AJAX to page elements 3.  Define a callback path and function Returns a render array of commands [D7]
  • 15. 1. Include Drupal AJAX library // Render a page of messages. function mymodule_messages_page() { // Include AJAX library. drupal_add_library('system', 'drupal.ajax'); // Create inital page content. $content = theme_item_list(array( 'title' => t('Unread Messages'), 'type' => 'ul', 'attributes' => array( 'id' => 'unread-msgs'), 'items' => mymodule_messages_list(mymodule_get_unread_messages()), )); $content .= '<div id="current-msg"><h2></h2><p></p></div>'; $content .= theme_item_list(array( 'title' => t('Read Messages'), 'type' => 'ul', 'attributes' => array('id' => 'read-msgs'), 'items' => mymodule_messages_list(mymodule_get_read_messages(), FALSE), )); return $content; } mymodule/mymodule.module Function to build a page of messages. On line #4, using the drupal_add_librry() function to include the AJAX library on the page.
  • 16. 2. Attach AJAX to page elements // Return array of message titles for use in a list. function mymodule_messages_list($messages, $display_link = TRUE) { $list_items = array(); foreach ($messages as $mid => $msg) { // Build link to AJAX callback to load message. $link = l($msg->subject, 'read-message-callback/nojs/' . $mid, array( // Add class to link so Drupal knows to use AJAX. 'attributes' => array('class' => array('use-ajax')), )); // Create list item for message. $list_items[] = array( 'id' => 'msg-' . $mid, // Set data to read message link or just message subject. 'data' => $display_link ? $link : $msg->subject, ); } return $list_items; } mymodule/mymodule.module Function to build a list of messages. On line #6, creating a link element which links to our callback path. On line #8, adding the class 'use­ajax' so AJAX framework knows to serve link with an AJAX request.
  • 17. 3.a Define a callback path // Implements hook_menu(). function mymodule_menu() { $items = array(); //.. Other menu items. // None JS callback, for graceful degredation. $items['read-message-callback/nojs/%'] = array( 'title' => 'AJAX Callback to Read Message', 'access arguments' => array('access content'), 'page callback' => 'mymodule_read_message_callback', 'page arguments' => array(1,2), 'type' => MENU_CALLBACK, ); // Create AJAX callback. Add ajax_delivery callback. $items['read-message-callback/ajax/%'] = array( 'delivery callback' => 'ajax_deliver', ) + $items['read-message-callback/nojs/%']; return $items; } mymodule/mymodule.module Creating two menu items for callback functions. The first is for handling graceful degredation when reached outside an AJAX Request. The second is the AJAX callback, which add a delivery callback of "ajax_callback" so Drupal know to return an AJAX Response object.
  • 18. 3.b Return array of commands using a render array [D7] // AJAX Callback to read a message. function mymodule_read_message_callback($method, $mid) { $message = mymodule_load_message($mid); // @TODO: Graceful degredation if not from ajax method or if no message. $commands = array( // Replace content of current message subject. ajax_command_html('#current-msg h2', $message->subject), // Replace content of current message body. ajax_command_html('#current-msg p', $message->content), // Remove message from unread list. ajax_command_remove('#msg-' . $mid), // Add message to read list ajax_command_append('#read-msgs', '<li>' . $message->subject . '</li>'), ); // Return an AJAX render array. return array( '#type' => 'ajax', '#commands' => $commands, ); } mymodule/mymodule.module Lines #5 thru #14, building an array of Core AJAX Callback commands. Each mapps to a javascript function. Line #16 building a render array of type 'ajax'. Drupal will package into JSON and send back to the client.
  • 19.
  • 21. To Create a Command... 1.  Add a function to the Drupal ajax command JavaScript object 2.  Write PHP code that returns an associative array. Must have an element with key of 'command' Value is name of the JavaScript function Additional elements for response data
  • 23. A Custom Command in Drupal 7 1.  Add a function to 'Drupal.ajax.prototype.commands' 2.  Define a PHP function to return an array
  • 24. 1. Add a function to 'Drupal.ajax.prototype.commands' (function($, Drupal) { // Add new command for reading a message. Drupal.ajax.prototype.commands.readMessage = function(ajax, response, status){ // Place content in current-msg div. $('#current-msg h2').html(response.subject); $('#current-msg p').html(response.content); // Remove from unread list. $('#msg-' + response.mid).remove(); // Add message to read list. $('#read-msgs').append('<li>' + response.subject + '</li>'); } })(jQuery, Drupal); mymodule/js/commands.js Attach a new 'readMessage' command to the Drupal AJAX Commands JavaScript object. Function takes in the 3 arguments "ajax", "response" & "status". Wraps jQuery functions to display a message on the page.
  • 25. 2. Define a PHP function to return an associative array /** * AJAX command to read a message. */ function mymodule_command_read_message($message) { return array( 'command' => 'readMessage', 'mid' => $message->mid, 'subject' => $message->subject, 'content' => $message->content, ); } mymodule/mymodule.module PHP function that mapps to the new JavaScript 'readMessage' array. Returns an associative array, with an element that has a key of 'command' and value of the JavaScript function name 'readMessage'. Then additional elements to be sent as request data.
  • 26. Using a custom command... 1.  Tell Drupal to include custom JavaScript 2.  Return custom command in callback function
  • 28. Using a Custom Command in Drupal 7 1.  Use drupal_add_js() to include custom JavaScript on page 2.  Add command to render array returned by callback
  • 29. 1. Use drupal_add_js() to include custom JavaScript on page // Render a page of my messages function mymodule_messages_page() { // Include AJAX library. drupal_add_library('system', 'drupal.ajax'); // Include custom JavaScript. drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/commands.js'); // .. Build $content. return $content; } mymodule/mymodule.module The example function for creating the messages page. In addition to adding the Drupal AJAX library on line #4 also using drupal_add_js() to include custom javascript file on line #6.
  • 30. 2. Add command to render array returned by callback // AJAX Callback to read a message. function mymodule_read_message_callback($method, $mid) { $message = mymodule_load_message($mid); // @TODO: Graceful degredation if not from ajax method or if no message. $commands = array( // Call the readMessage javascript function. mymodule_command_read_message($message), ); // Return an AJAX render array. return array( '#type' => 'ajax', '#commands' => $commands, ); } mymodule/mymodule.module The example callback function that returns an AJAX render array. Commands array on lines #5 thru #8, only returns a single command. The new custom command that was created.
  • 31.
  • 32. AJAX Commands in Drupal 8
  • 33. Changes to AJAX Commands 22 AJAX callback commands in Drupal 8 JavaScript attatches to 'Drupal.AjaxCommands.prototype' object A PHP object that implements CommandInterface Must implement 'render' method
  • 34. Example: The "Remove" Command Using the "examples" module (available on Drupal.org), showing using the 'remove' AJAX Callback command. The checkbox is checked, which makes an AJAX request, which returns the command to remove the element with the sample text.
  • 35. A function on the 'Drupal.AjaxCommands.prototype' object /** * Provide a series of commands that the client will perform. */ Drupal.AjaxCommands.prototype = { //... /** * Command to remove a chunk from the page. */ remove: function (ajax, response, status) { var settings = response.settings || ajax.settings || drupalSettings; $(response.selector).each(function () { Drupal.detachBehaviors(this, settings); }).remove(); }, //... } misc/ajax.js
  • 36. An object that implements CommandInterface Must implement 'render' method namespace DrupalCoreAjax; use DrupalCoreAjaxCommandInterface; // AJAX command for calling the jQuery remove() method. class RemoveCommand Implements CommandInterface { protected $selector; // Constructs a RemoveCommand object. public function __construct($selector) { $this->selector = $selector; } // Implements DrupalCoreAjaxCommandInterface:render(). public function render() { return array( 'command' => 'remove', 'selector' => $this->selector, ); } } core/lib/Drupal/Core/Ajax/RemoveCommand.php
  • 37. To Use Commands in Drupal 8 1.  Include Drupal AJAX JavaScript library Must attach to a render array 2.  Attach AJAX to page elements 3.  Define a callback path and function Returns an AjaxResponse object
  • 39. Attach library to a render array // Render a page of my messages function mymodule_messages_page() { // .. build $content // Create render array. $page[] = array( '#type' => 'markup', '#markup' => $content, ); // Attach JavaScript library. $page['#attached']['library'][] = 'core/drupal.ajax'; return Drupal::service('renderer')->render($page); } mymodule/mymodule.module Function for building messages page is now using a render array. to the '#attached', 'library' array of that render array, declaring the drupal.ajax library to be included.
  • 40. Callback returns commands using an AJAXResponse() [D8] // AJAX Callback to read a message. function mymodule_read_message_callback($method, $mid) { $message = mymodule_load_message($mid); // @TODO: Graceful degredation if not from ajax method or if no message. // Create AJAX Response object. $response = new AjaxResponse(); // Replace content of current message subject. $response->addCommand(new HtmlCommand('#current-msg h2', $message->subject)); // Replace content of current message body. $response->addCommand(new HtmlCommand('#current-msg p', $message->content)); // Remove message from unread list. $response->addCommand(new RemoveCommand('#msg-' . $mid)); // Add message to read list. $item = '<li>' . $message->subject . '</li>'; $response->addCommand(new AppendCommand('#read-msgs', $item)); ); // Return ajax response. return $response; } mymodule/mymodule.module Returning an AjaxResponse object instead of a render array like in Drupal 7. AjaxResponse has an 'addCommand' method, which takes the argument of a command object.
  • 41. Custom Commands in Drupal 8 1.  Add function to 'Drupal.AjaxCommands.prototype' 2.  Define a command object that implements CommandInterface
  • 42. 1. Add function to 'Drupal.AjaxCommands.prototype' (function($, Drupal) { /** * Add new command for reading a message. */ Drupal.AjaxCommands.prototype.readMessage = function(ajax, response, status){ // Place content in current-msg div. $('#current-msg h2').html(response.subject); $('#current-msg p').html(response.content); // Remove from unread list. $('#msg-' + response.mid).remove(); // Add message to read list. $('#read-msgs').append('<li>' + response.subject + '</li>'); } })(jQuery, Drupal); mymodule/js/commands.js Adding the custom 'readMessage' function to the Drupal 8 JavaScript AJAX Commands object. Still takes the same three arguments as in Drupal 7.
  • 43. 2. Define command object that implements CommandInterface namespace DrupalmymoduleAjax; use DrupalCoreAjaxCommandInterface; class ReadMessageCommand implements CommandInterface { protected $message; // Constructs a ReadMessageCommand object. public function __construct($message) { $this->message = $message; } // Implements DrupalCoreAjaxCommandInterface:render(). public function render() { return array( 'command' => 'readMessage', 'mid' => $this->message->mid, 'subject' => $this->message->subject, 'content' => $this->message->content, ); } } mymodule/src/Ajax/ReadMessageCommand.php Creating a Command object which implements the CommandInterface. Must declare a 'render' method, which will return an associative array. This associative array must have an element with the key of 'command' and value of the JavaScript function to run.
  • 44. Using a Custom Command in Drupal 8 1.  Tell Drupal about custom JavaScript library 2.  Attach library to a render array 3.  Add command to AjaxResponse object in callback
  • 45. 1. Tell Drupal about custom JavaScript library mymodule.commands: version: VERSION js: js/commands.js: {} dependencies: - core/drupal.ajax mymodule/mymodule.libraries.yml Must tell Drupal about custom library with a libraries.yml file. Provide an Asset library name, lists all the js files needed, and any dependencies on other libraries.
  • 46. 2. Attach library to a render array // Render a page of my messages function mymodule_messages_page() { // .. build $content // Create render array. $page[] = array( '#type' => 'markup', '#markup' => $content, ); // Attach JavaScript library. $page['#attached']['library'][] = 'mymodule/mymodule.commands'; return Drupal::service('renderer')->render($page); } mymodule/mymodule.module Function for building messages page is now using a render array. to the '#attached', 'library' array of that render array, including the custom library. No longer including the AJAX library, as Drupal will know to include it from the libraries.yml file.
  • 47. 3. Add command to AjaxResponse object in callback // AJAX Callback to read a message. function mymodule_read_message_callback($method, $mid) { $message = mymodule_load_message($mid); // @TODO: Graceful degredation if not from ajax method or if no message. // Create AJAX Response object. $response = new AjaxResponse(); // Call the readMessage javascript function. $response->addCommand( new ReadMessageCommand($message)); ); // Return ajax response. return $response; } mymodule/mymodule.module Returning an AjaxResponse object instead of adding the core commands, just adding the new custom command using the 'addCommand' method.
  • 48.
  • 50. AJAX Callback Commands Are... Returned by all AJAX Framework requests PHP abstraction for JavaScript functions Defined by core and modules
  • 51. To Use AJAX Callback Commands... Include Drupal AJAX JavaScript library Attach AJAX to page elements Have server side callback return array of commands
  • 52. To Create AJAX Callback Commands... Add function to Drupal ajax command JavaScript object. Write PHP code to return associative array with a 'command' key
  • 53. To Use Custom AJAX Callback Commands... Include custom JavaScript Include custom command in callback function
  • 54.