# Question
Title: How can I attach an existing server image to an image field rather than uploading a new image file?
Is there a module or some other way of attaching an image to an image field by selecting the image from existing files on the server rather than upload a new image?

I'm working on a project where many nodes have an image field. That image is displayed in various places at different sizes using image styles.

The users are migrating from another system and they're very used to the "image library" concept. They like to upload images that they will later use in various places around the site. The standard image field on a node only lets you upload from the local file system.

Ideally we'd like to have a "browse server" button instead of the upload button but end up with the same resulting image field.

The Media module comes tantalizingly close and I'm sure we'll use it for videos etc but it creates a media asset field, not an image field which I don't think can be resized with image styles and used so easily in views etc.

I tried the image picker module late last night. Maybe I need to try it again but I don't think I quite understood it. We don't really want resizing and create thumbnails etc on the node edit screen. We really just want a way to create an image field where the path points to an existing file somewhere below /sites/default/files. The files will be uploaded with something like IMCE.

Thanks for any ideas.

# Answer
I think Filefield Sources along with IMCE does what you need.
> 9 votes

# Answer
You can also use IMCE for filefield that was just released. IMCE for File Field allows users to select files from IMCE File Browser for file fields. It supports FTP uploaded files by automatically registering them as IMCE files thus making them usable in a file field.
> 2 votes

# Answer
The Media module is also useful for images, but you can also use a regular image field and use the Media widget to upload or select images from the server. The field remains the same, only the way for the image to get inputted changes. I believe you even have the possibility to search and filter in the widget that comes with Media module 2.x
> 2 votes

---
Tags: media
---


# Question
Title: drush - which folder for install on VPS / root server (newbie)
good evening,

new to drupal - I want to install drush on my linux root-server, which **runs OpenSuse Linux** my friend does the root adminstration.

What is aimed: i want to work on all my drupal domains - but i guess that i do not need root access. Can anyone please tell me which folder I should use to install drush?

Do you need to have my file structure? Well if so, i can give you later this week.

Well a friend told me to take `$HOME/local/drush,` but cant we put it anywhere; we just need to make sure that drush is in our $PATH. See the README.

or what is with this hint top take the domain path like so

```
/var/www/vhosts/mydomain.com and echo $HOME gives me /root.

```

So would I create a 'local' directory in /root and install drush there

so the path would be `/local/drush/drush.php?` I am not just asking from a drush point of view but also from a server file structure point of view ie that I think I am not allowed to upload stuff to some server directories.

But wait - i do not want to have all root rights - is this doable?! Can i install drush into the www-directory where all the domains are rooted!?

Thanks for any and all help - it will be greatly appreciated as allways. zero-your drupalnovice

hi there **just an update**:

if someone wants to update the sites trough the terminal?

in that case:

I don't think it's matter where we put it, we could put it in the root if we'd like, once installed after pear-chanell....

http://drupal.org/project/drush

we can update any site on our

srv/www/htdocs

we just have to get inside the htdocs/site1 and type drush sm update do our things and get into our new site htdocs/site2 and do whatever we want to do there with drush too.

and the best thing is: one install works on all our sites.

that rocks yeah

# Answer
You can install Drush in the folder of your choice. Preferably outside www-directory. But make sure the drush command is executable.

To make drush command executable on all domains just create a symlink to drush. For e.g

$ ln -s /path/to/drush/drush /usr/local/bin/drush
> 4 votes

# Answer
You didn't say much about the distribution you're using. but i would suggest searching for a package for your Linux distribution. Installing it that way usually is the safest and easiest. There is one for Debian/Ubuntu and Gentoo as far as i know.
> 5 votes

---
Tags: 7, users, drush, installation
---


# Question
Title: WYSIWYG Image Upload in Basic Page (CKEditor and CKFinder)
I was able to use CKEditor and CKFinder to add in-body image upload capability for article nodes. However, the functionality was not transferred to basic page nodes. What do I miss? Thanks!

# Answer
If it looks like you can upload nodes to your basic page, but they're not displaying then you're probably using filtered HTML as your page filter. If you don't have the ability to add pictures at all, then look at the configuration of CKEditor and you may need to add the appropriate button for the content type.
> 0 votes

---
Tags: media, wysiwyg, files
---


# Question
Title: Setting a View's Menu Item to a Sub-Menu
I'm using Drupal 7.10 and Views 3.1.

This seems like it should be simple but I can't find an answer. I have a menu structure similar to the following:

```
Main >
    About Us >
        History
        Contact Us
    Members >
        Wiki
        Tasks

```

The problem is that tasks is a view page but I can't seem to add the view to anywhere but a direct child of `Main`, there doesn't seem to be a way to add it so that it is a child of `Members`.

I can simply add a link to the page by adding another menu item but this causes the sub-menu to disappear so that, in this case `Wiki` disappears.

Is the only way to do this to add a block and add that block to a page? Or am I missing something?

Thanks!

# Answer
> 6 votes
Okay, so if I understand correctly you have a View Page that is part of your main site hiearchy (main menu). Unfortunately you can only assign a View (at least through the View interface) to a particular menu, but not any of the children of that menu. This should be a feature request in the Views issue tracker.

What you need to do is go edit the Main Menu through Administration -\> Structure -\> Menus, list links for Main Menu, and then find your Tasks page that was dropped in their (should be on the first level) and re-position it to where you want it in your menu hierarchy.

---
Tags: 7, views, routes
---


title: Pages by taxonomy

text:
# Question
Title: Pages by taxonomy
I'm creating a dummy website to learn Drupal 7. The idea is to build a car garage.

I added the *Cars* vocabulary, containing a list of car models.

* BMW
    + 1 serie
        - 1.18D
        - 1.20D
    + 3 serie
        - 3.30D
        - 3.35D
    + 5 serie
* Mercedes
    + A-Class
    + C-Class

I used the *Taxonomy Menu* module to display the vocabulary as a menu item in the main navigation. I want the child terms to be shown on this page. When I click on a specific term, I would like it shows the child terms page.

I also installed the *Views* module, and made a view that would filter like by vocabulary machine name, but it show everything within the vocabulary.

# Answer
> 2 votes
When creating a view, choose for Show: Taxonomy Terms instead of the default selected Content. Than you can define the Type of you terms and using a contextual filter (it is for Drupal 6, but the idea is the same) only show the terms that are a child of term page your on.

# Answer
> 0 votes
Also look at the default replacement of the taxonomy pages supplied by views. The view has an argument that is a taxonomy term (i.e. show me a subset of cars based on the current URL/term) but there is a depth modifier that says also show me cars that are also tagged with the parent term or child terms (or not at all).

---
Tags: views, taxonomy-terms
---


title: Filter by taxonomy in Views table

text:
# Question
Title: Filter by taxonomy in Views table
I have a vocabulary Area for classifying maths problems, with two parent terms (Pure and Applied) and appropriate child terms (Geometry, etc.) under each. Problems (a content type) are tagged with the appropriate areas of mathematics that they cover.

I also have a table page defined in Views with filter criteria Type (= Problem) and Area (exposed), for listing all the problems.

The problem I have is as follows: If someone selects \`Applied Mathematics', nothing appears, because Problems are only tagged with the child terms.

How can I get all the Problems to show up?

In Drupal 7 I should add!

# Answer
> 2 votes
If you look at the default Taxonomy Term view provided with views, you'll see that it has a contextual filters `Content: Has taxonomy term ID (with depth)` and `Content: Has taxonomy term ID depth modifier`. Both are needed. If you look at the description for the Depth field for the first filter you'll see the following:

> The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).

In your case fruit is applied and apple is, for example, Geometry. So if you specify a depth of 1 or higher you should get the behaviour you want.

---
Tags: 7, taxonomy-terms, views
---


title: Using Panels to display Taxonomy terms

text:
# Question
Title: Using Panels to display Taxonomy terms
My Drupal 6 taxonomy terms are linked to two types of content, one is called Results (text) the other is a Photo. Is it possible through Panels to develop a node where a user can select a term via a drop down menu then it will display only the Results and the pictures related to that term? My goal is to have all of the results together in their own region and the same with the photo.

If it can be done, is there a recommended recipe I should follow?

If it can't be done any suggestion on how to do it?

# Answer
Drupal Panels can do this using the Views module. The two modules work very well together to arrange your content on a page, but Views is the workhorse for sorting through the content and selecting what you want. Check out the video series "Taming the Beast" at Nodeone.se for how to use Views. They also have a series on Panels/Page Manger that shows how to link them.
> 1 votes

# Answer
I don't think panels is required here at all. Create one view that returns content of type Results and Photo. Have the content type as a field that will be hidden from display and then group your results by the content type.
> -1 votes

---
Tags: taxonomy-terms, panels
---


# Question
Title: Calendar with multiple content types on multiple field types
I'm hoping to set up a calendar using date + calendar. I have 2 content types, one of which specifically has a date field, the other of which I want to display on the calendar using the published date. How could I go about doing this? I can get the first content to display under two different dates, one for published date and the other for its date field, but obviously this is not the desired behavior.

The following issue kind-of comes close, but not quite: How to use multiple content types in a "Calendar" View sorting by the field type of "Date"?

# Answer
You're not going to get Views to add the 2nd content type (and only the 2nd content type) in this way, at least not through the Views UI. You could do this by programmatically altering the view's query or something like that, but it would be no fun.

I would recycle the "date" field from content type a into content type b and set the default value = now; that way when a new node is created it will have that value by default.
> 1 votes

---
Tags: 7, datetime
---


title: Hierarchical taxonomy structures

text:
# Question
Title: Hierarchical taxonomy structures
I am wondering about how to set up hierarchical taxonomies. For example say I have a vocabulary called Vehicle Make which consists of terms Audi and Honda, then I have a further vocabulary called Vehicle Model which consists of A4, Civic and Accord. So now say I wanted to create a vehicle registration content type with term reference fields corresponding to the two vocabularies listed above. Is there a way to define an is-a relationship between these vocabularies, I.E. an Accord is a Honda and an A4 is an Audi and therefore the selection in the Vehicle Model term reference would be dependent upon the selection in the Vehicle Make term reference. So if I select honda for the make I should be able to select Accord or Civic for the model and if I select Audi I should be able to only select A4. Is this something that can be done with Drupal taxonomy system?

# Answer
Yes but they would not be 2 vocabularies, they would be hierarchical terms in 1 vocabulary, ex:

```
Cars
-Ford
 -Focus
 -F150
