# Question
Title: d7: to be inserted ID, is there a cleaner way?
I need to know the 'to be inserted ID'

I wrote the following function, it works, however, **I'm sure this is not the way to do it.**

```
 function insert_node_style($style) {
  // get latest id
  $id = db_query("SELECT MAX(nid) FROM {node}")->fetchCol('nid');
  $id = array_shift(array_values($id));
  $new_nid = $id + '1';
  // insert nid, vid and style
  db_insert('nodestyle_node') ->fields(array(
    'nid' => $new_nid,
    'vid' => '1',
    'style' => $style,
  ))
  ->execute();
}

```

Is there are cleaner/drupal way to achieve the same result?

# Answer
I don't think there's a 100% reliable way to get the ID that will be used next. Even the method you've got won't work completely. Take this example:

* Insert a node into the database (it has the new nid of 1 for arguments sake)
* Insert another node into the database (it has the new nid of 2)
* Then delete that second node
* Add a new node to the database again. This time it will have a nid of 3, not 2 (as would be expected from your code).

The problem is that the MySQL `AUTO_INCREMENT` value exists completely independently of the primary key ids that are currently in the database; so unless you reset the auto increment counter each time there's no way to reliably determine the next id.

Also in a system with multiple simultaneous accessess to the database using code like that introduces potential race conditions.

It would be far simpler to perform this task when the node has been saved, perhaps in `hook_node_save()`.

Oh and one other little thing, the `vid` you're inserting should not be `1`, it'll be determined for you by the system. Using `1` for every node will link every single node to one revision in the `node_revision` table...probably not what you're looking for.
> 2 votes

# Answer
The next `nid` for a node is not determined based on the maximum value of the `nid` column in the node table. In MySQL, it can be set explicitly using

```
ALTER TABLE node AUTO_INCREMENT = 42;

```

and is also subject to the `auto_increment_increment` variable.

You will also run into TOCTOU-problems when making assumptions about what the next `nid` will be.

Look for some other way to solve the underlying problem without making assumptions about what the next `nid` will be.
> 2 votes

# Answer
How about replacing your current query with:

```
SELECT Auto_increment
FROM information_schema.tables
WHERE table_name='the_table_you_want'
AND table_schema = DATABASE();

```

See https://stackoverflow.com/questions/933565/get-auto-increment-value-with-mysql-query

But I would have to agree with Oswald; is there another way to solve this problem?
> 1 votes

---
Tags: 7
---


title: Omega theme showing 404 on iPhone

text:
# Question
Title: Omega theme showing 404 on iPhone
I have a site on my local server which is served by Apache using virtual hosts. I am using an omega sub-theme. On the desktop everything works fine. I try to browse to the site via the iPhone by changing the web proxy setting to point to my server. That works and I get to my site via Safari on the phone. Every link I go to on the site gives me a page not found. I'm using views on the site as well. Looking at the Apache access log I see the entry for Safari that results in a 404 and then Chrome when I browse on my laptop which succeeds.

Any thoughts on where I should start looking for the problem?

```
octopus.dev:80 192.168.1.106 - - [01/Oct/2012:11:00:52 -0500] "GET http://octopus.dev/ HTTP/1.1" 404 5756 "http://octopus.dev/" "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3"
octopus.dev:80 192.168.1.147 - - [01/Oct/2012:11:01:30 -0500] "GET / HTTP/1.1" 200 7475 "http://octopus.dev/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4"
octopus.dev:80 192.168.1.147 - - [01/Oct/2012:11:01:31 -0500] "GET /sites/default/files/videos/original/output_file_2.mp4 HTTP/1.1" 206 390 "http://octopus.dev/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4"
octopus.dev:80 192.168.1.147 - - [01/Oct/2012:11:01:31 -0500] "GET /favicon.ico HTTP/1.1" 404 661 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4"

```

# Answer
> 0 votes
I simply needed to install and configure a proxy server and point my iPhone to it. I installed squid on the ubuntu box via apt and then on the iPhone under the wireless settings pointed it to the proxy.

---
Tags: http-request
---


# Question
Title: Is it possible to add unlimited values as a group of fields?
Imagine I have a content type that asks you to list your friends. The 2 fields are:

| first name |

| last name |

Is there a way a user could add unlimited friends for both fields (i.e. first and last name) as a set? Right now Drupal is not smart enough and only let's me add unlimited first names or unlimited last names. In other words, they are not paired together.

If any of you have used Sharepoint, then you will know what I mean. In Sharepoint you can easily hit the "add another" link and it would create a new set of first name and last name fields that stick together as a group. You do not want to separate the first and last name fields.

# Answer
> 4 votes
For your use case, there is the Field Collection module; the description given in its project page is the following.

> Provides a field-collection field, to which any number of fields can be attached.
>
> A field collection is internally represented as an entity, which is embedded in the host entity. Thus, if desired field collections may be viewed and edited separately too.

The latest stable release for Drupal 7 is 7.x-1.2, released on December 26, 2020; it's not covered by the security advisory policy. The development snapshot for that release has been last updated on March 26, 2021.
For Drupal 8, the project maintainers suggest using a different module.

> Use Paragraphs and Entity Reference Revisions instead of field collection for Drupal 8 projects.

Since one of those modules doesn't have a release for Drupal 7, that suggestion isn't for users who are running Drupal 7 sites.

---
Tags: 7, entities
---


# Question
Title: searching custom node type contents from a module
If I create my own custom node type by writing my own module(s), is Drupal "smart" enough to index the contents of this new node type from my module? If not, then would I need to use the Search API's so that contents are included in search results?

# Answer
> 1 votes
Core search module will index all nodes, no matter where they have been defined (manually through admin/custom module.).

---
Tags: 7, search
---


# Question
Title: How to restrict creation of content based on unique field values?
I'm not entirely sure how to title this question. I want to restrict the creation of a particular content type to one entry per user per the value of a particular field. So essentially what I'm saying is you should be unable to create a second piece of content of a particular type if the value of a particular field is identical to the value of the same field but in another piece of content created by the same user.

Is there anyway to accomplish this?

# Answer
I'm not aware of an existing module with that functionality, but it wouldn't be too hard to code your own custom module to do the job.

This is an example using the 'article' node type:

```
function MYMODULE_form_article_node_form_alter(&$form, &$form_state, $form_id) {
  if (empty($form['nid']['#value'])) {
    $form['#validate'][] = 'MYMODULE_article_node_form_validate';
  }
}

function MYMODULE_article_node_form_validate($form, &$form_state) {
  global $user;

  // See if this user has already created a piece of content of this type.
  $args = array(':uid' => $user->uid, ':type' => 'article');
  $count = db_query('SELECT COUNT(nid) FROM {node} WHERE uid = :uid AND type = :type', $args)->fetchField();

  // If they have, check for another node created by the user with the same field value
  if ($count > 0) {
    $query = new EntityFieldQuery;
    $query->entityCondition('entity_type')
      ->entityCondition('bundle', 'article')
      ->propertyCondition('uid', $user->uid)
      ->fieldCondition('field_some_field', 'value', $form_state['values']['field_some_field'][LANGUAGE_NONE][0]['value']);

    $results = $query->execute();

    // If we have a result, invalidate the form.
    if (!empty($results['node'])) {
      form_set_error('field_some_field', t('Error message here'));
    }
  }
}

```

That'll need a bit of massaging to match your exact situation, but it should be a good place to start.
> 2 votes

# Answer
This is probably not ideal and the lazy and ugly way, but you could look at the unique field module

http://drupal.org/project/unique\_field

I say it's ugly because the user will still be able to fill out all the fields and believe they can submit the content, but when it comes to validation after submitting it, then they'll get the error, but probably won't know why.
> 0 votes

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


title: file_save_upload with multiple form

text:
# Question
Title: file_save_upload with multiple form
I have a form with the following input field:

```
<input type="file" name="photo_files[]" />

```

I would like to save each of this files using file\_save\_upload and then change their status to permanent via `file_save`. It seems `file_save_upload` only takes a name and NOT an array. How can I accomplish this?

# Answer
Here is how you could do it.

```
function mymodule_testes($form, $form_state) {
// your form definition goes here
  $form = array();
  $form['upload'] = array( // note the key
    '#type' => 'file',
    '#title' => t('Choose a file'),
    '#weight' => -10,
  );

  $form['upload2'] = array(
    '#type' => 'file',
    '#title' => t('Choose a file'),
    '#weight' => -10,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('submit'),
  );

  return $form;
}

function mymodule_testes_validate($form, $form_state) {
  dpm($form_state);
  // pass proper args to file_save_upload .. see documentation
  $file1 = file_save_upload('upload' , array()); // remember the key
  $file2 = file_save_upload('upload2' , array());
  // you dont have to do it verbosly
  // Do all your  validations  if(!$file1 || !$file2) form_set_error ...

  // save it onto form_State
  $form_state['files_storage'][0] = $file1
  $form_state['files_storage'][1] = $file1
  dpm($file1);
  dpm($file2);

}

function mymodule_testes_submit($form, $form_state) {
 // using devel so you could see how it is stored
 dpm($form_state);

  foreach ($form_state['files_storage'] as $key => $file) {
    $file->status = FILE_STATUS_PERMANENT;
    file_save($file);
  }
}

```

Hope this helps
> 1 votes

# Answer
Just loop through them in your submit handler:

```
foreach($form as $key => $item) {
  if($item['#type'] == 'file') {
    file_save_upload($key, array());
  }
}

```

That'll run file\_save\_upload on all form items with the type of 'file', you could also turn that conditional to an `in_array()` and select other file field types you could use.
> 0 votes

---
Tags: files
---


# Question
Title: How can we synchronize Nodes from Staging to Production Server
My Question is there any way we can track the node changes on Staging Server and Push the same to the Production Server. Best use case will be,

* Customer does not want to change the content on Production server.
* He wants to first change on Staging server get it tested and push the content to live server.
* Have revisions for changes so that he can revert back any time using node re- visioning system !

Can we do this maintaining the node id's same across staging and live servers ? Is there any out of the box solution for this like feature module does for configuration changes tracked using modules?

# Answer
> 3 votes
For Node changes, you can use node export module to migrate node between drupal installations. for Tracking Configurations changes there is another module configurations , i haven't tried yet. Be sure cos the module release is still in dev

# Answer
> 2 votes
Helpful conversation here.

You could also check the Deploy module

> The Deploy module is designed to allow developers to easily stage Drupal content from one site to another. Deploy automatically manages dependencies between objects (like node references). It is designed to have a rich API which can be easily extended to be used in a variety of situations.

---
Tags: 7, nodes, staging
---


title: Overriding hook_menu() { $items }

text:
# Question
Title: Overriding hook_menu() { $items }
For example, here's a snippet form the Comments Module (comment.module):

```
function comment_menu() {
  $items['comment/%'] = array(
    'title' => 'Comment permalink',
    'page callback' => 'comment_permalink',
    'page arguments' => array(1),
    'access arguments' => array('access comments'),
  );
  $items['comment/reply/%node'] = array(
    'title' => 'Add new comment',
    'page callback' => 'comment_reply',
    'page arguments' => array(2),
    'access callback' => 'node_access',
    'access arguments' => array('view', 2),
    'file' => 'comment.pages.inc',
  );

  return $items;
}

```

