Apress

Pro Drupal 7 Development

3rd Edition

By Todd Tomlinson , John VanDyk

Pro Drupal 7 Development Cover Image

Pro Drupal 7 Development is geared toward professionals who need to deploy and customize Drupal. This book delves deep into the internals of the Drupal 7 system and teaches you everything you need to know to deploy a highly customized and optimized Drupal installation.

Full Description

  • ISBN13: 978-1-4302-2838-7
  • 720 Pages
  • User Level: Intermediate to Advanced
  • Publication Date: December 28, 2010
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $49.99
  • eBook Price: $34.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

Pro Drupal 7 Development updates the most popular development reference for the release of Drupal 7. With several new and completely-rewritten essential APIs and improvements in Drupal 7, this book will not only teach developers how to write modules ranging from simple to complex, but also how Drupal itself works.

  • Learn the Drupal APIs and major changes in Drupal 7
  • Learn how to write Drupal modules using the APIs
  • Learn proper development practices and how to become a contributing community member

What you’ll learn

    • How to get started with writing basic modules
    • The flexible Drupal APIs and how they interact with modules
    • How new features in Drupal 7 make modules even more powerful and sophisticated
    • Best practices when developing in Drupal (coding standards, help developer modules)
    • How to write safe, secure, and tested code
    • How to contribute modules back to the Drupal community and maintain their modules using the Concurrent Versions System (CVS)

    Who this book is for

    This book is for existing Drupal module developers wanting to learn about Drupal 7 and people already knowledgeable in PHP who are interested in developing for Drupal. Simply put, if you are working with Drupal, then you need this book.

    Table of Contents

    Table of Contents

    1. How Drupal Works
    2. Writing a Module
    3. Hooks, Actions, and Triggers
    4. The Menu System
    5. Working with Databases
    6. Working with Users
    7. Working with Nodes
    8. Working with Fields
    9. The Theme System
    10. Working with Blocks
    11. The Form API
    12. Manipulating User Input: The Filter System
    13. Searching and Indexing Content
    14. Working with Files
    15. Working with Taxonomy
    16. Caching
    17. Sessions
    18. Using jQuery
    19. Localization and Translation
    20. XML-RPC
    21. Writing Secure Code
    22. Development Best Practices
    23. Optimizing Drupal
    24. Installation Profiles
    25. Testing
    26. Database Table Reference
    27. Resources
    Source Code/Downloads

    Downloads are available to accompany this book.

    Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

    Errata

    If you think that you've found an error in this book, please let us know about it. You will find any confirmed erratum below, so you can check if your concern has already been addressed.

    * Required Fields

    On page 14:

    files[] = annotate.admin.inc
    configure=admin/config/content/annotate/settings

    Not sure how important this is, but the initial .info file has the additional files array element and surely the configure path is wrong? As we read on we realise that we should state the dependency on php 5.2 too.

    On page 34:
    There is a small typo. Instead of implementing the function beep_user_login, the code only implements beep_user.

    On page 40:
    A reminder to enable the Beep module is necessary - otherwise the action doesn't show up.

    On page 67:

    "If you wanted to use the values passed in the URL... "
    is followed by sample code for menufun_hello(...) which fails to include arguments for the additional values from the URL, yet uses the values in the t(...) function. Pretty sure that's an error.

    Notes:
    1. The $last_name arg is shown with fancy quotes, indicating ad hoc manual editing (ie: not copied from working code).
    2. The args I expected are indeed shown at bottom of p67, where menufun_greeting(...) does show the extra args.

    On page 80:
    In function menufun_menu_alter all lines (3) with

    $items['logout']

    should be

    $items['user/logout']

    On page 85-86:

    The code references 'access arguments' => TRUE, throughout the milkshake.module code, however this will throw a warning. From researching it appears this used to work in Drupal 6 but no longer does for Drupal 7.

    The problem is that drupal now expects that parameter to always be an array.

    I replaced with 'access arguments' => array('access content') and was able to access the module menus. This may not be the best solution, but it works and is at least better than the code as-is.

    On page 128:
    Listing 6-6. loginhistory.module :
    its better to use
    $builder['#account']->uid
    instead of
    $user->uid

    because if you visit another user account you will find your own login counter not the current user login counter

    On page 145/146:
    The last argument of the $callbacks path is with a dash instead of a underscore.
    So it is not:

    $callbacks['node/add/job_post']…

    but:

    $callbacks['node/add/job-post']…

    On page 147:

    In code comments the word 'job' is replaced by 'joke'. These are the places:
    // Allow if user's role has 'create joke' permission.
    should be
    // Allow if user's role has 'create job' permission.

    // Allow if user's role has 'edit own joke' permission and user is
    // the author; or if the user's role has 'edit any joke' permission.
    should be
    // Allow if user's role has 'edit own job' permission and user is
    // the author; or if the user's role has 'edit any job' permission.

    // Allow if user's role has 'delete own joke' permission and user is
    // the author; or if the user's role has 'delete any joke' permission.
    should be
    // Allow if user's role has 'delete own job' permission and user is
    // the author; or if the user's role has 'delete any job' permission.

    On page 147:

    In source code any call of user_access() should have a first parameter string ended by 'job post', not only 'job'. I.e:

    if (user_access('create job', $account)) {

    should be

    if (user_access('create job post', $account)) {

    and so on.

    On page 157:
    Refers to function hook_access(), but hook_access() is not used in Drupal7. I believe it was replaced by hook_node_access().

    On page 264:
    $form['warning'] = array(
    '#markup' => t('We log all login attempts!'),
    '#weight' => -5
    );

    should be

    $form['warning'] = array(
    '#markup' => t('We log all login attempts!'),
    '#weight' => -5,
    );

    On page 349:

    on page 349, Drupal 7 does not support AND and OR on url for taxonomy

    On page 410:
    Near the end of the function plusone_vote, code reads:

    drupal_json(array(

    but there is no such function in drupal 7. Should be maybe:

    drupal_json_output(array(

    On page 538:
    Instead of:

    $field = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'type' => 'taxonomy_term_reference',
    // Set cardinality to unlimited for tagging.
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
    'allowed_values' => array(
    array(
    'vid' => $vocabulary->vid,
    'parent' => 0,
    ),
    ),
    ),
    );
    field_create_field($field);

    It should read:

    $field = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'type' => 'taxonomy_term_reference',
    // Set cardinality to unlimited for tagging.
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
    'allowed_values' => array(
    array(
    'vocabulary' => $vocabulary->machine_name,
    'parent' => 0,
    ),
    ),
    ),
    );
    field_create_field($field);

    the key difference being the «vocabulary key» instead of «vid» in the array nested in the «allowed_values» array under settings. The original code does not attach the vocabulary previously created to this field, thus leading to an error when a new content is created (something like: ... undefined index: vocabulary...).