# Question
Title: Converting static site to Drupal 7 - How to set-up department sites?
I am new to Drupal. We have a corporate site that is static html, has 13 departments. The template for the department sites are very similar to the main corporate site. The departments will not have a different DNS assigned to it, that is, the structure will be as so:

* main site URL: www.mycorp.com
* department Site: www.mycorp.com/hr

We would want the departments to update their own content. Each department has about 10 pages to maintain, but can grow. It is also important that all of the departments' content is shared/accessed/searched by the main corporate site. Would Drupal 7 multisite set-up be recommended for this?

# Answer
I think multisite is not the optimal solution for you. With a multisite installation, you will end up with completely separate sites that have their own content, categories, users, settings, user files etc. etc. In my experience, that is often too much separation for a site like yours.

For instance: With multisite, if one person needs to get access to two or more departments, you need to create a user account for him in each site. He will also need to login in every site. Another example: With multisite, it's not easy to take content from a department site and promote it to the main home page.

In your case, I would look into a solution built with Workbench and Workbench Access, or perhaps Domain Access. With those modules, you will end up with a system that is technically a single site, but where Drupal is configured to split the site into sections and control user permissions on a per-section basis.
> 3 votes

# Answer
There are a number of ways to do this and other answers may expand upon your options.

I would suggest enabling Views module to select the content for each department's path. You can also attach a field (using a taxonomy vocabulary) to each user to identify the department's they have access to. The view will then allow you to limit who can see the contents on each departments view definition.

There is a quirk in the current Views filters that requires you to set up a relationship to content author before you can see users in the filters section. If you have a problem seeing the users, ask a question on this site, and someone can guide you through the setup.
> -1 votes

---
Tags: migrations, multi-sites
---


# Question
Title: How can I cast a fivestar vote on a different node
I'm new to drupal and trying to figure out how i can use fivestar to implement a rating system.

I have around 15 products and want my site users to be able to rate & review them from a page named "User Reviews" and NOT from within each product page/node.

Adding the rating axis in the review node is nice and simple but can't figure out how to select the product node to associate the vote with. I want to create a select list field that would list all my products and where the user will be able to select the item they want to review. Then add their comments and ratings and submit it.

Its straight forward to do this when creating a review as a comment on the product node that is reviewed (i.e. select Parent Node as the Voting Target) but how can I achieve this from a different node and assosiate the nodeId with the nodeId of a product?

I'm using the latest releases of Drupal, Fivestar and Voting API.

# Answer
How are you generating your page with the 15 products? I think views can display the widget as a field so that might be an easy way to achieve the desired functionality.
> 1 votes

---
Tags: rating
---


# Question
Title: Permission problems after migrating from Apache to IIS
After **migrating from Apache server to IIS** (7.5), I have some permission problems in Drupal: **modules don't seem to have the permissions to delete (unlink) or create files**, not even from/into ***"sites/default/files"*** folder.

What really interesting is, that **if I create my own `test.php` with a simple `file_put_contents` in it, it does create and unlink files without any error messages**.

---

BUT for example from AddThis module I got the following error message:

> unlink(`sites/default/files/addthis/addthis_widget.js`) \[function.unlink\]: Permission denied in `C:\<mydrupalpath>\source\includes\file.inc` on line 481.

After that, I right clicked the mentioned file, Properties \> Security tab \> added Everyone with "Full control" rights. Not surprising, this way unlink was already successful.

BUT after that, I can see this it in the Drupal log:

> "The directory `sites/default/files/addthis` is not writable, because it does not have the correct permissions set"

---

OK, **tried to set the right permissions with** **`icacls`** with granting "modify" and "write" permission to `sites/default/files` directory like this:

```
c:\<mydrupalpath>\source\sites\default\files /t /grant "IIS APPPOOL\MyDrupalAppPool":(OI)(CI)(M,W,RX)

```

OK, result is "*Successfully processed 228 files*".
Refreshing Drupal site in browser...
Hmm, didn't work, the **same error message** again (permission problems)...

I don't understand... if I query the rights with icacls on "***`files`***" OR `files\addthis` directory, it says my application pool does have "modify" rights:

```
IIS APPPOOL\MyDrupalAppPool:(OI)(CI)(M)

```

