lucius drupal development cursus

82
DRUPAL DEV Training Introductie Lucius Websystems Robbenkoog 29a 1822 BA Alkmaar 072-564 90 90 [email protected]

Upload: luciuswebsystems

Post on 29-Nov-2014

6.120 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Lucius Drupal Development Cursus

DRUPAL DEV Training Introductie

Lucius WebsystemsRobbenkoog 29a1822 BA Alkmaar072-564 90 [email protected]

Page 2: Lucius Drupal Development Cursus

About

Drupal

Page 3: Lucius Drupal Development Cursus

Introductie Drupal

Geschiedenis

Huidige stats

Drupal association & DrupalCons

Drupal

Page 4: Lucius Drupal Development Cursus

Wanneer Drupal?

Bedrijfswebsites

Online communities

Intranets

Enterprise oplossingen

Webwinkel

Weblog

Multi site platforms

And many more..

Drupal

Page 5: Lucius Drupal Development Cursus

Enkele Drupal Features

Multi talig

Version control

Commentaarsysteem

Download systeem

Logs en error-reporting

Forum

Blog (+API)

Poll

Drupal

Zoekmachine

Aggregator

RSS

Gebruikersrechten – beheer (ACL)

Multi – site

Taxonomy

Page 6: Lucius Drupal Development Cursus

Waarom Drupal?

Stabiele foundation en gepassioneerde community

Snel en veilig

Krachtig en schaalbaar

Innoverend

Zeer zoekmachinevriendelijk

Krachtig en Flexibel templating systeem

Award winning

Many more..

Drupal

Page 7: Lucius Drupal Development Cursus

Waarom Drupal? part 2

Modulair systeem

Hooks

Content types

Taxonomy

Drupal API

Theming & overriding

NBS (Node Based System)

Vele modules werken met elkaar samen Synergie

Backend en frontend theming

Drupal

Page 8: Lucius Drupal Development Cursus

Waarom Drupal? part 3

Content management op maat

Content invoer (oa CCK)

Content output (oa Views)

Drupal

Page 9: Lucius Drupal Development Cursus

Benodigde kennis

PHP 5

MySQL

SQL

(X)HTML / CSS & Webstandaarden (W3c)

FTP

Localhost voor ontwikkeling

Drupal

Page 10: Lucius Drupal Development Cursus

Aftasting kennis in huis

Drupal

Wie heeft wat al gedaan?

Belangrijke Drupal modules: Administration Menu CCK Views Image / assist / api Pathauto Global redirect Token Webform Poormanscron FCK Editor Devel

Page 11: Lucius Drupal Development Cursus

Belangrijke Drupal terminologie

Module

Nodes

Users

Blocks

Pages

Taxonomy

Content typen & Content (cck) fields

Sessions

Drupal

Hooks

Theme

Cron

Cache

Input format

Watchdog

API

i18n

Page 12: Lucius Drupal Development Cursus

Drupal File Layout

Drupal

Bron afbeelding: http://www.ddj.com/linux-open-source/199201603?pgno=5

Page 13: Lucius Drupal Development Cursus

Introductie Drupal modules

Hoe om te gaan met open source modules

Goed kijken hoe ‘contrib’ modules gemaakt zijn. Soms beter dan core modules, omdat die al lang in dev zijn.

Gebruik de enorm actieve community correcte wijze

Vele modules werken met elkaar samen

Drupal werkt veel met titles, naamgeving is belangrijk

Dagelijks checken: Latest Drupal modules

http://drupal.org/project/modules?solrsort=ds_project_latest_release%20desc

http://www.drupal.org/planet

Drupal

Page 14: Lucius Drupal Development Cursus

Online Developer resources

Module developer's guide http://drupal.org/contributors-guide

Drupal beyond the basics: http://drupal.org/handbook/customization

Drupal coding standards: http://drupal.org/coding-standards