How can I override `$items['comment/%']` with `$items['comment/reply/%node']`, without hacking core.

In other words, I need `example.com/comment/[cid]` to look exactly like `example.com/comment/reply/[nid]/[cid]`?

# Answer
> 8 votes
Yes, you should use hook\_menu\_alter Create new module and add hook\_menu\_alter

```
function my_module_menu_alter(&$items) {
    // Unset core path
    unset($items['comment/%']);
    $items['your/pass/here/%node'] = array(
        'title' => 'Add new comment',
        ...
      );
}

```

But link "comment/reply/%nid/%cid" is used by Drupal for replies to other comments (where %nid - node id and %cid - comment id you are replying to). Use another path.

# Answer
> 1 votes
You can always use hook\_menu\_alter and pass the same page callback and arguments.

---
Tags: 7, routes
---


title: Show fields empty via render()

text:
# Question
Title: Show fields empty via render()
I have a content type with some fields. My client want that the empty fields must to be visible, obviously only the label. Like

```
Status: New
Owner:
Read: 714

```

I write these "fields" in my node--XYZ.tpl.php file via

```
<? echo render($content['field_all_status']); ?>

```

But there are not "emtpy fields"

How I can set Drupal to display all fields, empty too?

# Answer
> 2 votes
Try the Empty fields module. I didn't use it, but look like that's the module you need.

> This module provides a way to show empty fields that would otherwise be hidden.

---
Tags: 7, entities, theming
---


# Question
Title: Query and print out random nodes in drupal
How to query random nodes in Drupal 6 without views?

I can print out last nodes but random nodes are the problem.

# Answer
Not sure where you are doing this, but this would be one dull ax way of doing it:

```
$query=db_query('SELECT nid, RAND() as _random FROM {node} WHERE status = 1 ORDER BY _random ASC LIMIT 1');
$result=db_fetch_object($query);

```

and then you can do whatever you want with `$result->nid`, another dull ax:

```
drupal_goto('node/' . $result->nid);

```

or

```
$node=node_load($result->nid);
// do whatever you want with it

```

etc
> 5 votes

---
Tags: 6, theming, nodes
---


# Question
Title: What is the best way to migrate and optimize 300 GB database to drupal?
I have a database that was running on a propitiatory system with a hosting company. The data is about 10 years old and mostly text. The database it too large aprox 300GB. We are trying to migrate the database to Drupal and I am wondering if this is a good idea and whether drupal/mysql could support such large databases or not. I have a few thoughts such as archiving the data and using caching tools such as varnish. Is this a good idea? Can drupal support/serve it? What impact could this have on performance?

Edit: We have already migrated the database but performance is a extremely bad. ~17 million nodes, and ~90 million comments. What could I optimize? what kind of infrastructure would you recommend? caching and architecture? Load balancing? Any hints or tips that could help run such big site with drupal is what I need. Case studies if anyone is aware of.

# Answer
> 2 votes
Drupal can support any size of a database. Although as a CMS, Drupal is fairly light, it's still a lot more resource hungry than a simple coded site. It will almost definitely require more hardware resources, which can partially be addressed by caching.

I hope I don't get boo'd for this, but I did see a fair number of large sites switch away from Drupal, such as Realself, which had 150,000 nodes, you can read the story here.

If you decide to stick to Drupal, I'd recommend the following:

* Use caching. I personally use a combination of Memcache, Boost modules and Drupal's core caching modules. Memcache stores the recent & most used queries in memory for fast retrieval; in your case it would seem like a good choice. Boost is great for serving pages to anonymous people or to handle floods. It caches pages by generating a page once and serving the same page until it expires.
* To increase the database performance, you can also host your database on a cloud, such as Google's BigQuery.
* Last, but not least, give Pantheon or Acquia a try. Both of these companies employ some of Drupal's most talented people, providing scalable hosting and management of large Drupal sites. They also take care of all your caching needs, which will probably cost you less than hosting yourself.

# Answer
> 2 votes
The answer is Yes. First - because you are asking on Drupal Answers site. I would recommend you using configuration like this:

* 0 Load balancer managing several servers
* 1 Varnish (proxy cache)
* 2 Nginx (php-fpm)
* 3 Drupal
* 4 MySQL (Master+Slave)

Also memcache can be used. The main problem will be when you will try to update/insert new record in DB. All read queries will be managed by caching-proxying systems. If you need text search - use ApacheSolr. Try to not views or panels, with such DB size you can have perfomance issues.

---
Tags: database
---


# Question
Title: How to find out the terms which are not being used for some duration
I have vocabulary and it contains more terms, so I want to implement purge logic on it. i.e. I want to delete all the terms which are not used for some duration say 1 week.

**Example**

term1 was associated to node1 on Oct 1st term2 was associated to node1 on Sep 30 term1 was associated to node2 on Oct 5th

So now term 2 was not being used for last one week, so now I need to delete that term alone.

I have tried following query,

```
SELECT ti.tid, td.name, ti.nid
FROM taxonomy_index ti
JOIN taxonomy_term_data td ON ( td.tid = ti.tid )
WHERE td.vid =48
AND ti.created < UNIX_TIMESTAMP( DATE_SUB( NOW( ) , INTERVAL 2 WEEK ) )

```

However this query gives me both term1 and term2

# Answer
> 1 votes
Actually the reason for that is that the ti.created column is "The Unix timestamp when the node was created." It does not track the time when the tag was applied to the node, rather the time the node was created.

So that will always have the same value for each row that describes the tag associated with any one node. Look at this screenshot of my taxonomy\_index table that displays three different tags I just applied to my node at different times:

From what I can tell, if you wanted that functionality, you'd have to store that timestamp (when a node was actually tagged) in your custom module yourself and you'd have to query that value.

Anyway, hope this helps clarify the issues a little. :-)

# Answer
> 1 votes
You will need a custom module which will track term usage.

file `my_module.install`

```
/**
* Implements hook_install()
*/
function my_module_install() {
    $spec = array(
        'description' => 'Last used timestamp',
            'type' => 'int',
            'not null' => TRUE,
            'default' => 0
          );
        db_add_field('taxonomy_index', 'used', $spec);
    }
    return true;
}

file `my_module.module`

function my_module_node_update($node) {
    //read all fields created by taxonomy module
    $term_fields = array_intersect_key(field_info_instances('node', $node->type), field_read_fields(array('module' => 'taxonomy')));
    // array for storing added terms
    $diff_terms = array();
    foreach ($term_fields as $field_name => $field) {
        $new_terms = $old_terms = array();
        // detect language
        $field_langcode = field_language('node', $node, $field_name, LANGUAGE_NONE);
        // we need onli "tid" field
        foreach ($node->{$field_name}[$field_langcode] as $term) {
            $new_terms[] = $term['tid'];
        }
        foreach ($node->original->{$field_name}[$field_langcode] as $term) {
            $old_terms[] = $term['tid'];
        }

        $diff_terms += array_diff($new_terms, $old_terms);
    }
    // update table - set current timestamp
    db_update('taxonomy_index')
            ->fields(array('used' => time(),))
            ->condition('taxonomy_index.tid', $diff_terms, 'IN')
            ->execute();
}

```

This will update all terms, used by nodes. In table "taxonomy\_index" you'll get new field with last updated timestamp

After you can use hook\_cron to delete "old" terms.

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


# Question
Title: Is it possible to export arbitrary configurations?
I'm trying to create feature modules for as much as possible, such as

* my backup schedule (for the Backup & Migrate module)
* my shortcut sets
* etc. etc.

and I'm surprised how much ***can't*** be exported with Features. Is there some way to do this? Either with an alternative module, or with something that extends Features, or by hand-coding the feature module, or by dumping just a specific table from the database???

# Answer
For some of the configurations/settings that aren't picked up by the Features module, there is the Strongarm module.

> Strongarm gives site builders a way to override the default variable values that Drupal core and contributed modules ship with. It is not an end user tool, but a developer and site builder tool which provides an API and a limited UI.
>
> An example of such a variable is site\_frontpage. In Drupal this defaults to node, which ensures that the front page gets content as soon as some exists, but for many Drupal sites this setting is simply wrong. Strongarm gives the site builder a place in the equation - an opportunity to set the site\_frontpage to something that makes sense for their site.

At the time this answer has been posted, the *Backup and Migrate* module wasn't yet compatible with neither the Features module nor the Strongarm module. See Make backup profiles and schedules Features exportable, (closed as fixed on May 6, 2013) for what exactly the issue was and which branch fixed it. The bug report doesn't contain any patch: The code has been developed in a branch different from the branch for which the issue was opened.
> 5 votes

---
Tags: features, importing-exporting
---


# Question
Title: How to alter the default user permisions based on a returned value after login?
I am having some users who have access to a limited modules. Now after a user logs in, i want to alter the permissions of that user based on the uid. I mean i should be able to add or delete some permissions of that user immediately after a user logs in. Immediately after login i wrote a custom code which executes and returns a value whether the user is active or inactive. Then based on the result i should be able to delete some permissions to access some modules of my site if inactive or add if he is active.

# Answer
user\_role\_grant\_permissions can help you. Or you are using modules which grant permissions based on users not on roles? If yes, look into code of module which control permissions per user to find proper function
> 0 votes

---
Tags: users, 6
---


# Question
Title: path_to_theme() goes to parent theme not subtheme
I'm using zen as my parent theme and for some reason **path\_to\_theme()** is suddenly printing `/sites/all/themes/zen` instead of the subtheme `/sites/all/themes/<mytheme>`. What's even more confusing is that it's only happening when **node/12** is being displayed.

Could this code have something to do with it?

```
<?php
//template.php
if(isset($vars['node'])){
    if($vars['node']->nid == 12) {
        $vars['is_request_quote'] = true;
    }
}
?>

```

I use the variable `$is_request_quote` to change the layout in page.tpl.php. I do this through `<?php elseif( $is_request_quote ) : ?> -New layout here- <?php endif; ?>`. Could that be the one affecting it?

# Answer
I found the answer! It's probably not the best one so feel free to challenge. After several tests, I found out that `path_to_theme()` correctly points to the subtheme in **page.tpl.php** but when you use it in **node.tpl.php** it suddenly points to the parent theme (zen).

My answer is a 2 step process starting with creating the variable which stores the path I want:

```
function themename_preprocess(&$vars, $hook){
    $vars['THEMEPATH'] = base_path() . path_to_theme(); //points to subtheme
}

```

then to make sure it works in nodes, enable the following function to make it available in node.tpl.php. There doesn't need to be anything inside it, as long as the function gets declared in your `template.php` file.

```
function themename_preprocess_node(&$vars, $hook){
    // Put anything here or leave it blank
}

```

After doing so, voila! You can now use $THEMEPATH in both nodes and pages.
> 2 votes

# Answer
I had this problem too. Solution here, applied to node instead of page, worked for me: copy `node.tpl.php` to your custom theme templates directory. Once I did that, `path_to_theme()` behaved correctly.
> 4 votes