-Mazda
 -6
 -9
 -Protege

```

You can have infinite levels of parents.

This module would probably be a huge time saver for you: http://drupal.org/project/hierarchical\_select

Edit: I should add that since Drupal 7 provides taxonomies as fieldable entities, you could very easily attach a "Car photo" field or the like to your "cars" vocabulary and achieve a lot of functionality rather quickly.
> 3 votes

# Answer
You can construct your hierarchy using the core module taxonomy. Go to admin/structure/taxonomy, create your vocabulary and add your terms. The form that lists your terms precedes the name with a graphic arrow widget (points in four directions. Selecting that widget and dragging can reposition the terms in parent child relationships, and your done! The Taxonomy Manager module can help you add large quantities of terms to a vocabulary very quickly as well.
> 5 votes

---
Tags: taxonomy-terms
---


# Question
Title: Is there a Drupal Wiki documentation site?
Like on other Drupal support sites, there are many questions and very few answers here. The community appears to divide into two Drupal groups, coders and users. I am a user trying to make a website out of the tools available, not invent a new module.

One problem here is that a question quickly gets lost and answers harder to find. I am finding parts of answers at various sites and would be happy to contribute them to a central depository. Anyone know where that might be?

Added Related Question: I see a checkbox below the answers box for a Community Wiki. Does this option tag items for use in a Wiki about Drupal? If so, How do I filter to see them?

# Answer
> 4 votes
http://drupal.org/documentation is home to our documentation. While not usually referred to as a "wiki", most pages are editable by anyone with a drupal.org account.

Also consider connecting with the Documentation Team \- there are other users who can help you get started.

# Answer
> 0 votes
Interestingly enough, I have found a potential Drupal Wiki location on this site. The tags that questioners assign to their questions have brief descriptions and if selected, lead to an expand description. I have begun to add links and other information to some of these tags. ***IF YOU LEARN SOMETHING YOU WANT TO SHARE WITH OTHERS, CONSIDER ADDITING IT TO THE TAG DESCRIPTION.***

---
Tags: 7
---


# Question
Title: How can menu tabs be relocated to another region?
I want to move menu tabs to occur in the main menu region instead of immediately above the content. I cannot identify a block that contains them. Is there a module, template location or a hook for controlling their display?

# Answer
"I cannot identify a block that contains them." There is not a block that contains these. In Drupal 7, these tabs are a variable called $tabs found in /modules/system/page.tpl.php.

You could suppress these tabs by overriding page.tpl.php in your theme.

To put them in another region, you could:

1. Implement hook\_preprocess\_page(&$variables, $hook) in your theme's template.php or in a custom module.
2. Copy the contents of the $variables\['tabs'\] array key into another region.
> 3 votes

# Answer
If you want them in a block so you can easily place them using the UI, you can use the Local Tasks block or Omega Tools (Sub module called Delta Blocks) or Blockify modules.
> 3 votes

# Answer
They are in the $tabs variable that's available to page.tpl.php so changing where it's printing them is the quickest way.
> 2 votes

# Answer
I found another way as well. The breadcrumbs can be placed in a panel. I am creating a site using the Panels Everywhere module and have bypassed the standard theming process using page.tpl.php which gives me a clean slate to work from and have created a mini panel that contains my main menu, breadcrumbs and menu tabs in one package.
> 0 votes

---
Tags: 7, theming, routes
---


title: Get a url alias as a field value?

text:
# Question
Title: Get a url alias as a field value?
Is there any way to get this? I can get the node ID and link to a node using node/nid, but then I have to mix pretty links that pathauto gives me with ugly ones.

Is there any way to get the url alias as a field value when building a view?

Edited: My question was wrong.

# Answer
> 17 votes
Updated Answer for your Updated Question:

In views you will need to add one of 2 fields. 'Content: Path' is likely the one you are looking for though. Below is where to find it.

**1) First you need to open your view for editing.**

**2) Next, find "Content: Path" and add it to your view.**

**3) Side note** \- If you would like a simple link you can add "Content: Link" in stead. You also have access to Content: Edit, and Content: Delete among others.

---

**Pre-update:** I will update this answer if you clarify your question. Specifically what you mean by 'as a field value.'

As I currently understand your question I think this may be what you're looking for.

I believe you will need to use drupal\_lookup\_path() to find a path alias.

Example:

```
drupal_lookup_path('alias',"node/".$node->nid);

```

> **Source: Drupal Community Documentation for drupal\_lookup\_path()**
>
> Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
>
> **Parameters**
>
> $action One of the following values:
>
> **wipe**: delete the alias cache.
>
> **alias**: return an alias for a given Drupal system path (if one exists).
>
> **source**: return the Drupal system URL for a path alias (if one exists).
>
> $path The path to investigate for corresponding aliases or system URLs.
>
> $path\_language Optional language code to search the path with. Defaults to the page language. If there's no path defined for that language it will search paths without language.
>
> **Return value**
>
> Either a Drupal system path, an aliased path, or FALSE if no path was found.

---
Tags: 7, views
---


# Question
Title: Drupal sends emails to Hotmail but not to other accounts
I have a problem when Drupal sends email messages. I use the Rules module for doing it.

When the email is sent to a Hotmail account, the email is sent successfully; with other accounts (e.g. Yahoo, Gmail), the email is not received. The "recent log entries" shows the email as successfully sent, but the account doesn't receive it.

# Answer
> 1 votes
Likely the problem is not in drupal, but in server environment. You could use Drupal SMTP Support module to bypass this.

# Answer
> 0 votes
This may be due to the MIME Format. See Multi-part message in MIME format wrong plain text format and the patch reported there.

---
Tags: emails
---


title: Importing SQL databases

text:
# Question
Title: Importing SQL databases
The website I am creating needs to import a medium sized database into my new Drupal system. I will be able to do an SQL export on the old database but I am wondering if there is a good module that my facilitate this kind of transfer. Also, I might like to make some changes to the structure of the database, for example one table I will need to import has 39 integer that I would like to move into one single vector, is this something I could do with an existing module or would I need to write some php code to handle this?

# Answer
> 5 votes
The Migrate module, not to be confused with Backup & Migrate, can provide this functionality. The project page says it better than I can.

> The migrate module provides a flexible framework for migrating content into Drupal from other sources (e.g., when converting a web site from another CMS to Drupal). Out-of-the-box, support for creating core Drupal objects such as nodes, users, and comments is included - it can easily be extended for migrating other kinds of content.

Deliberately, it's fairly complicated module. Here's a talk on it from DrupalCon denver

# Answer
> 4 votes
In Drupal 7, the Feeds module may be what you're looking for. You may need to export as RSS/Atom, CSV or XML first but you can use Feeds to import the data into Drupal. You can set your field types as you configure the content type you're going to import into.

I find Feeds is very well suited for one time imports that contain simple data. IMO if you need to do frequent or giant imports or would simply rather use the table you've already created I would consider creating a custom module implementing hook\_schema() and hook\_views\_data() to access your table using Views directly.

# Answer
> 0 votes
You could leave your data structure and integrate it with views, which gives you a powerfull reporting tool. Have a look at the maillog module as an example of integrating dB tables with views.

---
Tags: importing-exporting, database
---


# Question
Title: How to change the redirect URL of a form that's already been set in a module?
I'm using the node gallery module in Drupal 6, and I'm having some trouble modifying it to suit my needs. When the manage images form is submitted, the function node\_gallery\_manage\_images\_submit is called. At the bottom of the function is this code:

```
$form_state['redirect'] = 'node/'. $gid;

```

I need to change the URL of that to 'my\_url' instead of node/123. Using the form\_alter I can set `$form['#action'] = 'my_url';` and when the form is submitted it goes to that page. But the module does a lot of image processing before then, so I have to use the redirect after that's all done. I also tried `$form_state['#redirect'] = 'my_url';` but that did nothing. Replacing $form\_state with $form does nothing either. Can anyone please help me out? I'm pretty new to Drupal forms and this is the first time I've really had to work with them. I know there has to be some way to do it, I just can't figure out how.

# Answer
> 4 votes
You should be able to achieve this by adding your own submit function to the end of the submit handler array and overriding `$form_state['#redirect']` there. Example code:

```
function mymodule_form_node_gallery_manage_images_alter(&$form, &$form_state) {
  $form['#submit'][] = 'mymodule_node_gallery_custom_submission';
}

function mymodule_node_gallery_custom_submission(&$form, &$form_state) {
  $form_state['redirect'] = 'my_url';
}

```

# Answer
> 1 votes
As reported in other, but change a bit in submission handler like this

```
function mymodule_node_gallery_custom_submission(&$form, &$form_state) {
    /* for D6 */
    $form['#redirect'] = 'my_url';
    drupal_redirect_form($form, true);
    /* for D7
    $form_state['redirect'] = 'my_url';
    drupal_redirect_form($form_state);
    */
}

```

---
Tags: 7, nodes, forms
---


title: Set language for a panel page

text:
# Question
Title: Set language for a panel page
How do I create multiple translations of a panel page? My homepage is designed with panels and I have both english and spanish content. For nodes everything is fine but I can't figure out how to do the multiple language thing with panels.

# Answer
I haven't attempted this myself, but I would assume you can pass the current selected language in as a context and then trigger different variants of the panel based on that.

You could then also trigger individual pane visibility based on the current language (i.e don't show this untranslated pane to German visitors).
> 1 votes

# Answer
This is possible, but support for language context in Page manager is still in the works, and there is a debate about how it should work. Because the functionality may yet change, I'm not posting a todo, but just link to the issue.
> 1 votes

---
Tags: 7, panels, i18n-l10n
---


# Question
Title: What is the best way/api to load a node by node content type and a field value?
Aside from plain SQL, is there any Drupal api to retrive node(s) by passing a node CCK type and a field value?

For example, I would like to get the node which is an `Assignment` CCK type, by matching an integer CCK field `Assignment Score` value \>= 65.

In PHP.

# Answer
> 3 votes
In both D6 and D7, you can use Views. Explaning all of Views is out of scope for this answer, but you can either add two, "Filters" one on content type, and one on field value. This however will require reconfiguring the View if you want to change the score, or type. If you add the same filters as "Contextual Filters", or "Arguments", depending on your Views version, the values can be pulled from the URL. This will allow completely different listings with a single view.

Two URL examples for using contextual filters:

```
example.com/results/easy_assignment/50
example.com/results/hard_assignment/75