Writing secure code: http://drupal.org/writing-secure-code

Best practices: http://drupal.org/node/287350

Working with Drupal API http://drupal.org/node/326

Use of underscore in Drupal functions http://drupal.org/node/70335

Guidelines for writing efficient SQL code http://drupal.org/node/559302

Creating new content type http://drupal.org/node/231019

Using Theme layer http://drupal.org/node/165706

Drupal

Page 15: Lucius Drupal Development Cursus

Online Developer tools

Drupal for firebug http://drupal.org/project/drupalforfirebug

Devel module: http://drupal.org/project/devel

Cache disable http://drupal.org/project/cache_disable

Use to check you coding on: http://drupal.org/project/coder

Use to extensivly check your code on: http://drupal.org/project/coder_tough_love

Trace http://ar.to/2006/12/easier-drupal-debugging-with-trace

Looking for a module: http://www.drupalmodules.comLooking for a module: http://www.drupalmodules.com

Drupal

Page 16: Lucius Drupal Development Cursus

Developer boeken

Pro Drupal development – John vanDyk & Matt Westgate

Learning Drupal 6 module development – Matt Butcher

Leveraging Drupal – Victor Kane

Cracking Drupal – Greg James Knaddison

Drupal

Page 17: Lucius Drupal Development Cursus

Coding standards & best practices

Coding standards: http://drupal.org/coding-standards

Writing secure code: http://drupal.org/writing-secure-code

Best practices: http://drupal.org/node/287350

Voorbeeld: $string = "Foo $bar"; (PHP)

Online resources: Standards, security and best practices http://drupal.org/node/360052 Readme.txt van module coder tough love

Drupal

Page 18: Lucius Drupal Development Cursus

Drupal API

De Drupal API http://api.drupal.org

Enkele API functies l(); url(); node_load(); node_view() arg(); t(); drupal_get_path(); check_plain(); variable_set, variable_get() & variable_del() database abstraction layer

Drupal

Page 19: Lucius Drupal Development Cursus

Database

API reference http://api.drupal.org/api/group/database/6

Secure code: http://drupal.org/writing-secure-code

Schema API: http://drupal.org/node/146843 Updaten Schema van een module : check system table

Drupal

Page 20: Lucius Drupal Development Cursus

Creating modules

Creating modules tutorial: http://drupal.org/node/206753

API reference http://api.drupal.org

Hooks http://api.drupal.org/api/group/hooks/6

PHP Library: http://w3schools.com/php/

SQL Library: http://w3schools.com/sql/

Creating modules tutorial: http://drupal.org/node/206753

Drupal

Page 21: Lucius Drupal Development Cursus

Module architectuur

Benodigde bestanden: .info definiering module info en dependencies .module de code

Optioneel LICENSE.txt wordt automatisch door drupal toegevoegd README.txt handmatig toevoegen .inc voornamelijk voor modules met veel code .install Help Translation files in aparte folder Theming files (tpl.php) UPGRADE.txt

Drupal

Page 22: Lucius Drupal Development Cursus

Module architectuur

Naamgeving is zeer belangrijk in module

Zorg voor unieke id in benaming van module, de naam werkt door in: Module map en definiering Functies in de module Dbase tables system variables url css classes Hooks Theming files

Drupal doorloopt de modules in alfabetische volgorde.

Het is mogelijk een weight aan een module toe te kennen.

Drupal

Page 23: Lucius Drupal Development Cursus

Hooks

Uitleg: Wat is een Hook en wat kan je ermee

Alle acties binnen cms waar je een hook kunt verwachten, daar zit er een.

Hooks http://api.drupal.org/api/group/hooks/6

Cheatsheet http://drupal.org/files/drupal_6_core_hooks_cheat_sheet.pdf

Demo gebruik van enkele Hooks

Drupal

Page 24: Lucius Drupal Development Cursus

Code validatie

Demo code validatie in Drupal

Drupal