---
Tags: 7, theming, uri
---


# Question
Title: Views api: how to create a 'conditional' join
I have 3 tables:

```
Table 1      Table 2            Table 3
id_1 [...]   id_1, type, id_2   id_2 [...]

```

I want to join table 1 to table 3 by way of table 2. This is easy enough,eg.

```
$data['table3']['table']['join']['table1'] = array(
  'left_table' => 'table2',
  'left_field' => 'id_2',
  'field' => 'id_2',
);
$data['table2']['table']['join']['table1'] = array(
  'left_field' => 'id_1',
  'field' => 'id_1',
);

```

However, the intermediary table also has a 'type' attribute in it. What if I want to specify, *as part of the join*, what the type is? eg. I want something like this:

```
SELECT id_a.table1 FROM table3
LEFT JOIN table2 ON table3.id_2 = table2.id_2 AND table2.type = 'blah'
LEFT JOIN table1 ON table2.id_1 = table2.id_1;

```

To be clear, I want the condition to the part of the join, not after the fact (as a filter will remove null rows).

# Answer
> 3 votes
I havent done this in Views 3, but try the following, adopted from Views2 blog post applied to your code: http://www.agileapproach.com/blog-entry/views-2-table-aliases-and-extra-criteria

```
# I think you had typo in your join for table2 where
# you had as the final key 'table1'.
$data['table3']['table']['join']['table2'] = array(
  'left_table' => 'table2',
  'left_field' => 'id_2',
  'field' => 'id_2',
  'extra' => array(
      array('field' => 'type', 'value' => 'blah'),
    ),
);

```

---
Tags: views
---


# Question
Title: Developing sites while using Aegir and Drush make
I read this article from mig5.net about 'Drupal deployments & workflows with version control, drush\_make, and Aegir'. I am impressed by the efficiency of the workflow described here, and I really want to implement this. I read it again and again, but one thing won't get clear to me.

How do you, while developing websites, get your changes into the next build? When you find out you need an extra module, how can you get this in the next build when the (for example contrib) module isn't controlled in git? Do you need to edit your .make file every time you want to add a module, library etc.?

Thanks in advance.

# Answer
> 2 votes
Yes. The short answer is you update your Drush make file to point to the new version of the module you want to be included in your new platform(build).

In your drush make file you would include the version of each module you are including in your platform build. So views for example would look like this.

```
projects[views][subdir] = "contrib"
projects[views][version] = "3.4"

```

Now if you want to update to the new version of Views module you would update your make file to something like this.

```
projects[views][subdir] = "contrib"
projects[views][version] = "3.5"

```

Then build a new platform in Aegir using this updated drush make file. Then you would migrate the site to the new platform and Aegir will do the update for you.

It's a pretty slick workflow. I keep all of my drush make files in a repo called builds so I can have a record of each build of a project. Hope that helps.

# Answer
> 1 votes
Bob beat me to it :) but in response to this and your email you sent me, yes indeed this is the correct procedure. Treat your Drush makefile as the 'blueprint' of your application.

Work away in development manually / clone your live site and manually 'drush up' or 'drush dl' a module and test that everything works as expected.

Then fold that new module/updated version into your makefile, build a new platform each time the makefile is updated, and use the 'Migrate' task to 'upgrade' your application onto the target platform.

If something goes wrong during the upgrade (e.g during the drush updatedb which occurs during a Migration to apply schema updates in your database), Aegir will, in most cases, automatically roll back to the previous platform, which is the appeal of such a system.

---
Tags: drush
---


title: Saving email addresses

text:
# Question
Title: Saving email addresses
I create a simple ecard page where users can send some (stupid) ecard to other people.

Now for some reason our clients wants to save all these email addresses, and I'm wondering what the best way to do this is? Obviously I would also need to show a list in the admin.

I was thinking of just using some newsletter module, but for none I checked there is a function where I can add email addresses using coding.

Does anybody know a quick and simple solution? I have custom coded this page, so I'm looking for a module that allows me to add email addresses in php.

# Answer
You might as well do it right and use webform. It will literally take you minutes once you figure it out.

And then for the ecard submission, you could install the rules module and pass the form values as tokens (including the email address) telling rules that when a webform with the id of "supid\_ecard" is submitted, fire this rule -- http://drupalcontrib.org/api/drupal/contributions!rules!rules.module/function/rules\_invoke\_event/7

All you'd need to do is setup a custom module with `hook_rules_event_info()` to tell Drupal about your rules, `hook_token_list()` to list out your tokens, and `hook_token_values()` so it knows how to render your tokens. Or use the tokens already available.
> 2 votes

# Answer
You could try and create a new content type and call it something like stupid\_ecard, Then you would create a module and use Hook\_node\_insert to get all the data from your form and insert it in your node.

Then you could create a view that would get the email field "or any other fields" from your content type and show it in a list.
> 0 votes

# Answer
Thanks for all the advice, it might not be the prettiest solution, but I ended up using the Watchdog to log the emails. I then used Watchdog Views to create a page with just these specific actions, as Watchdog is used for logging I figured I could just log every person who sends an ecard.
> 0 votes

---
Tags: emails, users
---


# Question
Title: Create a table with courses of a certain curriculum
I'm a newbie when it comes to Drupal. I already tried to do it with content types and views but can't seem to accomplish what I need.

I need to create a table with a list of curriculum. Each curriculum name should be a link. So, when you click on a certain curriculum, it'll take you to a page with a table that lists the courses for that curriculum.

Something like the following:

```
Curriculum List
| Name      | Total Credit Hours |
----------------------------------
| Drupal 7  |                 15 |
| WordPress |                 15 |
| Joomla!   |                 15 |
----------------------------------

```

Then, when user clicks on Drupal 7:

```
Drupal 7 Courses
| Name                                         | Credit Hours |
---------------------------------------------------------------
| Drupal 7 Essentials                          |           3  |
| Drupal 7 Advanced Training                   |           4  |
| Drupal 7: Reporting and Visualizing Data     |           4  |
| Drupal 7: Creating and Editing Custom Themes |           4  |
---------------------------------------------------------------

```

If possible, I don't want to create this by writing a template file since I'm new to Drupal. If someone can at least point me in the right direction I will really appreciate it.

Thanks in advance.

# Answer
> 1 votes
Add a vocabulary for Curriculum List ,then add Drupal 7, wordpress etc as terms in your vocabulary.

Create a content type for 'Courses'. Link your Curriculum List taxonomy to courses content type.

Then create view to list your taxonomy term and Total Credit Hours with format as table.

Create another view to list all courses, with a 'contextual filters' as taxonomy term id.

Link your first Curriculum view's taxonomy term to the courses view , eg: courses/2 where

courses is your course views display path and 2 is the term id.

---
Tags: views, nodes
---


# Question
Title: Show custom page while the server processes a form
Form submit handler sends some time consuming requests to other servers. I need to show custom page with some simple content like timer/progress-bar/images while server will process submitted data.

Not sure how this could be properly done in Drupal 6.26.

Found useful batch tool (set\_batch()), but didn't figure out how to replace default progress-bar with custom page and content.

# Answer
Just add an onclick event handler for submit button and add a DIV with a loading image with `display:none` attribute in CSS.

```
function show_loading_icon(){
  $("#loading_icon").show();
}

```

So when you click on submit button a DIV will now become visible which you can use to dispaly a loading icon. Once form is submitted it will reload page and DIV will be hidden again.
> 0 votes

# Answer
Checkout the module loader , it may solve your problem

A similar module hide\_submit
> 0 votes

---
Tags: 6, batch-operations
---


title: Acquia stack / Wamp slow on response

text:
# Question
Title: Acquia stack / Wamp slow on response
I am developing a site on my localhost. I used WAMP but it takes too long to load pages from time to time. Something like 20 seconds execution time according to devel. Not on every page, not every time, but happens often enough to disrupt any kind of work I am trying to do. After no much success in debugging the problem I decided to try "DAMP" the Acquia stack for Drupal.

The difference is enormous- execution time is less than 1000 ms, which although much is something workable for dev. stage; Memory used peaks at 12 MB instead of 50 in wamp.

Still there is this problem of pages not loading fully. When I click on a link the browser shows that it is "connecting" and it will stay like that indefinitely (takes more than 2 minutes to time out), but if I interrupt and refresh the page loads instantly (100-300 ms) This again would be acceptable if it didn't interfere with my work. I can't add or delete content because of this. It just stays on "connecting" and on refresh it hasn't made the action.

So my question is what makes acquia stack not finishing the page loads and wamp server to be so damn slow?

I am talking about drupal 7, hardware shouldn't be an issue (Core 2 duo at 3.1 Ghz, and 3 GB RAM, somewhat old, but still kicking)

# Answer
> 0 votes
I thank both Citricguy and MauiTechSpot for directing my attention to Cron failing.

The site uses apache solr server and turns out that during some actions ( cron and deleting content ) Acquia-Drupal stack tries to connect to it. If it isn't turned on, Drupal will be waiting for connection indefinitely. This wasn't the case with my WAMP setup so I had the habit of fiddling around without turning on solr. As you can see it took me obscene amount of time to figure that out.

# Answer
> 0 votes
The WAMP issue sounds like CRON was not configured properly on a low traffic development site. All of your scheduled tasks were likely backing up and running only when you loaded your site manually.

As for DAMP, do all php pages never complete or only Drupal? Also, do static pages complete or time out?

---
Tags: performance
---


# Question
Title: Automatic Item Number Creation (For article posting as a Reference for Quick Searching)
I'm looking for a solution for automatic item number creation that will auto-create a reference number/code for any posted article, whatever the Node type. The purpose being that for any posted article (any Node type) that is created & posted by an author (with permission Roles authorised to post content) will have an item reference which can be traced throughout all aspects of workflow (including any Ticket Support document output - printer etc). This could quite simply be a standard item number as of that used on eBay (string of numbers) or similar used in organisational-wide portal. It might be for use in a local sales listing references (as in Gumtree), a vehicle listing platform (autotrader.co.uk) or simply to give a volumous document based content site a posting reference (internal intranet/external netsite), which for example, a 3rd party reader can jot down on paper, (email, cut and paste in Notes etc) and come back later and do a simple 'search' with the reference number, but not a 'purchase order' reference (as in Ubercart), purely for article reference purposes.

I'm not looking for anything tremendous (I'm not a PHPer (yet!) and I know this is more of a backend SQL DB but being more a Drupal 'plumber'/experimentalist I'm looking for simple solution for now that can be built upon later; something that Barcode module can also take advantage of and I can use in future projects of informational DataBases. Does anyone know of such a suitable solution/module for D7?

Any comments or How-tos welcome. Thanks.

# Answer
Option 1. You can use an existing node ID (NID).

Each node already has an ID and can be accessed via `/node/[nid]`, \[nid\] being the ID of the node. Or you can generate a path alias by inserting `<?php print l('link', 'node/' . $nid); ?>`, `$nid` being the ID of the node. To retrieve NID of a current node, insert `<?php print $node->nid; ?>` into `node.tpl.php`.