I do have permission problems with Gallery module too... :(

***What should I do not to have permission problems in "files" folder when modules try to delete from/write into it?***

Thanks in advance!

# Answer
From here I got the idea to run the following command on a console (*"Determining the account used as IIS anonymous identity"*):

```
%windir%\system32\inetsrv\appcmd.exe list config "MyDrupalAppPool" ^ /section:anonymousAuthentication

```

The result was the following:

```
<system.webServer>
  <security>
    <authentication>
      <anonymousAuthentication enabled="true" userName="IUSR" />
    </authentication>
  </security>
</system.webServer>

```

And then **running the following command seems to have solved the problem of writing to/deleting from the "`files`" directory**:

```
icacls c:\<mydrupalpath>\sites\default\files /t /grant IUSR:(OI)(CI)(M)

```

I don't know if it's secure enough... Please leave comments if you think there is any kind of problem with this approach. Thanks.
> 1 votes

---
Tags: 6, migrations
---


# Question
Title: Form fields getting cleared off of user inputs after validation errors
This question is almost exactly my problem, but I'm not making the mistake made by that poster. As in, I'm not using #value to populate my fields, but the proper #default-value.

I'm working with ubercart, and the form I made is part of a checkout pane. Unfortunately, I have had to use drupal\_get\_form() within the main uc-cart-checkout-form as the value of a checkout pane. Otherwise, I cannot provide independent submit buttons or clump them together properly.

The problem is that after validation, the form fields are getting cleared out. Only the default values are being reset. I have tried writing a validation handler (even if actually the validation is taking place in a custom validation function that I'm calling from the hook\_form\_alter() of uc\_cart\_checkout\_form)

Is doing this manually with SESSIONS the only way out? By calling a drupal\_get\_form inside a drupal\_get\_form, am I confusing FAPI irrevocably?

# Answer
I reckon using the ternary conditional operator to check if there is anything in $form\_state\['values'\] would get there, i.e. something like:

```
$default_value = 'Test Default Value';

$form['test'] = array(
  '#type' => 'textfield',
  '#default_value' => !empty($form_state['values']['test'])?$form_state['values']['test']:$default_value,
);

```
> 0 votes

---
Tags: 6, ubercart
---


title: HTML Purifier filter

text:
# Question
Title: HTML Purifier filter
I installed HTML purifier because the default input format is filtered HTML and my users need to be able to add inline styles to the elements in their nodes. I'm trying to get it to work, but it is not very intuitive and there doesn't seem to be much documentation out there.

Can someone please suggest a tutorial or tell me how I can add the style attribute as well as width and height?

# Answer
What wysiwyg editor are you using? In my end I'm using TinyMCE and I have a related task as yours. What I did was I created a plugin to insert a class on a selected texts. Doing this will provide a convenient way to your users to add styles.

Note: you can use hook\_wysywyg\_plugin() for this.

Hope this help!
> 1 votes

---
Tags: 6, input-formats
---


# Question
Title: Deleting all terms from a vocabulary after timeout
When I tried to delete a vocabulary, Drupal timed out and I don't think any or all of the terms in the vocabulary were deleted. How can I delete them manually in the database?

# Answer
> 1 votes
Can you run sql queries directly against the database? What makes you think the terms are still there? The vocabulary table contains data about the vocabulary, and you could do a left outer join with term\_data to see if there are any "orpaned" terms. So something like (assuming you haven't used a prefix on your drupal database):

```
SELECT *
FROM term_data t
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

```

You can do a delete on a join if you need to but I suspect you won't find any orphans.

EDIT:

You should also probably check term\_node as well that links terms to nodes. If you're going to run these deletes please back up your database first! Also as these queries are written, the term\_node needs to run first.

```
-- Run this first
DELETE n
FROM term_node n
JOIN term_data t
ON n.tid = t.tid
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

-- Then run this query
DELETE t
FROM term_data t
LEFT OUTER JOIN vocabulary v
ON t.vid = v.vid
WHERE v.vid IS NULL;

```

Remember to back up your database first!

---
Tags: 6, taxonomy-terms
---


title: Disallow forward date input (CCK Date)

text:
# Question
Title: Disallow forward date input (CCK Date)
How do I disallow future dates in CCK date field?

# Answer
> 1 votes
Check out

```
http://drupal.org/node/751826

```

and look into forms validation. You could check if your date is less than the current date and if not, bzzzzt.

---
Tags: entities, datetime
---


# Question
Title: How to hide country in Address Field display?
Using Drupal 7 with Address Field module. How to prevent the country part of the address field from displaying on a node with an address field?

For example, address is:

```
123 Main St
Somewhere, NY 10001
United States

```

I want the node to show:

```
123 Main St
Somewhere, NY 10001

```

# Answer
> 6 votes
I overrode the field.tpl.php file as described in this video:

Drupal 7: Theming Fields and Nodes with Templates by linwclark

I copied the field.tpl.php file from `<site_root>/modules/field/theme/field.tpl.php` and put it into the templates directory of my zen subtheme (`<site_root>/sites/all/themes/somezentheme/templates/field--field_address.tpl.php`)

In that template I used the hide() function on country:

```
  <div class="field-items"<?php print $content_attributes; ?>>
    <?php foreach ($items as $delta => $item): ?>
    <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php hide($item['country']); print render($item); ?></div>
    <?php endforeach; ?>
  </div>

```

# Answer
> 0 votes
You have to use hook\_field\_formatter\_view to display it as you need.

# Answer
> -2 votes
you could also hide it with css. I use css\_injector module to just insert the css on the page(s) where you want to hide the element.

---
Tags: 7, entities
---


# Question
Title: Client-Side form validation issue with Fivestar module?
I've set up my review system of my Drupal 7.x site some what like mentioned in this http://drupal.org/node/1308114 and I've also set that field as "Required" but it seems that "Required Field" is not working since, its allowing user to submit the review without rating the article, for that I've created my custom module containing

```
<?php
/**
 * Implementation of hook_form_alter()
 */
function rishihrvalidate_form_alter(&$form, $form_state, $form_id) {
    $form['#attributes']['onsubmit'] = 'return comment_cs_validate()';
    if ($form_id == 'comment-form'){
  }
}

```

calling the JavaScript

```
<script type="text/javascript">
      function comment_cs_validate() {
        if ($('#edit-field-review-value div div').hasClass("on") && $('#edit-field-review-atmosphere div div').hasClass("on") && $('#edit-field-review-service div div').hasClass("on")) {
          return true;
        }
        else {
          alert ('You must rate the listing before submitting your review');
          return false;
        }
      }
    </script>

```

Though the above PHP code was not perfect, it was executing correctly and behaving as desired only the problem I'm getting is while logging on my site also its taking place since I've called all the submit buttons, hence I changed the from that above one to this, but now I'm getting nothing, may I know where I might be lacking?

```
<?php
/**
 * Implementation of hook_form_alter()
 */
function rishihrvalidate_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'comment_form') {
        $form['#attributes']['onsubmit'] = 'return comment_cs_validate()';
    }
}

```

I'm not getting where is the mistake, can someone help me in this issue?

Thanks in Advance :)

# Answer
Perhaps you are using the wrong `$form_id`

One way to check is to use Database Logging, also known as the Watchdog or Recent Log Entries, to log the `$form_id`. After you add this code, execute the form by performing a submit, and then check your Reports \> Recent Log Entries area for the result. This may require enabling the Database Logging core module before the messages are logged and/or visible.

```
<?php
/**
 * Implementation of hook_form_alter()
 */
function rishihrvalidate_form_alter(&$form, &$form_state, $form_id) {
  // Log the $form_id to the watchdog
  // in this example, 'form_id' is just the log entry name. I commonly use 'wtf'
  watchdog('form_id', $form_id);

  if ($form_id == 'comment_form') {
    $form['#attributes']['onsubmit'] = 'return comment_cs_validate()';
  }
}
?>

```

For more information about watchdog, visit http://api.drupal.org/api/function/watchdog
> 2 votes

---
Tags: 7, hooks
---


title: Has anyone used beta profiling module

text:
# Question
Title: Has anyone used beta profiling module
For most of my projects i am using Devel module. Recently i looked at other module Profiling - it also provide integration with views and Panels. I was thinking to use this, as mentioned here it is stable but still lacks the Views and Panels support. So not sure i should use it or not (i am using views and panels).

Is there anybody who used this module and found it working (without bugs) ?

OR

You would recommend other module?

Thanks in advance.

# Answer
> 0 votes
I have used profiling 7.x-1.0-alpha1, as it was alpha release there were some issues. I hope those have been fixed in the beta release, so maybe you can use it. I would recommend not to use the beta version either; it can break anything.

However, if you are willing to learn how to use this module, just use it; it is not too risky.

---
Tags: 7, debugging
---


title: Relation for fields

text:
# Question
Title: Relation for fields
The Relation module supports creating relations between entities. Is there a way I could create relations between fields.

# Answer
> 1 votes
As far as I know, Relation can only link entities to eachother. Since field values are not entities themselves (they don't even have unique ID's), Relation will probably not be able solve your problem.

Maybe Field Collection can be useful to you. It's not exactly what you describe, but it's the only module I know that allows you to bundle fields into meaningful groups.

---
Tags: 7, entities
---


# Question
Title: To process uploaded file for certain content type, how to?
For example:

* A new content type `Photo` is created
* The optional core module `Upload` is enabled
* Such that users can upload JPEG files

How can I:

* In view mode of a `Photo` node, show a small "View EXIF" button next to the `Photo`
* When the user click the "View EXIF" button, my module show some EXIF info about that photo

i.e.:

* add a button only for a particular content type (`Photo` in this example)
* trigger a hook to process a uploaded file (a JPEG file in this example)

Thanks!

# Answer
Use the Exif module to grab your exif data from the uploaded image:

Use some simple theming (eg: create node-photo.tpl.php if you are using d6 and content type is called 'photo') - there do some simple jquery show / hide type stuff with a div wrapped around your exif data.
> 0 votes

---
Tags: 6, hooks
---


# Question
Title: Secret forum visible only to users of a specific role
I need to create a forum that is visible to only users with a specific role. It should remain hidden to other users including registered users. How can I achieve this?

# Answer
> 3 votes
Try the Forum Access module.

---
Tags: nodes
---


# Question
Title: Is there any alternative to the Quiz module?
I like the Quiz module but its affiliated modules are not ported to D7.

Is there any alternative to the Quiz module?

# Answer
Webform is an option. You can show different questions in different page (something that quiz doesnot do). You will require little bit of programming to show the answers for the questions and their scores once the webform is being submitted. This is if you want to capture the score.
> 3 votes

---
Tags: 7
---


title: Content by credit/level in Drupal?

text:
# Question
Title: Content by credit/level in Drupal?
Ideally I want users to earn "credits". These credits will allow them to redeem "content" (nodes). My goal is basically to allow users to only gain access to content they "redeem" using their credits, and they only gain credits by submitting content which I approve and assign value to. So if user X submits content, I think its great and rank it 8 out of 10 and decide that he gets 8 credits, he then gets 8 credits. He can then use those 8 credits to redeem content, and content can have different values.

What is the best way to go about getting this functionality in Drupal?

# Answer
> 5 votes
The Userpoint provides a mean to store a user *credits* and can be combined with the Userpoints Node Access to sell node (ie. content) access in exchange of userpoints (*credits*). The User points Nodes and Comments allow you to setup automatic rewards for content contribution (ie. nodes and comments creation). But it doesn't seems to provides the rating feature you ask for, nor does any of listed User Points Contributed modules.

What should be easily doable, is to use the Fivestar to rates node and then to grant, and revoke userpoint to the rated node author on voting (`hook_votingapi_insert()` and `hook_votingapi_delete()`). By restricting access to voting (ie. the 'rate content' permission or through an `hook_fivestar_access()` implementation), you can control who is allowed to grant credits to your users.

# Answer
> 4 votes
I would take a look at the User Points module and the User Points Contributed modules module.

If that does not satisfy you, it should be easy enough to write a custom module for that.

* Create a table with primary key as nid and an credit value.
* Create another table with primary key as uid and assigned credits.
* Make a third table for access. uid as primary and nid. There you can store the nodes a certain user has access to.
* Create the table trough the schema api.
* Now with a menu hook, add a `MENU_LOCAL_TASK` item that assigns values for easy administration by adding a callback that gets a form API form.

With `hook_access()`, you can define when a user has access to a node trough tables mentioned above and the database layer API.

---
Tags: users, 7
---


title: Grouping a View by Custom Field

text:
# Question
Title: Grouping a View by Custom Field
Hi there i hope you can help. Drupal info below.

Core module : 6.22 Installed modules: CCK, Views, Image, SEO.

I have a custom field called field\_type which i need to group by.

After searching in vain on the internet for a long time I'm unable to find an answer that works.

Could anyone give me step by step instructions how to create a view like the sketch below. Basically each item has a type assigned to it, and i need to group the results of the view by type. Preferably with a title above the group to say which type it is.

Type 1 -

Item 1, Item 2, Item 3, Item 4

Type 2 -

Item 5, Item 6, Item 7, Item 8

Type 3 -

Item 9, Item 10, Item 11, Item 12

Thanks!

# Answer
> 1 votes
In a nutshell....

Create a view, with a filter of the node type that contains this field\_type and if it's published etc.

Add all the fields you want to display, including the field\_type.

In Advanced Settings, turn grouping on.

In Style Settings, click on the Unformatted Settings (the round dodad next to Unformatted :) and in there you will now see a grouping field...so select field\_type.

Save and preview. It should do what you want data wise, so just add whatever CSS is needed to make it look pretty.

---
Tags: views
---


# Question
Title: In Drupal 7, what is the proper syntax to call the theme function for a node, passing an argument?
I'm writing a Drupal 7 application that has many content types. Each of these content types has a custom template for display. For instance, I have node--event.tpl.php, node--person.tpl.php, node--feedback.tpl.php, and so on.

I'd like to be able to manually call a theme function on a node that should have an overriding template. i.e. something like the following:

```
<?php print theme('node', array('node' => $node)); ?>

```

The reason for this is that I've written a module called Content Inclusion which allows pieces of content to be manually included within one another. I'm trying to have this line of code in my node.tpl.php file to automatically display the included node along with the parent node.

I appreciate any and all suggestions, but I would be more interested in learning about ways to make this work - this module has some very specific requirements that existing modules were not able to address. Thanks.

# Answer
The function you're looking for is `node_view()`:

```
$view_mode = 'teaser'; // Or 'full'
print render(node_view($node, $view_mode));

```

It's the same function that Drupal internally calls to display the node page/teaser so your template files will be honoured as you'd expect.
> 3 votes

---
Tags: theming
---


title: Display content during site maintenance

text:
# Question
Title: Display content during site maintenance
Is it possible to display a static version of a Drupal 6 website while it's in maintenance mode? Could something similar to Boost help?

# Answer
Yes, Boost can do this actually. Here's a video that explains it: http://www.drupalove.com/drupal-video/how-can-boost-help-my-site

Pages which are set to static cache will remain running while in maintenance mode.
> 4 votes

---
Tags: 6, caching, maintenance-mode
---


# Question
Title: Disabling access to admin pages during maintenance
I need to do some maintenance on a website that is updated by a number of contributors, what is the easiest way for me to disable access to the admin part of the website while I'm working on it?

# Answer
Assuming that you are user 1, and that the contributing users all have a particular role; you should be able to just remove the `administer site configuration` permission from that user role whilst you're working. This should disallow access whilst under maintenance mode.
> 1 votes

---
Tags: 6, users, maintenance-mode
---


# Question
Title: Changes in the way Drupal 7 handles JavaScript and jQuery
I'm currently developing a JavaScript script that runs on an administration page. I read up on the changes made in Drupal 7, namely the move from `document.ready()` to its own jQuery function. However, the following script doesn't work.

```
(function ($) {
  console.log('hello');
  $('#edit-apiusername').append('test');
})(jQuery);

```

`console.log()` is firing and I can see the output, but the simple append doesn't work. The field ID is correct.
I am not sure what I'm missing here, but I suspect it has to do with the way I'm referencing the object. Looking at Views 3 JavaScript code, I can see it's done in a similar way.

# Answer
I think you misunderstood the changes.

JavaScript code should be wrapped in `(function ($) { ... })(jQuery);` to allow usage of `$` as shortcut to `jQuery`. This is to allow jQuery to play nicely with other libraries. In this function, you still have to wait for the DOM to be loaded if you want to alter it. That's what wrapping your code in `jQuery.ready(function(){ ... })` does.

But instead of using `jQuery.ready(function(){ ... })`, you should use behaviors to let Drupal's JavaScript knows that your code wants to process anything added (or removed) from the DOM.

```
(function ($) {
  Drupal.behaviors.exampleModule = {
    attach: function(context, settings) {
      $(context).find('#edit-apiusername').append('test');
    }
  }
})(jQuery);

```
> 27 votes

# Answer
You might also consider aliasing the whole jQuery object to another variable of your choice, as in:

```
$j = jQuery.noConflict();

```

You would put this outside of the ready statement to leave it accessible outside of the encapsulation.
> 1 votes

---
Tags: 7, javascript
---


# Question
Title: What is the best practice to split up a long global.css in an Omega theme?
I am building out a theme based on the excellent base theme Omega. I am using the standard CSS files for narrow, normal, etc. My global.css file is getting large. I would like to split it up. Is there any kind of best practice for this in Omega, or should I just do as I would any other Drupal theme?

# Answer
> 1 votes
Have you subthemed Omega? I would say just modify your .info file and include an extra css file. I do it all the time, splitting them on function, i.e. styling for node templates etc. in one file and so on.

---
Tags: 7, theming
---


# Question
Title: How to declare a custom theming function for block content?
My goal is to render an array of values (body, date) using my own theming function. I've read Using the theme layer, and checked out the example modules, and I can't see the reason why this isn't outputting the test string.

I've implemented registered my theme hook:

```
function mymod_theme() {
    $items = array(
        'mymod_items' => array(
            'variables' => array(
                'items'=>NULL
            ),
        ),
    );
    return $items;
}

```

I've implemented a theme function:

```
function theme_mymod_items($variables) {
    return 'I am themed output';
}

```

And I call this from my `hook_block_view`:

```
function mymod_block_view($delta = '') {
    switch($delta) {
        case 'mymod':
            $block['subject'] = t('My Module');
            $items = array(
                array('body'=>'body1','time'=>'time1'),
                array('body'=>'body2','time'=>'time2'),
                array('body'=>'body3','time'=>'time3'),
            );
            $block['content'] = theme('mymod_items',$items);
        break;
    }
    return $block;
}

```

This results in the block not displaying, and the following message turning up in the log:

> Theme key "mymod\_items" not found.

Can someone please tell me what obviously essential step I've missed, or if I'm going in entirely the wrong direction?

# Answer
It's an obvious answer, so sorry if you've tried it, but have you cleared your cache, specifically the theme registry?
> 5 votes

---
Tags: 7, theming
---


# Question
Title: The vertical tabs don't show when is one vocabulary
I am working in Drupal 6, and I am using the Hierarchical select. If my taxonomy consists in two or more vocabularies associated to a content type, the vocabulary shows into vertical tabs but if my taxonomy consists in one vocabulary associated to a content type, the vocabulary doesn't show into vertical tabs.

I thank to you for your help.

# Answer
It's the setting for "Minimum number of tabified fieldsets to show vertical tabs:" found at: /admin/settings/vertical-tabs

It's defaulted to 3, which means you must have 3 vocabs on the node type for it to put them in a tab... you can change the minimum value.
> 1 votes

---
Tags: taxonomy-terms
---


# Question
Title: How do I wrap two render array elements in a div?
Given this renderable array:

```
$output = array(
    'twitter-icon' => array(
      '#type' => 'markup',
      '#markup' => '<div class="twitter-icon"></div>'
    ),
    'twitter-link' => array(
      '#type' => 'markup',
      '#markup' => l('follow us on Twitter', 'https://twitter.com/#!/zujava'),
    ),
  );

```

How do I wrap both of these elements in a single DIV?

# Answer
> 34 votes
You can also use the `#container` form element, and code similar to the following one:

```
$wrapper = array(
  '#type' => 'container',
  '#attributes' => array(
    'class' => array('class-name'),
  ),
);

$wrapper['twitter-icon'] => array(
  '#type' => 'markup',
  '#markup' => '<div class="twitter-icon"></div>'
);

$wrapper['twitter-link'] => array(
  '#type' => 'markup',
  '#markup' => l(t('follow us on Twitter'), 'https://twitter.com/#!/zujava'),
);

```

The #container element wraps its children elements with a `<div>` tag, whose CSS class is the one passed in the `#attributes` property.

You could even use a container for the "twitter-icon" element, but that doesn't give you any pro, except in the case you could possibly add an element to that, as with the following code:

```
$wrapper = array(
  '#type' => 'container',
  '#attributes' => array(
    'class' => array('class-name'),
  ),
);

$wrapper['twitter-icon'] => array(
  '#type' => 'container',
  '#attributes' => array(
    'class' => array('twitter-icon'),
  ),
);

if ($condition) {
  $wrapper['twitter-icon']['twitter-icon-text'] => array(
    '#type' => 'markup',
    '#markup' => t('Icon text'),
  );
}

$wrapper['twitter-link'] => array(
  '#type' => 'markup',
  '#markup' => l(t('follow us on Twitter'), 'https://twitter.com/#!/zujava'),
);

```

# Answer
> 7 votes
Is this what are you looking for?

```
$output = array(
    'twitter-icon' => array(
      '#type' => 'markup',
      '#markup' => '<div class="twitter-icon"></div>'
      '#prefix' => '<div class="test">',
    ),
    'twitter-link' => array(
      '#type' => 'markup',
      '#markup' => l('follow us on Twitter', 'https://twitter.com/#!/fdgf'),
      '#suffix' => '</div>',
    ),
);

```

Hope that helps!

# Answer
> 2 votes
You also can create a theme for this.

```
$form['twitter']['#theme'] = 'my_twitter_theme';

$form['twitter']['icon'] = array(
'twitter-icon' => array(
  '#type' => 'markup',
  '#markup' => '<div class="twitter-icon"></div>'
);

$form['twitter']['link'] = array(
  '#type' => 'markup',
  '#markup' => l('follow us on Twitter', 'https://twitter.com/#!/zujava'),
);

```

And in your theme hook:

```
function my_hook_theme(){
  return array(
    'my_twitter_theme' => array('form' => NULL)
  );
}

```

And in the theme function:

```
function theme_my_twitter_theme($form){
  $output = "";

  $output .= "<div class=\"twitter\">";
  $output .= drupal_render($form['icon']);
  $output .= drupal_render($form['link']);
  $output .= "</div>";

  $output .= drupal_render($form);
  return $output;
}

```

*I use this in Drupal 6, i'm not sure if works also in D7 but i hope so*

---
Tags: 7, theming
---


# Question
Title: Calling get_theme_setting from php-as-css file
I'm developing a Drupal 7 theme, and I'm using a php file as my theme's css file, in order to be able to use variables to simplify colour changes across the entire css.

I've also defined some theme settings in the theme-settings.php

What I want is to be able to call get\_theme\_setting() from within my style.php file, and use the theme settings to determine CSS attributes.

# Answer
> 0 votes
The solution I ended up implementing is embedding the PHP/CSS within the html.tpl.php file, as in inline style.

# Answer
> 1 votes
I recommend you to take a look to less css:

http://lesscss.org/

In fact there is a drupal module for this:

http://drupal.org/project/less

I used it a project and works great.

---
Tags: theming
---


# Question
Title: Is there a hook function for a module's settings form being submitted?
I am maintaining a cache of data in my module using $\_SESSION, which gets rebuilt after an amount of time has passed. This works fine, but I now need the cache (session object) to be cleared when the user submits a change to the module settings.

Is there a hook I can implement that will be called on form submission? I have already implemented `mymodule_form_validate`, but this doesn't feel like the right place for it, I would prefer a hook that fires only when validation is successful.

I have tried checking for the rebuild flag in `mymodule_form`, but that doesn't seem to work:

```
function mymodule_form($form, &$form_state) {
    if($form_state['rebuild'] === true) unset($_SESSION['mymodule_cache']);
    //form elements and stuff...
}

```

**Update**

Trying to follow marcvangend's answer, but I'm struggling. I've implemented hook\_form\_FORM\_ID\_alter:

```
function mymodule_form_mymodule_form_alter(&$form, &$form_state, $form_id) {
    echo $form_id.'<br>';  // mymodule_form
    $form['#submit'][] = 'mymodule_form_submit';
}

```

and this seems to work, in so much as the form id traces out as expected. The trace in my submit function never seems to appear and the session object is unchanged, although the form values do submit:

```
function mymodule_form_submit($form, &$form_state) {
    echo 'form submit';
    $_SESSION['mymodule_cache'] = array();
}

```

# Answer
You can implement hook\_form\_alter or hook\_form\_FORM\_ID\_alter and add a custom submit handler to the form in which you can clear the session data. It would look something like this:

```
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "some_form") {
    $form['#submit'][] = 'mymodule_some_form_submit';
  }
}

function mymodule_some_form_submit($form, &$form_state){
  // Do your fancy stuff here.
}
?>

```

This example implements hook\_form\_alter. If you only have one form to alter, I recommend using hook\_form\_FORM\_ID\_alter because it results in cleaner code.
> 3 votes

---
Tags: 7, forms
---


title: Node form alter query

text:
# Question
Title: Node form alter query
While editing a node I've printed the dsm($form) in hook\_form\_alter and in the dsm array I see the following values:

```
....
form_id (Array, 3 elements)

    #type (String, 6 characters ) hidden
    #value (String, 14 characters ) unit_node_form
    #id (String, 19 characters ) edit-unit-node-form

.....

```

This node's machine name is **"unit"** I want to know what is the difference between #value and #id values.

I want to catch form alter of only this node while editing it.

# Answer
> 2 votes
Typically you would use a check on $form\_id to make sure your hook\_form\_alter would only apply the specific form. A node editing form is normally only present on edit pages, so it would only apply to edit pages as the form is not displayed anywhere else.

Don't forget that hook\_form\_alter is called on all forms, so you need to check for the some values to not apply it to all forms. Usually this is the form\_id.

To check for a specific form you would use:

```
/**
* Implementation of HOOK_form_alter()
*/
function MYMODULE_form_alter(&$form, $form_state, $form_id) {

  // 1.UNIT CONTENT TYPE FORM
  if ($form_id == 'unit_node_form') {

  }

}

```

This can be helpful if you modify multiple forms in one module. If you prefer not to do that you should maybe use hook\_form\_FORM\_ID\_alter() to modify only a specific form.

Checking the form api $form\_id is defined as:

> String representing the name of the form itself. Typically this is the name of the function that generated the form.

The question this throws up now is:

Is $form\_id defined from

```
$form['form_id']['#value']

```

or from

```
$form['#form_id']

```

Both of which give the same results. So unfortunately I can not directly give you an answer, other than that the form will only display on edit pages, so using $form\_id seems to be standard proceedure.

---
Tags: 6, forms
---


# Question
Title: Is it possible to make only one field in a content type language neutral?
If you have a text field, that you do not want to be translated (i.e. language neutral) as in a field for an email address, how do you set just that one field to be language neutral, while leaving the rest of the fields in the content type multilingual (enabled, with translation under workflow settings)? I've tried toggling the checkboxes under "Content Translation" but I think that's just for the Translation Management modules translation jobs handler, not for the actual field settings itself.

The idea is to not have to enter an email address twice in both, for instance, English and Spanish since the value will be the same in both language. Otherwise you have to enter the value in each language to get it to show up in that language.

# Answer
> 3 votes
I don't believe that it's possible to configure the language type of fields and translate per field. Not in Drupal 6 anyways.

This shouldn't be a problem anyways. When you translate a node, drupal makes a copy of the original node, which means the e-mail address will be pre filled with the correct value.

The does require some extra work when editing, but if you really wanted to, you could create some custom code, or maybe setup a rule, to keep that field in sync with the other translated nodes.

# Answer
> 3 votes
Drupal 7 allows per field translations using the Entity Translation module. I haven't used the module as I require full node translations, not just some fields. I think it will fit your use case. Check it out at http://drupal.org/project/entity\_translation

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


# Question
Title: How to hide node title while in edit without automatic nodetitle module?
Actually in hook nodeapi(op:presave) I'm setting my own custom title so I want to hide the title field from the node edit form.

It does not work if I use automatic nodetitle module since it is also changing the title.

What is the best way to hide the title without using automatic nodetitle module?

# Answer
Use hook\_form\_alter and unset($form\['title'\]) in a custom module (since the node create / edit form will usually be displayed in your admin theme this will be a better approach than adding the function to your themes template.php file.

So create a module with a basic mymodule.info file.

Create a mymodule.module file and add:

```
function mymodule_form_alter(&$form, $form_state, $form_id) {

   // 1.NODE TYPE FORM
   if ($form_id == 'NODE_CONTENT_TYPE_node_form') {
     unset($form['title'];
   }

 }

```
> 2 votes

---
Tags: 6, nodes
---


# Question
Title: "Add content" button on related content node?
Let's say I have 2 content types "Shopping center" and "Shop".

"Shopping center" is a OG group. "Shop" has node reference field "Shopping center".

I would like to allow moderators to add shops to shopping centers on the shopping center node screen.

How to add "add shop" button on "Shopping center" node view ?

# Answer
I don't know how OG handles the "This Shop belongs to that Shopping Center" relation, but for a Node reference field there is the Node Reference URL Widget which can be used for this. It provides both the *widget* that wil sets the node reference field value from the URL and the link to create a new referencing node from the referenced node page.
> 2 votes

# Answer
You are doing redundant work by having a node reference field. If "shop" is set up as a group post, you should be able to add new shops when in a shopping center context. There should be some kind of "group options" block that will give you these options. (Haven't done this exact thing in 7 yet but it must be similar to the way it works in 6).
> 2 votes

# Answer
I think the Contextual Administration module may help you to create that.

In the project page, you can also find the link to a really nice video about using the module.
> 1 votes

---
Tags: 7, nodes, organic-groups
---


# Question
Title: Setting php E_NOTICE within my .module file
I want to set E\_NOTICE only within the .module files which I create. How can I do it?

I want to catch mis-spelled variable names which are difficult to catch.

# Answer
I've never tried this, but if you don't mind modifying core on your dev server you can change `drupal_error_handler()`: examine the results of `debug_backtrace()`, decide if the error came via your module and act appropriately.
> 1 votes

# Answer
You can not set E\_NOTICE only to your module files. In PHP when you activate the notices, it will be activated for all running scripts.

To display errors, warning and notices:

```
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

```
> -1 votes

---
Tags: configuration
---


title: Problem with Node module on website

text:
# Question
Title: Problem with Node module on website
Please bear with me on this one, as I am a complete newbie with Drupal, and am helping out a client on this one, so am trying to relay the problem they are having.

It appears that they are having trouble with a Node module, this module is used to add events and sell tickets to these events.

Currently when a new event is added by 'admin' it is only viewable by admin, so anonymous users can't see any see any events events. We think it has something to do with permissions or a between some modules, but as a say not really understanding the product i'm struggling to get to the bottom of it.

One of our developers also thinks that it could be something relating to a field used in the event, and user doesn’t have access to read this field (permissions).

It seems that for each there is a diferent permision filed in permisions section in admin panel.

Has anyone had this trouble before? Any help, ideas or even questions on this very welcome. We may have to get someone in to finish this job off.

I may also have most of this backwards, so please ask if you need anymore info, or what I should look at and I can supply this straight back to you.

Thanks for the patience :)

# Answer
> 2 votes
There are a number of permissions that could be affecting this.

First off, node permissions. The most important one here is 'access content,' so make sure anonymous users can do that. After that, they can be set up so different users in different roles can create, delete and/or edit nodes.

Given that they aren't trying to do any of this, I doubt it's related to these node permissions, so let's go drill down a granularity level and look at permissions on fields in the nodes themselves. Here, permissions can be set on edit and view. Given they aren't trying to edit a node, just look at it, I'd look at the view permissions.

Assuming 'admin' is uid 1, s/he can do anything, so look for fields that aren't viewable by the more casual user/role. Somewhere in there as you surmised above is the field that this module needs to show itself. (Oh, also, if you are using imagecache, make sure its permissions are set up as well)

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


# Question
Title: /admin path display login box along with access denied message (drupal 7)
In drupal 6 when visiting /admin, an access denied message was shown in the admin theme along with a login box. How can I do the same in drupal 7? Currently the regular theme is shown along with an access denied message.

# Answer
You need to install the Login Toboggan module, which show the login block on the *Access denied* pages and give the *View the administration theme* permission to anonymous users.

> The LoginToboggan module offers several modifications of the Drupal login system in an external module by offering the following features and usability improvements:
>
> 1. Allow users to login using either their username OR their e-mail address.
> 2. Allow users to login immediately. Provide a login form on Access Denied pages for non-logged-in (anonymous) users.
> 3. The module provides two login block options: One uses JavaScript to display the form within the block immediately upon clicking "log in". The other brings the user to a separate page, but returns the user to their original page upon login.
> 1 votes

---
Tags: 7, users
---


# Question
Title: Mailing content to a list/group of email addresses
What kind of module should I use to send content to a list of emails?

* I need to create a groups with list of emails.
* I need to send it to one or a few of these groups.
* I need for admins to be able to look at the email addresses which will receive the emails.

I am thinking about using mailchimp, but it does not fulfill all of my needs. Also simplenews\_roles can be a good decision, but whre is no version on drupal-7. Is there another option available?

# Answer
You can use the Newsletter module, which has a release for Drupal 7.

> Newsletter module aims to be a full blown newsletter solution for Drupal 7. It is especially recommended for people that need more than one newsletter list for their site.
>
> ### Features
>
> * **Multiple newsletters lists** configurable on existing terms
> * Plain text or HTML out of the box.
> * **Multiple schedules** Each newsletter can have more than one schedule, e.g. Daily, Monthly, Weekly, manually or even custom, eg after 10 new posts for this term.
> * **Centralized administration and configuration** on a single page.
> * Users can **customize** the terms in the list they subscribe to.
> * Custom template per list.
> * **Statistics** (CTR and Open-Rate).
> * Drupal 7 only.
> 0 votes

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


# Question
Title: Exposing Individual Fields on Output for Styling
I've created a view which outputs a particular content type into a jCarousel.

One of my fields is a 'background colour' and I want to use this value for the actual background colour of the `li` element in my jCarousel. The next is an image and I want this image to be wrapped in a div that I can lay out correctly within the same `li` of the carousel.

So, this carousel will have a customisable image and background colour for each member of the content type.

The problem is, in jCarousel, the fields are just dumped into an array haphazardly, so I cannot output different fields in different ways. Ideally, what I'd like to happen is: in the `jcarousel-view.tpl.php` I'd like to output `$rows[0]['background-color']` into my custom html `div` tags and then `$rows[0]['image']` output into my own custom classed `div` tags also - obviously iterated within a loop to apply the individual settings to each element.
However, the current set up is that $rows\[0\] dumps both fields into their default styles and I can't access individual fields.

Now, is this something I can control in Views? Or do I need to do some custom hacking to get this to work?

# Answer
> 1 votes
This is a complex but ultimately pretty easy thing to do once you understand how this "haphazard" array is built :)

In Drupal 6....

If you go into views, look under Style Setting at Theme Information. There, it will tell you all the templates it uses to create its output. The one here you are interested in is Row Style Output, because it is the template that is building the $rows that are ultimately passed to jcarousel-view.tpl.php.

What you want to do is make a copy of this template in your theme directory that overrides the default one, and in this case, the easiest is the first one that incorporates your view name into it. Doing a quick test here, with a view named jc-test, that would be views-view-fields--jc-test.tpl.php.

Rescan the templates files to make sure it's selected and edit that bad boy. What you want to do now is change how it creates the individual row. Normally, views just passes the information given to it along, but you want to work on it programatically, eg, turn the content of a field into some html based upon it.

So, if you don't have devel set up on your machine, a quick:

```
<?php drupal_set_message('<pre>' . print_r('field id: ' . $id . ' field raw: ' . $field->raw,true) . '</pre>'); ?>

```

right after the first foreach() will tell you want's inside here you have to work with. Let's say for ease of discussion, the field you have that you want to use for the color is named field\_color. For ease, it should be the first field passed to the row, which is easily set up in views.

So, inside here, you'd do something like this:

```
<?php if ($id=='field_color'): ?>
  <?php print '<div class="' . $field->raw . '">'; ?>
<?php else: ?>

  -- ALL THE REST OF THE CODE BEFORE THE ENDFOREACH GOES IN HERE
  -- BECAUSE YOU DON'T WANT TO PRINT OUT THIS FIELD
  -- BUT YOU DO WANT TO PRINT EVERY OTHER FIELD

<?php endif; ?>

```

Now....that OPENS the DIV. You need to close it at the end of the row, so just put:

```
<?php print '</div>'; ?>

```

after all the php in the template (after the last endforeach).

So, now, barring any typos of mine above, you've wrapped a row in a div classed with the content of the first field of the row :) Use CSS to make it pretty.

You do have to make sure your data is sane, though, $field-\>raw isn't friendly at all, so you may need/want to check\_plain() it if it's user input etc etc.

Anyways, hope this helps out!

---
Tags: views, entities, javascript
---


# Question
Title: How to create multiple option field for product display?
I am trying out the Commerce feature (bulk product creation), but the result is that the product has only one option list with all internal options. I want have more multiple options list with relative options, in the picture below you can see what I want to have in the product display:

# Answer
> 2 votes
How the products have no influence on how they are rendered on a product reference field.

What matters is what data the products hold, you need to be able to create unique combinations for all, and setup the reference field to try to do this. The problem you might be facing is that some products are too similar. To reviewing the product data and the products reference in the product reference field.

It's likely that you have created near identical products forcing the user to pick from a list containing all products, instead of have multiple select boxes.

---
Tags: commerce
---


# Question
Title: Custom Content types nodes with Nodeblocks module
I have been unsuccessful in accomplishing the following:

I am using the Nodeblocks module and trying to follow its documentation for using it with a custom content type. My custom content type machine name is `content_block`. I want a client to be able to create a new `content_block` and then be able to place it wherever he wants using the Admin \> Blocks page.

The `content_block` content type has these fields (machine names - purpose):

* title - Title of the block (nodeblock) that will be seen on the Blocks administration page. Will be hidden from output.
* field\_headline\_level - stores a value like, "h2", "h3", "h4", etc. To be used to customize the HTML Headline tag. Will be hidden from output.
* field\_headline - The actual words for the headline
* field\_content - Content to be displayed below the headline

I've been trying to follow the Nodeblocks documentation (linked above) as well as the Drupal 7 Template Suggestions but I can not get it to work. I keep running into nested template problems, such as the default block template wrapping around the node type template and getting double headlines. I also can't figure out the correct syntax to display the various `content_block` fields.

Can anyone out there help me out or point me to a "Node Templates for Dummies" article? I've done lots of searches on Google, but can't find anything very helpful.

# Answer
> 1 votes
Figured it out by getting my head around what Drupal calls "Template Suggestions". The Theme Developer Module helped.

For my particular use case I had to create a template file called `block--nodeblock.tpl.php` to override the default block output. I basically stripped everything out of the default except the actual content so that this was all that was left: `<?php print $content ?>`.

Then I made a `node--content_block.tpl.php` template to override this particular content type's display the way I wanted it. I had to add some trim() methods to strip out some leading spaces that Drupal insisted on inserting.

```
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

    <?php if($content['field_headline']): ?>
        <?php print render($title_prefix); ?>
        <<?php print trim(render($content['field_headline_level'])) . ' ' . $title_attributes; ?>><?php print trim(render($content['field_headline'])); ?></<?php print trim(render($content['field_headline_level']));?>>
        <?php print render($title_suffix); ?>
    <?php endif ?>

    <div class="content"<?php print $content_attributes; ?>>
        <?php print trim(render($content['field_content'])); ?>
    </div>

</div>

```

The last thing I had to do was create a template to strip out all the extra tags that the Drupal default field comes with. I did so with this file, named `field--content_block.tpl.php`:

```
<?php foreach ($items as $delta => $item) : ?>
      <?php print render($item); ?>
<?php endforeach; ?>

```

---
Tags: 7, nodes, theming
---


# Question
Title: What's wrong with my custom node template?
I'm attempting to make my first custom node template that is supposed to be used for a certain content type with the machine name of "content\_block." I copied the "/modules/node/node.tpl.php" file to my theme's directory at "/sites/all/themes/mytheme." Then I renamed the file to "node--content\_block.tpl.php."

Then I cleared the site's cache via "Administration » Configuration » Development » Performance."

It seems to only be partially working. Some of my content type's field variables render, but not with the values I expect. Others don't render anything but the word "Array".

My template code looks like this:

```
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
  <?php if ($field_headline == TRUE && $field_headline != " "): ?>
    <?php print render($title_prefix); ?>
    <?php print $field_headline_level; ?><?php print $title_attributes; ?>><?php print $field_headline; ?></<?php print $field_headline_level; ?>>
    <?php print render($title_suffix); ?>
  <?php endif; ?>
  <div class="content"<?php print $content_attributes; ?>>
    <?php print $field_content; ?>
  </div>
</div>

```

One thing I definetly don't understand is when to use `print render($variable)` and when to use `print $variable`.

# Answer
render() renders the argument it gets using drupal\_render(), and the documentation for this function reports the following text:

> Renders HTML given a structured array tree.
>
> Recursively iterates over each of the array elements, generating HTML code.
>
> Renderable arrays have two kinds of key/value pairs: properties and children. Properties have keys starting with '`#`' and their values influence how the array will be rendered. Children are all elements whose keys do not start with a '`#`'. Their values should be renderable arrays themselves, which will be rendered during the rendering of the parent array. The markup provided by the children is typically inserted into the markup generated by the parent array.
>
> HTML generation for a renderable array, and the treatment of any children, is controlled by two properties containing theme functions, `#theme` and `#theme_wrappers`.
>
> `#theme` is the theme function called first. If it is set and the element has any children, it is the responsibility of the theme function to render these children. For elements that are not allowed to have any children, e.g. buttons or textfields, the theme function can be used to render the element itself. If #theme is not present and the element has children, they are rendered and concatenated into a string by `drupal_render_children()`.
>
> The `#theme_wrappers` property contains an array of theme functions which will be called, in order, after `#theme` has run. These can be used to add further markup around the rendered children; e.g., fieldsets add the required markup for a fieldset around their rendered child elements. All wrapper theme functions have to include the element's `#children` property in their output, as it contains the output of the previous theme functions and the rendered children.

The other elements that influence how the element passed to `drupal_render()` (or `render()`) is rendered are:

* `#type`, which causes the array to be merged with the array returned by element\_info()
* `'#pre_render`, which causes the element to be passed to a function that alters the element before is rendered
* `#post_render`, which causes the element to be passed to a function that alter the rendering result

The following are all examples of rendering arrays that you can pass to `render()` (and `drupal_render()`):

```
$markup = array(
  '#type' => 'markup',
  '#markup' => '<div class="messages">' . t('This is the message') . '</div>',
);

```

```
$form['nodes'] = array(
  '#theme' => 'table',
  '#header' => $header,
  '#rows' => $options,
  '#empty' => t('No content available.'),
);

```

```
  $node->content['links']['node'] = array(
    '#theme' => 'links__node__node',
    '#links' => $links,
    '#attributes' => array('class' => array('links', 'inline')),
  );

```

In the first example, the array is extended by `element_info()` (as the array contains the `#type` property) and what is really used from `render()` is the following array:

```
$markup = array(
  '#type' => 'markup',
  '#markup' => '<div class="messages">' . t('This is the message') . '</div>',
  '#pre_render' => array('drupal_pre_render_markup'),
);

```

You can also pass a string to `render()`, as the code that the function executes is the following one:

```
if (is_array($element)) {
    // …
}
else {
  // Safe-guard for inappropriate use of render() on flat variables: return
  // the variable as-is.
  return $element;
}

```

This means that it is safe to call the function with a string.

As in the comment for your question you are referring to a node field, fields are always passed to `render()`; if "field\_name" is the ID of the field found in the node, then you render it using the following code:

```
render($content["field_name"]);

```
> 2 votes

# Answer
* Use `print render` when the variable is a build array and use
* Use `print` when the variable is a PHP string containing HTML.

For more details, render arrays on d.o. (render and build arrays are the same thing).
> 4 votes

# Answer
This is how I ultimately solved my problem (though the render() explanations were good too). Custom Content types nodes with Nodeblocks module
> 0 votes

---
Tags: 7, nodes
---


title: Add html ID to content field

text:
# Question
Title: Add html ID to content field
When I create the content (specific to the content, not to the content type), I want to type in an optional ID, that would be set on the html element.

Is there a module for this?

# Answer
> 2 votes
In Drupal 6, you can theme cck fields by copying content-field.tpl.php from the CCK module's includes directory to your theme directory and then creating a content-field-FIELDNAME.tpl.php to customize the look of that individual field. Or, if you want to wrap every field with a uniquely id'ed div, you could edit your copy of content-field.tpl.php and add:

```
<div id="<?php print $field_name_css . '-' . $node->nid; ?>">

-- php code between the check if the field isn't empty --

</div>

```

to the template, or around whatever portion in it you needed. Just be careful with multiple field items, their ids would need a -$delta added to them if you put this inside the code of the template instead of wrapping it entirely, or adding the id= to the first div, etc. If you want to id it with a user supplied field, you can grab that from the $node given, eg

```
$node->field_my_optional_id[0]['value']

```

but you have to sanitize it.

Now, I know you said Drupal 7, and I am sure it's subtly different there, but this should put you on the right path. Hope it helps!

UPDATE/EDIT: It's field.tpl.php from the system module field's theme directory in D7.

---
Tags: 7, nodes
---


# Question
Title: Show a block on a certain URL with wildcard
How do I show a `<div>` inside page.tpl.php, on every page except for URLs that start with "audio/track"?

# Answer
If the page is not a node (is a landing page, view, panel etc) you can use the function arg

```
if(arg(0) != "audio" && arg(1) != "track") {
  print "<div></div>";
}

```

Or if is a node you can make the conditional using a taxonomy or using the node type.

```
if(arg(0) == "node" && is_numeric(arg(1)) && $node->type != "your-node-type" ){
  print "<div></div>";
}

```
> 1 votes

# Answer
In the configuration or your block you've a "Page specific visibility settings". Choose the "Show on every page except the listed pages." option and in the textarea below add your url.

In your case it will be something like that `/*/audio/track`

In the code, you can directly use the function drupal\_match\_path, you get the current path with request\_uri function and in the patterns you add the example given above.
> 0 votes

---
Tags: blocks
---


# Question
Title: UbertCart Cart does not follow my cart count
I customized my cart link using Views to show the cart product count. It's not updating the count. However, the normal cart block that came with drupal 7 and ubercart (in blocks) shows the correct count of my products in cart.

The view FIELDS list contains:

**FIELDS<br>Cart product: qty**

then use the replacement pattern: Your cart contains \[qty\] item(s) within the views Rewrite Output of this field.

Not that my custom cart link does not update but it's erratic. Clearing the cache does not seem to also affect my custom cart link. While the normal view cart block is working fine.

I just needed to be able to customize the cart link to say something like 'Your cart contains 2 item(s) VIEW CART on top of my website. and it seems it does not work though...

Anyone knows this issue?

# Answer
The Ubercart block probably defaults to having `DRUPAL_NO_CACHE` set, while the view may have a different cache setting per default. Check the cache settings on the view?

May help for you to say whether this behaviour differs for logged-in and anonymous users.
> 0 votes

---
Tags: 7, views, ubercart
---


# Question
Title: Is there an alternative Drupal 7 module for the Advertisement module?
We are looking to upgrade a site to from Drupal 6 to Drupal 7 that uses the Advertisement module. There is an alternative module to the Advertisement module for D7?

# Answer
> 5 votes
Just released is the SimpleAds module for Drupal 7. This module provides a way to feature advertisements on a Drupal website. It displays graphical ads in configurable blocks. It records and reports useful statistics. It is easy to configure and does not depend on other contrib modules.

# Answer
> 2 votes
You can try OpenX.

> Show ads from a OpenX (formerly OpenAds) server. OpenX is a open source online program that will allow you to catalog and display advertisers, just like Google, Yahoo or Microsoft.

---
Tags: 7
---


title: Contextual Filters and URL Paths

text:
# Question
Title: Contextual Filters and URL Paths
I have a taxonomy of region names, and a content type of products. Each product is referenced to a region. I am attempting to create a single view that would show the products for a given region based on the url. For example, http://www.mysite.com/\[region-name1\]/products and http://www.mysite.com/\[region-name2\]/products should display products referenced to those specific region. Right now I have the view path set to /%/products, and a contextual filter set, but when I attempt to view the products, I get page not found. (It does work when I am previewing the view).

It works when I set the view path to \[region-name\]/products for a specific region and don't use a contextual filter, but I am trying to avoid having to create a view for each region if there is a way that I can do it once for all regions.

# Answer
> 1 votes
Arguments don't seem to work in the first position. So `/%/product` won't work, but `/content/%/product` will. Just move the argument to at least the second position and all should be fine.

# Answer
> 1 votes
I'm not sure if this is too late or not, but I managed to do this exact thing. You need to create a relationship for "Content: Taxonomy terms on node," putting in the given vocabulary you're using. You then make a contextual filter based on this relationship. Mine looks like "(term) Taxonomy term: Name."

Hope this helps. I struggled with it for quite some time, as well.

# Answer
> 0 votes
have you checked this link yet? I think i had a similar problem.

D7 views 3, display content based on path

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


# Question
Title: Will deleting the Body Field from one Content Type also delete this field from other Content Types?
When creating a new Content Type that does not need the body field, is it safe to just delete the body field from that new Content Type without affecting other Content Types?

# Answer
Yeah is safe, but directly you can't delete the body field, in the page where you admin the fields there is no link for delete it.

The way to delete it is when you create a new content type in the field where you put a label for "body" just let it in blank.
> 2 votes

---
Tags: entities, nodes
---


# Question
Title: How do I set a tag via cookie and filter content on the whole site based on that tag?
I have a site which has different tags for different cities. Most of the content on the site is either for all cities or a set of specific cities. I am planning to have all the content pieces taggable via taxonomy references. Within my template I want a dropdown which sets the current city. What is the easiest way to only show correct content based on this drop down througout the site?

# Answer
> 1 votes
you can build a view to show your content, then add a "filter" for the city term and "expose it" to your visitors. There is an option to remember the selection for each user.

# Answer
> 0 votes
The way to i do this is using the panel module (unfortunately this module is not yet available for Drupal 7)

When you use panels you can create regions where you can put many views or blocks and in these views you can set taxonomies as a filter.

---
Tags: cookies, taxonomy-terms
---


title: How to tell the filter views is using

text:
# Question
Title: How to tell the filter views is using
I'm in the process of writing a custom views filter handler. In order to learn from the existing filters, I'd like to know how I can tell which filter class views is using when I'm configuring an (exposed) filter on the GUI.

# Answer
Adding an exposed view filter inserts the following (sample) code into the view output:

```
 <div class="view view-... view-id-... view-display-id-default view-...-id-1">
    <div class="view-header">
        ...
    </div>

    <div class="view-filters">
        <form action="..." accept-charset="UTF-8" method="get" id="views-exposed-form-...">
        <div>
            <div class="views-exposed-form">
               <div class="views-exposed-widgets clear-block">
                  <div class="views-exposed-widget views-widget-filter-tid">
                     <label for="edit-tid">...</label>
                     <div class="views-widget">
                        <div class="form-item" id="edit-tid-wrapper">
                           <select name="tid" class="form-select" id="edit-tid" >
                              <option value="All">...</option>...
                           </select>
                        </div>
                     </div>
                 </div>
                 <div class="views-exposed-widget views-submit-button">
                    <input type="submit" id="edit-submit-..." class="form-submit" />
                 ...

```

It is not clear, though, why you can't find out the same by simply creating a view, exposing its filter and looking up the source code. Perhaps you could explain your question better?
> 0 votes

---
Tags: 6, views
---


# Question
Title: Users, subusers, and assigning subuser to multiple users
I want the following functionality in Drupal 7: Create a few parent users/business representatives (e.g. Google, Microsoft); these business representatives will add their business profile, and add employees of that specific company, add/edit/delete them. An employee can be from multiple companies and all business representatives can edit/delete employee's profiles.
Employees can also log in, and manage their own profiles.

Which modules should I use?

# Answer
> 3 votes
There is a Subuser module to create subusers and a Profile2 module to create user profiles for every user.

---
Tags: 7, users
---


# Question
Title: change Userlogin block on header to custom
How can we change userlogin block on header to custom, I am using D 7.9, theme : bartik, and how can i change the below userlogin block to custom block in image2 below. And `login` button should take upto example.com/user and `signup` button should take out to register a new account

And image1

And image2

# Answer
> 1 votes
You need just to remove the login block and create for example a new menu or use the existing service navigation where you place the links to the login form and to the reigster form. Show this menu then in the place where the login-block was. Optionaly place a link to Logout too. Drupal will recognize if the user is logged in or not.

---
Tags: 7, users
---


title: Drupal's main-menu not displaying

text:
# Question
Title: Drupal's main-menu not displaying
I've started my first custom theme and I pulled the main-menu print statement from the default page.tpl but it didn't display. Curiously, if I create a region and add the main menu to that region via the blocks administration it will show up. Why won't this show when hard-coded?

```
<?php if ($main_menu || $secondary_menu): ?>
  <div id="navigation"><div class="section">
    <?php print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Main menu'))); ?>
    <?php print theme('links__system_secondary_menu', array('links' => $secondary_menu, 'attributes' => array('id' => 'secondary-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Secondary menu'))); ?>
  </div></div> <!-- /.section, /#navigation -->
<?php endif; ?>

```

If I switch the theme over to Bartik, that uses the exact same print statement, the menu seems to work fine.

# Answer
I spent countless hours figuring it out as well; the solution was so dumb simple !

Edit your theme's ".info" file and add :

```
features[] = main_menu
features[] = secondary_menu

```

Otherwise main\_menu and secondary\_menu doesn't display at all.

Hope that helps.
> 6 votes

---
Tags: routes, navigation
---


# Question
Title: In Drupal, how can I set a role to allow/deny user account requests but not be able to change User 1's password?
I created a Drupal 6 site for a client which I, as user #1, will edit and maintain. However, I want the client to be able to allow/deny new authenticated user requests. I have created a new role and assigned it the following user permissons:

* access user profiles
* administer user
* change own username

This works and the users with that role can manage new user requests exactly like I want. However, they now also have the ability to change the User 1 password and do some serious damage to the site.

Is there a setting, permission, or module I can use to prevent this?

# Answer
> 3 votes
* User protect: protects specific fields of users from being edited.
* Administer Users by Role: lets you decide which roles a user can edit. Assign a dummy role to the admin user and give permissions for every other role.

First one says it is complicated, second one may be a pitfall if you add new roles but don't give access to edit them.

---
Tags: users
---


# Question
Title: Problems displaying full article - teaser only
My problem is that when I manually define teaser and body of the article, only the teaser displays after clicking "Read more" (the text entered in "Body" section isn't visible in any case)
I've defined max lenght of teaser to high value (2000) because I would manually set part of article which is visible in teaser mode but I think it should not impact on displaying full body.

# Answer
It sounds like the "Format" for the Default display is wrong. What is the "format" value shown in http://YOUR.DOMAIN/admin/structure/types/manage/YOUR\_CONTENT\_TYPE/display? Typically it should be "Default". If the Default Display is set to "Summary or Trimmed", then you'll get the effect you mention, with the Summary in both the Teaser and Default versions.

You can check this by changing the settings and doing Preview on the node edit page. Preview shows the Teaser and Default versions simultaneously.

Also, is "Custom Display Settings" checked for the Full Content, or just the Teaser? Typically it would be just the Teaser. If you have set Custom Display Settings for Full Content, then check the settings as above.

By the way, `<!-- break -->` works fine in Drupal 7. I use it.
> 0 votes

---
Tags: 7, nodes
---


title: Drupal 7: hook for comments placeholder

text:
# Question
Title: Drupal 7: hook for comments placeholder
How can i implement a hook in my theme template that will display a placeholder in my comment box? I am using drupal 7 and zen sub theme. Thank you, in advance.

# Answer
> 2 votes
You could use the hook\_form\_FORM\_ID\_alter to modify your comment form.

Also have a look at How Theme Comment Form Drupal 7 wich will tell you exactly how to achive this.

---
Tags: hooks, comments
---


title: Uploading pdf newsletters

text:
# Question
Title: Uploading pdf newsletters
How would I upload a pdf and link it to a post on my homepage? Basically the PDF is a newsletter and every week I want to upload a pdf (newsletter) and have a link as a story on the home page. I'm using Drupal 7, is this possible? does a module exist for it?

# Answer
You don't need a new module as this functionality is built into core. Go to (yoursite)/admin/structure/types and click "manage fields" for the content type you want to add your pdf's to. Add a new field whose field type is "File".

Working with files in Drupal 7
> 2 votes

---
Tags: files
---


# Question
Title: Architechture/ Foundation help for a drupal project
I am thinking to develop my drupal website for various products like camera, mobile and others.

For this i will have various content types like camera and mobile and others and have term references for feature of products so that it will be helpful in filtering the products.

Now my big problem is here. 1. Each product i.e camera, mobile should have its rating properties like camera will have its own set of rating properties and mobile will have its own rating properties. How do i attach these rating properties to a content type ? 2. When user goes to the product page, He should give ratings for properties and add comment against each property. How ill i do this ? 3. If he has already given ratings and commented on the product it should be default displayed.

Main problem is that how do i attach rating properties to the content type and make user comment on these properties.

If i create separate content types will it be a problem to create a search on all products

# Answer
I'm not sure what you mean by "properties" in your question. However, you can use the Fivestar module to add ratings to a content type. So your Camera content type could have a rating for each camera and your mobile content type could have a rating for each mobile.

Search will work across all content types. http://drupal.org/documentation/modules/search
> 1 votes

---
Tags: 7
---


# Question
Title: Display an image for the first item in a Views news list
I want to create a view to display news like in this image:

The list shows an image only for the first news, the other news only display the title.

# Answer
Views nodes split does exactly this:

> This module allows site administrators or builders to have a different view mode for the first nodes of a view result.

**Source:** Lullabot - Module Monday: Views Nodes Split
> 3 votes

# Answer
Quick and dirty, if you don't mind having all the images loaded in your page, you can use CSS to display the first one and not all the rest, eg:

```
.views-row img {
   display: none;
}

.views-row-first img {
   display: block;
}

```

I would just theme it a bit more specifically on your site, eg, with the views css names and views field names and so forth, the point is that views themes each row specifically, just take a look at the html output.
> 1 votes

---
Tags: views
---


# Question
Title: Relation adding not working in Drupal 7.9
I am a adding a new relationaship type, when i add up its not adding up, it gives one more time asking for details for input of relationship type and when i give the details and add it an fatal error displays..

I am using Drupal 7.9 and latest versions of modules on Drupal.org below is the error message

```
Fatal error: Call to undefined function ctools_export_crud_load_multiple() in R:\xampp\htdocs\sitename\sites\all\modules\relation\relation.module on line 397

```

# Answer
There is a known incompatibility with CTools rc1; use the development snapshot, and it will work.
> 1 votes

---
Tags: 7
---


title: change drush rsync for use with aegir

text:
# Question
Title: change drush rsync for use with aegir
I'm looking to drop the `-a` flag from the `drush`'s `rsync`, but not sure what the best place for it as far Aegir is concerned. Would it be the `sitename.alias.drushrc.php` files in `/var/aegir/.drush?` Or should this change be configured in `/var/aegir/drush/commands/core/rsync.core.inc` ? Ideally, it would get set in once place and be effective for all sites, and without impact to other functionality.

The reason I am looking to drop `-a` flag is to not preserve file ownership when the files are pushed out to clustered web servers -- we keep running to weird file permission issues, when files have different ownership on the Aegir server than the target web servers.

Thanks!

# Answer
> 1 votes
I put this in my drushrc.php file to change the default rsync mode to -rlptz for all sites:

```
$command_specific['rsync'] = array('mode' => 'rlptz');

```

You could also put it in each site alias if you did not want the change to be affected on a global basis:

```
$aliases['mysite'] = array(
  'root' => '/path/to/drupal',
  'uri' => 'mysite.org',
  'command-specific' => array(
    'rsync' => array(
      'mode' => 'rlptvz',
    ),
    'sql-sync' => array(
      'mode' => 'rlptvz',
    ),
  ),
);

```

---
Tags: drush, aegir
---


# Question
Title: Load and interact with a node comments from their related node
I am having some trouble in my quest to build a Drupal 7 custom node based image gallery module. I've got it working, but now I need AJAX to load and manipulate comments.

### What I am doing

I've created a Drupal 7 one-image-per-node image gallery; it uses relationships, EVA and even BBQ for deep linking, when viewing the 'gallery' node, EVA feeds in the thumbs and helpful attributes, e.g. URL to full image, url to actual node. I have jQuery in my gallery node, which AJAX preloads the full images on thumb click & manipulates them for fast dynamic full screen browsing, it works perfectly! Even the BBQ deep-linking which was difficult. Some of my gallery display js code is based on http://manos.malihu.gr/tuts/sideways\_jquery\_fullscreen\_image\_gallery.html.

### Update

I am trying all angles to bring in the comments. I've added one possible solution below but am going to try and figure out some other/better ways of doing this.

I am unsure about Services & Json or the views json output module and if that would be useful to me in this situation? Would json be better to call a nodes comments?

I suppose now my question remains what is the best way to do this? Even though this is working for me now I don't think I've found the best way yet.

Well thats where Im at, once I refine this I will pull everything into a module rather than a mix of module & theme layer bits, this will be my first module that defines content types, views and well all sorts of Drupal fun!

# Answer
> 1 votes
Ok so here is one way to do it, it's not very elegant and needs improvement.

I created a comment view that has a page display which gets NID from url so when ajax calling the content with ajax my/url/89 will return the comments for node 89. This works; even Ajax\_Comments are working!

Edit: Ive fixed it so it will cache the data for the user, so when traversing the gallery, it does not load the data ad-nauseum. It stores in .data and pulls it back in if the user has already viewed it.

Anyway, even though this works I feel it needs a lot of improvement and/or different approach. Below is *some* of the related updated latest code.

```
$(function(){

  // Override the default behavior of all `a` elements so that, when
  // clicked, their `href` value is pushed onto the history hash
  // instead of being navigated to directly.
  $("a.thumb_link").click(function(){
    var href = $(this).attr( "rel" );

    // Push this URL "state" onto the history hash.
    $.bbq.pushState({ image: href });

    // Prevent the default click behavior.
    return false;
  });

// Keep a mapping of url-to-container for caching purposes.
  var cache = {

   '': $('#gall-default') // If url is '' (no fragment), display this div's content.
  };

  // Bind a callback that executes when document.location.hash changes.
  $(window).bind( "hashchange", function(e) {
    // In jQuery 1.4, use e.getState( "url" );
    var url = $.bbq.getState( "image" ); //Get State from the above push "image"

    // In this example, whenever the event is triggered, iterate over
    // all `a` elements, setting the class to "current" if the
    // href matches (and removing it otherwise).
    $("a.thumb_link").each(function(){
      var href = $(this).attr( "rel" );

      if ( href === url ) { //Mark the active thumb and launch its content!

            $(this).addClass( "current" );
            $("#gall-default").css("display","none");
            //event.preventDefault();
            var $this=this;
            $bgimg.css("display","none");
            $preloader.fadeIn("fast"); //show preloader
            //style clicked thumbnail
            $outer_container_a.each(function() {
                $(this).children(".selected").css("display","none");
            });
            $(this).children(".selected").css("display","block");
            $outer_container.data("selectedThumb",$this); //get and store next image and selected thumb
            $bg.data("nextImage",$(this).next().attr("href"));
            $bg.data("newTitle",$(this).children("img").attr("title")); //get and store new image title attribute
            itemIndex=getIndex($this); //get clicked item index
            lastItemIndex=($outer_container_a.length)-1; //get last item index
            $bgimg.attr("src", "").attr("src", $this); //switch image

            //set context for node load bits
            var node = $(this).attr( "node" );

            $("#ajax-div .inner").empty();

             if ($(this).data('comm.cachedHtml')) {
                  $('#ajax-div .inner').html($(this).data('comm.cachedHtml'));

             } else {

                var toLoad = $(this).attr('node');// Get the URL of the clicked link.
               $.ajax({ // Now load the content
                    url: toLoad,
                    cache: true,
                    beforeSend: function () {
                    $("#preloader2").fadeIn("fast");
                },
                    success: function(data) {

                      $('#ajax-div .inner').html($('#content', data));// Inject new content
                      $("#preloader2").fadeOut("fast");
                      $(this).data('comm.cachedHtml', data);
                      Drupal.attachBehaviors('#ajax-div .inner');
                    }
                });

              }

      } else { //Un-Mark Thumb & other deselecting
         $(this).removeClass( "current" );

      }
    });

    //do something  here..
  });

  // Since the event is only triggered when the hash changes, we need
  // to trigger the event now, to handle the hash the page may have
  // loaded with.
  $(window).trigger( "hashchange" );
});

```

---
Tags: 7, ajax, javascript
---


# Question
Title: How to print a field content link in the views-view-field template in Drupal 7?
I am trying to figure out if it is possible to print the content link of a field in the Views' template.

I would like to link an article title to its node, something like the following code:

```
print '<a href="' . $node_url . '">' . $article['und']['0']['value'] . '</a>'

```

This is a dumbed down version of my code in the view-view-field--field-article-title.tpl.php

```
$article = $row->_field_data['nid']['entity']->field_article_title;
$subtitle = $row->_field_data['nid']['entity']->field_article_subtitle;

if (isset($subtitle['und']['0']['value'])) {
  print $article['und']['0']['value'] . ': ' . $subtitle['und']['0']['value'] . '</p>';
}
else {
  print $article['und']['0']['value'];
}

```

Can anyone point me in the right direction? I've tried printing out the available fields, but for some reason I cannot print the fields in the view.

# Answer
I'm not an expert and this may not be the absolute best way, but it works for me in D7 view-view-field templates.

Include something like this in your template file

```
<a href="<?php print base_path().drupal_get_path_alias("node/{$row->nid}") ?>">...</a>

```
> 6 votes

---
Tags: views, entities, theming
---


# Question
Title: menus from modules: help me understand basic menu concept in drupal7
Here's some paths I'm using in my module

* control (this isn't really a page, it just goes to the next item)
* control/jobs (provides list of jobs)
* control/jobs/% (path for editing a particular job)
* control/download (separate page)
* control/settings (separate page)

I would like a simple menu that shows jobs, download and settings. I would like it to add the 'active' class when visiting the page. And when visiting a particular subpage (e.g. a particular job), I would like the parent menu items to have an "active-trail" class or such.

Using `hook_menu` I've created these menu items, all as `MENU_NORMAL_ITEM`s and I've put them in a new menu called menu-control. I've added this menu's block to my page. I get the menu items listed. But when I visit a particular job, there is nothing to indicate I'm on a child page of 'jobs' (or indeed, 'control').

This seems like the simplest implementation of a menu and I've been hacking at it for weeks (on and off!). Can anyone help?

# Answer
**It was(is) a bug!**

The patch at entry #262 on that page applies and works for me on Drupal 7.10.

Thanks for contributions/answers.
> 0 votes

# Answer
1. Take a look at the Views Module. You can define your page view and attach it any menu.
2. Define it with a path such as control/%/jobs and set it to provide a list of all jobs using filters and format settings Set the menu type as menu tabs, and give it a name.
3. Add additional pages to the same view and with paths such as control/%/job and use a contextual filter to read the value in the URL in the % wildcard position. (You may have a bit of trouble if the wildcard is multiple words due to spaces vs. dashes in the path. If so ask another question here). Set the menu tab for this item as well.

Menu tabs are the menu that appears above the content (user Admin has View and edit tabs for content pages). Note that you must have two menu tabs for them to show.

Your pages for download and settings sound like they require user input. Those pages will require either an add-on module or custom coding to design a form.
> 1 votes

# Answer
I guess you are trying to get the breadcrumb navigation working properly. Maybe the Menu Breadcrumb module can help? Here is an excerpt about it from the module's project page:

> By default, Drupal 6+ use the Navigation menu for the breadcrumb. This module allows you to use the menu the current page belongs to for the breadcrumb.
>
> As an added bonus, it also allows you to :
>
> * Append the page title to the breadcrumb (either as a clickable url or not).
> * Hide the breadcrumb if it only contains the link to the front page.
> * Generate the breadcrumb from the URL structure if content does not belong to a menu (7.x-1.6 and older only).
> 0 votes

---
Tags: 7, routes
---


# Question
Title: What tables should or could be migrated to InnoDB, and which should remain MyISAM?
As per title: Is there a quick list of candidates for tables to migrate to InnoDB? And what should remain MyISAM.

**Some additional information**

* The site has a fairly heavy read-load, but inserts approximately 10 nodes per hour, with tags and such.
* We make heavy use of CCK (a huge amount of normalised tables in the form of `content_field%`).
* We also use Views for about all our blocks and pages; but many of those are candidate for replacement with custom modules (as to reduce database-queries and the heaviness of those queries).
* Users are all anonymous; with the exception of a few logged in editors and webmasters.

# Answer
You should convert all data to InnoDB to prevent table locking issues. However, here are somethings to think about:

## **FULLTEXT Indexing**

At present, only MyISAM supports FULLTEXT indexing. FULLTEXT indexing for InnoDB is currently in the works for MySQL 5.6 but is not production-ready. If you have any Drupal tables that have FULLTEXT indexes, they cannot be converted to InnoDB at this time.

## **UPDATE on FULLTEXT Indexing**

MySQL 5.6 is now GA (out for Production Use). Please try out FULLTEXT indexing in InnoDB.

To locate those tables that have a `FULLTEXT` index, run this query:

```
SELECT table_schema,table_name
FROM information_schema.statistics
WHERE index_type='FULLTEXT';

```

If no rows come back, convert all InnoDB tables to your heart's content. I wrote an earlier post on how to convert all MyISAM tables to InnoDB using only mysql.

## **MySQL Replication**

If you have a read-heavy environment, reads can go faster in MyISAM if you do the following:

* Setup Master/Slave Replication
* Create one or more Read Slaves under the Master
* Add `--skip-innodb` in /etc/my.cnf on all Slaves (converts tables to MyISAM when loading data into the Slave)
* Change the row format of all MyISAM tables on every Slave to FIXED by this command: `ALTER TABLE tblname ROW_FORMAT=FIXED;`
* I posted something on this in the DBA StackExchange
* The book **MySQL Database Design and Tuning** recommends using `ROW_FORMAT=FIXED` on pages 72,73. This will internally convert all VARCHAR fields to CHAR. It will make the MyISAM table larger, but executed SELECTs against it will be much faster. I can personally attest to this. I once had a table that was 1.9GB. I changed the format with `ALTER TABLE tblname ROW_FORMAT=FIXED`. The table ended up 3.7GB. The speed of the SELECTs against it was 20-25% faster without improving or changing anything else.

The only headache with this is making your application aware of separate read slaves.

## **EPILOGUE**

If you are looking at other benefits each storage engine has, check the DBA StackExchange:
> 8 votes

# Answer
Since your website is on the read-heavy side, I'd simply convert all tables to InnoDB. You'll then be able to optimize read performance by sizing the InnoDB buffer pool and the query cache appropriately. This way, we're achieving several thousand queries per second on the dedicated database servers in our Drupal hosting infrastructure.
> 4 votes

---
Tags: performance, database
---


# Question
Title: Is "access administration pages" a valid access argument?
In Drupal 7, it appears that *access administration pages* is a VALID access argument. Is this the case?
How can I determine all the correct access arguments?

# Answer
That permission is defined from system\_permission().

The access arguments that an access callback uses can be any value, as any access callback can define its own access arguments in the implementation of `hook_menu()`.
If you are referring to the access arguments accepted from `user_access()`, which is normally the access callback used from most of the menus defined from Drupal modules, then the access arguments are just the string for the permission the user needs to have to access that menu. The "access administration pages" string is just a possible value, and third-party modules can extend the permissions adding new ones to the ones already defined from Drupal core modules.

To get all the permissions defined from the installed modules, and assigned to one of the roles used in your site, you can use the following snippet (it requires the Devel module):

```
$cache = array();
$result = db_query("SELECT rid, permission FROM {role_permission}");

foreach ($result as $row) {
  $cache[] = $row->permission;
}

dsm(array_unique($cache));

```

To get any permission defined from the modules enabled in your site, you can use the following snippet:

```
$permissions = module_invoke_all('permission');
dsm($permissions);

```

The difference between the snippets is that the first one can return also the permissions defined from a module that you disabled, as long as the permission has been assigned to a role; the second only returns the permissions defined from currently enabled modules. If you have temporary disabled a module, the second snippet will not return its permissions.
> 5 votes

---
Tags: 7, users
---


# Question
Title: How do I maintain persistent information over a multi-step input process?
I don't have a multi-step form. I have many forms that are presented over many steps depending on decisions made in previous forms and user role. How do I best store persistent information across all forms? Should I use some type of ctools cache, store the information in a cookie or should I attach the information as a query string to each URL request? I am currently using Rules and Rules link for this. Also, I intend to use hook\_form\_alter() to manage the information through the steps but I not sure how to securely maintain persistent information.

# Answer
Easiest is just save to $\_SESSION which effectively stores it using the cookie for you. Are these anonymous users? Care may need to be taken if cookies are disabled in that case.
> 1 votes

---
Tags: 7, forms
---


title: clearfix to views-row

text:
# Question
Title: clearfix to views-row
What is the recommended way to add a "clearfix" class to a `div.views-row`?

Note that I dont want to add the clearfix to all views, just a specific view.

Is this best done with a template override, or is there a mystical alter hook that will let me add in what I need in my `template.php` without having to override and thus maintain an entire views template file, just to add a class.

# Answer
> 4 votes
Is this views 3? If so if you go to the Settings for the format you can add a Row class (the description says "The class to provide on each row") which should do what you want without templates etc.

---
Tags: views, theming
---


# Question
Title: Is it considered bad drupal style to have a large number of 'static' pages scattered around the website?
I'm developing a website in Drupal 7 which has a large number of pages that are either A) static, or B) dynamic in some sense, but not abstractable into a node.

My first instinct would be to just add implementing menu items in a `hook_menu()` function, then add `hook_theme()`, theme files, etc. etc. The thing is, across my website, I'll have probably 15 or more of these pages - that's a lot of URL's that are hard-coded into this site, in a way that isn't necessarily obvious to content managers who will be maintaining it.

The thing is, all of these hard-coded pages are going to be in the context of a landing-page. I am toying with the idea of creating a landing page content type, where they can edit the basic pieces (pretty much just the title and a single sentence) and assign it to a menu item, but then allowing them to select from a variety of pre-hard-coded solutions for each of the possible necessary pages. This is also a very sloppy solution, but it will give the content manager a tiny bit of control.

The pages in question are all too different, with too specific of requirements to make use of any module such as Views - they all need to be one-off, server-side code.

Any thoughts?

# Answer
Have you looked at panels for assembling smaller pieces of content into a larger piece? Or even panel nodes which is a bit more lightweight than panels but allows layout and inclusion of other page elements in a regular node.
> 2 votes

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