Page 25: Lucius Drupal Development Cursus

Content filtering

Demo input formats

Drupal

Page 26: Lucius Drupal Development Cursus

Productie filter module

Opdracht 1: produceer een filter module

Definieer module / benodigde files

Drupal

Page 27: Lucius Drupal Development Cursus

Drupal

Productie filter module, tip toevoegen

Opdracht 2: produceer de filter tip Zoek correct hook op

Schrijf de code

Page 28: Lucius Drupal Development Cursus

Productie filter module

Opdracht 3: produceer een filter, die ingevoerde tekst analyseert en bij output een woord hierin wijzigd.

Drupal

Page 29: Lucius Drupal Development Cursus

Productie filter module

Opdracht 4: produceer admin gedeelte je te wijzigen woord kan instellen

Drupal

Page 30: Lucius Drupal Development Cursus

Productie filter module

De code toegelicht

Code validatie

Drupal

Page 31: Lucius Drupal Development Cursus

i18n opdracht

Demo i18n

Oefening i18n

Page 32: Lucius Drupal Development Cursus

Taxonomy Vocabularies & terms

Content types & taxonomy

Taxonomy API functions

Taxonomy output in theme, voorbeeld

Kan gebruikt worden door modules (bv forum)

Check hoe Drupal bv taxonomy_node_get_terms() gebruikt op api.drupal.org

Page 33: Lucius Drupal Development Cursus

Menu system

hook_menu()

Menu item & wildcard voor variabele

Title

Page callback

Page arguments

Access arguments

Type

MENU_NORMAL_ITEM (default, maakt menu item aan)

MENU_CALLBACK

Page 34: Lucius Drupal Development Cursus

Hook menu

MENU_LOCAL_TASK (gebruik werkwoord)

MENU_DEFAULT_LOCAL_TASK (gebruik werkwoord)

Weight

File

Hooken in bestaande menu items hook_menu_alter()

Menu tabs

Verbergen van menu items

Page 35: Lucius Drupal Development Cursus

Enkele API Functies pager_query

drupal_set_message()

watchdog()

cache_clear_all()

user_access()

format_date()

drupal_set_header()

node_access()

pager_query

menu_tree_all_data

drupal_goto

function image_get_info

user_is_logged_in

Page 36: Lucius Drupal Development Cursus

Drupal files systeem Demo file handling in Drupal

Page 37: Lucius Drupal Development Cursus

Form API Form API reference

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html

Form API: http://drupal.org/node/37775

Form API upload field :http://drupal.org/node/111782 & http://www.imedstudios.com/labs/node/22

Form API Elements reference http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6

Form functions http://api.drupal.org/api/group/form_api/6

Page 38: Lucius Drupal Development Cursus

Enkele ‘Form controls’ Texfield

Submit

Checkboxes

Select

Hidden

Radios

Weight

Fieldset

Markup

Button

Date

Password

Item

Page 39: Lucius Drupal Development Cursus

Enkele ‘Form Attributes’ #theme

#tree

#access

#title

#default_value

#maxlenght

#required

#weight

#description

#prefix & #suffix

#ahah

#attributes

Page 40: Lucius Drupal Development Cursus

Form API functies Uitleg van enkele belangrijke form functies:

http://api.drupal.org/api/group/form_api/6

Page 41: Lucius Drupal Development Cursus

Form API, Validate Validate functies stanaard

Validatie functies toevoegen aan een bestaand form

Page 42: Lucius Drupal Development Cursus

Form API, Submit Submit functies standaard

Submit functies toevoegen aan een bestaand form

Page 43: Lucius Drupal Development Cursus

Productie ‘lingo’ module Nieuwe module aanmaken

Menu hook

Alleen definiering velden mbv FAPI

Page 44: Lucius Drupal Development Cursus

Productie ‘lingo’ module Extra veld definieren

Veld verplicht maken (*)

