Introduction to Drupal Basics

Post on 14-Jun-2015

5,867 views 1 download

Tags:

transcript

DrupalIntroduction to Drupal Basics

Juha Niemi, 2009

Drupal vs. My-own-CMS

• Powerful ready-to-go platform to produce web services and applications

• Open source - Free to use and free to modify

• Open API’s provides easy expandability

• Tested and safe. Regular security updates

• Lots of prepared core functions to ease simple coding tasks

• Lots of ready-made modules and code snippets available

Drupal vs. Some-other-CMS

• Power and scalability based on modular architecture and API’s

• Less out-of-the-box modules and features than some others

• More development tools and small functions that enable the user to build almost any kind of web application

• Active community, helping hand available at drupal.org

File structure

• Extension modules and themes always to sites/ folder

• The modules and themes in sites/all are shared through all sites (multisite configuration)

• Sites/mysite.com contents available only to one specific site

Drupal standalone installation

• Easy installer wizard asks for database access information and stores them in settings.php

• Installer writes the basic tables and data into database

• By default sites/default is used

• Available as any hostname

Drupal multisite installation

• Easies way to install a site in multisite configuration:

• Create sites/mysite.com folder (mysite.com is your site’s hostname)

• Duplicate sites/default/settings.php to that folder

• Create sites/mysite.com/files folder and give 777 permissions

• Run installer wizard

Drupal terminology INode

• The general term for all stored content; articles, pages, news...

• Ability to create new content types with a simple GUI (D5+)

• Ability to extend content types beyond standard title+body fields (with CCK module)

Taxonomy

• Content categorization system in core

• Predefined categories (vocabularies)

• Hierarchical terms

• Free tagging

• Single or multiple terms per content

• Multiple vocabularies per content

Drupal terminology II• Block

Small pieces of content that are usually presented in sidebars: menu links, news topics, etc

• Module

Extension modules can expand and modify Drupal’s core funcionalities and normal behaviours

• Theme

The layout and output in general what Drupal generates in HTML

• Core

Drupal core files, that should never be modified, added or removed

User managementUsers

• User UID 1 is the root user

• Profiles with custom fields

• Can be used with external authentication (LDAP, OpenID)

Roles

• Access control defined by roles

• User can have multiple roles

Access to nodes (in core)

• Access granted per role / content type

• Cannot restrict read access by default, except for all content

ACL modules (nodeaccess)

• Extends the core access control

• Show/edit/delete grants can be given for roles and individual users. Even per node.

Modules• Always store under sites/ folder

• The core provides ‘hooks’ that modules can attach to

• Some very often used hooks:hook_form_alterhook_cronhook_nodeapi

• Developer resources available athttp://api.drupal.org

Themes

• PHPTemplate engine (other theme engines available)

• Zen theme (xhtml/css) - great, clean way to start theming

• Overriding theme functions without modifying or breaking any code in core/modules

• Block regions - can be added when needed

Essential module: Views

• GUI to build queries from content, users, files

• Multiple displays (page, block, embed)

• Type how the data is selected from database (full nodes/fields)

• Output styles (list, table, node view)

• Filters (=‘WHERE’ clause), sort order definable

• Arguments provide way to modify the filters based on URL

Essential module: CCK• Drupal allows creation of new

content types (e.g. page, news, event)

• Regular content type only has fields title and the body text

• CCK allows content types to be extended easily with additional fields

Some commonly used fields (fields are modules that expand cck)

• Text field

• Select list

• Image field

• File field

• Date field

• Link field

Node API

• Enables modules to interact with nodes. Data can be added, modified and removed

• Additional data can be shown when node is shown

• hook_nodeapi is called when nodes are stored, edited, viewed, deleted, searched, etc...

Form API

• API that handles programmatical form creation and renders them as usable HTML forms

• All system forms and forms provided by additional modules are created using Form API

• Modules can modify forms that are created by other modules

Menu System

• URL to callback mapping

• Modules can implement new menu items, that initiate a function when a user enters a certain URL

• Menu items can be displayed as

• Links in navigation

• Tabs

• Hidden callbacks

Input formats

• Filtered / Full HTML for standard text and HTML content

• PHP Code allows PHP code to be run as a part of the node

• Simple code can be put in nodes

• More complex code should be put in a module instead

• Input format modules can be added (wiki, textile, etc)

URL aliases

• Essential part of succesful search engine optimization

• Manual paths can be given to any node or other paths

• Pathauto provides automatic URL creation mechanism based on user-definable terms and other data, for example mysite.com/news/2009/01/05/my-news

Updating Drupal

• Drupal core should be kept up-to-date

• Updates can be rolled by overriding the core files and run update.php script

• Minor version updates should be always safe

• Major version updates are usually not recommended because of module incompatibilities and significant code changes

• Backup the database manually prior to every update

Good practices

• Root -user should be used only for low-level configuration and an additional admin role should be created

• Use a right role for the right kind of task when testing

• End user usually runs into problems that the admin role didn’t encounter

• Set-up framework first before adding any content (languages, user management, pathauto’s, etc...)

Valuable resources

• Pro Drupal Development (2nd edition) bookJohn VanDyk, Apress 2008

• http://drupal.org forums and module issue cues

• http://api.drupal.org

About the authorJuha Niemi (Mr.) is the lead web developer and

entrepreneur at Juha Niemi Design Ltd, Finland. He has been using and committed to

Drupal since 2006.

http://www.jnd.fi