Option 2. You can also use the combination of Automatic Nodetitles and Token module. This will allow you to automatically generate node title with the values from the Token.

Once the modules are installed, go to Structure -\> Content Types, click on Edit, next to your content type. While on the Automatic title generation tab, select to Automatically generate the title and hide the title field, and in Pattern for the title, post a token from the options below; see the image below. There are many options with tokens, such as Unix timestamp (my favorite), random numbers and more.

Update:

For a truly random serial number, instead of using the Token module, I'd suggest using uniquid(); it generates a 13 character long random serial, no duplicates. This would be my choice. To do so, put this into "Pattern for the title" field, don't forget to check "Evaluate PHP in pattern":

```
<?php echo uniqid(); ?>

```

If you have spare time, there is also a Serial Field and Universally Unique IDentifier module, which also generate unique values.
> 1 votes

# Answer
Checkout this module Universally Unique IDentifier . It may suit your needs.
> 0 votes

---
Tags: 7
---


# Question
Title: Display a value for an empty CCK Field without setting a default value?
I have a few fields in one of my content types that will not always have values entered for them. One such field is "Booking Contact." When content is created, if the author does not know the booking contact, then they are supposed to leave the field blank. However, this means that the field data is empty, and the field does not display in the node at all. I'd like to display a message for these empty fields-- similar to Views' no results text -- so that users can see that there is not a value assigned to the field. What would be the best way to go about doing this?

EDIT: I'd like to avoid using "default value" to define this. The message I want displayed doesn't make as much sense in the creation form, and will likely be confusing to users. Unless, of course, there's a way to hide the default value in the creation form.

# Answer
The empty\_fields modules will help in this case
> 1 votes

# Answer
I assumed you already know $node.

you can write the code belowed!

```
$node=node_load($nid);
$temp=$node->yourfield['und'][0]['value'];

if(empty($temp))
{
   drupal_set_message(t('alerting for empty field'));
}

```
> 0 votes

# Answer
```
yourmodule_node_submit($node, $form, &$form_state)
{

     if(empty($form['yourfield']['#value']))
     {
           drupal_set_message(t('alerting for empty field'));
     }
}

```

but if u already know the node id, u can use node\_load
> 0 votes

---
Tags: entities
---


# Question
Title: Aegir/OpenAtrium site crashing out of memory. Help?
Aegir/OpenAtrium site crashing out of memory. Help?

I have a 768 Linode on a CentOS LAMP running Drupal Aegir with just 3 Open Atrium sites, and about 10-20 concurrent users. At random times, it pukes Out of Memory kill. I can't figure out what's causing it. I'm not sure if i need to do some memory usage tweaking on my CentOS LAMP stack. I need to get this under control quickly or management is going to kill this project.. After a couple hours of a crash and burn OOM, here's some info. To my eye, it doesn't look like anything is wrong.

**First the ugly OOM output**

> ck:0kB pagetables:0kB unstable:0kB bounce:0kB writeback\_tmp:0kB pages\_scanned:0 all\_unreclaimable? y es lowmem\_reserve\[\]: 0 700 754 754 Normal free:5060kB min:3348kB low:4184kB high:5020kB active\_anon:339984kB inactive\_anon:340208kB act ive\_file:0kB inactive\_file:0kB unevictable:1408kB isolated(anon):0kB isolated(file):0kB present:7172 88kB mlocked:1408kB dirty:0kB writeback:0kB mapped:604kB shmem:28kB slab\_reclaimable:7776kB slab\_unr eclaimable:8448kB kernel\_stack:1128kB pagetables:4404kB unstable:0kB bounce:0kB writeback\_tmp:0kB pa ges\_scanned:0 all\_unreclaimable? yes lowmem\_reserve\[\]: 0 0 428 428 HighMem free:116kB min:128kB low:192kB high:256kB active\_anon:17624kB inactive\_anon:17932kB active\_f ile:0kB inactive\_file:0kB unevictable:3136kB isolated(anon):0kB isolated(file):0kB present:54868kB m locked:3136kB dirty:0kB writeback:0kB mapped:3080kB shmem:0kB slab\_reclaimable:0kB slab\_unreclaimabl e:0kB kernel\_stack:0kB pagetables:0kB unstable:0kB bounce:0kB writeback\_tmp:0kB pages\_scanned:2 all\_ unreclaimable? yes lowmem\_reserve\[\]: 0 0 0 0 DMA: 64kB 28kB 716kB 832kB 864kB 7128kB 5256kB 0512kB 01024kB 02048kB 04096kB = 3096kB Normal: 6394kB 2978kB 916kB 032kB 064kB 0128kB 0256kB 0512kB 01024kB 02048kB 04096kB = 50 76kB HighMem: 64kB 18kB 016kB 332kB 064kB 0128kB 0256kB 0512kB 01024kB 02048kB 0\*4096kB = 128kB 56664 total pagecache pages 55697 pages in swap cache Swap cache stats: add 17100319, delete 17044622, find 7567477/9043262 Free swap = 0kB Total swap = 524284kB 198640 pages RAM 13826 pages HighMem 6639 pages reserved 14545 pages shared 188067 pages non-shared Out of memory: Kill process 3448 (httpd) score 41 or sacrifice child Killed process 3448 (httpd) total-vm:74716kB, anon-rss:26132kB, file-rss:1120kB

**Processes running**

```
[root@li21-298 ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2208 492 ? Ss 19:34 0:00 init [3]
root 2 0.0 0.0 0 0 ? S 19:34 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 19:34 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/0:0]
root 5 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/u:0]
root 6 0.0 0.0 0 0 ? S 19:34 0:00 [migration/0]
root 7 0.0 0.0 0 0 ? S 19:34 0:00 [migration/1]
root 9 0.0 0.0 0 0 ? S 19:34 0:00 [ksoftirqd/1]
root 10 0.0 0.0 0 0 ? S 19:34 0:00 [migration/2]
root 12 0.0 0.0 0 0 ? S 19:34 0:00 [ksoftirqd/2]
root 13 0.0 0.0 0 0 ? S 19:34 0:00 [migration/3]
root 15 0.0 0.0 0 0 ? S 19:34 0:00 [ksoftirqd/3]
root 16 0.0 0.0 0 0 ? S< 19:34 0:00 [cpuset]
root 17 0.0 0.0 0 0 ? S< 19:34 0:00 [khelper]
root 18 0.0 0.0 0 0 ? S 19:34 0:00 [kdevtmpfs]
root 19 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/u:1]
root 21 0.0 0.0 0 0 ? S 19:34 0:00 [xenwatch]
root 22 0.0 0.0 0 0 ? S 19:34 0:00 [xenbus]
root 162 0.0 0.0 0 0 ? S 19:34 0:00 [sync_supers]
root 164 0.0 0.0 0 0 ? S 19:34 0:00 [bdi-default]
root 166 0.0 0.0 0 0 ? S< 19:34 0:00 [kblockd]
root 176 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/3:1]
root 178 0.0 0.0 0 0 ? S< 19:34 0:00 [md]
root 262 0.0 0.0 0 0 ? S< 19:34 0:00 [rpciod]
root 263 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/2:1]
root 275 0.0 0.0 0 0 ? S 19:34 0:04 [kswapd0]
root 276 0.0 0.0 0 0 ? SN 19:34 0:00 [ksmd]
root 277 0.0 0.0 0 0 ? S 19:34 0:00 [fsnotify_mark]
root 281 0.0 0.0 0 0 ? S 19:34 0:00 [ecryptfs-kthr]
root 283 0.0 0.0 0 0 ? S< 19:34 0:00 [nfsiod]
root 284 0.0 0.0 0 0 ? S< 19:34 0:00 [cifsiod]
root 287 0.0 0.0 0 0 ? S 19:34 0:00 [jfsIO]
root 288 0.0 0.0 0 0 ? S 19:34 0:00 [jfsCommit]
root 289 0.0 0.0 0 0 ? S 19:34 0:00 [jfsCommit]
root 290 0.0 0.0 0 0 ? S 19:34 0:00 [jfsCommit]
root 291 0.0 0.0 0 0 ? S 19:34 0:00 [jfsCommit]
root 292 0.0 0.0 0 0 ? S 19:34 0:00 [jfsSync]
root 293 0.0 0.0 0 0 ? S< 19:34 0:00 [xfsalloc]
root 294 0.0 0.0 0 0 ? S< 19:34 0:00 [xfs_mru_cache]
root 295 0.0 0.0 0 0 ? S< 19:34 0:00 [xfslogd]
root 296 0.0 0.0 0 0 ? S< 19:34 0:00 [glock_workque]
root 297 0.0 0.0 0 0 ? S< 19:34 0:00 [delete_workqu]
root 298 0.0 0.0 0 0 ? S< 19:34 0:00 [gfs_recovery]
root 299 0.0 0.0 0 0 ? S< 19:34 0:00 [crypto]
root 862 0.0 0.0 0 0 ? S 19:34 0:00 [khvcd]
root 976 0.0 0.0 0 0 ? S< 19:34 0:00 [kpsmoused]
root 1016 0.0 0.0 0 0 ? S< 19:34 0:00 [deferwq]
root 1019 0.0 0.0 0 0 ? S 19:34 0:00 [kjournald]
root 1023 0.0 0.0 0 0 ? S 19:34 0:00 [kworker/1:1]
root 1044 0.0 0.0 0 0 ? S 19:34 0:00 [kauditd]
root 1077 0.0 0.0 2424 356 ? S<s 19:34 0:00 /sbin/udevd -d
root 2692 0.0 0.0 2452 40 ? Ss 19:34 0:00 /sbin/dhclient
root 2759 0.0 0.0 10624 420 ? S<sl 19:34 0:00 auditd
root 2761 0.0 0.0 11184 444 ? S<sl 19:34 0:00 /sbin/audispd
root 2781 0.0 0.0 1964 532 ? Ss 19:34 0:00 syslogd -m 0
root 2784 0.0 0.0 1808 288 ? Ss 19:34 0:00 klogd -x
named 2825 0.0 0.1 58936 1032 ? Ssl 19:34 0:00 /usr/sbin/named
dbus 2847 0.0 0.0 2896 504 ? Ss 19:34 0:00 dbus-daemon --s
root 2884 0.0 0.0 23272 524 ? Ssl 19:34 0:00 automount
root 2903 0.0 0.0 7256 632 ? Ss 19:34 0:00 /usr/sbin/sshd
ntp 2917 0.0 0.5 4548 4544 ? SLs 19:34 0:00 ntpd -u ntp:ntp
root 2928 0.0 0.0 5344 160 ? Ss 19:34 0:00 /usr/sbin/vsftp
root 2964 0.0 0.0 4676 572 ? S 19:34 0:00 /bin/sh /usr/bi
root 3018 0.0 0.0 0 0 ? S 19:34 0:00 [flush-202:0]
mysql 3057 7.9 1.7 126808 13296 ? Sl 19:34 14:23 /usr/libexec/my
root 3089 0.0 0.0 9372 696 ? Ss 19:34 0:00 sendmail: accep
smmsp 3097 0.0 0.0 8284 336 ? Ss 19:34 0:00 sendmail: Queue
root 3106 0.0 0.0 2044 152 ? Ss 19:34 0:00 gpm -m /dev/inp
root 3115 0.0 0.1 27820 1320 ? Ss 19:34 0:00 /usr/sbin/httpd
root 3123 0.0 0.0 5380 552 ? Ss 19:34 0:00 crond
xfs 3141 0.0 0.0 3308 436 ? Ss 19:34 0:00 xfs -droppriv -
apache 3235 0.0 4.6 56924 35484 ? S 19:34 0:03 /usr/sbin/httpd
apache 3239 0.0 5.7 72740 44192 ? S 19:34 0:04 /usr/sbin/httpd
apache 3240 0.0 4.4 56636 34068 ? S 19:34 0:02 /usr/sbin/httpd
apache 3241 0.0 4.1 52836 31660 ? S 19:34 0:01 /usr/sbin/httpd
apache 3242 0.0 3.9 52800 30372 ? S 19:34 0:01 /usr/sbin/httpd
apache 3243 0.0 4.0 52788 31428 ? S 19:34 0:02 /usr/sbin/httpd
apache 3244 0.0 4.4 56924 34556 ? S 19:34 0:02 /usr/sbin/httpd
apache 3245 0.0 4.5 57196 34828 ? S 19:34 0:03 /usr/sbin/httpd
root 3264 0.0 0.0 2408 180 ? Ss 19:34 0:00 /usr/sbin/atd
root 3279 0.0 0.2 26680 2192 ? SN 19:34 0:00 /usr/bin/python
root 3281 0.0 0.0 2704 536 ? SN 19:34 0:00 /usr/libexec/ga
root 3282 0.0 0.2 19420 1660 ? Ss 19:34 0:00 /usr/bin/perl /
apache 3491 0.0 3.3 52792 26060 ? S 19:35 0:01 /usr/sbin/httpd
apache 3492 0.0 4.8 59656 37352 ? S 19:35 0:02 /usr/sbin/httpd
apache 3493 0.0 4.5 56956 34564 ? S 19:35 0:01 /usr/sbin/httpd
apache 3494 0.0 4.0 52788 31128 ? S 19:35 0:03 /usr/sbin/httpd
root 5343 0.0 0.0 3028 624 ? Ss 19:49 0:00 login -- root
root 5796 0.0 0.0 4808 604 hvc0 Ss 19:53 0:00 -bash
root 6054 0.0 0.0 0 0 ? S 19:55 0:00 [kworker/0:2]
root 6583 0.0 0.0 4320 352 hvc0 S+ 20:00 0:00 less
root 21913 0.0 0.0 0 0 ? S 21:53 0:00 [kworker/2:0]
root 22407 0.0 0.0 0 0 ? S 21:57 0:00 [kworker/3:0]
root 23117 0.0 0.0 0 0 ? S 22:02 0:00 [kworker/1:0]
root 24625 0.0 0.3 10264 2656 ? Ss 22:13 0:00 sshd: root@nott
root 24628 0.0 0.1 6692 1536 ? Ss 22:13 0:00 /usr/libexec/op
root 26703 0.0 0.3 10108 2932 ? Rs 22:28 0:00 sshd: root@pts/
root 26812 0.0 0.1 4812 1452 pts/0 Ss 22:29 0:00 -bash
root 27493 0.0 0.0 0 0 ? S 22:34 0:00 [kworker/1:2]
root 27494 0.0 0.1 4400 932 pts/0 R+ 22:34 0:00 ps aux

```

