Getting Started with DrupalGap

26
GETTING STARTED WITH DRUPALGAP Schedrov Alexander - sanchiz

description

Getting Started with DrupalGap

Transcript of Getting Started with DrupalGap

Page 1: Getting Started with DrupalGap

GETTING STARTED WITH DRUPALGAP

Schedrov Alexander - sanchiz

Page 2: Getting Started with DrupalGap

SCHEDROV ALEXANDER AKA

SANCHIZLead Drupal Developer at TrellonMaintainer : • pathauto_i18n • user_profile_comment • DrupalGapManager

https://github.com/Sanchiz/DrupalGapManager

Participant: • crm_core • relation_lists

Page 3: Getting Started with DrupalGap

MOBILE WEBSITE TRAFFICPercentage of website traffic from mobile devices

0

8

16

24

32

Q1 2013 Q2 2013 Q3 2013 Q4 2013 Q1 2014

32.0%30.0%

28.0%29.0%

23.9%

Page 4: Getting Started with DrupalGap

MEET DRUPALGAP

• Created by Tyler Frankenstein

• First release Feb 25, 2012 ~100 lines

• Currently ~10,000 lines

Page 5: Getting Started with DrupalGap

DRUPALGAP

Drupal module hosted on d.org

It's connection between mobile applications and Drupal websites via web Services.

Development Kit hosted on GitHub

Developers can create custom multi-platform mobile applications that communicate with their Drupal websites.

Page 6: Getting Started with DrupalGap

REGULAR SITE

Website

+

Responsive Website

Page 7: Getting Started with DrupalGap

WHY DO YOU NEED MOBILE APPLICATION?

Our mobile phone have features which don't have our regular devices!

!

DrupalGap features:

You don't need a Objective-C and Java developers.

If you know how to build Drupal modules and know JavaScript - Welcome to DrupalGap

developers.

Page 8: Getting Started with DrupalGap
Page 9: Getting Started with DrupalGap

HOW IT WORKS?PhoneGap generates HTML, CSS

and JavaScript and make application iOS and Android mobile

devices.Apache Cordova provides access

via JavaScript to device features such as the

Camera, GPS, File System, Contacts, Compass, etc.

Page 10: Getting Started with DrupalGap

REQUIREMENTSDRUPAL

Services, Rest_server, Views_datasource, Views_json, Drupalgap

!

DEVELOPMENT ENVIRONMENTS

Google Chrome and the Ripple Emulator extension OR

node.jscordova(node.js package)

Java SDK for Android or xCode for iOS

Page 11: Getting Started with DrupalGap

DRUPALGAP INHERITS DRUPAL DEVELOPER CONCEPTS

• Themes, modules

• Blocks

• Menus

• Pages

• Entities

• Fields

• Forms

• Views

• Messages

• Services

• Other Drupal tools

Page 12: Getting Started with DrupalGap

2 FOR DEALS

https://play.google.com/store/apps/details?id=com.twofordeals

Page 13: Getting Started with DrupalGap

BETTRACKS

https://bettracks.co.uk

Page 14: Getting Started with DrupalGap

EXTENSIBLE WITH CONTRIB MODULES• Force Authentication

• Telephone

• Address Field

• AmazonS3

• AudioField

• Colorbox

• Commerce

• Commerce DrupalGap Stripe

• Date

• Email Registration

• Entity reference

• Fivestar

• Flag

• Geofield

• GeoTracker

• Link

• Location

• LoginToboggan

• Pathfix

• Push Notifications

• Rate

• Services Menu

• Shadowbox

• User registration password

• Voting API

• Webform

http://www.drupalgap.org/project/modules

Page 15: Getting Started with DrupalGap

DRUPALGAP MANAGER

https://github.com/Sanchiz/DrupalGapManager https://www.npmjs.org/package/dgm

is a command-line tool and interface for DrupalGap

Page 16: Getting Started with DrupalGap

EVEN MORE…. INTEGRATION WITH COMMERCE

http://tylerfrankenstein.com/code/build-mobile-app-sell-products-with-drupal

Page 17: Getting Started with DrupalGap