```

In D7 you have entities, and could in code do:

```
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'assignment')
->propertyCondition('status', 1)
->fieldCondition('field_assignment_score', 'value', 65, '=');
$result = $query->execute();

```

---
Tags: 6, views
---


title: Error importing csv with batch API

text:
# Question
Title: Error importing csv with batch API
I'm using this code in my batch job:

```
<?php

function my_module_csv_import() {

  $folder = "csv";
  $files = scandir($folder);

  // define batch array structure
  // NOTE: minimal parameters defined to simplify code
  $batch = array(
    'title' => t('Reading File'),
    'operations' => array(
      array(
        '_my_module_batch_read', array($files_array),
        ),
        ),
        'finished' => '_my_module_batch_finished',
        );

        // set batch
        batch_set($batch);

        // process batch
        batch_process('');

        return '';

}

function _my_module_batch_read($files, &$context) {

  variable_set('site_offline', '1');

  // define batch limit
  $batch_limit = 500000;

  // assume the batch process has not completed
  $context['finished'] = 0;

  foreach($files as $csv_file_path) {

    // open the file for reading
    $file_handle = fopen($csv_file_path, 'r');

    if ($file_handle){
      // check if file pointer position exists in the sandbox, and jump to location in file
      if ($context['sandbox']['file_pointer_position']) {
        fseek($file_handle, $context['sandbox']['file_pointer_position']);
      }

      // loop through the file and stop at batch limit
      for ($i = 0; $i < $batch_limit; $i++) {

        // get file line as csv
        $csv_line = fgetcsv($file_handle);

        // NOTE: at this point, do what ever you'd like with the CSV array data!
        if (is_array($csv_line) && isset($csv_line[0]) && isset($csv_line[1])) {
          // DO STUFF
        } else {
          dpm("PROBLEM READING LINES");
        }

        // retain current file pointer position
        $context['sandbox']['file_pointer_position'] = ftell($file_handle);

        // check for EOF
        if (feof($file_handle)) {
          // complete the batch process
          $context['finished'] = 1;

          // end loop
          break;
        }
      }
    }
  }

  $context['finished'] = 1;

}
?>

```

it works fine, but sometimes it breaks.
The $csv\_line results to have PROBLEM READING LINES and I get
`warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument.`
I can't figure out how this could be possible, since the csv is correct.
Can anyone point me in some solution?

# Answer
Found the error: the problem is that I'm not resetting $context\['sandbox'\]\['file\_pointer\_position'\].
This causes batch pointer start reading the CSV file in the wrong position.
To correct this, it's enough to add

```
$context['sandbox']['file_pointer_position'] = 0;

```

to the check for EOF

```
if (feof($file_handle)) {
    // complete the batch process
    $context['sandbox']['file_pointer_position'] = 0;
    $context['finished'] = 1;
    // end loop
    break;
}

```
> 2 votes

# Answer
The Drupal 6 Feeds module may be better suited for this task that a custom module. I've only used the D7 version myself, but I believe it supports Batch processing out of the box. It seems to have a decent API as well that you may be able to integrate with your module.

You may want to verify your CSV with a tool like Flat File Checker to ensure the issue isn't with the format of the document.
> 1 votes

---
Tags: 6, importing-exporting, batch-operations
---


title: Making terms as a list format

text:
# Question
Title: Making terms as a list format
This is my layout http://www.gorgeoushentai.com/content/saber-marionette-j-2 If you look at the genres section it shows them as a div class and I want it as a \< li \> . How can I make it a list format? I can't find where it's printing the terms in the templates. This is for drupal 7

# Answer
The template file you're looking for is field.tpl.php. The naming suggestions for this template are explained fairly well here and here \- although they aren't in the documentation and I haven't tested them. So the steps you need to take are:

1. Copy the .tpl.php file from *modules/field/theme*
2. Rename it so it targets only the field type you wan't ('list\_text' I think in your case).
3. Change the `divs` into `ul`/`ol` and `li` as required.
> 2 votes

---
Tags: theming
---


# Question
Title: Adding fmath editor plugin to ckeditor through wysiwyg module
How to add fmath editor plugin to ckeditor through wysiwyg module. The link (http://www.fmath.info/plugins/drupal/doc.jsp) provides documentation for ckeditor module but it does not explains the steps for wysiwyg module.

# Answer
> 2 votes
This started out as hacking it in, but things are always nicer in a module. The code is on my Github but if you just want the module it is hosted here for the moment. Full install instructions are similar to your link above and are including in the README for the module.

Basically, if you have the Wysiwyg CKEditor module installed already, you'll need to:

1. Install fMath plugin:
Download the plugin for CKEditor from the fMath site
and unzip the package. Copy the folder fmath\_formula to `sites/all/libraries/ckeditor/plugins` folder
2. Install the fMath WYSIWIG module (linked above):

Download and add the module to Drupal and activate it. Enable the fMath button in the WYSIWYG profiles page for the wanted formats (e.g. Full HTML).

Now, the button on toolbar should be displayed. When you click the editor, it should show up. You will not be able to save the image to the page until you complete the next steps.
3. Install the server side script to generate the images:

Go to www.fmath.info/editor/ and download editorPhpServerSide-vx.x-x.zip Unzip the file. Create on your server a folder "capture", it must be available from www.yourserver/capture Copy the file imageCapture.php to this folder, it must have the permission to execute.

Create a folder img in capture folder (capture/img). Edit the file imageCapture.php and change www.yourserver.com with your server url

Edit the file `sites/all/libraries/ckeditor/plugins/fmath_formula/dialogs/configMathMLEditor.xml` to add or edit the property `"urlGenerateImage"` to http://yourserver/capture/imageCapture.php
4. Test

Clear the cache of your browser (temporary files). Create an equation and save.

---
Tags: 7, wysiwyg
---


title: click image to play video in iframe

text:
# Question
Title: click image to play video in iframe
Objective - have a blank screen with only an image on it. (a "play video" button) when the button is clicked a video (from youtube) opens in a section on the screen that is maybe 200X300. Ideally this would all be done within ckeditor so the end user can setup and change as desired. (note - I am not sure if iframe is needed, but this is how I was able to do it)

I can get the appearance I want easily by embedding the following code into ckeditor in "source" mode:

```
<p><iframe frameborder="0" height="333" src="http://www.youtube.com/embed/-J3HfllvXWE" title="YouTube video player" width="547"></iframe></p>

```

But can not figure out how to have a blank screen that shows only an image that opens the video when it is clicked. thanks for any help

# Answer
You would need to use JavaScript to make this happen. You're not going to have a good time with users doing this in CKEditor though, as they'll likely break this functionality when they use the editor and alter the content in it (the JS will be invisible to them, unless they're in source mode, and they could easily delete it without knowing it).

I have achieved similar behavior using a dedicated field called "YouTube Video Link". The user pastes a link in there and then I have a play button execute that link in an iframe overlay using Fancybox.

The JavaScript (jQuery) that you'd want to use is:

```
// When a user clicks the link...
$('.video-link').click(function(e) {

  // Don't let the browser open the link like normally.
  e.preventDefault();

  // Capture the link's HREF attribute in a variable.
  var youtubeLink = $(this).attr('href');

  // Set the HTML (the content) of the "video destination div" to = your iframe, including the youtubeLink that the user original saved into this node.
  $('#the-video-destination-div').html('<iframe frameborder="0" height="333" src="' + youtubeLink + '" title="YouTube video player" width="547"></iframe>');
});

```

Where your video link has `class="video-link"` and somewhere on the page you have a `<div id="the-video-destination-div"></div>`.

Please add a comment to this answer to help funnel the nuances of what you're trying to do and I can edit my answer to reflect.
> 1 votes

---
Tags: wysiwyg, files
---


# Question
Title: How to integrate CAPTCHA in a search form with Views
I have created a search page with the Views module, which includes a few exposed filter criteria. The form will be available to guest users, so I would like to include a CAPTCHA in the form.

The CAPTCHA module has been installed and works just fine in the user registration, but I cannot figure out how to integrate it inside the search page.

PS: I am using Drupal 7.10.

# Answer
If you go into the CAPTCHA configuration page, there should be an option to "Add CAPTCHA administration links to forms". If you enable this then visit your views page, an option should appear to add a CAPTCHA next to the exposed filter (the option may be a little mangled depending on your layout, it expands out fine when you click it).

A heads up that this can sometimes generate some extra warnings, see how you go.
> 2 votes

---
Tags: 7, views, captcha
---


# Question
Title: Using confirm_form to lead into a batch process
How can you use confirm\_form from hook\_menu and present the user with a Confirm action page, when clicked, goes and sets a Batch process?

# Answer
I always do this with a simple submit handler on the form...works a treat:

```
function my_confirm_form($form, &$form_state) {
  return confirm_form($form, 'Are you sure you want to run this batch?');
}

function my_confirm_form_submit($form, &$form_state) {
  $batch = my_batch_function();
  batch_set($batch);
}