**Free usage stats**

```
[root@li21-298 ~]# free -m
    total used free shared buffers cached
Mem: 750 497 252 0 6 77
-/+ buffers/cache: 413 336
Swap: 511 87 424

[root@li21-298 ~]# free
    total used free shared buffers cached
Mem: 768004 490708 277296 0 8680 79892
-/+ buffers/cache: 402136 365868
Swap: 524284 73136 451148

```

**List of running processes sorted by memory use**

```
ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less

%MEM %CPU RSS VSZ COMMAND
4.9 0.0 38240 59656 /usr/sbin/httpd
4.7 0.0 36324 72740 /usr/sbin/httpd
4.6 0.0 35724 56940 /usr/sbin/httpd
4.6 0.0 35512 56924 /usr/sbin/httpd
4.2 0.0 32676 56924 /usr/sbin/httpd
4.2 0.0 32312 56380 /usr/sbin/httpd
3.8 0.0 29604 52800 /usr/sbin/httpd
3.7 0.0 29024 52792 /usr/sbin/httpd
3.7 0.0 28992 52788 /usr/sbin/httpd
3.7 0.0 28664 52788 /usr/sbin/httpd
1.8 7.8 13928 127624 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
0.9 0.0 7260 52836 /usr/sbin/httpd
0.5 0.0 4544 4548 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
0.3 0.0 2940 10108 sshd: root@pts/0
0.3 0.0 2680 26680 /usr/bin/python -tt /usr/sbin/yum-updatesd
0.2 0.0 2208 53236 /usr/sbin/httpd
0.2 0.0 1660 19420 /usr/bin/perl /usr/libexec/webmin/miniserv.pl /etc/webmin/miniserv.conf
0.1 0.0 1460 4812 -bash 0.1 0.0 1320 27820 /usr/sbin/httpd :

```

**Type of MPM in use by Apache**

```
[root@li21-298 ~]# httpd -V | grep 'MPM'
Server MPM: Prefork
-D APACHE_MPM_DIR="server/mpm/prefork"

```

**Current settings in my httpd.conf file (/etc/httpd/httpd.conf)**

```
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000

```

**Current settings in mysql (located /etc/my.cnf)**

```
[mysqld]
max_allowed_packet=50M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql

```

# Answer
> 3 votes
Is this error displaying on the site's front-end? Or in your apache logs? And are you planning to run many more OpenAtrium instances?

If you're getting that error on the front-end, and aren't planning to run very many more OA installs, just up the memory\_limit in php.ini, as it looks like you've actually got RAM to spare, and individual processes are maxing out the RAM they've been permitted. If you don't know which is the proper php.ini, check your Status Report.

If you're planning to run many more OA instances, I would increase the amount of RAM on the VPS. OA is heavy on memory.

If the site is just totally whiting out (aka WSOD), check your apache logs (though if that's the behavior, I'm guessing you already have) hopefully it'll give an idea of exactly what part of the system is maxing out the memory.

---
Tags: aegir
---


# Question
Title: How to exclude some keywords from a search with Search API?
I can't find how to do boolean search, and ignore some keywords from a search.

I would like to do a search like `"house+garden" - parking`, which return all the nodes containing house, and garder as keywords, but not parking.

How is it possible?

# Answer
> 2 votes
I believe the "custom\_search" module can do that. http://drupal.org/project/custom\_search

Although I don't know whether the exact boolean syntax is used, I know the module offers two ways to search in the way you want:

* With three different text fields (one for OR, one for AND, and one for WITHOUT)
* With one text field (By using some kind of syntax like you described)

# Answer
> 2 votes
Custom search module http://drupal.org/project/custom\_search works for me. What you mentioned above is Boolean search.

---
Tags: search
---


title: ubercart recurring payment for paypal

text:
# Question
Title: ubercart recurring payment for paypal
Does any one have experience of implementing uc\_recurring module along with paypal as I have configured it as per the documentation specified from module's documentation but its still not working.

Any insights on it would be helpful.

Tks, Vil

# Answer
> 1 votes
After going through all the configurations, I found out that skipping review order step was causing the problem.Now its working fine.

Tks -Vil

---
Tags: ubercart
---


title: Drupal multi-site not working

text:
# Question
Title: Drupal multi-site not working
I am trying to create a sample multi-site drupal on my local machine. I use windows XP and XAMPP. For creating a multi-site i created a folder in **/sites**. Like **/sites/example.com.** After that I changed `example.sites.php` to `sites.php` and removed # from the line given below.
`# $sites['localhost.example'] = 'example.com';`

After that i tried to rum by typing `localhost/example.com` it is not installing to the new folder example.com but to default folder. My drupal 7 files are in **htdocs** I need help... Is there anything missing????

