Drupal

Importing and Exporting Drupal Taxonomy

Submitted by tomo on August 31, 2011 - 3:10am

There are multiple modules for importing and exporting Drupal taxonomies (Drupal switches between using the term "taxonomy" and "vocabulary" like a clinical schizophrenic). Some use CSV format (http://drupal.org/project/taxonomy_csv), others XML (http://drupal.org/project/taxonomy_xml), and still others use a PHP array (http://drupal.org/project/taxonomy_export).

Some of these modules use the same paths for the export and import pages but they are different modules and aren't compatible. If you have both Taxonomy Export and Taxonomy XML installed at the same time they will conflict.

Except for CSV, the other import/export modules need you to create documents in a rather wordy XML or PHP code format, which can actually be more work than entering the terms in manually. Some people may use taxonomy import/export for only the taxonomy definition rather than terms. It's sometimes unclear what happens if you want to re-import duplicate term names later.

What worked best for me was using Taxonomy Manager which gives you an improved UI for organizing terms within a vocabulary. I wish it made editing the core fields of a taxonomy more ajax-y but what it does provide is an easy way to add multiple terms at once, a textarea for pasting in a list of terms, and a way to select where the new terms will go. So you can paste in all the top level terms, then paste in all the 2nd level children of the 1st term and select the 1st term to indicate they will all go under it. As long as you don't have too many different branches, then this can be done fairly easily.

[This blog post is a rewrite of just the main points due to my baby Macbook Pro dying while I was distracted.]

Drupal content types with CCK make it quite easy to add any number of defined fields to an 'object', and with multiple/unlimited values for a field or with node references it's possible to make a Drupal node 'two-dimensional'.

Sometimes you need more. Sometimes you want tabular data, a table, to be part of a node. If the table always has the same dimensions, and at least the same columns for each node, then the above can work through node references and views.

What if you want to add a different two-dimensional table to nodes of a content type, but without knowing the number or labels for the columns and rows beforehand.  For example, you might want to attach a pricing table to a node, with multiple products and multiple ways to price each product.  An example of that might be 5 t-shirt designs, where shirts are priced based on size and quantity ordered.

Read the rest of this article...

Drupal Views UI Filter Fields by Content Type

Submitted by tomo on April 21, 2011 - 4:18am

Late night hack:

You have a lot of fields in a lot of content types. You're creating a view with new display fields but it's a pain to find just the content type fields you want. Wouldn't it be cool if you could just select a content type from a pulldown and see content fields filtered to just the ones in that content type?

Add this bookmarklet to your bookmarks bar:
Views UI Filter

Read the rest of this article...

Drupal Add Comment Form Above Comments

Submitted by tomo on March 24, 2011 - 12:57am

Drupal 6 allows you to either display the comment form below saved comments or on a separate page. There's surprisingly no way to configure the form to appear above the comments. It's hard-coded at the bottom of comment_render to either append the form, or not at all.

There's a micro-module aptly titled 'Comment form above comments' which does the job but does so using string replaces on resulting html so it's not the ideal or elegant solution.

It turns out to be simple to get the same effect in code.

First, we need to "configure" the form to appear on a separate page, but only because we're going to manually show it. You can ensure this configuration with the line:

variable_set('comment_form_location_'.$node->type, COMMENT_FORM_SEPARATE_PAGE);

You could even variable_get and re-variable_set after printing the form if you really wanted to.

Next, output the following where you want to display comments, whether in a PHP code block or node template:

$edit = array('nid' => $node->nid);
print comment_form_box($edit) . comment_render($node);

Another recent discovery was that the comment form is hard-coded to redirect to /node after submitting. This hack, as a module, will get you back to the page you submitted from:

function noredirect_comment_form_submit(&$form, &$form_state) {
    $form_state['redirect'] = ltrim($form['#action'], '/');
}

function noredirect_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'comment_form') {
       $form['#action'] = request_uri();
        $form['#submit'][] = 'noredirect_comment_form_submit';
    }
}

PHP 5.2 has support for showing the percentage uploaded for a file upload in progress. If you're not running Apache as your web server,

Drupal's FileField module automatically detects for and uses upload progress support on the server end. This can either be APC (Alternative PHP Cache) with rfc1867 support or with the uploadprogress PECL extension. In Drupal, the upload progress bar looks like this:

You can check to see if you already have support by going to admin/reports/status.

If the report shows that your server has support yet FileField CCK fields aren't updating the upload progress bar then your server has a problem.

Read the rest of this article...

Getting Drupal to stream video using PHP and the FlashVideo module to manage video uploads is not easy. It involves 5 distinct pieces of software, which means 5 places where things could go wrong with little error logging.

Here's what you need:
1. FlashVideo http://drupal.org/project/flashvideo
2. ffmpeg
3. flvtool2
4. xmoov-php
5. JW Player

Read the rest of this article...

Drupal Administration Menu Missing Links

Submitted by tomo on December 7, 2010 - 5:30pm

Working on a Drupal site that's already half-way started, I noticed that after installing the admin_menu module many links I expected were missing, such as the refresh cache links and several content types under the Content Types menu.

First, I tried clearing out all caches manually via the Performance page.

Next, I tried truncating all cache tables in case cache_menu or another table was corrupted.

Still no go, so I tried disabling, uninstalling, and reinstalling the admin_menu module which should rebuild the admin_menu links in the menu router.

In the end it turned out to be a Wampserver problem as it (as well as Xampp) use PHP 5.3, which Drupal has a lot of problems with. PHP 5.3 has a change from earlier versions in that function declarations like:

function admin_menu_admin_menu(&$deleted)

no longer work. Normally, you'd see that in your error messages.

The solution is to remove the & before $deleted on line 107 in admin_menu.inc in the admin_menu module. This will also make the related PHP warnings go away.

Running 5.2 and 5.3 on one computer using XAMPP (on OSX) is easy by following these instructions: https://gist.github.com/1012774

Theme developer saving to wrong temp directory

Submitted by tomo on September 7, 2010 - 1:36am

After importing a database for a Drupal site from a different server, you may see errors such as:

warning: file_put_contents(/devel_themer_19527646904c852428ef200) [function.file-put-contents]: failed to open stream: Permission denied in /home/tomo/xxx/sites/all/modules/3rdparty/devel_themer/devel_themer.module on line 638.

And if you try to select an element:

Ajax variables file not found.

What's going on here is the files aren't being written to the temp directory which is a Drupal variable stored in the database.  Delete the row from the variables table where name is file_directory_temp and then Drupal will automatically set the variable to the correct directory.

delete from variables where name='file_directory_temp';
or
delete from variable where name='file_directory_temp';

Read the rest of this article...
Syndicate content
© 2010-2014 Saigonist.