HOOKS IN 7.X-1.0-RC3*_404 *_assemble_form_state_into_field *_block_info *_block_view *_deviceready *_drupalgap_goto_post_process *_drupalgap_goto_preprocess *_entity_post_render_content *_entity_post_render_field *_field_formatter_view

*_field_widget_form *_form_alter *_image_path_alter *_install *_menu *_services_postprocess *_services_preprocess *_services_request_postprocess_alter *_services_request_pre_postprocess_alter *_services_success

and custom forms

http://api.drupalgap.org

Page 18: Getting Started with DrupalGap

FILE STRUCTURE

modules

themes

settings.js

Page 19: Getting Started with DrupalGap

• core_app (module folder)

• core_app.js (module file)

Drupal.modules.custom['core_app'] = {};

settings.js:

/** * Implements hook_menu(). */ function core_app_menu() { var items = {}; items['homepage'] = { title: 'New Sandbox', page_callback: 'core_app_homepage' }; return items; } !function core_app_homepage() { var content = {}; content['homepage'] = { markup: 'some markup' }; return content; }

Page 20: Getting Started with DrupalGap

OR CUSTOM BLOCK?/** * Implements hook_block_info(). */ function core_app_block_info() { var blocks = { latest_news_block: { delta: 'latest_news_block', module: 'core_app' } }; return blocks; } !/** * Implements hook_block_view(). */ function core_app_block_view(delta) { var content = ''; if (delta == 'latest_news_block') { content = '<h2>Latest news</h2>'; content += 'Some content...'; } return content; }

drupalgap.settings.blocks.amazing = { content: { homepage_menu: { pages:{ value:['homepage'], mode:'include' } }, latest_news_block: { pages:{ value:['homepage'], mode:'exclude' } }, users_block: { pages:{ value:['node/*', 'user/*'], mode:'include' }, roles:{ value:['authenticated user'], mode:'include' } }, }, };

Page 21: Getting Started with DrupalGap

OR CUSTOM FORM?function core_app_voting_form(form, form_state) { form.elements.name = { type:'textfield', title:'Name', default_value: Drupal.user.name }; form.elements.email = { title:'Email Address', type:'email', required: true, default_value: Drupal.user.mail }; form.elements.categoty = { title:'Category', type:'select', options:{ 0:'Feedback', 1:'Question' }, default_value:0 }; form.elements.comment = { title:'Comment', type:'textarea', }; form.elements.rating = { title:'Rating', type:'radios', required: true, options:{ 0:'0', 1:'+1', }, default_value:3 }; form.elements.submit = { type:'submit', value:'Submit' }; return form; }

Page 22: Getting Started with DrupalGap

NEED ADDITIONAL FUNCTIONALITY? YOU GOT IT!1. Create custom services resource in Drupal module

hook_services_resources();

2. Create custom services call in DrupalGap moduleDrupal.services.call(options);

var output = ''; Drupal.services.call({ method: 'POST', path: 'news.json', data: args, success: function(result) { output = ''; $.each(result, function(i, node) { output += node.title; }); } });

Page 23: Getting Started with DrupalGap

Need to create page with JSON data document format (views_json module)

VIEWS

Displaying a View in mobile app

function core_team_menu() { var items = {}; items['team'] = { title: 'Our team', page_callback: 'core_team_page' } return items; }

Page 24: Getting Started with DrupalGap

function core_team_page() { var content = {}; content['team'] = { theme: 'view', format: ‘ul', /* ul, ol, table, unformatted_list */ path: 'mobile/team_new', /* the path to the view in Drupal */ row_callback: 'core_team_page_row', empty_callback: 'core_team_page_empty', attributes: { id: 'team-view' } }; return content; } !function core_team_page_row(view, row) { var output = ''; output += '<img class="team-image" src="' + row.field_photo + '">'; output += l(row.title, 'node/' + row.Nid); return output; } !function core_team_page_empty(view) { return 'Sorry, no results.'; }

Page 25: Getting Started with DrupalGap

DEMO

Page 26: Getting Started with DrupalGap

THANK YOU!

https://www.drupal.org/u/sanchiz

https://github.com/Sanchiz

http://sanchiz.net

Email: [email protected]

Twitter : @alexschedrov