Page 45: Lucius Drupal Development Cursus

Productie ‘lingo’ module Vergelijken tekstvelden

Foutmelding wanneer niet gelijk

Wanneer ‘te raden woord’ leeg: foutmelding uit core

Wanneer ‘gok’ leeg is: custom foutmelding verschijnt

Page 46: Lucius Drupal Development Cursus

Productie ‘lingo’ module Voorbeeld functionaliteit

Page 47: Lucius Drupal Development Cursus

Productie ‘lingo’ module Voorbeeld functionaliteit

Page 48: Lucius Drupal Development Cursus

Productie ‘lingo’ module Productie 2e menu hook

Validatie veld: altijd 6 karakters, kleine letter, geen cijfers

Opslaan veld in dbase

Page 49: Lucius Drupal Development Cursus

Productie ‘lingo’ module Melding geven wanneer nieuwe invoer voor oplossing gevalideerd is

Page 50: Lucius Drupal Development Cursus

Productie ‘lingo’ module Antwoord verborgen inladen

Vergelijken van invoer met antwoord

1e letter weergeven van antwoord

Page 51: Lucius Drupal Development Cursus

Productie ‘lingo’ module Foutmelding bij verkeerde gok

Log toevoegen: welke waarden zijn al gegokt.

Waarden schrijven naar ‘watchdog’ (log)

Page 52: Lucius Drupal Development Cursus

Productie ‘lingo’ module Je hebt max 6 pogingen, daarna verschijnt antwoord

Log op beeld leeg na 6 pogingen

Counter resetten, zodat je opnieuw kan proberen

Page 53: Lucius Drupal Development Cursus

Productie ‘lingo’ module Oplossing is goed

Log in beeld leegmaken

Goedmelding geven

Page 54: Lucius Drupal Development Cursus

Productie ‘lingo’ module Permissies toevoegen

Page 55: Lucius Drupal Development Cursus

Diverse demo’s Demo multiple-page

Demo multi button

Demo Captcha implementatie

Page 56: Lucius Drupal Development Cursus

Database Schema API Demo gebruik Database Schema API

.install file

Oefening gebruik Database Schame API

Page 57: Lucius Drupal Development Cursus

Drupal Theming System

Page 58: Lucius Drupal Development Cursus

Theming system

xHTML / CSS

Javascript & jQuery

Custom vs voorgecodeerd

Veel themes beschikbaar

Garland als voorbeeld theme

Garland als backend theme

Page 59: Lucius Drupal Development Cursus

Online resources

Anatomy of Drupal 6 theme http://drupal.org/node/171194

Drupal 6 theming documentation http://drupal.org/theme-guide/6

Core tpl-files and vars (cheat sheet) http://drupal.org/node/190815

Drupal coding documentation: http://drupal.org/node/360052

Secure code http://drupal.org/writing-secure-code

Use the Theme developer module http://drupal.org/project/devel

HTML en CSS tools en techniques http://drupal.org/node/37156

Theming forum http://drupal.org/forum/3

Theming layer in modules http://drupal.org/node/165706

Page 60: Lucius Drupal Development Cursus

Theme anatomy

Bron afbeelding:http://drupal.org/node/171194

Page 61: Lucius Drupal Development Cursus

Enkele Theme Files

In Folder: sites/all/themes/[theme_naam]

.info

page.tpl.php

node.tpl.php

block.tpl.php

template.php

page-front.tpl.php

Images folder

Css folder

Screenshot.png

Comment.tpl.php

Favicon

Page 62: Lucius Drupal Development Cursus

Enkele Theme Files .info

variabelen: http://drupal.org/node/171205 deafults: http://drupal.org/node/171206theme_get_registry()

page.tpl.phphttp://api.drupal.org/api/file/modules/system/page.tpl.php/6

node.tpl.phphttp://api.drupal.org/api/file/modules/node/node.tpl.php/6