```
> 3 votes

---
Tags: 7, forms
---


title: Best Practice - Node Template Logic

text:
# Question
Title: Best Practice - Node Template Logic
I have a node template file that requires a lot of logic. So much so that in order to make things easier I have created functions inside my custom node.tpl file. What is best practice for separating logic from the node.tpl?

Thanks!

# Answer
> 3 votes
You should use the template\_preprocess\_node() function. Add this to your template.php in your theme and do whatever you have to do.

---
Tags: 6, nodes
---


# Question
Title: How to Disable "Upload" in IMCE to only keep "File browser"?
I'm working on a website (Drupal 6) where filefield and IMCE are set to upload media into nodes.

The customer don't want the users to upload files in the default directory but in specific places, for this reason he asks me to remove the "upload" possibility and only keep the "file browser".

How can I say to the widget to use "file browser" by default?

# Answer
> 1 votes
Go to:

> Administration » Configuration » Media » IMCE

Select your profile. Under Directories there are checkboxes: *Browse*,*Upload*,*Thumbnails*,*Delete*,*Resize*.

Uncheck: *Upload*

---
Tags: files
---


title: Create successive Batch script?

text:
# Question
Title: Create successive Batch script?
How can you create a successive batch job in the Batch API?

For example, if I wanted to queue and assemble 1000 nodes as a batch, then process them in a second batch when the first batch is done, automatically? Do I just call the second batch job in the finished callback? Can it be passed arguments?

# Answer
> 3 votes
I haven't tried to do exactly this before but something tells me it would be tricky. This is from the Batch docs:

> The API is primarily designed to integrate nicely with the Form API workflow, but can also be used by non-Form API scripts (like update.php) or even simple page callbacks (which should probably be used sparingly).

I remember trying to set batches outside of a form context before and always resorted back to using a form as I could never get them to work.

You might have more joy than me though so you could try simply doing a `batch_set` in the finished callback like you suggest. Assuming you're adding some data to the `$context` variable in your first batch's callback function (such as the node ID) you should be able to pick that context data up again in the finished callback and pass it though to your second batch's setup function.

Hope that makes sense!

---
Tags: 7, batch-operations
---


# Question
Title: Email notifications for disqus comments on a node
I setup a blog in drupal and used the disqus module to integrate it with the disqus commenting system. The drupal commenting system isn't used. When someone posts a disqus comment on the node, I'd like drupal to email the node author a notification of the comment. Disqus' system is setup to notify a primary administrative account when a new comment is posted but not the node author, as that information lies within Drupal. How do I go about this?

# Answer
> 1 votes
This feature is not supported out of the box. There are a few solutions:

* Use http://drupal.org/node/1117622 to fire a callback to Drupal to notify the author.
* Sync disqus with the Drupal comment system. The module supports it, but I haven't tested.

---
Tags: notifications, comments
---


# Question
Title: Can I use Pathauto with additional url values?
Is it possible to use pathauto url aliases and still use additional url parameters?

For example, I use pathauto for polls to map "node/123" to "poll/title-of-my-poll". The poll results are at "node/123/results" but using "poll/title-of-my-poll/results" doesn't work.

# Answer
The Sub-pathauto module is for exactly that purpose.

> The Drupal Path module matches only full URLs when creating SEO-friendly aliases. This module extends that behavior by also matching known sub-paths and replacing them with their respective alias.
>
> For example, if user/1 is aliased to users/admin, this module rewrites the link to the user contact page user/1/contact to use the aliased URL users/admin/contact instead. This also includes Views URLs taking a node as argument (e.g. node/%/yourview), in short, every URL that is based on, or extends, an existing alias. In combination with the Pathauto module it is possible to get rid of all remaining exposed internal non-administrative URLs.
> 7 votes

---
Tags: 7, path-aliases
---


# Question
Title: When developing a module's theming functions, should you use "template_preprocess..." or "mymodulename_preprocess..."?
I got into a discussion with co-workers today after reviewing some code on a Drupal 6 project.

When creating a module, I tend to define all template preprocessor functions by including the module name

```
function mymodulename_preprocess_news_item(&$vars){ ... }

```

If another module/theme needs to override/expand this, I add the function definition with the new module/theme name. This is how I've come to understand the theme layer to work.

My co-worker's mentioned that I should be using the following instead for custom preprocessor definitions:

```
function template_preprocess_news_item(&$vars){ ... }

```

According to the documentation on theme(), template\_preprocess gets executed before anything else so I'm leaning towards agreeing with my co-workers since these are custom theme elements and the originating module should process the initial content.

I am curious if there are any best practices/opinions out there on this matter.

# Answer
> 3 votes
Why not look at drupal core for best practice which favors template\_process\_X.

Also for some processors both `template_preprocess` and `module_preprocess` hooks can get called, see `template_preprocess_block` and `system_preprocess_block` as an example.

# Answer
> 1 votes
Whether or not it's best practice, I've always made sure that a module's code only includes functions that begin with the module name or underscorename. With that in mind when preprocess()ing, I've put the template\_ ones in my theme's template.php file. That way, I know where everything is. Also, this keeps things "in order" with respect to drupal's theme hierarchy.

---
Tags: theming
---


# Question
Title: requesting suggestions on using core poll module
I'm working in Drupal 6.22.I have a peculiar requirement with my poll module as below

* Display the most recent poll block such that anonymous user could vote in it.
* Once the user has voted display the vote results block with link to all previous polls page.
* In all polls page again display the poll-vote block of the most recent poll with links to previous polls.

I'm not expecting a contributed module that fits all my requirement in a tailor made fashion but wish to know if there's any module that would aid me in satisfying some portion or giving better ideas in implementing it. I did my search and found Poll Enhancements Module and Poll Improved Module which sound promising for D7 but are not quite there for D6.

Is there a better option of implementing this than arm twisting the poll module with coding? If anyone could share their suggestions, ideas or experiences it would be nice...

Thanks in advance!

# Answer
Finally managed to get it done with a custom module

Set permission for Anonymous user to vote in poll.

Accomplished the desired with a custom module, used the core poll.module code with its menu callback method for listing poll content ($items\['poll'\]) as an example and implemented customized logic. Used to module\_invoke to invoke the block content of the poll module and added it to the output.
> 0 votes

# Answer
You can try Decisions module in your site. This module depends on VotingAPI module. This module have some nice features. I havent tested much but its good module to look at. Good Luck.
> 0 votes

---
Tags: 6, polls
---


# Question
Title: Authenticating users and uploading content with Services module
I am trying to learn how to set up a service that will accept http-posts including user login and password, authenticate the user, then allow the user to upload a file that will be used to create a new piece of content. I could not find any good resources explaining how to handle user authentication with the services module nor did I find any good resources about how an upload or content creating could be accomplished. Does anyone know of any such resources I may have missed?

# Answer
http://drupal.org/node/736522 should help you.
> 2 votes

---
Tags: files, services
---


# Question
Title: put views block in a content type different than the one in views block
I have 2 content types. One called "tributes" and another called "offers". Both content types have a field reference to pages of a third content type called "county".

What i want is to display a view block with content from "offers" in the pages of content type "tribute" based on the value of the field county that appears in the node each time.

Is there a way to create a contextual filter on field county and use as default value the value of the field county appearing in the "tribute" node?? (through PHP perhaps?!)

Thanks in advance!

# Answer
> 0 votes
Getting a block view to get a parameter from the node view can be tricky. Here's what you can do:

For "tribute nodes":

1. create a new view to display "offer" nodes
2. add a filter to that view to limit the content type to "offer"
3. add an argument to that view to your node reference
4. Under "Action to take if argument is not present" select "Provide default argument"
5. For default argument type, select PHP Code
6. We now need to write some php code to grab the node reference id from the node being viewed. your case might be a bit different, but here's a starting point: (you dont need php tags)

```
<?php

if(arg(0) == "node" && is_numeric( arg(1) )) {
  $node = node_load(arg(1));
  if($node->type == 'tribute') {
    return $node->field_county[0]['nid'];
  }
}

```

replacing field\_county with whatever your cck field is named.

Then you should be able to add that block to any tribute node page and it will pull in the associated offers, and just do the same thing again for the offers-\>tribute direction.

---
Tags: views
---


title: Getting the value of a select option

text:
# Question
Title: Getting the value of a select option
I would like to validate the company name chosen in a form in a "select" form field.

When I try `$form_values['submitted_tree']['company_1'];` it shows me the key instead of the string value.

I tried the following code, but it still prints '1' (the key) instead of the value associated with the key.

```
    $_page_num = $form_state['values']['details']['page_num'];
    $key1 = $form_state['values']['submitted_tree']['company_1'];
    $value1 = $form['submitted_tree']['company_1']['#options'][$key1];
    $key2 = $form_state['values']['submitted_tree']['company_2'];
    $value2 = $form['submitted_tree']['company_2']['#options'][$key2];

    if (($_page_num == 2) && ($value1 == $value2)) {
      drupal_set_message(print_r($form['submitted_tree']['company_2']['#options'][$key2]));
    }

```

Could anyone help me to retrieve the actual text value displayed in select option chosen? I have tried `$form_state` as well, but it returns the same result.

# Answer
> 8 votes
You can use the key to get the value by referencing the options array in the original form element:

```
$key = $form_state['values']['submitted_tree']['company_1'];
$value = $form['submitted_tree']['company_1']['#options'][$key];

