Drupal

In this example, we just use checkboxes to determine whether textboxes are displayed.

One of the fundamental ideas of having a form change based on selections within the form is that the form is reconfiguring itself based on $form_state. So here, the generation of the form is driven by $form_state['values']. If the checkbox for last name is checked, then we generate a textfield for last name.

Topics: 

Form API Changes for Drupal 7, Part 1: $form_state changes

You may know that lots of delicious things have happened to Drupal's Form API in Drupal 7. (Only a geek can say "delicious" and "Form API" in the same sentence. Try it!) The finest minds in the business have been working on it, I can assure you. Give effulgentsia, fago, frando, and chx a big hug when you see them, because Form API is much improved. (Sorry to those of you I forgot to name, but THANKS!)

I'm going to do a series covering Form API changes, starting with this one. I won't attempt to cover the deep details, just the things that ordinary developers might use:

  1. $form_state changes and form builder function signature changes
  2. AJAX Forms changes
  3. New properties (#attached and many friends)

Let me know if you have other topics to suggest.

OK, to business. This article is mostly parroted from the api.drupal.org topic: Form Generation. Thanks to Alex Bronstein (effulgentsia) for his reviews and contributions to that doc.

Don't forget that the form builder function signature changed!

In Drupal 6 the form builder function looked like this:

Drupal is great at handling multilingual situations, but how do you make user-contributed content in multiple languages accessible to those who can't read them?

The Translatable Regions module tackles this by using the automated Google AJAX Language API via the jquery-translate plugin.

What do you have to do?

  • Install the module.
  • Decide what selectors you want to have translation buttons.
  • Configure the selectors at admin/settings/translatableregions.

Whenever those selectors appear on the page, a button is added offering to translate to many languages, the default being the browser language.

Here's an example of the use on user profiles on http://warmshowers.org.

New Queue and Menu Examples for Examples Project

The Examples for Developers Project aims to provide high-quality, well-documented API examples for a broad range of Drupal core functionality. You can download the code from the project page, view it on api.drupal.org, or experience it (for several of them) at drupalexamples.info.

Recently, we've added two new example suites:

PHP 5.2 on Ubuntu 10.04 Lucid Lynx

Edit 2011-11-23: Since Ubuntu 9.10 (Karmic) is now out of support, the repositories to use for it have changed to old-releases.ubuntu.com. I've changed the karmic.list files attached. Please be aware that although 10.04LTS is still supported for years still, 9.10 is out of the support window, meaning that security issues in these packages will not be fixed.

Update: Look here to solve same problem with Ubuntu 10.10.

Lots of us are starting to run Drupal on Ubuntu 10.04 Lucid Lynx, and of course, Lucid comes with PHP 5.3, for which Drupal 6 is not yet ready.

I've seen a couple of fine recipes, but here's mine, with the files you need attached.

Update: You'll probably want to look at Khalid's more extensive discussion of various ways to do this.

Essentially, all you have to do is tell the apt system where to find Karmic packages and then tell it that you want it to use Karmic's PHP packages.

DrupalCon: Drupal 7 AJAX and Javascript

Rob Loach, Kat Bailey and I will be presenting Drupal 7 AJAX and Javascript Monday, 3-4pm, in room 307.

Here are the basics:

  • The new AJAX Framework
  • AJAX forms, with a complete how-to and sample, easy to understand code.
  • The fantastic new #states feature for dynamic forms.
  • D7 Javascript changes from D6.
  • Using Javascript Libraries.

We've made great strides in Drupal 7. Come and hear about it.

If you used AHAH in D6, you're probably afraid of AJAX forms. But if you never used #ahah, you'll walk out of the room feeling competent to try out #ajax. You can't believe how easy it is now.

D8 Software Process Improvement Discussions at Core Dev Summit

We can substantially improve our core software development process with some simple steps in Drupal 8.

<

ol>

  • Improve our issue queue setup on drupal.org.
    Our issue queue works the way it does because Drupal worked that way a long time ago. We can do better than that.
    • Each core issue should have an issue summary, and the issue summary should be correct and complete before commit.
    • An issue should have links to related and dependent issues.
    • There should be checkoffs for docs, usability, security, etc.

    Of course we know how to do this with Drupal. Let's do it. Related issues: Improve the workflow for documentation of core API changes and Provide a mechanism for issue meta discussions

  • Drupal 7 FAPI's #states: A Great New UI Improvement For Forms

    The little-known #states feature has gone into Drupal 7, and it rocks.

    Before you read on, try this dynamic form live at d7.drupalexamples.info. It's developed without using a line of javascript, just plain Form API.

    Essentially, you can provide dynamic behavior in a form based on changes to other elements in the form. An easy example: Often you only need to collect information if a particular element is selected. If they select type=student, you don't have to require them to fill in a further "Employer" field.

    The new #states example in the Examples module's Form Example shows how a dynamic form can work. You can try it out live as well at d7.drupalexamples.info.

    Examples module now on api.drupal.org

    Thanks to excellent work by api module maintainer drumm, all of the examples in Examples module are now available on api.drupal.org.

    If you're not familiar with Examples module, it's an attempt to provide easy-to-understand examples of key Drupal APIs, so that developers have a known source of a working example they can understand. Back in the day, there were a few examples in the Documentation branch of contrib in CVS, but they were poorly maintained and nobody knew how to improve them. All of those have been moved to Examples (for D6 and D7) and updated.

    So with Examples now on api.drupal.org, you have more than one way to access the various examples:

    Drupalcon: Best Practices in Contrib Development

    Mark your calendar for Wednesday the 21st at 3pm: Greg Knaddison, Dave Reid, Derek Wright, Jennifer Hodgdon and I are doing a panel presentation on how to maintain and support a contrib module or theme. It will cover:

    Community management: Enlisting help, finding maintainers and co-maintainers, handling abandoned projects, dealing with duplication, handling the issue queue.

    Drupal project management: What's expected of a maintainer, code and release management.

    Coding issues: Coding standards, documentation, namespacing, simpletest, internationalization.

    Resources for maintainers.

    If you're a maintainer or might become one, or want to start helping overburdened module maintainers by helping out with these responsibilities, come and hear about how to contribute to the community more effectively and efficiently.

    Pages

    Subscribe to Drupal
    Drupal theme by Kiwi Themes.