# Answer
> 2 votes
A multisite configuration is used when a web server is associated to different domain names, and you want the web site to appear different when accessed from different domains. (If you want the web site appears the same in both the domain, there isn't any special Drupal configuration to follow.)

Suppose that your web site answers to example.com, and example.org. You can have two different settings.php files:

* sites/example.com/settings.php for example.com
* sites/example.org/settings.php for example.org

In the case those files are not found, Drupal would use the default one (sites/default/settings.php).

The same can be done for subdomains.

On your Mac, you should edit your hosts file (/private/etc/hosts) to add something similar to the following one:

```
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 first.localhost
127.0.0.1 second.localhost

```

In this case, the following files would be used:

* sites/first.localhost/settings.php for first.localhost
* sites/second.localhost/settings.php for second.localhost

If those files are not found, Drupal would look for the following ones (and other files as well):

* sites/localhost/settings.php
* sites/default/settings.php

# Answer
> 0 votes
you would wanna follow this link , everything is mentioned there with logic:
here

---
Tags: multi-sites
---


title: how to obtain proper 'call back URL'

text:
# Question
Title: how to obtain proper 'call back URL'
I have installed drupal 7 using MAMP and following this tutorial to configure drupal with oAuth,

While adding consumer I tried call back URL with **domain name** like `http://mastmobilemedia.com/oauth/request_token` which gave `http status 404 error` in browser , when i tried with **IP Address** `http://192.168.1.4/drupal/services/xmlrpc` ( as i found in one of the sample code) i got `page not found error` in browser

so please can anyone help me in knowing what is the proper **call back URL** to be specified ? how to get client side URL ?

# Answer
> 3 votes
You are getting 404 error because actually there is no page in your site with that url.

In your referenced tutorial the following statements can found as a note:

" Note: The sample callback URL above is incorrectly shown. The callback URL should be an URL on the client side. When Drupal has authorized the consumer, it will call this URL with the access token as a parameter."

So you have to define a page call back with path as you want. You can define in your custom module. OR You can give a valid site path as callback url. So When Drupal has authorized the consumer, it will call this URL with the access token as a parameter.

---
Tags: authentication-authorization
---


# Question
Title: use imce for images in articles but not within the editor
By default, there's an imagefield of for the article and by default, in this imagefield you are only able to upload a file from your local disc.

Now i've installed imce and i can manage different folders with diffrent files but how do i connect the imagefield from the article to get one of those files from the folderstructure? To get the popup and click through the folderstructure and get the certain file?

# Answer
You need the Filefield sources module. It allows you to select an existing file on the server.
> 0 votes

---
Tags: media, files
---


# Question
Title: Where can I get permission string to use with user_access?
There is a long permission list at `admin/people/permissions`.
For example there is permission with title `Article: Edit any content`.
But where can I get the string which can be used with function `user_access()`?

# Answer
It's pretty lo-tech but you can actually get it with developer tools/firebug.

If you inspect one of the checkboxes next to a permission you'll see something like this for the `name` attribute:

That's your permission string: **edit any media\_gallery content**

The more bulletproof way to find out the exact string would be to inspect the module's implementation of `hook_permission()`. In this case that would be `node_permission()` which internally calls `node_list_permissions()`.

If you look through that last function it should become quite clear what permission strings are generated for the various node operations.
> 2 votes

# Answer
Pop Devel on your site and head to *yoursite.com/devel/php* and enter the following:

```
$permissions = module_invoke('node', 'permission');
dsm($permissions);

```

The key for each part of the array will be the string you want to apply the permission.

The following will get a list of permissions on every enabled module on your site (modules sorted by name):

```
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
  if ($permissions = module_invoke($module, 'permission')) {
    // Print the module title
    dsm($module);
    // Print the permisions
    dsm($permissions);
  }
}

```
> 3 votes

---
Tags: users
---


# Question
Title: Creating multiple blocks programmatically
I am writing a custom module for Drupal 7. I need to create 5 different blocks with the module. Drupal has the `hook_block_info` and `hook_block_view` hooks which create blocks. How can I add multiple blocks since these hooks allow only one block per module?

# Answer
> 19 votes
The following code should help. You'll obviously need to add your 5 blocks as appropriate, but it's just to show how you can add multiple blocks in one module:

```
function MYMODULE_block_info() {
 $blocks = array();
 $blocks['myfirstblock'] = array(
   'info' => t('My block admin info'),
   'status' => 1,
 );
 $blocks['mysecondblock'] = array(
   'info' => t('My second block admin info'),
   'status' => 1,
 );

 return $blocks;
}

function MYMODULE_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'myfirstblock':
      $block = array(
        'subject' => t('My first block title'),
        'content' => t('My first block content'),
      );
      break;
    case 'mysecondblock':
      $block = array(
        'subject' => t('My second block title'),
        'content' => t('My second block content'),
      );
      break;
  }

  return $block;
}

```

Reason for `status => 1` from `hook_block_info()` API docs:

> status: (optional) Initial value for block enabled status. (1 = enabled, 0 = disabled). Most modules do not provide an initial value, and any value provided can be modified by a user on the block configuration screen.

I'm not sure where you got the one block per module idea from. You can create as many blocks as you'd like in a module.

---
Tags: 7, blocks
---


# Question
Title: Where do I find the translation overview?
I'm totally spooked about this. Last week I activated the contributed module Translation Overview. All worked great, a very usefull module for my project. Now, one week later, I'm totally unable to find this translation overview in Drupal. I have searched every corner, browsed the web to no avail, I have all permissions, the module is activated...

**Where do I find the translation overview?**

# Answer
You can find the translation overview on:

*admin/config/content/translation-overview-manage*
> 1 votes

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


# Question
Title: Drupal 7: How to add tags to a new content type?
Newbie here!

I go to `Structure > Content types > Add content type` and create a new content type.

But how can I add tags to my new content type, just like when you go to `Content > Add content > Article`, you get the option to enter a title, **tags** and body.

How can I add the capability to add tags to my new content type?

Thanks

# Answer
> 7 votes
From the Manage Fields page of your content type, add a new *Term Reference* field. Set the widget to be *Autocomplete term widget (tagging)*.

When you get to the field settings you'll be given the option of which vocabulary to use for the tags (for the default Article content type this is usually Tags I believe).

---
Tags: taxonomy-terms, nodes
---


# Question
Title: How to make a specific region use a specific template?
I'm currently working on Drupal 7 project in a Zen sub-theme. Each of my region uses "region.tpl.php" as HTML/PHP template. I just created a new region called "foo". This region needs a different HTML/PHP than the other regions.

**How do I make Drupal use my custom template "region--foo.tpl.php" instead of the default "region.tpl.php"?**

# Answer
> 7 votes
I thought Drupal already added the theme hook suggestion for region--name.tpl.php, but if not you can add it yourself with a preprocess function in your theme's template.php file:

```
function MYTHEME_preprocess_region(&$vars) {
  $vars['theme_hook_suggestions'][] = 'region__' . $vars['region'];
}

```

Once you clear Drupal's caches your new template file should start being used for that region. It might be worth noting that you'll probably need a copy of the core region.tpl.php file somewhere in your theme folder as well, or the theme registry might not pick up your custom file.

---
Tags: theming
---


title: Editing a Drupal 7 sub-themes menu HTML

text:
# Question
Title: Editing a Drupal 7 sub-themes menu HTML
I have a subtheme based off the Zurb Foundation Drupal Theme. The Zurb foundation theme defines the main navigation menus in it's `template.php` like so:

```
function zurb_foundation_preprocess_page(&$variables) {
    ...
    $variables['main_menu_links'] = '';
    if (isset($variables['main_menu'])) {
        $variables['main_menu_links'] = theme('links__system_main_menu', array(
            'links' => $variables['main_menu'],
            'attributes' => array(
                'id' => 'main-menu',
                'class' => array('nav-bar'),
            ),
            'heading' => array(
                'text' => t('Main menu'),
                'level' => 'h2',
                'class' => array('element-invisible'),
            ),
        ));
   }
   ...
}

```

and in `page.tpl.php`:

```
<?php if ($main_menu_links): ?>
    <nav>
    <?php print $main_menu_links; ?>
</nav>
<?php endif; ?>

```

which works fine. I want to edit the HTML being generated (convert the links to uppercase to be precise).

I create a `template.php` **in my sub template** and add to it:

```
function mycustomtheme_menu_link(array $variables) {
    $element = $variables['element'];
    $sub_menu = '';
    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }
    $output = drupal_strtoupper(l($element['#title'], $element['#href'], $element['#localized_options']));
    return '<li data="test-custom-menu" ' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

```

But this doesn't have any effect; the normal menu is generated with out my text value attribute. The docs says that the `theme` function (used by the Zurb theme):

> Generates themed output. All requests for themed output must go through this function. It examines the request and routes it to the appropriate theme function or template

so I would have thought that it would have detected the current theme (my subtheme) and called the appropriate hook `caketoppercompany_menu_link` when rendering the links, but this doesn't seem to be the case. Any suggestions?

# Answer
You just want to make the links show as uppsercase text!? Since you're not altering the HTML structure of the menu -- there is no need to modify any `theme` function. You just do it using CSS.

```
/* In ideally your last css file listed in your .info file
 * add a line such as
 */
#main-menu a { text-transformation: uppercase !important; }

```
> 1 votes

---
Tags: routes, hooks, theming
---


# Question
Title: Trigger a rule when a module update is available
It would be terrific to have Rules integration for when the Update Manager module finds an update. Is there a way to do this?

Potential ways I'd use this would be to have an update page, customized emails, adding logs in Heartbeat, and so on.

# Answer
> 2 votes
I know that you specifically asked about Rules, but you might also consider using Drush for this. For example, if you want an email to be sent to you every time an error appears on your status page, you could just drop this one line into your crontab:

```
0   */1   *   *   *   /usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/drush --root=/path/to/drupalroot --uri=mysite.com status-report --severity=2

```

(n.b. your path may vary.) If there is output from the status-report command, cron will send it out in an email; if there is no output, nothing happens.

Hope you don't find this answer to be too off-topic. Rules is great for responding to user actions, but for scripting site maintenance tasks, Drush is often more convenient.

---
Tags: rules, updating, actions
---


# Question
Title: views exposed filters - return user selection or another value
I have a content type with multiple fields and a view to display them. I have an exposed filter for one of the fields and want to achieve this functionality:

when a user select a value for this filter I want to return those nodes but also the ones that have a certain value on another field.

Is there any way I can achieve that from the interface? I know how to do it with hook\_views\_query\_alter()

Thanks

# Answer
Easy to do but hard to find the answer.

In the views's `FILTER CRITERIA` click the down pointing arrow and select the second option (`and/or, rearrange`). Then create a new filter group and play around with the options there :)
> 0 votes

---
Tags: 7, views
---


title: Add a Folder to an ImageField

text:
# Question
Title: Add a Folder to an ImageField
I'm currently trying to setup a picture gallery with Drupal 7. The Gallery module is set up and works, but it needs pictures added to an image field.

Since I have thousands of pictures to add, I don't want to add them one by one. The best solution for me would be uploading them via FTP and then adding the whole folder into the image field.

I found a script (http://drupal.org/node/1266646) which would do this for me, but it's for Drupal 6 and it doesn't work anymore.

I also tried IMCE with FileField Sources, but I can't add files I uploaded via FTP.

# Answer
> 0 votes
The IMCE for FileField module suits your use case. The description given in its project page is the following.

> IMCE for FileField allows users to select files from IMCE File Browser. It supports FTP uploaded files by automatically registering them as IMCE files thus making them usable in a FileField.

The latest stable release (7.x-1.1) has been released on April 8, 2015. It's covered by the security advisory policy. The development snapshot for that release has been last update on August 11, 2017.
As of April 10, 2021, there are 5 bug reports still open; two bugs are marked major, and one is marked critical; the older of them has been opened almost 7 years ago. Only one of them got a reply from the project owner, who is also the only project maintainer.

---
Tags: 7, media
---


# Question
Title: How to avoid no-wrapper tags on regions?
**How do I make sure ALL regions are wrapped according region.tpl.php?**

In a subtheme of Zen I have created my own regions and modified the page.tpl.php file to something like the following:

```
<div #page>
    <?php print render($page['header']); ?>
    <?php print render($page['content']); ?>
    <?php print render($page['footer']); ?>
</div>

```

Some of the regions get a region wrapper from region.tpl.php, others get the code from no-wrapper.tpl.php (no wrapper). How can have all regions receive a wrapper?

# Answer
> 1 votes
To avoid region-content blocks from receiving the block--no-wrapper.tpl.php template, go to template.php in your sub-theme and unquote or add the final function:

```
function zen_expeditiedokter_preprocess_block(&$variables, $hook) {
    if ($variables['block_html_id'] == 'block-system-main') {
        $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
    }
}

```

This will give the block.tpl.php template to the content region (without editing the Zen main theme) and thus avoiding the no-wrapper.

# Answer
> 1 votes
From the code it looks like Zen adds that template suggestion in `zen_preprocess_region()`, but only to the content region:

```
elseif ($variables['region'] == 'content') {
  // Allow a region-specific template to override Zen's region--no-wrapper.
  array_unshift($variables['theme_hook_suggestions'], 'region__no_wrapper');
}

```

If you're editing the Zen theme directly (which you shouldn't be :P) just remove those 4 lines; if you're creating a sub-theme, implement your own region preprocess function, copy the code from Zen's, and leave those lines out:

```
function MYTHEME_preprocess_region(&$variables, $hook) {
  // Sidebar regions get some extra classes and a common template suggestion.
  if (strpos($variables['region'], 'sidebar_') === 0) {
    $variables['classes_array'][] = 'column';
    $variables['classes_array'][] = 'sidebar';
    // Allow a region-specific template to override Zen's region--sidebar.
    array_unshift($variables['theme_hook_suggestions'], 'region__sidebar');
  }
}

```

---
Tags: theming
---


# Question
Title: Book page appears in one language (of four) only
I run a Drupal 7 site with 4 languages installed: English (for me as admin) and 3 balkan languages (I don't speak them actually): Serbian, Croatian, Slovenian.

I have added a book there (url shortcut should be: `help`) and have added 3 book pages: Imprint (in German, url shortcut `imprint`), Privacy and Terms of Services (both pages have English content and url shortcuts `privacy` and `tos`).

**All 3 book pages should be visible in all languages - i.e. in English, Serbian, Croatian, Slovenian.**

However for some reason they are only visible in the Croatian view of my web site and also only `/hr/shortcuts` work.

And when I look at http://balkan-preferans.de/en/node/1#overlay=en/admin/content they have Croatian as language:

Can I somehow change the language to be **All**?

# Answer
Ok, found that setting under

```
Home » Administration » Configuration » Search and metadata » URL aliases

```

Or go to Modules and configure Path module settings

Setting the language to **All languages** has solved my problem
> 0 votes

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


# Question
Title: For $vars['id'] == 1 render field Y instead of field X
So on my Blog listing page, the first listing is "featured" meaning it spans two columns rather than one, I've achieved most of my styling changes by adding CSS class *feature* to `$vars['id'] == 1` for the blog page.

However, the image for first teaser is a different proportions and therefore uses custom field *header image* rather than custom field *thumbnail image*. In the following:

```
function innovista_preprocess_node(&$vars) {
  if ($vars['id'] == 1 && arg(0) == 'blog') {
    $vars['classes_array'][] = 'feature';

    //do stuff to switch field here?

  }
}

```

I want to add a command to switch render of `$content['field_blog_thumbnail_image']` with render of `$content['field_blog_header_image']`. How can I go about this?

Thanks for your time!

# Answer
Ok so the way I achieved this was to go into my node--content\_type.tpl.php file and do a simple check for *'feature'* in the classes string. Printing the correct image depending on the outcome of the check.

So first in admin I set both header and thumbnail images to display when showing as a teaser. But then in the template file I began by hiding them:

```
hide($content['field_blog_thumbnail_image']);
hide($content['field_blog_header_image']);

```

This means that they don't render with `print render($content);`

In the place where I wanted to display the image I then used simple logic to check the $classes variable to see if the string contained 'feature'. If it did I render the header image, if not, the thumbnail image:

```
if(strpos($classes,'feature')==true){
    print render($content['field_blog_header_image']);
} else{
    print render($content['field_blog_thumbnail_image']);
}

```
> 0 votes

---
Tags: 7, nodes
---


# Question
Title: Forms API: 'file' or 'managed_file' type with multiple/unlimited values
I've got a form that needs to have either a 'file' or 'managed\_file' type field in it for uploading files via the form. Is there an attribute that can be set on the form item render array that will allow multiple/unlimited files to be uploaded via the one form item?

For example, when you add a new field via the admin UI to a content type, select the 'file' type widget and then in the field settings set the number of values to 'unlimited' - that's the sort of behavior I'm looking for in this file field via the forms API. Thanks in advance for any pointers!

# Answer
> 4 votes
If you are trying to build this functionality for a custom form using the Forms API, it may not yet be possible. It's documented on Drupal.org to be an issue. See this discussion, the bottom talks about the problems with implementing AHAH with a file field.

# Answer
> 2 votes
I use the Plupload form element. Example of implementation can be found at http://drupal.org/node/1647890

---
Tags: forms, files
---


title: URL patterns with entity reference

text:
# Question
Title: URL patterns with entity reference
> **Possible Duplicate:**
> Path alias tokens and node references

I'm having some difficulties setting up url patterns for my drupal project.

The site has 3 different content types, Main category, sub category and products. All of these are linked together by entity references.

So a sub category is linked to a main category, and a product is linked to a sub category. But now I want my urls to look like: main\_category/sub\_category/product Or for a sub category it should look like: main\_category/product

How would I be able to achieve this? I've installed path auto, but can't seem to figure it out.

EDIT: And another question would be, what would be the easiest way to create a menu out of this?

# Answer
> 2 votes
It has been solved before. Have a look at https://drupal.stackexchange.com/a/36025/6286

---
Tags: path-aliases
---


# Question
Title: How to troubleshoot Push Notifications module
I'm trying to get the Push Notifications module to work correctly. So far I have successfully gotten my device to register with the service, and now I am trying to test the push back to APN. I went through This entire process and created the .pem file from my certification. When I attempt to test the push, I get the following error

```
Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure

```

I'm at a bit of a loss on how to proceed, or how to further troubleshoot. I've tried looking up the error but the definitions seem vague.

# Answer
This turned out to be my own error, I was using the wrong certificate, one that was not set up for push notifications, otherwise, everything works just like the instructions.
> 3 votes

---
Tags: services
---


# Question
Title: For product type 'donation' allow customer to choose "price" and add allocation field
Using Drupal commerce I want to change checkout functionality to allow the user to choose the amount for product type 'donation' on the user details page. See here:

The user should be able set "the price". How would I go about this?

You may also see that I want to add a custom input for choosing allocation of the donation. Would I do this using a hook to alter the form? How? And would it capture the data within commerce store admin?

# Answer
> 1 votes
Did you try Commerce Donate module ?! I think it should solve the issue you are looking for !

Check the Screenshot below.

# Answer
> 1 votes
Rather than paraphrasing, and potentially creating confusion, I'll just point you to Randy Fay's blog post and video that describes exactly how to do this. (Randy works for Commerce Guys, the developers of Drupal Commerce). I've tried it and it works like a charm :-)

Using Custom Line Items To Provide a Donation Feature to Drupal Commerce

---
Tags: 7, commerce
---


# Question
Title: How can I make URL Alias required when creating new content
When a user creates a new article they often forget to put in the URL path alias for the article. How can I make that field required before they can save the content?

# Answer
> 1 votes
The easiest solution is to use the pathauto module. If the user does not touch the URL path alias field, pathauto will automatically generate a URL for the node based on the node title. Other configuration options are available. The user may still uncheck the pathauto checkbox and type in a specific URL for their new node.

**Update:**

If the URL format is built from fields or metadata in the node that is created, pathauto can do that for you automatically through its pattern configuration page. For example, I have one content type with a pattern \[node:field-gender:name\]/\[node:field-era:name\]/\[node:field-genre:name\]/\[node:field-item-type:name\]/\[node:title\] to create four levels of nesting in the URL based on field values entered. If the user does not have the permission to create and edit url aliases, they will be stuck with the pattern pathauto provides.

If you want to allow users to also edit the URL, you could validate the field from hook\_node\_validate. I don't know if there is a way to do node validation with rules.

**Update 2:**

If you have a field called "tag" that is a taxonomy term, then \[node:tag\] will return all of the terms in this field, concatenated together, and \[node:tag:1\] will return just the first taxonomy term. In both cases, spaces are converted to dashes.

---
Tags: nodes
---


# Question
Title: How to change the Front page for the Commerce Kickstart distribution?
Just that. I changed the front page to "my-front-page". Now if I go to the front page the fields for this node aren't shown at all. Just the blocks are shown.

I guess there is a preprocess function related to the front page. The only one that I see is this one, but nothing happens if I delete this function:

```
function commerce_kickstart_theme_alpha_preprocess_page(&$vars) {
  if ($vars['is_front']) {
    unset($vars['page']['content']['content']['content']['system_main']);
  }
}

```

# Answer
It looks like this preprocess function needs to be changed in the parent theme.

In this case it can be found in the `/profiles/commerce_kickstart/themes/omega_kickstart/preprocess` folder.
> 0 votes

---
Tags: commerce
---


title: What is a variant in Page Manager?

text:
# Question
Title: What is a variant in Page Manager?
I am trying to follow this tutorial, but it does not explain the concept of variant very clearly. It does not provide a definition of it.

Can someone clarify this concept in plain English? What are the practical cases where you would use variants?

# Answer
Variants are to do with Panels, and are a way to *vary* an output slightly. Variants can inherit most of their behaviour and can override what they need. If you have experience with Views then it is most closely like having another display. The variant may be changing how the panel is laid out or may add other elements. The decision to use one variant or the other can be based on selection rules or contexts, selection rules being more *global* and context more about what is being looked at, i.e. the node being viewed etc.
> 3 votes

# Answer
I've never been forced to define it before, but here's an attempt at it.

"A variant is a specific response to a request on a Page", in the Page manager. Mostly, using Panels, this involves the rendering of a node or other full page, but not always.

While there are some similarities to "Views displays", unlike Displays, Variants have *no inheritance* between each other. All variants on any particular Page has the same basic access rules if any, and starts of with whatever context-objects that Page manager derives from the URL, but are not aware of eachother in any way. Based on selection rules, they are evaluated from top to bottom. The first selection rule to return TRUE, gets picked.

A common example is to separate two different content/node-types from each other, allowing you to render them entirely differently. Since each variant may pick its own layout, and place fields/forms/etc in an arbitrary way, the "Article" and "Blog" types may look entirely different. In this case the variants would correspond to node-article.tpl.php and node-blog.tpl.php.

There are various other "Responders" available for Variants that don't involve the use of Panels, such as Contextual administration and plain HTTP Response codes, but I believe this answer is long enough as it is.
> 5 votes

# Answer
Letharion's answer and Malks' answer are both very good, but let me add something I think may be helpful. (And please leave a comment if you think I got some of this wrong, and I'll correct it.)

You can think of Panels as a replacement for Blocks, sort of like they could have been called "Smart Blocks" (or context-aware blocks, or something like that). Panels can appear differently in different contexts, since sometimes you may want your block's contents to behave (appear) slightly differently on one page than on the other. Doing this with Blocks can be a bit kludgey, so Panels attempt to improve matters.

A variant is just a different *version* or *variation* of how to display things. You can set context and selection rules to determine which variant to use.

So in short, a variant is just a *version* of your blockpanel, and every panel needs at least one version.
> 1 votes

---
Tags: 7, panels
---


# Question
Title: Module for managing permissions on per node basis integrated with shopping cart or checkout
Hey I'm looking for a way to manage specific users access to specific nodes in Drupal. I'm wondering which modules I can use to accomplish this.

To elaborate:

Lets just say I have 20 stories on my site that cost 5$ each to access. Users need to sign up, and then they pay $5 for each story they want to have access to.

I need to manage the individual user's access to specific nodes automatically after they are paid for...

Anything you can point me toward would be helpful

Thanks

# Answer
Content Access module restricts users per node basis or per content type basis.

> This module allows you to manage permissions for content types by role and author. It allows you to specifiy custom view, edit and delete permissions for each content type. Optionally you can enable per content access settings, so you can customize the access for each content node.

You need to use commerce checkout hooks and Content Access API to achieve this. Try rules modules too it may help with out using coding also.
> 0 votes

---
Tags: users
---


# Question
Title: How to make the date field of authoring information in Create Article page a date field?
In the page to create new article, at the bottom in the authored on tab, how do I make the date textbox to a date field with date picker? I mean, I want it to be easy for the publisher to choose custom date.

# Answer
Use Date Popup Authored module.

> Date Popup Authored provides a jQuery UI datepicker for the Authored on date field found on node submission forms.
>
> This allows content editors to pick a human-understandable date and not have to type the exact date format of the default Authored on field.
> 1 votes

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


title: Regarding MySQL and PHP versions

text:
# Question
Title: Regarding MySQL and PHP versions
MySQL Server version: 5.0.77 and Current PHP version: 5.1.6

Does Drupal 7 support them?

# Answer
For Drupal 7 you'll need at least PHP 5.2.5. Have a look at http://drupal.org/requirements One specific issue I had with PHP less than 5.2 was that I could not install http://drupal.org/project/drush so I had to upgrade. Probably I'd have more problems down the line if I hadn't.

The MySQL version you have is OK.
> 4 votes

# Answer
No, you PHP version is too old. Please see the Drupal System Requirements page for more details.
> 0 votes

---
Tags: 7, installation
---


# Question
Title: Prevent accessing files in Drupal files folder directly by following link
I have member area on my site, and there i have files available only to members. (also, not to all members, but to members of some role, and also they are further granulated by field condition, but that is a long story :)

But technically, anyone can download a file, if knowing the link to the file.

I would like to prevent downloading files by direct link, or by being logged of site.

It would be perfect if i can execute a script when someone asks for file by direct linking, to check if user is logged in, if he has a role that grants him download.

But if that is not possible, i would like to disable accessing files directly, they should be only accessible by browsing the site.

Thanks for clues

# Answer
> 1 votes
Have a look at hook\_file\_download

> Control access to private file downloads and specify HTTP headers.
>
> This hook allows modules enforce permissions on file downloads when the private file download method is selected. Modules can also provide headers to specify information like the file's name or MIME type.

---
Tags: users, files
---


title: Nginx Drupal rules for Views pager

text:
# Question
Title: Nginx Drupal rules for Views pager
I just realised many guide on the internet not works for Drupal 7 Views pager

This is generally Nginx and Views pager issue. I've tried in Apache2 and the pager works without problem.

For example, I'm installing Commerce Kickstart. After submitting contents (SKU), I try to browse `admin/commerce/products`. But sadly, when clicking next page, it not showing any change

The first page URL is

```
http://www.website.com/admin/commerce/products

```

while second page, third page, and so on is:

```
http://www.website.com/admin/commerce/products?sku=&page=1
http://www.website.com/admin/commerce/products?sku=&page=2
http://www.website.com/admin/commerce/products?sku=&page=3

```

Currently, below is my nginx config:

```
server {
    server_name *.com *.net *.org *.in *.cc;
    root   /var/www/html/$host;
    index  index.php index.html;
    set $boost "";
    set $boost_query "_";
    if ( $request_method = GET ) {
      set $boost G;
    }
    if ($http_cookie !~ "DRUPAL_UID") {
      set $boost "${boost}D";
    }
    if ($query_string = "") {
      set $boost "${boost}Q";
    }
    if ( -f $document_root/cache/normal/$host$uri$boost_query.html ) {
      set $boost "${boost}F";
    }
    if ($boost = GDQF){
      rewrite ^.*$ /cache/normal/$host/$uri$boost_query.html break;
    }
    try_files $uri $uri/ /index.php;
    location ~ \.php$ {
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass    127.0.0.1:9000;
    }
    location ~ (.*)/x-progress-id:(\w*) {
        rewrite ^(.*)/x-progress-id:(\w*)  $1?X-Progress-ID=$2;
    }
    location ^~ /progress {
        report_uploads uploads;
    }
    location ^~ /files/private/ {
        internal;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        track_uploads uploads 60s;
    }
}

```

# Answer
change the line:

```
try_files $uri $uri/ /index.php;

```

to:

```
try_files $uri $uri/ /index.php?q=$uri&$query_string;

```

to pass the query\_string to drupal.

(see HttpCoreModule for more informations about nginx variables)
> 3 votes

---
Tags: 7, commerce
---


# Question
Title: Why I cannot change views page title using views_post_render?
I have view that uses url args: parent term id and term id/ids, so the url structure is like page/%/%

Title pattern for this view is: %1(%2)

However I have few pages with multi tids as second argument, so generated title is strange (very long). I am trying to change this title programmatically:

```
function bip_title_alter_views_post_render(&$view, &$output, &$cache)  {

    if ($view->name == 'kategorie_artykulow' && $view->current_display == 'page_9')
    {
        $args = explode(' ', $view->args[1]);
        if (sizeof($args) < 2) {
            return;
        }
        $title_pattern = 'Archiwum Oświadczeń Majątkowych w %dr.';
        $term = taxonomy_term_load($args[0]);
        if (! $term) {
            return;
        }
        $title = sprintf($title_pattern, $term->name);
        drupal_set_title($title);
    }
}

function bip_title_alter_module_implements_alter(&$implementations, $hook) {
    if ($hook == 'views_post_render') {
        $group = $implementations['bip_title_alter'];
        unset($implementations['bip_title_alter']);
        $implementations['bip_title_alter'] = $group;
    }
}

```

but title remains the same, I am sure that I am altering proper view.

Adding another display to view is not good option for me, because I have a lot existing urls and if I create another display with the same url structure and different args config always first display is handling request.

**edit**

I changed my custom module weight in system table to 9999 and I still see that title is altered after my module hook :/ It's so annoying

# Answer
> 1 votes
Thanks to @Andy advice the solution is so simple.

Views set title after calling to views\_pre\_render and views\_post\_render: (views\_plugin\_display\_page.inc)

```
  // And now render the view.
    $render = $this->view->render();

    // First execute the view so it's possible to get tokens for the title.
    // And the title, which is much easier.
    drupal_set_title(filter_xss_admin($this->view->get_title()), PASS_THROUGH);

```

If there is a get method there is a big chance that setter exists ;)

So calling:

```
$view->set_title($title);

```

inside hook (pre or post) do the job

# Answer
> 1 votes
I always use a `hook_views_pre_view()`:

```
function mymodule_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == "foo" && $view->current_display == "bar") {
    $view->display[$view->current_display]->display_options["title"] =
    $view->display[$view->current_display]->handler->options["title"] = "The New Title";
  }
}

```

This should then funnel up to be pulled in as the page title, but I never use views directly as pages.

# Answer
> 0 votes
I would use hook\_views\_pre\_render and alter the views display title.

Refer to http://drupal.org/node/438370 as well.

---
Tags: 7, views
---


title: Create node from custom form using ajax

text:
# Question
Title: Create node from custom form using ajax
How do I add a node from a custom form using ajax? I want it to be submitted in the backend. How will it be if there are custom fields?

# Answer
> 4 votes
in drupal you can create node using node\_save function as below

```
$node = new StdClass();//creating a bare node
$node->type = 'answer';//giving it type
$node->status = 1;//give it a published staus
$node->title = "Step up to the FLava";//gives title
$node->body = "Body Body body"; //gives body

node_save($node);
//save it and give it the rest of the attributes`

```

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


# Question
Title: Automatic generate a parent category when adding a new node
I have a content type Artist and a content type Songs. Each artist has a number of songs. I want to be able when I add a new song to assign it to the artist that it belongs and then have a view of the songs from a specific artist. I don't want to do a seperate term in taxonomy for every artist I add. Can this be automatically? ex. When I add an artist, and then I add a song I want to be able to assign this new song to the new artist without me having to manually add a new taxonomy term for the artist and then assign this song to this taxonomy term...

I want my paths to look like this. ex: artist/songallery ----\> artist/songname

Hope I made myself clear, thank you in advance.

# Answer
> 1 votes
You have content types a)Songs b)Artist

Create a node reference field with artist, in Songs content type. So when you add a new song you can you can select the artist belongs to that. I hope no need of taxonomy.

You can create two page displays in view by selecting necessary fields and give the appropriate path as you wish.

Hope this may help you!

# Answer
> 0 votes
Use hook\_node\_insert to create taxonomy term based on Artist node title. This can help too: http://steindom.com/articles/creating-vocabularies-and-taxonomy-terms-programmatically-drupal-7

---
Tags: taxonomy-terms, nodes
---


title: How to print out search results

text:
# Question
Title: How to print out search results
I created a custom searchpage.tpl.php to print out search form and search results using the following code:

```
<div class="searchblock">
<?php
print drupal_get_form('search_form');
?>
</div>

<div class="search-result <?php print $search_zebra; ?>">
  <dt class="title">
    <a href="<?php print $url; ?>"><?php print $title; ?></a>
  </dt>
  <dd>
    <?php if ($snippet) : ?>
    <p class="search-snippet"><?php print $snippet; ?></p>
    <?php endif; ?>
  </dd>
</div>

```

It shows the search form correctly and when I search a phrase, URL changes to `http://domain.com/search/node/phrase` But it doesn't show the search results, How can I make it work please?

# Answer
> 1 votes
Here's the solution:

```
<div class="searchblock">
<?php
print drupal_get_form('search_form');
?>
</div>

<?php
$keys = arg(2);
print search_data($keys, $type = 'node');
?>
</div>

```

---
Tags: 6, theming, search
---


title: Display fields only once (Views)

text:
# Question
Title: Display fields only once (Views)
I would like to show a table of products. I grouped them by nid. In the table header views shows me the nid. Instead of this, I would like to add fields of the node to be displayed once like: node title, image, price.

I attached two illustrations:
Screenshot 1: This is what Views shows me.

Screenshot 2: This is what I would like to have

# Answer
> 2 votes
You can use attachment for this. In Views UI push add and choose attachment. Add the fields as you want them to be displayed. Also look under Attachment settings in the attachment display, choose which view to attach to, before / after etc.

# Answer
> 1 votes
1. Add the fields you want "Product name, Dimensions, List price".
2. Click on Settings from your view FORMAT section in settings page.
3. Chose group items from the dropdown list.

# Answer
> 1 votes
Use a different block display for just the first element, with a limit of 1, and add it as a header of the view page (the view you currently have). Also, to not output the first element twice, add an offset of 1 in the view page.

And add any additional fields you want in the block display.

---
Tags: 7, views
---


# Question
Title: Configuring Node Reference URL to auto populate with outbound (internal) link (node title)
I have this Node Type called "Services", and I have a Node Type called "Booking". The latter is a form to request a booking of one of the Services. So by default, every "Services" node has a link to this form. I have Installed Node Reference and Node Reference URL and in the form (because of the configuration of the mentioned modules) I have a Select List where the client can choose all "Services" available (It's the titles of the nodes of the Type "Services")

How could I achieve that, instead of the client having to manually select the Service from the list, it is already marked the title of the node corresponding to the URL the user is accessing the form, from. (meaning where they were at when they clicked the link to the form)

THANK YOU in advance.

# Answer
> 0 votes
Adding the node reference field step 1:

Adding the node reference field step 2:

a) Choose your Content type from 'Content types that can be referenced ' select list b) Fallback behavior \*-\> choose Use select list widget , leave all other options if you not need

All the settings are over.

Now access your create content type with the node\_id, in url

sitename.com/node/add/{the content type}/23, where 23 is the node id passed from the link

You can find that the options with particular node is is selected in the list box

**Creating links - it is well explained in modules readme.txt please go through well**

---
Tags: nodes, uri, navigation
---