```

---
Tags: forms
---


title: Blank Page Template for ajax requests

text:
# Question
Title: Blank Page Template for ajax requests
I'm still pretty new to Drupal. I needed help creating a blank page template for a certain content type. When I say blank, I mean the only thing thats displayed on the page is the render($page\['content'\]) information. None of the markup that is added with the html.tpl.php template.

To give you a wider perspective of what I'm trying to accomplish - I'm trying to use the assets that are housed here in an .ajax request to display elsewhere.

Thanks for your time.

# Answer
> 6 votes
Personally I deal with situations like this in a custom module by registering a path with a callback function that prints the needed content:

```
function mymodule_menu() {
  $items['somepage/%'] = array(
    'title' => 'Somepage',
    'page callback' => 'mymodule_ajax_callback',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function mymodule_ajax_callback($nid) {
  if ($node = node_load($nid)) {
    $view = node_view($node, 'full');
    print drupal_render($view);
  }
}

```

This would get you the view of node 12 without any external markup on 'somepage/12' for example. Note that when you use return instead of print you get the page with additional markup added (just for future reference).

If you want to go with the template approach you could create 2 templates: 'html--blank.tpl.php' and 'page--blank.tpl.php'. The first one should contain only `<?php print $page; ?>` and the second `<?php print render($page['content']); ?>`. In your template.php file add:

```
function mytheme_preprocess_html(&$variables) {
  if (isset($variables['page']['content']['system_main']['nodes'])) {
    $nodes = $variables['page']['content']['system_main']['nodes'];
    $key = key($nodes);
    if (count($nodes) == 2 && $nodes[$key]['#node']->type == 'my_content_type') {
      $variables['theme_hook_suggestions'] = array('html__blank');
    }
  }
}

function mytheme_preprocess_page(&$variables) {
  if (isset($variables['node']) && $variables['node']->type == 'my_content_type') {
    $variables['theme_hook_suggestions'] = array('page__blank');
  }
}

```

These solutions will give you a slightly different result, but either should get the job done (just remember to modify them to fit your needs and clear the caches).

# Answer
> 2 votes
You can change the suggestions that Drupal uses on the fly, and I do believe it's possible to create a suggestion so that Drupal will load an appropriately named html.tpl.php file based on a number of factors. You need to elaborate more on the requirements of your AJAX request... for example, is it a specific content type that your AJAX will be rendering out?

Also if you're using content generated by Drupal to display elsewhere you should look into using the Services module as it sounds like it does exactly what you need it to do, based on what you've written so far.

# Answer
> 2 votes
The way that core modules do this type of thing is to provide a `delivery callback` for menu items defined in `hook_menu()`. You could work a little bit of logic in a custom module to do it for node pages of a certain type:

```
function MYMODULE_menu_alter(&$items) {
  // Override the page delivery callback for the node view page.
  $items['node/%']['delivery callback'] = 'MYMODULE_deliver_node_page';
}

function MYMODULE_deliver_node_page($page_callback_result) {
  // This function will only ever be called for a node view page
  // so we can safely assume menu_get_object() will provide a valid node
  $node = menu_get_object();

  // Check you're on the right type of node page
  if ($node->type == 'content_type') {
    // Set any headers you need, e.g.
    drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');

    // Output just the content that lives in the system_main block.
    echo render($page_callback_result['content']['system_main']);
  }
  else {
    // Default to the standard drupal_deliver_html_page()
    drupal_deliver_html_page($page_callback_result);
  }
}

```

# Answer
> 1 votes
I don't think that's possible in Drupal in the way you're going about it. When it comes to blanking out the base markup provided by html.tpl.php, node.tpl.php, etc. the only solution that comes to mind is to actually blank out the aforementioned files, which unfortunately would apply to your entire theme.

What I'd image you'd need to do is that you'd have to introduce your own small custom module that handled the AJAX requests, then you have full control over the output that's being sent back to your AJAX handler.

# Answer
> 1 votes
Have you tried suggestions? For the particular content type.

---
Tags: 7, theming
---


# Question
Title: How to disable/turn off Automatic URL alias
Could anyone suggest how to disable/turn off automatic URL aliases?

# Answer
Automatic URL aliasing? It will be the Pathauto module doing that. You can disable it, but you will need to delete your current aliases as well, which the Pathauto module provides an interface for if you check its settings.
> 7 votes

---
Tags: 6, uri, path-aliases
---


# Question
Title: How do I copy a "purchase limit" field from a product to a product line item
I am working with Drupal Commerce and am trying to copy a field on the product named "copy limit" to the line item when it's added to the cart so that I can access it in shopping cart form view when a user views his/her cart.

I am not sure of the best way to go about this.

I am using Commerce 7.x-1.0 and Drupal 7.7.

# Answer
> 5 votes
You'll need to add a "copy limit" field to the line item first. If you just want to use the standard "product" line item that will work. Add a "copy limit" field at admin/commerce/config/line-items/product/fields

Then you need a rule that says:

Event: "After adding a product to the cart"

Condition: Entity has field: Entity:commerce\_product, Field: field\_copy\_limit Condition: Entity has field: Entity: commerce\_line\_item, Field: field\_copy\_limit

Action: Set a data value. Data: commerce-line-item:field-copy-limit, Value: commerce-product:field-copy-limit

You may then want to add the copy limit to your cart view.

However, If you really want to just validate that the amount in the cart is less than or equal to the copy limit, you may want to do something like this:

1. Set up as above. The display settings on your product display node add to cart field must be set to "combine like products"
2. Add a rule like this:

Events: * After adding a product to the cart * After saving a new commerce line item * After updating an existing commerce line item

Conditions: * Entity has field: Parameter: Entity: \[commerce-line-item\], Field: commerce\_product * Entity has field: Parameter: Entity: \[commerce-line-item..., Field: field\_copy\_limit * Data comparison: Parameter: Data to compare: \[commerce-line-item:quantity\], Operator: is greater than, Data value: \[commerce-line-item:commerce-product:field-copy-limit\]

Actions: * Set a data value: Parameter: Data: \[commerce-line-item:quantity\], Value: \[commerce-line-item:commerce-product:field-copy-limit\] * Show a message on the site: Parameter: Message: No more than \[commerce-line-item:quantity\] "\[commerce-line-item:line-item-label\]" may be ordered, so your order has been set to \[commerce-line-item:quantity\] items.

I put an export of this last rule at http://dl.dropbox.com/u/7350603/stackexchange/commerce\_limit\_items\_in\_cart.txt

# Answer
> 2 votes
Other way you can use this module Commerce Product Limit

---
Tags: commerce, entities
---


# Question
Title: Can I use Ubercart Stock to monitor individual components of a product?
For example, I'm selling Hamburgers.

Hamburgers require the following ingredients:

1. Bread
2. Beef
3. Tomato
4. Lettuce
5. Onions

For every one hamburger sold, stock decrement should be: 1 Bread, 1 Beef, 2 Tomatoes, 1 Lettuce, 3 Onions.

The ingredients will never be sold individually, they collectively make one product.

Is it possible to do this?

# Answer
> 1 votes
It is. Make your hamburger a product kit which is made up of products, bread, beef, tomato, lettuce and onion. When you sell a hamburger Ubercart will be smart enough to control stock of the ingredients.

---
Tags: 7, ubercart
---


# Question
Title: Using Drupal as a server application user front-end (feasability question)
I am very new to Drupal. I am currently watching videos and reading many online tutorials. I came to Drupal, because I understand it is a good CMS system (at least recommended by many, and the more I learn, the more I agree).

But, the more I learn, the more I am wondering whether it could solve another of my needs: acting as a user front-end for a server-side application. Let me describe this.

* I have a couple of experts entering technical information in a system (i.e. database). I understand I can create specific screens with specific fields in Drupal (that's great, no coding) and that it would be stored in the database when ready.
* After information is entered by experts, heavy time and cpu consuming asynchronous processes should be started in background and resulting information stored in the database.
* Next, users should be able to read results with another screen in Drupal.

Instead of performing the heavy processes on the web-server, I was wondering whether I could use another server to connect to the drupal database instance (with a deamon application written in Java for example), perform the heavy duty tasks, and store the information in that same database.

My questions are:

1. Is this realistic? Has anyone attempted this?
2. Is it easy for a 3rd party application to read data from a Drupal database and store results in it? Does Drupal offer specific modules faciliting this? Any documentation or tips available?

Thanks.

# Answer
> 2 votes
Here's my understanding:

* Drupal will allow you to quickly create a content-type to store the data you need, and customise how your users enter their data.
* It's possible to query the Drupal database directly, but if you're not familiar with Drupal's schema, you'll need to spend a little time understanding where your data is stored.
* Once you do understand the schema, you may find the database is over-normalised for your requirements, which will mean a lot of joins will be required. Might not be an issue depending on your infrastructure and the quantity/frequency of data you're talking about.
* There are several APIs you can use to get data out of the database (assuming Drupal 7):
    + For direct SQL queries, use db\_query
    + For the Drupal db access layer, use db\_select
    + For something you configure, you could use views which you could output to any number of formats (json, XML, HTML etc.)
    + There are dozens of other modules which will allow you to integrate with other systems, one of those might suit your purpose.
* Storing the processed information again will depend on how much the data has changed, and how it need to be stored. For example: are you just overriding the existing data? Will the new data be added to the existing nodes, or will new nodes be created? Regardless, you'll probably need a custom module for this.

# Answer
> 3 votes
Absolutely.

Do not be put off by the 'CMS' label, Drupal is actually quite a framework in itself. Drupal really does a good job for small to mid-sized applications, as the application gets larger though one has to tweak and push the limit a bit more. To be fair, this is true of most any PHP application.

I have built quite a few applications myself that leverage the power of Drupal, some internal, some public: production management, calendaring applications, rental/item reservation for 4000 items +, mailing list management, (and more).

In my (very humble) opinion, Drupal saves a lot of time, especially for the 'user-management' aspect of application building. As a bonus, you have the rest of the framework to play with when developping your app.

Hope that helps, happy coding, good-luck!

---
Tags: database
---


# Question
Title: Fetch content from another website into a new one
I want to fetch content from a website into another website. When I edit that content, it will automatically display changes. I am using Drupal 6.

Does anybody have an idea about I can achieve this?

# Answer
> 3 votes
You should take a look at the Feeds module. It can import many different things into your Drupal site. I am using it to import RSS feeds as nodes.

---
Tags: views, 7, hooks
---


# Question
Title: How to use subgroups in drupal_add_tabledrag()
I am trying to implement a form that is themed with drupal table drag using subgroups. My form consists of a list of 'employees' that need to be assigned to different 'departments'. The order of the employees does not matter once they are inside a department.

The admin/structure/block table is similar to what I am looking for but with just the select box for region and no weights.

I've looked through the documentation here: http://api.drupal.org/api/drupal/includes--common.inc/function/drupal\_add\_tabledrag/7 and I've also studied the admin/structure/block table code but after several hours of trying different combinations - I am stuck!

The block module uses custom JS and a template tpl file for outputting the table. I think this doesn't take full advantage of Drupal. Therefore, this solution should make use of theme\_table and #ajax (for the region select fields).

# Answer
If you want ajaxed example perhaps you can study the Display Suite UI.

In my opinion the easiest way to do this if you need similar functionality is just to use the block module tpl's and change the data presented inside it (from block region to your custom module regions)

to remove the weights, I think if you remove :

```
drupal_add_tabledrag('blocks', 'order', 'sibling', 'block-weight', 'block-weight-' . $region);

```

it will remove the ability to drag and sort the weight.

some rough examples for "Drupal compliant" way :

note: this is VERY rough code, you will need to adjust it heavily

```

function theme_example(&$variables) {
  // build the header
  $header = array(
    '', // this will be hidden when table drag run
    '', // this will be hidden when table drag run
    t('Block Region'),
    t('Region Area'),
  );
  // enabled region
  //$regions = region_area_grab_region('enabled');
  // substitute this to what ever your module provides
  // this should be in $form array
  $regions = array('example_one', 'example_two', 'example_three');

  $region = array('example_block_one', 'example_block_two', 'example_block_three');

  // Add table javascript.
  drupal_add_js('misc/tableheader.js');
  drupal_add_js(drupal_get_path('module', 'block') . '/block.js');

  // take notice of the key that will be related to real options
  // in the select box, this should be in $form array
  $options = array();
  foreach ($regions as $key => $region) {
    $options[$region] = $region;
  }

  // add additional class here
  $attributes = array(
    'class' => array('draggable'),
  );

  // building the table rows
  $rows = array();

  // looping for each regions
  foreach ($regions as $region) {

    // this is the heart of the draggable
    // take good notice for the region-manager (the table id), region-area-weight (group of rows class)
    // and regionarea-weight- $region (unique row class), you will need to add this to the form array
    // element NOT in the table row

    // if you want to emulate the block page table drag, comment out the drupal_add_tabledrag
    drupal_add_tabledrag('region-manager', 'order', 'group', 'regionarea-weight', 'regionarea-weight-' . $region , $hidden = FALSE);
    // build the region row

    // replace this with your form element array eg $variables['form']['whatever']
    $elements = regionarea_build_admin_region_form($region, $form, $form_state);

    $row = array();
    $row[] = '';
    $row[] = drupal_render($elements[$region['name']]['weight']); // replace this to actual form array for the weight
    $row[] = $elements[$region['name']]['name']['#value']; // replace this to actual form array for the value / title
    $row[] = drupal_render($elements[$region['name']]['enabled']); // optional
    $row = array_merge(array('data' => $row), $attributes); // merge the array, add draggable class
    $rows[] = $row; // build the row

    // ----------------------------------------------------------------------------------------------------------------- //
    // Usually up to this point is enough for just normal draggable, only continue if you have a sub child to drag
    // ----------------------------------------------------------------------------------------------------------------- //

    // build the block regions
    // now we looping for the sub child AKA regions as in the block region page
    foreach($region['regions'] as $regionkey => $blockregion) {
      // add two table drag, one for weight the other for 'region'
      drupal_add_tabledrag('region-manager', 'match', 'sibling', 'region-select', 'region-' . $blockregion, NULL, FALSE);
      drupal_add_tabledrag('region-manager', 'order', 'sibling', 'region-weight', 'weight-' . $blockregion);

      // replace this with your form element array eg $variables['form']['whatever']['children']
      $elements = regionarea_build_admin_blockregion_form($blockregion, $regionkey, $options, $form, $form_state);

      // build the current row
      $row = array();
      $row[] = '';
      $row[] = drupal_render($elements[$blockregion]['weight']);
      $row[] = $elements[$blockregion]['name']['#value'];
      $row[] = drupal_render($elements[$blockregion]['regions']);

      $row = array_merge(array('data' => $row), $attributes);
      $rows[] = $row;
    }

  }

  // some options to pass to the theme_table
  $element = array(
    '#empty' => t('There are no region area available'),
    '#attributes' => array(
      'id' => 'region-manager',
    )
  );

  // build the theme
  return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => $element['#empty'], 'attributes' => $element['#attributes'])),
}