Page 63: Lucius Drupal Development Cursus

Features en color Toevoegen features http://drupal.org/project/themesettingsapi

Color module http://drupal.org/node/108459

Page 64: Lucius Drupal Development Cursus

Regions Assignen van blocks/content aan regions

http://drupal.org/node/171224

Demo inrichten regions

Page 65: Lucius Drupal Development Cursus

Theme variables $styles

$scripts

$head

$content

$closure

$base_path

$language

print $regionname

$directory

$tabs

$tabs2

$title

$breadcrumb

$show_messages /$messages

$help

$front_page

$is_front

Core templates (cheat sheet) http://drupal.org/node/190815

Page 66: Lucius Drupal Development Cursus

Enkele API functies voor theming

format_date()

l()

url()

t()

Sanitizing functions

check_plain()

check_markup()

filter_access()

filter_xss_admin()

drupal_add_css()

Page 67: Lucius Drupal Development Cursus

API functions in theme Demo API functions in theme aanroepen

Page 68: Lucius Drupal Development Cursus

Theme overriding “Overriding”, dus geen “overwriting”

pages

blocks

tpl.php files in modules

Overriden van tpl files mbv theme functies

Standaard Drupal functions:

theme('item_list')

theme(’table’)

Page 69: Lucius Drupal Development Cursus

Overriding voorbeeld pages

Page-[front|internal/path].tpl.php

blocks

Block-modulename-delta.tpl.php

Block-modulename.tpl.php

Block-region.tpl.php

Block.tpl.php

Page 70: Lucius Drupal Development Cursus

Theme hooks & overriding Functions in modules (theme_%)

http://api.drupal.org/api/group/themeable/6

Overriden van tpl files mbv theme functies

Sinds D6: registreren theme hooks

Theme registry & cache

Page 71: Lucius Drupal Development Cursus

Custom variables in theme http://drupal.org/node/223430

Extra variabelen toevoegen in preprocessing

<?php function template_preprocess_foo(&$variables) {   $variables['foo_list'] = array(    'list item 1',    'list item 2',    'list item 3',  );} ?>

Wijzigen/ toevoegen data aan bestaande variabelen.

Page 72: Lucius Drupal Development Cursus

Theming tools Devel module

Validatie html & css. http://validator.w3.org

Firefox:

Drupal for firebug. http://drupal.org/project/drupalforfirebug

Web developer toolbar

Firebug

Yslow

Total validator

Page 73: Lucius Drupal Development Cursus

Oefening Registreer theme

Screenshot toevoegen

Theme activeren in Front-end

Page 74: Lucius Drupal Development Cursus

Oefening Implementeer statische html

mbv theme files en variables

Page 75: Lucius Drupal Development Cursus

Oefening Regio’s definieren

Page 76: Lucius Drupal Development Cursus

Oefening Themen page, variabelen inladen

Page 77: Lucius Drupal Development Cursus

Oefening Menu items themen

Block themen

List page themen mbv:

Views

CCK

Imagefield (+dependecies)

Imagecache

Image api

+ dependencies

Page 78: Lucius Drupal Development Cursus

Oefening

List page themen mbv menu hook in custom module

Submenu afhankelijk van hoofdmenu tonen

Submenu active state themen

Page 79: Lucius Drupal Development Cursus

Oefening, CCK themen Extra content type definieren

Met CCK velden definieren

Output voor die velden themen

De custom ‘CCK’ velden:

Image mbv: Imagecache

Introtekst

Page 80: Lucius Drupal Development Cursus

Divers Demo Multi site theming

Demo LTR / RTL (Left To Right / Right To Left)

Demo Subtheming

Page 81: Lucius Drupal Development Cursus

Oefening Oefening Multi site theming

Oefening LTR / RTL (Left To Right / Right To Left)

Oefening Subtheming

Page 82: Lucius Drupal Development Cursus

Afsluiting, wrap it up