Drupal 7 First Impression of Field API and Image Styles


 Thomas Svenson

Two of the most interesting new features in Drupal 7 is the Field API and Image Styles. Basically they are CCK and ImageCache directly in Core.

The advantage of having these in Core can not be underestimated. The media management in Drupal 6 is more or less a nightmare. Yes, almost every feature you need when building a website exist in contributed modules. The problem is that they are in different modules and those are often not possible to use together. Unless you are a developer you are limited to make rather big compromises on the features you end up with.

For Drupal 7 that problem will be history. The Field API and Image Styles will make sure of that.

Creating an Image Style

It is not much different from Drupal 6, but is now more streamlined and the UI is much more polished.

You simply go to Configuration / Image Styles in the Media category. You are then presented with a list of the default core sizes; thumbnail, medium and large. You can edit and override the default settings, but not delete the default styles.

Above the list you have the option to "Add style". A click on it and you are prompted to fill in a name for your new style. After you click on the Create new Style button you get to the edit style page.

This page is similar to the ImageCache presets settings, but more polished. Instead of a long list of options, they are now in a drop down menu. The preview is also above instead of below the settings.

Creating a new style is a snap and a simple scaling style takes less than a minute.

Adding Image Fields to Content Types

This too is not much different from how it works in Drupal 6. It is also much more polished and much easier to understand.

Core comes with a default image field, used in the Article content type, and it can easily be reused for other content types.

One thing that is a little annoying is that very few of the field settings are copied to the new content type when you reuse fields. Description, file paths, image dimensions are left blank. In many cases these wont change when you reuse a field so having to have two browser windows open and then copy and paste between them is not ideal.

When you are done with the settings you go to Manage Displays where you control how the images will be displayed. It is similar to CCK in Drupal 6, but again much more polished and easier to work with.

You have three ways to display an image style; just the image, linked to the content and linked to the original file.

It doesn't take long to get used to the new UI and then it is very quick to get all settings right.

Drupal will then display your images on the pages.

Embedding Images in the Body Text

Often though you want to embed images in the content and that is where it currently gets rather tricky.

The problem stems from how the styled images are generated. That happens when they are first displayed and not when they are uploaded. For images that Drupal is managing the displaying of this is not a problem, but when embedded it is.

Simply manually adding the HTML code, with correct path, where the styled image will be stored, doesn't work. The directory is not created until the first image of that style is created to start with. Therefor you will not see anything in your content.

There is no function to manually trigger generation of uploaded images, at least I haven't found any.

The workaround I am using now is to set the preview in the node edit window to the style I most likely will use. Then the build in preview will generate the styled image.

Then I have a HTML code snippet that I manually edit and past in the editor.

The problem is that this limits how I can use styles for the images and is of course not optimal. Also, if the style is a big image the node edit page looks horrible. Right now I have no problem living with this. After all Drupal 7 is still in alpha.

The Insert module will fix this. It does exist in an alpha version, but it seems that Drupal 7 alpha 5 contains some changes that breaks it. Hopefully that will be sorted soon because I cant wait until I can use it.

Impression so far

I am very impressed about my experiences using both Image Styles and fields. I believe this is one of the most important additions to Drupal Core ever. My reasons for this is, as I mentioned in the beginning, the mess of media management we have in Drupal 6.

Now we have a Core standard that defines a very solid foundation to build on. Projects such as the Media module shows much promise about what we can expect to be able to play with shortly.

Another module I hope to see ported to Drupal 7 is the ImageCache Actions module with all its great features for manipulating images on the fly.

Those two modules, and sub-modules would combined with the Insert module offer an extremely powerful and flexible media solution for websites.

Did I say that I can't wait until I can play around with them?