```
> 1 votes

# Answer
As I can see, Commerce module uses the same functionality and the same realization. File `commerce_checkout_admin.js` is very similar to draggable part in `block.js` so you have to use Block way. Maybe you can reuse code in `block.js` if you will follow the same naming.
You can choose between `tpl.php` and `theme_YOUR_FORM` to add tabledrag logic.
> 0 votes

---
Tags: 7
---


# Question
Title: Drupal 6 - How to check which module is caused high loading(high CPU usage)
I am running a Drupal 6 site on my server, when I use Linux command `top` to check the CPU usage, I always get a high figure 80-90% of CPU loading, so my server down frequently.

I have installed over 50 modules,I am going to check which module was caused high CPU usage, could someone suggest how can I check which module was caused high CPU usage(by code or module)?

Thanks

# Answer
Use **Devel** module It will give you list of queries run when the page is loaded and the time the query has taken. From there you can check which query is coming from which module. There are many performance improvement module you could try with.
You could use too much of cache if you site has most of the static pages.
> 1 votes

# Answer
I'd also try a PHP profiler which gives you a lot of metrics. Take a look at the XHProf module. Here is an excerpt about it from the module's project page:

> ... allows you to profile your Drupal application using the XHProf profiler from facebook.
>
> It also provides a native Drupal UI (as opposed to facebook's original php front end) to view the profiling data. Having this in Drupal provides several advantages:
>
> * Simpler setup
> * No need to setup extra vhosts
> * Limit access via roles and permissions
> * Use alternative storage backends such as MongoDb
> 3 votes

# Answer
Might not be the answer you're looking for, but I'd look at disabling all modules (in a test environment if you can't do this on the same machine), then enabling them one at a time until the load hits an unacceptable level.
> 1 votes

---
Tags: 6, performance
---


# Question
Title: How to automatically create nodes according to related content types?
I am very new to Drupal. I have a situation where I have 3 content types, say A, B, C.

For each node instance of type A, there should be 3 corresponding nodes instances of type B. And for each instance of type B, there should be 5 corresponding nodes instances of type C. So in total 1 + 3 + 15 = 19 nodes.

Is it possible to automatically create the B and C node instances when the A node is created? And it is automatically possible to delete them if A is deleted? In other words, I would like to create tree-like instances of nodes.

Is this possible in Drupal? Is there a module for this, assuming I am creating the 3 content types A, B and C? Alternative solutions/ideas are welcome too.

# Answer
I think you can do it using hooks you can use hook\_node\_save it will be execute after node A is saving to add a new node B,C after you create A hook\_node\_save($node) { if($node-\>type=="A") { node\_save(B); node\_save(B); node\_save(B); node\_save(C); node\_save(C); node\_save(C); node\_save(C); } }
> 1 votes

# Answer
In order to relate content to each other you could try Relations module. But you'll have to extend it in order to automatically create the linked node and delete them if the master node is deleted. Take a look over the docs of this module.
> 1 votes

---
Tags: nodes
---


title: Forcing flag to be unique

text:
# Question
Title: Forcing flag to be unique
In Drupal 7, using Flags (and possibly Rules or another contrib module) how can I force a flag to be unique for a specific content type. I do not want to force users to manually 'unflag' content before 'flagging' a new node. I would like reviously flagged nodes to be automatically unflagged once a new flag has been set.

The goal is to allow users to select a 'default node' by use of flags. Only one default node should be allowed.

How can I force and automate flag uniqueness?

# Answer
> 3 votes
Drupal Rules has a Trim-A-Flag action that lets you set a 'queue' size, or a 'max' number of flags allowed. If you set the queue to 1, you can force a flag to be unique, and have it automatically update when a new entity is flagged.

Screenshot below.

# Answer
> 1 votes
You could use `hook_flag($action, $flag, $content_id, $account)` to do this. In this hook, check for content type, and then unflag all unneeded nodes.

---
Tags: 7, flags
---


title: Layout pushed down

text:
# Question
Title: Layout pushed down
This is my layout http://www.gorgeoushentai.com and this screenshot is what it looks like when logged in. You notice the background image doesn't move down if there's a toolbar. How can I make the bg image to move down with the layout? It looks perfect when logged out but broken when logged in

# Answer
Instead of having the background on the body, you should create a wrapping div which holds the background image (in the page.tpl.php) Then Drupal should add the toolbar above this div and push the image down.
> 0 votes

---
Tags: theming
---


title: Drupal database innodb or MyISAM?

text:
# Question
Title: Drupal database innodb or MyISAM?
I have a Drupal site, and I am suffering performance issues. I found How do I convert a database from MyISAM to InnoDB? indicating that performance may improve by switching.

How can I tell if my MySQL database is InnoDB, or MyISAM?

# Answer
> 8 votes
You can run a custom query:

```
SELECT TABLE_NAME, ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'database_name'

```

to list all the tables in your database and the engine that's in use for each.

Alternatively you could log into your database using phpMyAdmin and select your database...you'll see the engine in the `Type` column in the list of tables.

Personally I'd recommend Navicat for MySQL, it's a very nice MySQL GUI and makes finding out things like this very easy.

Source

# Answer
> 6 votes
My best experience was to decide on a per table basis. InnoDB is nice, because it can avoid table locking (no other process can read from a table while one process writes), but it performs terribly with COUNT() which is used often for pager queries.

*(Edit: please see Clives comment below)*

There are also implications on your MySQL setup, depending which DB you are using. If you have access to the server, mysqltuner should be your first step, to check the configuration:

https://github.com/rackerhacker/MySQLTuner-perl#readme

# Answer
> 6 votes
Just trying things to get a web site faster is like blindely changing cars and hope you get a faster one next time.

First try the low hanging fruits, if it doesn't help, try to find the real bottleneck.

1. Did you turn on the built in mechanisms: page caching (only effective for anonymous users), CSS and JS agregation?
2. If your host offers an opcode cache like APC, turn it on.
3. Set up your Drupal localy, including the full DB.
4. Make sure you have XDebug running.
5. Start doing real performance profiling. This way you can identify what part of your website consumes a lot of time. The slower your website the easier it is to find the guilty code/component.

Often it's just a slow DB query which needs an index, or a module doing things in a slow way.

I also discovered big differences between hosters. If you install a fresh drupal out of the box, is the performance ok? If not, it's time to look for an other hoster.

# Answer
> 5 votes
FWIW our almost 20K node Drupal 6.x site was experiencing some performance issues and I did elect to move all the tables to InnoDB. It was easy and the way I handled it was to use mysqldump to dump all content to a sql file, use an editor (sed) to replace all occurrences of MyISAM to InnoDB then reload the database from that file. One of the down sides is that you cannot recover space from an InnoDB database (IIRC) but as long as you keep your duplicate tables in a separate DB you should have no problems. Oh, and we did see a significant performance increase. And because we have four Drupal instances the sheer number of table files was eliminated from the file system (yes, they're contained inside the InnoDB file itself). This is my $.02 worth.

# Answer
> 5 votes
Just a heads up. If your on Drupal 6, you can install the DBTuner module; it can easily move your tables from MyISAM to InnoDB. So yes, there's a module for that!

---
Tags: performance, database
---


# Question
Title: Drupal file manager that shows relations to content
Is there module or simple way to show file relations to content with file manager like elfinder or any other? I am using Drupal 7.

# Answer
I had that need recently for sorting my images since their file names were weird. What I ended up doing was to create a View of files, with relation to content that used the field that the file was assigned to.

After you do that you can either add the content's fields and properties (like title, nid, etc) and/or group by them.

Hope this helps.
> 1 votes

---
Tags: 7, files
---


title: Fields UI export to code for editing?

text:
# Question
Title: Fields UI export to code for editing?
I am creating a new registration form with the Fields UI module and need to be able to add variable\_get instances for username, email, etc and also add select lists for birthday info, typical drop downs like range(1,12), range(1,31), and range(2015,2012). I'm having trouble trying to figure out how to do this, or how to put preset variables into my fields. Can I dump this and edit it myself, or can I put in what I need?

**EDIT**

I found out that I can use list(int) then select widget type select list to create select boxes, BUT I still cannot assign things *known* variables.

To further this along, lets say I have I have $variables\['bio'\]\['firstName'\], I am trying to assign *name*\_bio\_firstName to the field for name, if that doesn't confuse anyone more.

# Answer
> 0 votes
You can export it with Features module. Basically it creates a new module which you download and plug into modules folder. There you can further edit it's code.

---
Tags: 7, entities
---


# Question
Title: how to make unsortable header colmn in theme_table drupal 6
I m using Drupal 6
I m using pager\_query and theme\_table
How can I make any column unsortable, by default it is making all columns sortable

```
$tableHeader = array(
        array('data' => ''),
        array('data' => 'Article','field' => 'a.title'),
        array('data' => 'From date','field' => ''),
        array('data' => 'To date','field' => ''),
        array('data' => 'Perpetual','field' => ''),
        array('data' => 'Access type ','field' => ''),

        );

```

here first column shows check boxes along each row so don't want this column sortable
Thanks

# Answer
Looking at the code for `tablesort_header` the sortable stuff is only added if the particular header item is an array. So you can cancel off certain columns by just setting the header to a string, e.g.:

```
$tableHeader = array(
  'This colum header is not sortable.',
  array('data' => 'Article','field' => 'a.title'),
  array('data' => 'From date','field' => ''),
  array('data' => 'To date','field' => ''),
  array('data' => 'Perpetual','field' => ''),
  array('data' => 'Access type ','field' => ''),
);

```
> 0 votes

---
Tags: theming
---


# Question
Title: Asking for confirmartion on node creation
I want ask for confirmation if a duplicate node is getting created. But how do I do it?

I know how to do it if I'm creating the form myself but in node creation I'm not creating the form.

I also know Drupal confirm\_form, how "storage" is used in multistep forms. But how to use it along with the code which is not mine. Where to plug it?

# Answer
> 4 votes
@AgA: "I want ask for confirmation if a duplicate node is getting created. But how do I do it?"

The way you do it is to validate any new node added by a user against existing nodes.

Towards this end, `hook_node_validate()` is your friend. :-) You'd make a module that implements `hook_node_validate()`, and within that function do a query using the data the user input. If you find similar nodes that already exist, you can `form_set_error()` an error message. Click through to the API site and there's even some sample code.

# Answer
> 0 votes
Implement hook\_form\_alter() or hook\_form\_FORM\_ID\_alter() to modify an already built form. Here you can include your custom validation function to insert the required code.

From your second sentence, I understand that this isn't necessary but for those looking to implement validation functions using hook\_form\_alter() here are a few resources to check out.

You may even be able to use the Rules module with a bit of custom PHP code for the condition component of your rule.

---
Tags: forms
---


# Question
Title: Does Strongarm need to be enabled on Production site using Features?
I'm using Features in order to make my site content configuration exportable for purposes of staging my server. I'll be using Strongarm to make some of the site variables exposed for management in a feature.

Does the Strongarm module need to be enabled on my live production site in order for the active features to be able to present and set the variables which I have encapsulated within them?

Or, does Strongarm only need to be enabled on my dev server where and when I am creating my features components?

# Answer
Yes, you need the strongarm module on production site as the module implements `hook_features_revert` and `hook_features_rebuild` which is needed to do any reverts to the variables you have featurized or to apply new variables that u have introduced in your feature.
> 2 votes

---
Tags: features
---


# Question
Title: Adding a query string to a link in Views
I've added an "Add Comment Link" to a View and I'm wondering how I would go about adding a custom query string to the generated URL?

I'd guess I need to do something under "Rewrite Results", either with "Rewrite the output of this field" or "Output this field as a link" but I only seem to have an option to include the fully rendered link as a replacement token.

Is there a way (without resorting to regex) to get the URL from the link so I can rewrite the output myself? Or is there an easier way to add the query string?

Thanks

# Answer
If the link is a field of view, it could be possible to get the URL in the template file using the `$row` variable.
> 3 votes

---
Tags: 7, views
---


title: Dynamic block titles

text:
# Question
Title: Dynamic block titles
I have added a custom block to my users' profile page that shows a list of all that user's submissions. I would like the title to be the user's name then projects so for the user Mike I would like to see "Mike's Projects" as the block title. Is there a way to do this?

# Answer
If you don't like to get dirty with PHP code than you can install Token Filter module, hide the title (add `<none>` in the title field) and create your title in the content of the block wrapping it in a tag. The new title would be like this: `<h2>[user:name]'s Projects</h2>`
> 4 votes

# Answer
If you're familiar with Drupal's hook system, you can do this via hook\_block\_view\_alter
> 7 votes

# Answer
You can do this thing with block.tpl.php in theme .$block-\>subject

```
if ($block->module=block && $block->delta='Your block ID' ){
print 'company name' }
else {print $block->subject;}

```

your block id ==click in config in block section in admin and you can have the block id in url at end
> 1 votes

---
Tags: 7, blocks
---


# Question
Title: Which Apache module is required by Drupal system
Could anyone advise which Apache module is required by Drupal system?

# Answer
> 2 votes
The most common enabled module (or installed if not available) is mod\_rewrite which helps your site have nice and clean urls. But even this isn't really required ... you can live without it but your site won't have nice links instead they will look like : www.example.com?q=node/12345. If PHP is working than that means that you have the necessary config to run Drupal.

# Answer
> 0 votes
I think you really only need (these are PHP extensions): mbstring curl gd mysql mcrypt jpeg png xml

...but not completely sure. my configuration above suits me fine. not sure if it can be of any help. If you using php as a module in apache, you can eliminate the fastcgi part.

---
Tags: 6
---


title: adding new field to imceimage

text:
# Question
Title: adding new field to imceimage
I have imceimage.module,v 1.1.2.4. the default of this module is to create a table for the field i want to create as below:

```

desc content_field_slideshow_image;
+-----------------------------------------+------------------+------+-----+---------+-------+
| Field                                   | Type             | Null | Key | Default | Extra |
+-----------------------------------------+------------------+------+-----+---------+-------+
| vid                                     | int(10) unsigned | NO   | PRI | 0       |       |
| nid                                     | int(10) unsigned | NO   | MUL | 0       |       |
| delta                                   | int(10) unsigned | NO   | PRI | 0       |       |
| field_slideshow_image_imceimage_path    | char(255)        | YES  |     |         |       |
| field_slideshow_image_imceimage_width   | int(11)          | NO   |     | 0       |       |
| field_slideshow_image_imceimage_height  | int(11)          | NO   |     | 0       |       |
| field_slideshow_image_imceimage_alt     | text             | YES  |     | NULL    |       |

```

and i want to add new field for seo\_alt

```
| field_slideshow_image_imceimage_seo_alt | varchar(255)     | YES  |     | NULL    |       |

```

I have doen this:
1- i have altered the table `alter table content_field_slideshow_image add field_slideshow_image_imceimage_seo_alt varchar(255);`
2- added `'imceimage_seo_alt' => array('type' => 'varchar', 'length' => 255));` in `imceimage_field_settings hook`
3-changed #columns in `imceimage_elements hook` to be  `'#columns' => array('imceimage_path','imceimage_width','imceimage_height','imceimage_alt','imceimage_seo_alt'),`
4- added `$element['#value']['imceimage_seo_alt'],`  to `$element['imce_view']` in `imceimage_process hook`
but now when i edit a slideshow and add the imceimage\_seo\_alt, it wouldn't be saved in the database :(... what shall i do to add this customized field??
Thanks for your help

# Answer
> 0 votes
I have managed to solve my problem and to make life easier for anyone needs to do this, the above steps in my questions are correct 100%.
now to accomplish the process you have to do the following steps:

1. in mysql: `rename table content_field_slideshow_image to content_field_slideshow_image_org`
2. in drupal: go to `/admin/content/node-type/slideshow` here 'slideshow' is my content type, and delete the imce image field
3. again in drupal: create new imce image with the same configuration of the old item
4. now in mysql, you will find that drupal has created a table content\_field\_slideshow\_image for you
5. in mysql
    1. drop table content\_field\_slideshow\_image;
    2. `rename table content_field_slideshow_image_org to content_field_slideshow_image`

# Answer
> 0 votes
You have taken the wrong approach. It's not as simple thing to do as you would like.

What's needed depends on your Drupal version 6 or 7. The columns in the table for the field is created though the field definition that defines which columns are needed. It's not possible to alter this without hacking the module that provides the field. This is not the approach you want to take.

Instead you need to create your own version of the field definition. You should be able to copy most of the code and alter the bits needed for the table definition. Only field or cck knows that the table contains the column for SEO it will also save and load values for that column. If you are not familiar with CCK/Fields it might take a little while to get things working. Also a down side is that you most likely will create your own version of the image field that you will have to maintain.

An alternate solution is to not store the values in the field table, but create your own table and handle saving and loading the data yourself. If you don't need integration with Views, this would probably end up as a cleaner solution.

---
Tags: media, files
---


# Question
Title: How does node import happen when importing from features module?
I used the Node export module to export few pages into features; when I import it is randomly imported.

Is there any particular pattern that it is followed while importing? I want to make a particular page as node 1.

# Answer
That kind of thing is not really possible. The problem is that the node id is serial, so on one machine it will have on id but on another machine it will have another id. Also the the node id is the primary identification, so changing it is not always that easy (if you have comments etc.)

For this kind of thing, UUIDs is really needed (Universally Unique ID). There are modules for this in Drupal 7 and it's being worked on in Drupal 8, but neither will effect the node id, instead it will maintain a UUID which will be the same on all machines that has the node imported.
> 2 votes

---
Tags: 7, features
---


# Question
Title: How to get Taxonomy Menu working properly with Contextual Filters in Views?
I can't get taxonomy menu links working properly with contextual arguments in Views.

This is what I have done:

0) I create a menu called: **Catalog menu**

1) I create a Vocabulary called: **Catalog terms** and in the Taxonomy menu area I set Catalog menu for the Menu location *(I have Taxonomy menu module enabled which allow me to do this)*

2) I the Catalog vocabulary I added 2 terms: **Cars** and **Phones**

3) In admin/config/search/path/patterns I set **Pattern for all Catálogo taxonomy paths** to **catalog/\[term:name\]**

4) In admin/structure/block I enable the **Catalog menu** block to the **First sidebar**

So far so good. I have a menu in my first sidebar with the links: *cars* and *phones*.

5) I have a content type called **Products** with a field of the type **Term reference** called: field\_catalog

6) Now I create a new view called: **Catalog view** where I need to show **Products** which has an specific term in the url. The path of this view is **catalog**

7) I added a RELATIONSHIP called: **Content (field\_catalog)**

8) I added a CONTEXTUAL FILTERS called **Taxonomy term: Name** using the previous relationship

Now if I enter "cars" in the **Auto preview Preview with contextual filters:** area it works fine. It only shows **products** that has **cars** term.

So the Catalog Menus is fine and the view is fine.

But if I go to the url www.mysite.com/en/catalog/cars it takes me to the list of content that has the temr **cars**. Here I need to show the **Catalog view** passing **cars** as an argument and not that list.

# Answer
> 2 votes
You have made one mistake that is easy to make. The alias created in the menu doesn't change the "true" url. So when you go to `catalog/cars` Drupal will perceive that as `taxonomy/term/[tid]`.

What you could do instead is to enable the default taxonomy term view that ships with Views (which uses `taxonomy/term/[tid]` as the path) and then set it up like you want.

See Screen shot:

---
Tags: views, taxonomy-terms
---


title: Fetch feed from a given URL

text:
# Question
Title: Fetch feed from a given URL
I have a URL like www.example.com/test/rss.xml, and I want to import this XML automatically in Drupal 6. I created the content type as in rss.xml, but I am not able to import automatically. I tried the Feed module for this, but I am able to upload manually, not automatically, when I need it to update all the feeds from rss.xml automatically.

Does anybody have an idea about this?

# Answer
Have you tried the Feeds module?

> Import or aggregate data as nodes, users, taxonomy terms or simple database records.
>
> * One-off imports and periodic aggregation of content
> * Import or aggregate RSS/Atom feeds
> * Import or aggregate CSV files
> * Import or aggregate OPML files
> * PubSubHubbub support
> * Create nodes, users, taxonomy terms or simple database records from import
> * Extensible to import any other kind of content
> * Granular mapping of input elements to Drupal content elements
> * Exportable configurations
> * Batched import for large files
> 2 votes

---
Tags: views, 6, feeds
---


title: Drupal 6, adding a admin menu?

text:
# Question
Title: Drupal 6, adding a admin menu?
I have a new module I made called kameleon\_create\_report, and I want to add a menu item to Reports. So I created my .module

```
<?php
function create_report() {
    print "test";
}

function kameleon_create_report_menu() {
    $items['admin/reports/orderreport'] = array(
        'title' => 'Order Report',
        'page callback' => 'create_report',
        'weight' => 1,
        'type' => MENU_LOCAL_TASK
      );
}
?>

```

And the info

```
; $Id$
name = Create Report
description = Report generator for orders
core = 6.x

```

But it's not showing up, even after a refresh.

# Answer
> 3 votes
You're missing one of either `access callback` or `access arguments`:

From the `hook_menu()` docs:

> "access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user\_access() unless a value is inherited from the parent menu item; only MENU\_DEFAULT\_LOCAL\_TASK items can inherit access callbacks. To use the user\_access() default callback, you must specify the permission to check as 'access arguments'

Sorry to paste so much but it's all relevant, the last sentence in particular.

Choose a permission that applies to your site and added it to your menu item:

```
function kameleon_create_report_menu() {
  $items['admin/reports/orderreport'] = array(
    'title' => 'Order Report',
    'page callback' => 'create_report',
    'access arguments' => array('access content'), // This is almost certainly NOT the permission you want to use, choose one with restricted access.
    'weight' => 1,
    'type' => MENU_LOCAL_TASK
  );

  return $items;
}

```

Also as Attiks points out you've forgotten to return `$items` from the menu hook.

Finally, simply refreshing the page won't work when you add a menu item (they are cached), so you need to clear Drupal's caches to see the new item.

# Answer
> 2 votes
You forget the return $items line.

Also rename create\_report to kameleon\_create\_report\_create\_report to avoid namespace clashes.

---
Tags: 6, routes
---


# Question
Title: Can I upgrade from Drupal 7.10 directly to Drupal 7.12
Should I upgrade from 7.10 to 7.11 first, then upgrade from 7.11 to 7.12?

Or can I just upgrade from 7.10 directly to Drupal 7.12?

# Answer
> 8 votes
You can update directly to 7.12 without any problems. Drupal 7.11 contains security fixes while 7.12 contains bug fixes. Updating to 7.12 would also add the security fixes from 7.11.

# Answer
> 3 votes
Theorically you can upgrade from any version to any version if you stay in the same major version (7.x), as new version contains all changes of the old ones.

This principe applies to contrib modules, too.

# Answer
> 0 votes
Yes you can upgrade it but it will be nice practice to have backup of your source before upgrading your drupal to remain safe from issue like this.

Also note that you haven't change or coded in any of drupal core files.

---
Tags: updating
---


title: When should I use a multi-site setup?

text:
# Question
Title: When should I use a multi-site setup?
I have 4 Drupal sites that have nothing to do with each other, except that they all run on Drupal and they're all managed by me.

The modules each site needs will vary, but they probably share some small subset of modules.

Is this situation a good candidate for using multi-site configuration?

What if I want to add a fifth site? How would I upload the new one, or how would that work?

# Answer
> 11 votes
Multi-site setups are a little tricky due to their reliance on the same codebase. You can use a multi-site setup in this scenario, but bear in mind that when you upgrade a module in `sites/all/modules`, it'll affect all the sites (unless overridden in `sites/$SITENAME/modules`).

This leads to potential issues where one of your sites relies on N version of a module, but you want to use N+1 on another site. The module in question might not have an upgrade path, or it might've drastically changed its functionality between versions (not as uncommon as you might think, given Drupal culture towards major versions).

Additionally, if there are critical database changes needed during a module upgrade, you'll find that you need to take down multiple sites at the same time to ensure you run `update.php`.

So for most use-cases, multi-site isn't the way to go. Unless you're really strapped for space or you have some weird hosting restriction that prevents you from mapping each site's domain to a separate folder, you're likely better off maintaining separate code bases and using tools like Drush and version control to speed up code deployment.

The prototypical use-case for multi-site, outside of its use as a workaround for restrictive hosts, is when you're deploying a ton of sites that are extremely similar. You might be running a hosting service, or building a bunch of micro-sites for a company, or what-have-you. In those cases, you can roll your own multi-site setup, but you should also consider using Aegir, which automates and abstracts a lot of the hassles of running such a set-up.

Adding new sites to a multi-site setup is pretty straightforward: create a new folder under `sites`, edit `sites/sites.php` (Drupal 7 only), copy `sites/default/default.settings.php` to `settings.php` in that new folder, and visit the site in a browser. Drupal should begin the installation process and use the new folder. Your new site will have access to all the modules under `sites/all/modules` just like your exiting sites.

# Answer
> 2 votes
I would use a Multi site where you have a related content offering but for different audiences.

For example we use it for our Intranet which supports multiple brands. This allows each brand to be administered individually with an option to share content / users (huge time saving on reducing duplication).

Also having a unique interface (menus/blocks/themed) goes a long way in ensuring different departments can easily access what is most important to them.

Lots of features are available using Domain Access such as allowing a user to set their default site, different sites by sub domain (So you could have marketing.intranet.local or engineering.intranet.local etc), search between sites, access control etc.

---
Tags: multi-sites
---


# Question
Title: Looking for a workflow module that can control content access
I have a content type called "article". It needs to go through some workflow states when people try to submit a new article: submitted -\> review 1 -\> review 2 -\> published.

During each workflow state, only certain roles should be able to see it, modify it, and comment on it. This needs to be done independently by its current workflow state. The workflow module appears to have access control based on states, but then the access control part does not work so essentially everyone can see the content no matter what state it is in. Not sure if this is a major security bug, permission being overridden by another module, or me doing something wrong.

Any other suggestions for modules that can do workflow? I heard Workbench is another good one. Can it keep track of comments and separate out comments based on workflow states?

# Answer
Update and solution: Turns out that I was not using the Workflow module correctly and Drupal's permissions correctly. I was assuming that the Workflow module could remove permissions. Instead I had to start with the least privileges in Drupal and then let the Workflow module allow/deny access to the content type.

For example, if Drupal permissions allow a visitor to see unpublished content, then the Workflow module's content access control will not block the person from seeing unpublished content.
> 0 votes

---
Tags: 7, nodes, users, workflows
---