title: Does Drupal ignore <b> (bold) tags?

text:
# Question
Title: Does Drupal ignore <b> (bold) tags?
I have custom content type with body made of full html. I am using the bold tag to emphasize a word, but it is not displayed as bold. It thought it might be the Google font I used, so I disabled it, but I still get the issue.

I checked the page source:

```
    <div id="begin_block">
      <div id="fw_begin"><h2>Find words <b>beginning</b> with:</h2></div>
        <div id="inp_begin"><input type="text" /></div>
        <div id="aft_begin">(max. 5 characters)</div>
        <div id="but_begin"><button type="button">Go</button></div>
    </div>

```

But I still get:

What could be causing this issue? Is it Drupal related?

# Answer
As a matter of fact, the answer to the question is no. This is was caused by the `reset.css` delivered in the Versatile theme.
> 0 votes

---
Tags: 7, nodes
---


# Question
Title: How can I update this db_query statement to db_insert for D7?
I'm trying to update someone's module to D7, but I'm unsure of how to convert the usage of places and values in the query to use 7's api properly.

```
$fields = implode(',', array_keys($args));
$places = implode(',', array_fill(0, count($args), "'%s'"));
$values = array_values($args);

$insert_result = db_query(
  'INSERT INTO {bluga_request}(' . $fields . ') VALUES (' . $places . ')', $values
);

```

# Answer
The standard way is to use the `db_insert()` function with an associative array of field names/values:

```
$fields = array(
  'id' => $id,
  'name' => $name
);

db_insert('bluga_request')->fields($fields)->execute();

```

It actually looks like in your case the fields are already set up as an associative array in `$args` so you would just do this:

```
db_insert('bluga_request')->fields($args)->execute();

```
> 5 votes

---
Tags: 7, database
---


# Question
Title: Staging process -- how NOT to overwrite user content/data @ DB push to Production site?
I've finally gotten my Drupal7 Development-\>Staging-\>Production file & db syncing all working nicely using a mix of rsync, rsyncd, git &, where it doesn't cause more/unnecessary work for me, drush.

Not the cleanest approach, but all working quite nicely.

Until i realized ...

a DB push from Staging-\>Production that contains changes I've made & QA'd @ my Staging site (for modules, site config, etc), will overwrite any/all user data/content @ the Production site. Unless, of course, I specifically identify & exclude the tables that contain data/content -- and simply don't inclue them in the push.

My question is -- other than manually checking -- is there a reliable method (a pre-existing static list? a sql query on table names? something?) to know those tables to exlude?

This

How to migrate from test environment to production environment? How to migrate from test environment to production environment?

in addition to countless other threads I *have* found, mentions "Features" and "Deploy", and basically says "it's hard". If the answer's "in there", I haven't wrapped my head around it yet.

Again, I've got the mechanics working as I want them. This last step is identifying -- and voiding overwrite of! -- the user content/data at the Production site.

# Answer
This is a big architectural issue and as answers to the other question says: UUIDs in core in D8 will be a big improvement. They'll give all content a unique ID (independent of the content id in the database), and so if you make important modifications to content in some staging phase, the software could reconcile which content is worth transferring.

There's a UUID project for Drupal 7, which I believe Deploy module can use in this way.

> The integration with Services module alters all UUID enabled entity resources (nodes, users, taxonomies etc) to be based on UUIDs instead. This way it becomes easier to share and integrate content between sites. This functionality is used by Deploy module.
> 1 votes

---
Tags: database, staging
---


title: Alter the menu_edit_item form

text:
# Question
Title: Alter the menu_edit_item form
I'm trying the alter the menu\_edit\_item (Edit menu link in a menu element) with a module. So far I tried

```
   function module_name_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
    $form['additional_desc'] = array(
        '#type' => 'textfield',
        '#title' => t('Additional Description'),
        '#maxlength' => 180,
        '#required' => TRUE,
        '#description' => 'Name of the Additional Description'
      );
   }

```

But it doesn't work. I'm new to Drupal. Thanks!

# Answer
> 1 votes
That code should work in both in Drupal 6, and Drupal 7.

If you edit an already enabled module, you should clear the Drupal cache, as the list of hooks implemented by modules is cached by Drupal; that means that changing the code of an enabled module doesn't cause Drupal to notice the new added hook.

As alternative, you can go to the page listing all the enabled modules (admin/modules), disable your module, click on the "Save configuration" button you find at the bottom of the page, re-enable your module, and click again on the the "Save configuration" button. This will force Drupal to clear the cache where it saves the list of hooks implemented by the enabled modules.

---
Tags: forms
---


# Question
Title: Suggestion for "Convert line breaks into HTML" and text editor for corporate website
Previously when developing my own community website in Drupal 6, I've never know what people like when dealing with text editor. So I simply go with Ckeditor and untick `Convert line breaks into HTML` in the Text format options.

But now developing corporate website in Drupal 7. Ckeditor is in early stage (lack of visibility option) and I cannot use wysiwyg module because it has many conflict.

One good choice is use Bueditor. It looks clean and perfect but i must tick `Convert line breaks into HTML` in the Text format options to make it works for paragraphs.

So, should I:

* use wysiwyg editor and untick `Convert line breaks into HTML` ?
* or use Bueditor and tick `Convert line breaks into HTML` ?

# Answer
You can use Wysiwyg (or CKEditor) along with most editors and use Wysiwyg Linebreaks to make the editor work great with existing content, or when switching between editors, and in other circumstances.

Also, Wysiwyg should be pretty stable (I've been using it on a ton of different sites), especially when using it with CKEditor, TinyMCE, or most other editors.

For most of my sites, I have the `Convert line breaks into HTML` option checked no matter what, mostly because I like being able to see/edit content without extraneous paragraph and line break tags all over the place, and so paragraphs don't get run together.
> 1 votes

---
Tags: 7, input-formats
---


title: Filter by color with exposed filters

text:
# Question
Title: Filter by color with exposed filters
I have taxonomy list of color names(red, black, etc). If I create an exposed filter form, how can I show the color with corresponding coloring? I want to style each select option with background color, i.e for the option Red, the background should be red. Can we style that in the stylesheet?

I use view3 and views\_hacks thanks.

# Answer
What you're asking is not necessarily Drupal related (although there is the Color module which also shows a color value in a select list, you could look into using the Color module to use its select widget or colorpicker instead of a taxonomy listing of colors by English name).

Anyways, if you want to stick with using a taxonomy select with like "blue" being the 3rd option in the select list -- you could reference this StackOverflow example using Jquery to style select items. You could make a call to `drupal_add_js()` in a theme function whenever your view and its filters are shown on the page to add the necessary jquery.

I would recommend looking into the Color module in the long run.
> 1 votes

---
Tags: views
---


# Question
Title: How to theme the page template for search results
I want to change the page template when displaying search results. This seems straigh forward when dealing with a content type, but what is the content type for "search results".

E.g. I'll like to use something like page--search\_results.tpl.php but I'm not sure of the correct name.

Note, I'm happy with the formatted output of the result items, so I assume I wouldn't be changing the templates under drupal/modules/search...

Thanks

# Answer
> 5 votes
You can use a template, eg, `page--search.tpl.php` which would match the path to search and anything under it, eg, `search/node/term`, or you could create one called `page--search-node.tpl.php` which wouldn't match just the search page itself, but only search results from nodes, or you could use a template suggestion inside a preprocess\_page() hook, eg, something like

```
mymoduleortheme_preprocess_page(&vars) {

  if (arg(0)=='search' && arg(1) && arg(2)) { // we are somewhere down in search/node/term or similar
    $vars['theme_hook_suggestions'][] = 'page_my_template_for_search_results';
  }
}

```

and then create a template file `page-my-template-for-search-results.tpl.php`.

In any case, http://drupal.org/node/1089656 has some great documentation on template suggestions in D7.

---
Tags: search, 7
---


title: User Fields pending Admin Approval?

text:
# Question
Title: User Fields pending Admin Approval?
I'm putting together a public facing site with not always mature users, and I'm wondering if there is an off the shelf module for **requiring admin approval to user field submissions/changes**?

I.e. so that one of our staff get a notification when a user updates some selected settings (My Biography, that kind of thing) and it sits, pending review, before it goes public?

I'm trying to avoid the inevitable genital-graffiti that I know this lot are very capable of...

# Answer
> 1 votes
I set up a workflow for doing this using field permissions, rules, and revisioning. It works at the node level rather than the field level though, and it's rather complicated to set up. In my searching there was no single module able to handle this.

Basically, I used rules to create a workflow in which users can only create and edit certain content types, all of which are subject to approval either upon creation or edit (using revisioning).

---
Tags: entities, users
---


# Question
Title: Migrating to the webserver - what do I have to take care for?
What do I have to keep in mind? What do I have to take care for - especially if I have troubles with

* file ownership
* permissions

If I set up a drupal-commons version 6.25 locally on my machine at home - which is a openSuse 12.1 - everything runs nice. All goes smoothly. especially if I want to upload files - no problem here.

But if I want to do the same - uploading pictures - on the version that I either installed directly on the webserver or ported over to the webserver I have terrible issues. It is not possible to upload any file - I have troubles and get error messages....

regarding the temp-directory (which is complained to be missing)
regarding the permissions on site/default/files

Well some words regarding the server and the circumstances and conditions it runs with: my serveradmin works with the setgit bit

I run a linux sever that is administered by a friend of me. He prepares the chown and permissions - with the setgit-bit to on. See the issues with the server described more detailed here

**on a sitenote:** Well the trouble is that i get lost the setgitbit every time when I touch the permissions with FileZilla. That is the terrible issue! Note - at the moment I do not have a access to the server wit WinSCP - WinSCP can set the Setgit. FileZilla cannot do this at all!

The question is: what do I have to take care for if porting over Drupal. Both versions:

.a a Drupal commons version 6.25 and .b a Drupal version 7.12

Do I have to set up a tmp directory again? Note: if I create the whole installation here on my local server then my assumption is, that all things have been done properly.

What experience do you have - what do I have to take care for?

I love to see a fruitful discussion.

# Answer
> 2 votes
I strongly recommend you look into using drush to synchronise sites. Although it admittedly will not solve your permission woes, it will greatly ease the pain of doing this for every update you need to push.

As for permissions, there are many ways of configuring depending on your set-up and how safe you want to be. I usually just have all files belong to webserver and add my user to webservers group, but like I said many things can go wrong with permissions.

Coming back to `drush rsync`, I would most probably attack this by setting up 2 aliases, one for `@dev` and the other one for `@live` (or @stage). So, with those aliases you can rsync via the simple command `drush rsync @dev @live` your whole site will be transferred. Just set proper permissions the first time you do this on /files and other folders needing write access, and you should be set to go.

PS: Do look into `drush sql-copy` and other goodies hidden in drush. I cannot imagine doing this manually anymore, I have used aliases for a few years now and would NOT go back the old way!

Hope that helps, good-luck!

---
Tags: 7, migrations
---


# Question
Title: Views: Ranking users by pageviews this month, last month
I have created a view to rank Users by the total numbers of pageviews their nodes have received. I now want to clone that view and create 2 blocks:

1. Totals views their nodes have received this month
2. Total view their nodes received last month.

I have tried using contextual filters and I can create a view to show total pageviews in a date range, but, that would mean me updating the filter every month. Is there another way I can do this? I don't want to limit the results to "last 30 days". Rather, January, December etc

Thanks!

# Answer
Take a look at the "archive" example view, which is provided by default (though disabled) as part of the views module. It can be found under "Archive" on the admin/structure/views page.

This view groups the content created on the site by year and month; the contextual filter, filter criteria, and sort criteria are already configured and working correctly. Study this example view and hopefully it will help you create what you want to do.
> 2 votes

---
Tags: 7, views
---


# Question
Title: Is there a way to disable username for logging in?
I'm using realname with this small moduel to generate username from some profile field.

Now users can login with both username and email by using LoginToboggan.

Only the problem is that I don't want to let users login with their username. It looks like LoingToboggan has the function to let users login with email but not disable username login.

Is their anyway I can just disable username login?

# Answer
> 3 votes
I don't know of an existing module that does this, but it would only take a few lines of code in a custom module to get the effect you're looking for:

```
function MYMODULE_form_user_login_alter(&$form, &$form_state) {
  // Add an extra validation step to the form.
  // The user is actually authenticated during the validation stage
  // so we have to make sure this validate function runs before any others
  array_unshift($form['#validate'], 'MYMODULE_user_login_validate');
}

function MYMODULE_user_login_validate($form, &$form_state) {
  // Make sure the provided username field is in the form of an email address.
  // If not we can safely say the user shouldn't be allowed to log in,
  // regardless of whether or not a user exists with that username.
  if (!valid_email_address($form_state['values']['name'])) {
    form_set_error('name', 'The email address you have entered was not found in the system.');

    // Empty the name variable so further validation definitely fails.
    // There are probably better ways to do this so be creative :)
    $form_state['values']['name'] = '';
  }
}

```

---
Tags: 6, users
---


# Question
Title: Theming views and overwriting the default file upload display
Theming views in Drupal 7 can be very tedious to newbies. In the following example, a seemingly simple task has become an overwhelming research project into the innards of Drupal! Hoping an experienced drupalite can make quick sense of this.

In our example view we are outputing a product list to a page. One of the fields is a file type where the user uploads a PDF file. To gain maximum control of the layout, we were trying to utilize '**Rewrite the output of this field**, and want to create a link to the PDF file with text inside of it that says Download PDF. Sounds simple!! However, so far it has not been.

Because this view is a list of a certain content type, node theming doesn't appear as one of the potential options for template theming. See bottom of the post for potential theming file name conventions that Drupal is offering up.

Also, this may be something easy to do with a hook in the theme's template file, but as of now, that is a little confusing as well and I'm not sure where to look for that solution.

So, for this post, we're hoping to get a clearer picture into the stock views management system. However, all suggestions are welcome!

---

Here is the code that resides in the rewrite section of the view for the Content-PDF field:

**Here are the relevant Replacement Patterns:**
\[field\_pdf\_upload\] == Content: PDF
\[field\_pdf\_upload-fid\] == Raw fid
\[field\_pdf\_upload-display\] == Raw display
\[field\_pdf\_upload-description\] == Raw description

The problem, \[field\_pdf\_upload\] - gives you a PDF icon, a link to the PDF and it names the title of the file. If I could figure out how to replace the file name inside the href tag with "Download PDF", then this would be essentially solved. I've tried many options in the replacement patterns and what not, but nothing has worked yet. I tried stripping HTML and then adding the direct path to the file and that worked, but if the upload has spaces in it, the path breaks.

If I had access to php in this section, I could do something like this

```
$fid = [field_pdf_upload];
$file = file_load($fid);
```

Maybe there is a way to do this and I'm just not getting it? I am going to start a separate jquery option thread for this in a second, bare w me and it will be written soon.

---

**An alternate method would be to alter one of the theme suggestion templates listed under Advanced-\>Information - Below is the list of options.**

Display output: views-view.tpl.php, views-view--product-landing.tpl.php, views-view--page.tpl.php, views-view--product-landing--page.tpl.php, views-view--default.tpl.php, views-view--default.tpl.php, views-view--page-1.tpl.php, views-view--product-landing--page-1.tpl.php

Style output: views-view-unformatted.tpl.php, views-view-unformatted--product-landing.tpl.php, views-view-unformatted--page.tpl.php, views-view-unformatted--product-landing--page.tpl.php, views-view-unformatted--default.tpl.php, views-view-unformatted--default.tpl.php, views-view-unformatted--page-1.tpl.php, views-view-unformatted--product-landing--page-1.tpl.php

Row style output: views-view-fields.tpl.php, views-view-fields--product-landing.tpl.php, views-view-fields--page.tpl.php, views-view-fields--product-landing--page.tpl.php, views-view-fields--default.tpl.php, views-view-fields--default.tpl.php, views-view-fields--page-1.tpl.php, views-view-fields--product-landing--page-1.tpl.php

Field Content: PDF (ID: field\_pdf\_upload): views-view-field.tpl.php, views-view-field--field-pdf-upload.tpl.php, views-view-field--product-landing.tpl.php, views-view-field--product-landing--field-pdf-upload.tpl.php, views-view-field--page.tpl.php, views-view-field--page--field-pdf-upload.tpl.php, views-view-field--product-landing--page.tpl.php, views-view-field--product-landing--page--field-pdf-upload.tpl.php, views-view-field--page-1.tpl.php, views-view-field--page-1--field-pdf-upload.tpl.php, views-view-field--product-landing--page-1.tpl.php, views-view-field--product-landing--page-1--field-pdf-upload.tpl.php

Can anyone recommend a method and sample code for accomplishing this task?

# Answer
You don't need to use a template or get your hands dirty with code.

Just add the field to the view twice. Hide the first field from display, but change the formatter to "URL to file". Rewrite the output of the second field to "Download PDF". On the second field, select output field as link and assuming your field is named 'pdf', make the path \[field\_pdf\].
> 1 votes

---
Tags: 7, views, theming, entities, files
---


# Question
Title: How do I get the userpoint description to include clickable node link?
I would like to get a clickable link of the current node stored in the description parameter of the **userpoints\_userpointsapi**

Am using the code below at the moment. Its working fine but the link shown under the user profile is not clickable.

How can I make this link clickable whenever its displayed in anywhere else on the site for example under the user profile list of points by that user:

```
$params = array (
    'points' => round($percentage/10),
    'tid' =>16,
    'description' => '<a href="/node/'. $nid .'">'. $node->title .'</a>'
    );
userpoints_userpointsapi($params);

```

# Answer
You can reference the node using the entity\_type =\> 'node' and entity\_id =\> $node-\>nid arguments, then the description will automatically be linked to the node.
> 1 votes

# Answer
**UPDATE**

Unfortunately this is not possible. Userpoints calls strip\_tags which removes the html on line 1808 of userpoints.module. You may want to patch the module to allow your html code to exist, but it could introduce a potential security vulnerability.

---

Try this snippet:

```
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
if (isset($nodeid)) {
  $node = node_load($nodeid);
  $description = "Awarded points for doing something on " . l($node->title, '/node/' . $nodeid);
} else {
  $description = "Something awful";
}

//Add results to user point database
$params = array (
  'points' => round($percentage/10),
  'tid' =>16,
  'description' => $description,
);
userpoints_userpointsapi($params);
// end add user point

```
> 0 votes

---
Tags: userpoints
---


title: Database Pager for a new entity type

text:
# Question
Title: Database Pager for a new entity type
I have implemented a new entity type that requires paged access to DB and meet a probem with several pagers for independent entities on the same theme page.

The problem is that that entity can be used along with the node, thus two (or more) pagers may co-exist on the same page. The `element` property of `PagerDefault` apparently does not work (see discussion). In addition, `PagerDefault` simply uses `$_GET['page'])` to find required page number, which leads to even bigger confusion - both absolutely independed DB queries share same HTTP page query parameter.

What do you believe is good solution of this problem?

Further investigations have revealed a bug with `EntityFieldQuery::pager()`

# Answer
I'm not sure I understand your problem ... Are we talking about like a node/edit page or a View? Or is this a menu page callback where you want node(s) and this entity both with paged output on a single html page ... ?

If you have written custom PHP/SQL/EFQ in a menu page callback, I see no reason you cannot explicitly set $element uniquely as needed in your queries.

Where is your http page query parameter coming from? A view? A url() you created by hand? If you have 2 pagers, you should have 2 $GET parameters ...

Edit: this is what I mean blog example
> 1 votes

---
Tags: database, entities, paging
---


# Question
Title: Can I use Node Reference Field as a Text Field if there are no references?
I'm creating a content type Event. I want to reference the node of another content type Venue, so the user will be able to click to the venue node from the event.

To reference the venue on the Event creation page, ideally it would be a text field with autocomplete showing a list of possible venue nodes.

Now if the venue node hasn't been created yet, can Drupal allow the Event to be created using the entered text as display (i.e plain text)?

# Answer
> 1 votes
Use the Node Reference Create module.

> Node Reference Create is an enhancement to the nodereference autocomplete widget that allows users to reference non-existent nodes.
>
> When no matching node is selected, the new nodes are automatically created allowing for a seamless and intuitive user experience that is similar to free tagging.

# Answer
> 0 votes
It is absolutly possible

---
Tags: nodes, entities, ajax, 7
---


title: Add markup to form during validation

text:
# Question
Title: Add markup to form during validation
I have a custom validator on a webform. When a person enters an address, I validate it. When the address is not right, I set an error in the validation function. This is all going well. But now I want to give the visitor suggestions when he enter a wrong address. This should be done by giving the suggestion in a markup underneath the address input.

I allready set up an empty markup field in the webform, now I just want to put information in it during validation. How is this possible. If you need any dpm or printout let me know please.

Thanks in advance.

# Answer
In your validate you can set a variable in the `$form_state` that tells if the validation failed or not:

```
function webform_validate_handler(&$form, &$form_state) {
  if ($mail_invalid) {
    $form_state['mail_invalid'] = TRUE;
  }
  else {
    $form_state['mail_invalid'] = FALSE;
  }
}

```

Then in your form, you can check for `empty($form_state['mail_invalid'])` and show the markup when the empty check returns false.

```
function hook_form_alter(&$form, &$form_state, $form_id) {
  ...
  if (!empty($form_state['mail_invalid']) {
    $form['markup'] = ...;
  }
}

```
> 2 votes

---
Tags: 7, webforms, forms
---


# Question
Title: Performance (or other) benefit to adding CSS and JS files in a .info file rather than tpl?
Ive always the Zen theme and added additional CSS and JS files in the page's tpl file, rather than using the .info file. Is their any performance or other downside to my method?

Thanks

# Answer
> 3 votes
Yes, the JavaScript cannot be aggregated meaning that instead of asking for a single (few) css/js files, the browser will have to ask for more files which is slower and required more work of your web server.

Depeding on how many JS and CSS files you add in your `page.tpl.php` you can get a noticeable performance improvement using the `.info` file method. It's also a lot better should you need to use your theme as a base theme, since it allows for better alters of the JS/CSS files.

---
Tags: javascript, theming, performance
---


title: Custom URL for entity create and view

text:
# Question
Title: Custom URL for entity create and view
I am using ECK (Entity Construction Kit) to create my custom entities. Now I want to create custom url for various operation on my entities such as create (example.com/my-entity/create) or view (example.com/my-entity/view/custom-unique-field)

I have tried pathauto but it seems I cant define custom patterns for my own entities. Any help towards this step is highly appreciated.

Thanks, Naveen

# Answer
> 4 votes
You can use the path (url alias) module for the create path. Since that's a single url, you can create a single path alias to change that.

It's a bit harder for your custom entities. You would have to create a custom module and integrate with path auto module to be able to create path aliases for the view urls of your custom entities. It's a lot of code, you can see how the path auto module does it for the node module. But be warned, it's not easy as there are many parts.

The gist of it is that you need to make some tokens available for the path system you are going to make, like the entity label and such. Then you need to create a function that can create an alias when given an entity. This is, however, a bit harder since you need to use the path auto API functions for this.

---
Tags: entities, path-aliases
---


# Question
Title: I need to have my site visitors post comments even if they are not logged in as a member
I need to have my site visitors post comments even if they are not logged in as a member in my drupal 7 site. How do I do that? or is it better to have them sign up so they can post comments?

# Answer
> 4 votes
You need to give the "anonymous user" role permissions to post comments. Go to `admin/people/permissions` and look for the Comment section. Check the box for "Post comments" for the Anonymous user role, then save the settings.

I would not suggest this unless you have good anti-spam measures in place. You can search drupal.org for modules in the Spam Prevention category to help with that. Otherwise, I would require users to sign in before posting comments.

Note that even when requiring users to sign in to post comments, you'll still likely run into spam. Couldn't hurt to look into the list of modules linked to above.

# Answer
> 0 votes
One possibility is to use the Disqus remotely hosted comments system. Users do need to log in to that - but not to your site. They can use a number of other sites they already have accounts in like Facebook or Google.

---
Tags: 7, comments
---


# Question
Title: How to list Taxonomy Terms with Pictures in View?
I want to create a View with the list of Taxonomy Terms in Drupal 7. I edit the taxonomy content type so that it has 1 extra image field.

I want to show all Taxonomy terms with their image but I cant seem to find it anywhere in View options.

# Answer
When you create the view, you need to create a view of taxonomy terms instead of of content/nodes like you have done in your SS above. Then you have all the fields etc available that you have on your terms.
> 2 votes

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


# Question
Title: is there a module for status updates in drupal 7
I am looking for a module that will allow users on my site to post status updates similar to Facebook and twitter. Or is there a way to configure the heartbeat module to allow users to post status updates? i am using the zen sub-theme in drupal 7.

# Answer
> 3 votes
Somthing along the lines of statuses? It doesn't have a stable release yet, so is DEFINITELY not ready for production. I've not used Heartbeat, so I can't help any more than that I'm afraid :(

# Answer
> 1 votes
The 7.x Statuses module looks like it may work ok in certain circumstances. It doesn't yet work with Drupal 7 Rules or Drupal 7 Flag modules.

I would recommend trying it out and seeing what it can and can't do for you.

It doesn't, for instance interact with UserRelations so that you can start to "follow" or "friend" people.

---
Tags: users
---


# Question
Title: Can't see User fields as options for a context filter
I was following this video to add a contextual filter so the page I'm creating would display content created by the logged-in user only.

However, when I scroll down the list of contextual filters, I don't see the `User:` options. How can I see them? Am I missing some module or option? My Drupal 7 setup is almost all by default.

# Answer
> 1 votes
The tutorial you're watching is out of date (I watched it too); it was created when Views was in beta/RC and things have changed a bit since then.

You just need to add the user as a Relationship under the "Advanced" options...then you'll get the user filters as you'd expect.

---
Tags: 7, views
---


# Question
Title: Apache filehandle issue expected to be mission critical for image uploading
I have a fresh install of Drupal Commons (version 6.25), and I am not allowed to upload an image. See the full description of this so called **image upload issue** here on this site.

new **Update** one a sitenote...

i want to mention that i - for the purpose of some tests have put two **sites onto the server**

http://schulcenter.net (for sure Version Drupal-Commons 6.25) http://schulcenter.org \- (probably Version Drupal-Commons 6.23)

and they run on the same database ;-)

guess that that can cause the open File handles what do you think !? Love to hear from you

well i guess that i have to switch off one site. ;-) greetings (end of update)

here the **original-initial-thread starts:**

I have changed some settings regarding the file handling; I set the permissions for sites/default/files, I created a temporary directory and edited the paths accordingly. All of these seem to work, and workarounds did not change the bad habit of the site: The image upload is impossible.

Can we verify the impact of a decreased amount of Apache File handlers on the possibilities and capabilities of file, and image-handles, especially of the option to upload images? Is there any impact?

dman, a very experienced web and Drupal developer, had a closer look at the site and noticed the site status under the 'Reports' tab lists many errors, including the following one:

> opendir(\*) \[function.opendir\]: failed to open dir: Too many open files in /home/vhost/WWW/schulcenter.net/includes/file.inc on line 963.

It seems like it could make *anything* on the site break, especially things that work with files, but also anything that reads files.
I have more than 1200 repots of such message about `opendir("profiles/drupal_commons/modules/acquia/acquia_search/apachesolr/drush")`.

I do not have installed any drush. Besides this thing, I have no clue why we get such a big amount of open file handles the server is faced with.

> The dblog module monitors your website, capturing system events in a log to be reviewed by an authorized individual at a later time. The dblog log is simply a list of recorded events containing usage data, performance data, errors, warnings and operational information. It is vital to check the dblog report on a regular basis as it is often the only way to tell what is going on.
>
> Details Type php Date Sunday, 18 March, 2012 - 21:48 User martin Location http://schulcenter.net/?q=admin/reports/dblog Referrer
> Message opendir(profiles/drupal\_commons/modules/acquia/acquia\_search/apachesolr/drush) \[function.opendir\]: failed to open dir: Too many open files in /home/vhost/WWW/schulcenter.net/includes/file.inc on line 963. Severity error Hostname 188.99.184.201 Operations

# Answer
Did you find this comment on drupal.org?

> The problem is a maximum open files limit per users.
> We had several web servers, and several new Apache2 VirtualHost; Apache2 (www-data) reached the maximum number of open files (1024).
>
> You can check that with `ulimit -a` or `ulimit -n`. (The default is maximum 1024 open files.)
>
> You can modify it with `ulimit -n 1500`, but it will be lost after reboot.
>
> To make the change permanent, add in /etc/security/limits.conf:
>
> ```
> #<domain> <type> <item> <value>
> #
> www-data soft nofile 1600
> www-data hard nofile 65535
>
> ```
>
> Of course, restart your web server.

It explains how to set a per-user limit and increase the number of files that can be opened. If you don't have enough memory in the server, there may not be many options.
> 1 votes

---
Tags: media, theming, files, 7
---


title: overlay submit feedback

text:
# Question
Title: overlay submit feedback
This might be a very simple question, but I can't figure out the answer.

I love the overlay module in drupal 7, but I am annoyed by the lack of visual feedback when a form is submitted in an overlay. eg. admin/structure/block, hitting submit doesn't give any indication that something is happening in the background.

I would love to know what I have to do to attach some behavior to the submit button of a form in an overlay that provides visual feedback that the form has been submitted (like greying out the overlay or something).

# Answer
I just added a block with following code to the content region of my administration theme

```
<style type="text/css">
#overlay-inactive {
 z-index:100;
 opacity:0.5;
 background-color:grey;
 position: absolute;
 top: 0px;
 left: 0px;
 width:100%;
 height: 100%;
}
</style>
<script>
jQuery(document).ready(function(){
 jQuery('input[type=submit]').click(function(){
   jQuery('#overlay').append('<div id="overlay-inactive"> </div>');
  return true;
 });
});
</script>

```
> 3 votes

# Answer
You could use jquery-loadmask. It looks like it grays out the div and puts a throbber over it.
> 0 votes

---
Tags: 7, modal-dialogs
---


# Question
Title: Editing the post time displayed for comments in Drupal 7
I need to display the post time of comments for a particular content type. I want these post times of comments to be in the "time ago" format.

Example: 1 minute ago

How can I do this in Drupal 7?

# Answer
> 1 votes
There is a native function in Drupal to format date intervals, it is called format\_interval.

Usage example:

```
 // Date since forum post was created
 format_interval(REQUEST_TIME - $variables['topic']->created)

```

Hope this helps, happy coding!

PS: See the answer I gave on your stackexchange post for the longer custom version you can also use.

---
Tags: 7, comments
---


title: Other modules like the Devel module?

text:
# Question
Title: Other modules like the Devel module?
I've just started learning Drupal, and the devel module is great and everything but I had a couple of questions about it:

1. Is it possible to change the output text when generating article or basic page content? For example, instead of using Latin Lorem Ipsum filler text, I'd like to be able to use something that puts out actual English words, like Candy Ipsum.
2. I noticed that when generating article content, it will also generate a small image to go with it, but the images are not of a uniform size. Is there any way to set it to use a fixed resolution?
3. This is more of a personal preference, but the user names it generates are a little hard to work around. Back when I worked with Django, I had whipped up a script that put together random user names using common first and last names I had compiled into a text file. Is it possible to do something like that here?

Any suggestions on how I could go about doing these things? Is there perhaps another module(s) I could use to get these functions?

# Answer
> -1 votes
Drupal is Open-Source. Just dive in the source code my friend, and mash it up to your taste.

I would probably copy the devel module and rename it devel2, implement custom modifications in there, but it\`s just a matter of preference.

# Answer
> 1 votes
I believe devel generate uses a pattern like `[FIELD_NAME]_devel_generate()` when deciding who/what to ask for generated data, and then devel implements those functions itself for the core fields.

Unfortunately I don't really see a way to alter this behaviour as there is no Factory pattern or similar that one could use to instantiate derivative/overridden functionality.

What my team usually does is creating content more to our liking in the install profile. This allows us to gradually build in some basic content that the client will want anyway into the development process, and we use a variable to tag nids that won't be useful one we go live, so that we can easily remove the junk content.

If we stick with using devel, here's what I would do:

1. Hack the module. The code you are looking for is in devel/devel\_generate, and then split up into many files, mostly one for each type of content it creates.
2. Make the functionality generally useful.
3. Post a patch in the issue queue saying. "I wanted to use devel like this instead, is there a way to incorporate this into Devel?".

---
Tags: 7, debugging
---


# Question
Title: How can I adjust Drupal links on shared hosting so that they don't point at the root?
I have installed Drupal on shared hosting. Drupal is installed in the public\_html folder of an Apache user directory (UserDir). Unfortunately, I notice that Drupal always defaults its administrative links to the root, for example: http://www.domain.com/?q=admin. I don't want this, since my site is located in the user directory. Therefore, I want Drupal links to look like: http://www.domain.com/~sitename/?q=admin. How do I get this to happen when the url contains a tilde?

Is there a setting(s) I can change to make a global adjustment?

Thanks in advance, Doug

# Answer
You have a variable (`$base_url`) for this in `settings.php`, in /sites/default usually.

Set `$base_url` to match the address to your Drupal site:

```
$base_url = "http://www.example.com/~stef";

```

Hope that helps!

PS: There is also a url setting in .htaccess you may want to look at if the above does not work.
> 1 votes

---
Tags: 7, installation
---


# Question
Title: Change Menu Item's links Dynamically, per page basis
I've been looking for this for a while, but found no solution.

What I want is: Whenever someone visits to a user's profile, say http://mysite.com/user/**1** there should be an *item* available in ***Main Menu***, with the link: http://mysite.com/custom\_module/**1**

Here, I'll be dynamically changing the menu item's links based on the current page. How to achieve that?

Thanks.

# Answer
> 1 votes
It depends on how exactly you want to change the links, but views can handle most links if you configure the contextual filters correctly. Basically, just display a link to the content as the field and then set your filters and contextual filters (getting the argument from the node/user) as you need.

If you just want to change around links for user profiles, there's also the me module.

---
Tags: 7
---


# Question
Title: Drupal 7 - Error on Checkout, e-Commerce
I installed a **e-commerece** module for my website. And enalbed all the supporting files under 'modules'. I'm able to **add products and view them** and can also **add to the shopping cart.** however when i **checkout**, it sends me some here..like this

```
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column
'exid' at row 1: INSERT INTO {ec_customer} (type, exid, uid, name) VALUES
(:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => anonymous
[:db_insert_placeholder_1] => 4mePOKXg5_hhSCYgVSumyWMhsej6EZ5LRLKafRfPBTA
[:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => ) in drupal_write_record()
(line 6975 of C:\xampp\htdocs\cart\includes\common.inc).

```

Does anyone know why is it throwing an error.

# Answer
> 0 votes
If you're new to Drupal commerce, try installing Commerce Kickstart. There are detailed installation instructions available.

Drupal Commerce is fairly complex and there are lots of different types of errors that can result. Commerce Kickstart is a package (known in Drupal as an installation profile) that sets up most of the commerce stuff for you. If you're not experienced in working with Drupal, this is an easy way to get started without having to troubleshoot error messages.

If you do try Commerce Kickstart, do so from a new site. If you try to install over Drupal Commerce it could get messy.

---
Tags: commerce
---


# Question
Title: How does the Drupal template engine work?
I've just started learning about Drupal 7's theme system. I need to know how the template engine handles php, html, and css inside its template files and how it interacts with Drupal core to make its final output onto the page.

Basically, when we load a Drupal page in browser, what does the template engine do?

# Answer
The Theming Guide is a good place to start. Also the Theming Drupal 6 and 7 pages should be of some help to you (more specifically, How the Drupal theme system works).

**Theming guide:**

> This handbook is about customizing the look and feel of a Drupal site. We'll show you how you can modify the appearance of your Drupal site without requiring expert knowledge of programming. And if you wish to go further, we cover that too.
>
> This guide assumes some knowledge of HTML and CSS but no PHP programming knowledge is necessary. It also assumes you have administrator's privileges to a Drupal site. You might also want to familiarize yourself with some of the terminology used in Drupal. We concentrate on Drupal 7 with notes for Drupal 6 where applicable.

**How the Drupal theme system works:**

> Pages in this section describe the way the Drupal theme system operates, theme components and settings, .info files and page templates. This section is a starting point for creating a new custom theme.
> 6 votes

---
Tags: 7, theming
---


title: Video streaming cloudfront

text:
# Question
Title: Video streaming cloudfront
I am administering a drupal 6 website for a small company. We want to offer our customers restricted streaming video content on the drupal site.

What I heard it is a good idea to place these type of media files on a cdn service, everybody keeps recommending amazon s3 / cloudfront.

Is it possible to have the files on amazon, but have a restricted area on my website, where the user needs to enter some login information and after being authenticated can view the content?

If it is possible, how, what are your recommendations?

I am not familiar with using cdn, so sorry if I ask something very simplistic (:

# Answer
> 1 votes
The Video module supports storing videos on Amazon S3. Restricting node access can be done by creating a special content type for your videos and only giving view access for that content type to a role that you assign to some users, possibly by using the Content Access module.

---
Tags: 6, media
---


# Question
Title: How to create a Custom Content type without Title?
I'm trying to make an auction website. Therefore I made 2 Custom Content Types:
1)Item for sale
2)Offer(Bid) from user(with node reference url to Sale item)
I need to receive only 1 field(Price) from the user while making a Bid (creating the second content type).

I deleted the 'Body' field from my Content Type but I could not find a way to remove '**Title**' field because it is mandatory(required) field :(
The user that makes a Bid(offer) has nothing to do with Title (he doesnt need to know that he's creating a content)

How can I remove the '**Title**' field?

# Answer
You can use the Auto Nodetitles module.

> "auto\_nodetitle" is a small and efficient module that allows hiding of the content title field in the form. To prevent empty content title fields one can configure it to generate the title by a given pattern.
>
> When the token module is installed it's possible to use various node data for the auto generated title - e.g. use the text of a CCK field (since 5.x).
> 2 votes

# Answer
You can use hook\_form\_alter:

```
function sample_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'article_node_form') {
    $form['title']['#required'] = FALSE;
  }
}

```

or

```
function sample_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'article_node_form') {
    unset($form['title']);
  }
}

```
> 1 votes

---
Tags: 7, nodes
---


# Question
Title: Can I create a custom interface to power views search?
My content is well structured from an internal point of view, but I want to provide a more customer-focussed front-end to an advanced search form.

e.g. I want to offer a list of check boxes like

```
Show:
[ ] All
[X] Articles
[X] Yellow things
[ ] Super cheap things

```

I would then intercept this data and mangle it, so for example *Article* might become a parameter to `node_type` but *Yellow things* might be changed into `node_type = things AND field_colour = 'yellow'` while *Super cheap things* might be a different thing again.

i.e. I'd like to have a parameterised view set up but use my own customer-focussed forms, rather than use Views' own data-focussed exposed forms.

Is this straight forward?

(More info: I'm on Drupal 7.x. I'm very comfortable with PHP and SQL but I'm keen to do things the Drupal Way unless it's ridiculously inefficient)

# Answer
> 2 votes
Write a custom views\_handler\_filter. See Views' API for a step by step introduction to implementing handler classes for Views.

---
Tags: 7, views
---


# Question
Title: switching language requires users to login again
I have a multilingual site, that when people switch from one language to another, they are required to log in again.

but if they switch to the language they switched from the user is still logged.

so basically you could log into my site with 2 different accounts.

how is this possible? any ideas whats causing this?

# Answer
> 1 votes
Check out the issue here for i18n.

It seems that the Single Sign-On module should help you out.

> This module enables 'single sign on' between multiple web sites that share common user tables (see http://drupal.org/node/2622#advanced).
>
> Single Sign-On (SSO) means that if you are logged onto the master site, you will automatically be logged into any slave site that you visit.
>
> SSO needs at least two Drupal sites running in order to use it (even if you are using Domain Access module!). One is called Controller, second (third and others) are called Clients. See README for more information about setting this up.

I'd think that as the issue in the queue states the cookies are stored per language. This should be amendable in `settings.php`.

# Answer
> 0 votes
What have you tried to fix this? This certainly isn't the normal behavior. First, I'd do the following:

1. Try switching languages in a different way (change the language in the user profile vs. using a language switcher block, etc.) Does the problem still occur?
2. Disable the i18n modules one by one (so long as there are no dependency problems) and test each time. See if one of the modules is causing this.
3. If you only have two languages, add a third language to the site and see if changing to that language causes the same behavior.

It may go without saying but all of the above tests should be done on a local/test server, not your live site.

---
Tags: 6, i18n-l10n
---


# Question
Title: Use different settings for a Views' block basing on the content type of the node being shown
I have 2 content types, photo articles and video articles. On a photo article page, I want to have a block that shows 5 other photo articles. When I place this same block on a video page, it should show 5 video articles.

How can I use contextual filters to achieve this? I don't want to install a separate module to achieve this.

# Answer
> 1 votes
You can use Entity Views Attachment to attach your view to those content types instead of using blocks. EVA will allow you to pass in the content type of the current article as a contextual filter.

# Answer
> 1 votes
If you want to avoid creating 2 views (for whatever reason), you can create 1 view with a Contextual Filter for Node:Type. But you'll need Panels and cTools.

With this, you get a new display for Views called "Content pane": Output your View in this display, and you can select these Panes from "Mini Panels" module that comes with "Panels" module. Mini Panels creates blocks for you; you just need to create 2 instances of the mini pane, with a different contextual filter applied to the view.

# Answer
> 0 votes
You can setup 2 different views: one for related photos, and one for related videos. Create a block display for both. You use a regular filter to only show photos in the photo view and only videos in the video view. Limit it to 5 items.

You want a contextual filter for "content:nid" to prevent the current photo from showing in your view. When the filter value is not in the URL, use "content ID from URL" for "Provide default value"; then click "more" and select "Exclude" to exclude.

Now you just need to show your photo block on your photo page and vise versa. Go to "Structure \>\> Blocks", assign the photo block to a region, and restrict it to your photo pages or your type photo.

---
Tags: views, nodes
---


# Question
Title: Is it possible to export organic groups global roles using features?
I like to keep functionality that I build in features, both for version control and deployment.

I'm new to using Organic Groups and I wanted to know if it's possible to add an organic gorups global role to a feature. I couldn't see any mention of this when I tried to recreate my feature through the UI or drush.

# Answer
> 0 votes
There is a issue for this in the organic groups queue. features integration for organic groups permissions and roles. You may also want to install strongarm and see if that helps you store the configuration settings that are stored as variables.

---
Tags: organic-groups, features
---


# Question
Title: Can I sort a view by a custom date field without the date module?
I would like to organize products in my site by year of production. And sort them in a view. With the date(year) as exposed filter, in this format:

```
Products :
From  year :…
to year:….

```

Can I do this only by creating a CCK text field with a list of years? Or should I use the date module instead?

If I have to use this module , How can I change the format in which the date is input. By default, it shows years ,months and days. I want it to show only years.

# Answer
With D6 and views 2.16 (the integer text way approach) is as follows:

Your content type need to have Integer CCK field (year\_int).

In your Views create node view, place some field (i.e. title) and add Filter\>Content\>year\_int **exposed** grater or equal. After add another time Filter\>Content\>year\_int **exposed** less or equal. Configure the rest as You need and its done.

Notice: you must type years into the filter, there is no select widget available, when field type is text.

Warning! If your type where year is stored is just text (not decimal), filter in views doesn't have less or greater option.
> 1 votes

# Answer
Using date field gives you more flexibility, but year made with text field would work also.

But in my opinion after your site grow larger you will probably say to yourself: "Gosh, now I wish to order with moths and days..." and you'll regret not using date field at the beginning.
> 1 votes

# Answer
With D6 and views 2.16 and date 2.8 (the suggested date way approach) is as follows:

You have to have date field in your content with granularity year (field\_date). You can choose list to provide year list when updating/creating product with some range.

In your Views create node view, place some field (i.e. title) and add Filter\>Content\>field\_date exposed grater or equal. After add another time Filter\>Content\>field\_date exposed less or equal. Configure the rest as You need and its done.

Date approach is more flexible and scalable in my opinion and gives more widgets when adding, editing and exposing in views filter. It's just smarter.
> 0 votes

---
Tags: 6, views, datetime
---


# Question
Title: Help with Drupal.behaviors and AJAX refresh
After a pause, I've been working on my Drupal 7 site again, and I have stumbled upon a minor problem regarding JavaScript and Ajax.

Thanks to this great website, I've learned of Drupal.behaviors, and I tried implementing my JavaScript code with it, so it shows up after an Ajax refresh within a view.

```
(function ($) {
Drupal.behaviors.borderfarba = {
    attach: function (context, settings) {

        var nmbr = 1;

        $(".moviescreenss",context).each(function () {

            var clrclass = "clr" + nmbr.toString();
            $(this).addClass(clrclass);
            addborder(clrclass);
            nmbr++;
        });

        function addborder(clrclass) {
            $("." + clrclass + " img").insetBorder({
            borderColor: get_random_color(),
            inset: 5
            });
        }

        function rand(min, max) {
            return parseInt(Math.random() * (max - min + 1), 10) + min;
        }

        function get_random_color() {
            var h = rand(40, 130);
            var s = rand(30, 75);
            var l = rand(40, 60);
            return 'hsl(' + h + ',' + s + '%,' + l + '%)';
        }
    }
};

})(jQuery);

```

I'm not that experienced with JavaScript, and I'm sure there are many possible improvements with the core code itself (e.g. the way functions are called).

What it does is add the jQuery inset border effect to every image link generated by the Views module, and color them with a random color within a specified range from reddish to green. (I somehow implemented this with a for-loop that adds a new "class+1" to each image, and the random HSL generator I found somewhere online.)

After adding the Drupal behaviors, the inset borders are still there after the AJAX action, but they are static and the hover effect is gone.

*** UPDATE *** I have noticed this only happens afte clicking on a submit button. For example when using the VIEWS pager in ajax mode, the javascript applies fine

Any help would be greatly appreciated, as I'm certain it will help me understand JavaScript scripting better, besides new Drupal techniques

# Answer
Well it seems I have found a solution :-)

I needed to add 'context' to the function of border adding itself

so this

```
 $(".moviescreenss").each(function () {

```

becomes this

```
 $(".moviescreenss",context).each(function () {

```

and now it seems to work fine :-)

Still need to see if I can make the whole code more efficient, I'll go to stackoverflow with this and update here if I get anything better
> 0 votes

---
Tags: views, ajax, javascript
---


# Question
Title: Annotate term relationships with data via edit form
I'm building a simple download area for a web site. All it should do is to provide material of lectures for users which are grouped into user groups. As I don't want to make the system to difficult I'm not using organic groups or similar but just a share taxonomy between users and my "document" content type. If a document has no terms of that taxonomy or the user has one of the documents terms the document will be shown. Here helps Access by Term (ABT) module perfectly.

However, one caveat is that the publish date of the documents is based on the group. Some groups. Thus some lecturers will use the same document in different courses. To avoid that someone can see the document too early I'd like to add a date to the document/term relationship and filter hide those documents by checking these values in a custom template.

Does anyone know how best to implement such a system. Thinking of adding multiple text fields and letting the editors add TERM NAME|DATE into it. Then I'll loop through all the values on creation of the teaser. Shying a bit away of creating my own module and database table to store maintain these values.

# Answer
Just for reference. I found a solution: I used the field collection module to implement the needed relationships.
> 0 votes

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


# Question
Title: Is there a way to not show some fields of a content type on the add form?
I have a content type "Print" with several fields. Some fields need to be filled out by users and thus, should be hidden from the anonymous users who create content of type "Print." Is there an easy way to do this?

# Answer
> 3 votes
The Field Permissions module sounds exactly like what you're after.

> The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.
>
> **Features**
>
> Enable field permissions on any entity, not just nodes. Role-based field permissions allowing different viewing patterned based on what access the user has. Author-level permissions allow viewing and editing of fields based on who the entity owner is. Permissions for each field are not enabled by default. Instead, administrators can enable these permissions explicitly for the fields where this feature is needed. Field permissions overview

Simply don't give anonymous users permission to add/edit these fields.

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


title: drush failure on error in drupal 7

text:
# Question
Title: drush failure on error in drupal 7
My initial installation of Drush couldn't even recognize commands such as "drush migrate-status", therefore I reinstalled drush and followed the steps in the included README.

After reinstallation, drush now recognizes the command "drush migrate-status", hwoever it is throwing an error and crashing. I am confused as I have not even enabled the migrate\_example module included with the Migrate module, however drush is throwing the error message below:

```
require_once(/var/www/drupal7/sites/all/modules/migrate_example/beer.inc):[warning]
failed to open stream: No such file or directory bootstrap.inc:3024
PHP Fatal error:  require_once(): Failed opening required '/var/www/drupal7/sites/all/modules/migrate_example/beer.inc' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/drupal7/includes/bootstrap.inc on line 3024
Drush command terminated abnormally due to an unrecoverable error.   [error]
Error: require_once(): Failed opening required
'/var/www/drupal7/sites/all/modules/migrate_example/beer.inc'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/drupal7/includes/bootstrap.inc, line 3024

```

This all seems very cryptic to me, especially when I have not enabled the migrate\_example module and I have the migrate\_example directory under migrate.

Could someone please explain why drush might be throwing this error?

# Answer
It sounds like the file `/var/www/drupal7/sites/all/modules/migrate_example/beer.inc` is missing.
> 1 votes

---
Tags: 7, drush, migrations
---


title: Many views for many taxonomy terms

text:
# Question
Title: Many views for many taxonomy terms
I need some help with the taxonomy view.
How can I create many views for many terms ?
I want that many terms from different taxonomies terms point to different views or at least to different structures of the same view.
The problem is that drupal translate each link of all taxonomy term to the model taxonomy/term/% that makes that all taxonomy term point to the same view. and I want that each taxonomy term point to a different views.
I hope i expressed myself well !
Thank you very much!

# Answer
> 0 votes
Create a view with a page display that has a Drupal path of e.g. `taxonomy/term/5`. This page display will then only be used for the term with the `tid` 5. Create other views or page displays for the other terms.

If you want separate views based on the vocabulary that the term belongs to, have a look at the Taxonomy Views Integration module.

# Answer
> 0 votes
The way I would go would be to first create the desired views, then create custom "page–taxonomy–term–\[tid\].tpl.php" files, and in their code use the `views_embed_view` invoking the desire per-page view. I'm not sure though if this is the most effective way.

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


title: setup cron to browse all pages

text:
# Question
Title: setup cron to browse all pages
On drupal 6 I use page caching and I would like to setup cron to browse all my pages on my website (30pages) before they get expired. What are best options to do that? I know about boost module but I think it is too robust for my needs. Thank you

# Answer
In short: wget is your friend when you want to warm up your page cache.

In more detail: http://linuxreviews.org/quicktips/wget/ for example. If you want to warm the cache for page requisites (all images, css, js etc linked to from any page) too, you can use `wget -p` which is not mentioned in that article.

Got more interested about this and found some Drupal specifics: http://www.metaltoad.com/blog/how-drupals-cron-killing-you-your-sleep-simple-cache-warmer

To summarize: just setup your system's scheduled tasks (cron on \*nix for example) to run wget in a manner that finds all your pages before your cache runs cold.
> 1 votes

---
Tags: caching, cron
---


# Question
Title: Setting a default value in views jump menu d7
I followed a tutorial on how to use the jump menu functionality in views drupal 7 link http://dev.nodeone.se/node/771,it was successful. i have one problem though,I need to show a default value(for example a taxonomy term by default) if nothing is selected instead of the drupal default to -select- . i have opened the file in views/plugins/views\_plugin\_style\_jump\_menu.inc and found this code,it looks like here is where i am supposed to change. but i just dont understand this code. Any help will be appreciated

```

function option_definition() {
    $options = parent::option_definition();
    $options['hide'] = array('default' => FALSE);
    $options['path'] = array('default' => '');
    $options['text'] = array('default' => 'Go', 'translatable' => TRUE);
    $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE);
    $options['default_value'] = array('default' => FALSE);

    return $options;
  }
?>

```

# Answer
I figured it out, just went to views admin, deleted the -select-, reordered my taxonomy terms and bum!! it worked! am so dumb.
> 0 votes

---
Tags: views, routes
---


# Question
Title: Is there something like a private FAQ/ask-the-expert?
I've been looking for a module that allows something like *ask the expert* with these conditions:

* A registered user `U` uses a form to submit the question. Anonymous users do not have access to this section.
* The expert `E` is notified of the new question by email.
* When `E` answers the question, `U` is notified by email.
* `U` can only see the questions asked by himself/herself (with their respective answers). No regular user can see the questions asked by other user, or the answers given to other users.
* An administrator `A` can see all the questions and answers at all times.

The modules faq and faq\_ask seem like an option, but I can't use the traditional FAQ format, since that format allows all users to see all questions. The module question is not available for Drupal 7.

Is there anything like what I'm describing? If not, is there any way of modifying, for example, the `faq` module, so permissions will work the way I want?

Thanks in advance!

# Answer
> 3 votes
The question\_answer module is probably what you want. I used to make a private Q/A for registered users on a site. All the "workflow" you talk about can be done via either the workflow module, drupal actions or the Maestro module ... I'd give Maestro a shot only because I haven't used it.

---
Tags: 7
---


# Question
Title: What can cause an incorrect base_url to intermittently appear for images?
I have a set of images provided by a view. They are displayed on the site home page via a panels page. JCarousel is used on display. An image cache style is applied. When previewed in the view, they appear without issue.

When displayed on the home page, the path to the images uses localhost, not the server domain name, and thus are broken. All other images on the site load fine, including other images provided by image cache.

I've tried:

* Clearing the cache
* Flushing the image cache style

I'm not really sure what else to check. Do I have any other options beyond settings base\_url in the settings.php file?

# Answer
I have had a very similar issue before.

Basically, the problem I had was that the image path was saved as url, instead of being a relative path. If this is the case, the fix is fairly simple, simply go look at that node's attributes in the database, and change the url path to a relative paths.

If you are in doubt, a quick and dirty way to see if this is really the problem:

1. Do a DB dump, with `mysqldump` or whatever you use,
2. grep in that file for "http://localhost"

grep -b3 -a3 "http://localhost" yoursqlfile.sql

* The b and a flag are for the number of lines returned upon a text match before and after the match it is optional and can be tweaked to higher values if wanted/needed.

Now, if there is any reference in the sql data pointing to your http://localhost, in your node meta-data these 2 simple steps will quickly help identify where the offending nodes are. Just note the table and field names that grep found & the nid's and go change the values to relative paths using either the commandline, a script or php-myadmin!

Of course, there are many ways to do this I just pointed out a very general way of fixing your data so it is portable.

Good-luck, happy coding.
> 1 votes

# Answer
Sounds like you have a conflict in your settings file and your variables table.

Try disabling the site root in the settings file and enable just your database connection. Then make sure your file paths are validating under file settings.
> 0 votes

---
Tags: 6, media, files, uri
---


# Question
Title: what is drupal 6's version of hook_user_cancel for drupal7?
I'm trying to execute some custom code in drupal 6 after i ban/block a user. What would be the appropriate way to do this? I tried using hook\_user specifically looking for an 'update' $op when I block a user, but no 'update' operation seems to get passed into my hook, only 'load' gets passed. I guess the equivalent of this in Drupal 7 would be hook\_user\_cancel.

# Answer
hook\_user() has an operation for **delete**, it does however lack an option for **ban** or **block**. In this case you should use the **rules** module and implement a custom action that gets called when a user is banned, the action being in your custom code. There's a few Drupalcon presentations on Rules, Conditions and Actions available on Drupal.org.
> 3 votes

---
Tags: 6, users
---


# Question
Title: drupal q=vectorize-files means which php file?
I started learning drupal today but I am unable to understand where https://www.artworkgeeks.com/vectorize-files is going. In htaccess file any url is getting pointed to index.php?q=$l but I dont understand which php file in which folder is getting executed. I know this is really basic but I m unable to find out answer online.

How to detect which template file and which php file is getting executed for particular url. Some other developer have removed all of the site theme control and module control options from admin panel. Now how to locate files.

# Answer
There is no specific "file" to find as paths don't need to map to files in Drupal. One registers a path in the system by implementing hook\_menu.

```
hook_menu() {
  return array(
    'vectorize-files' => array(
      'page callback' => 'some_function',
    ),
  );
}

```

I would start by grepping or otherwise searching all the custom modules of the site for the string "vectorize-files", which is the path you are looking for. You should be able to find a `.module` file that defines this path.

Failing that, the path is registered, together with it's module name , in the `menu_router` table, where you can track down it's origin.
> 4 votes

---
Tags: uri
---


title: Hide create new account tab

text:
# Question
Title: Hide create new account tab
How to hide Create new account and Request new password tabs in user login form? I use Drupal 7. I use custom theme. Maybe in template.php file some function?

You can see my page - http://broceni.garm.lv/

# Answer
> 1 votes
The Tab Tamer module will do it for you without having to write a single line of code:

> Tab Tamer is an administration utility that provides easy re-ordering, hiding, and deactivation of tabs and subtabs. You can also rename tab labels.

---
Tags: forms, users
---


# Question
Title: how to add field programmatically in Drupal 7 with dynamic content value?
I have a function in my e-commerce website that allow users to create own stores, i need to add dynamic field (select list) contain the stores created by the logged user when he add new product to assign this product with store.

i try to add field on the content type 'product' but i found that drupal save the values in the database. What is he best method that resolve my problem?

# Answer
I'm not sure what you are trying to do. But if you are trying to add a new field programmatically, below is a code snippet that can get you started.

```
    $myField_name = "my_new_field_name";
    if(!field_info_field($myField_name)) // check if the field already exists.
    {
        $field = array(
            'field_name'    => $myField_name,
            'type'          => 'image',
        );
        field_create_field($field);

        $field_instance = array(
            'field_name'    => $myField_name,
            'entity_type'   => 'node',
            'bundle'        => 'CONTENT_TYPE_NAME',
            'label'         => t('Select an image'),
            'description'   => t(''),
            'widget'        => array(
                'type'      => 'image_image',
                'weight'    => 10,
            ),
            'formatter'     => array(
                'label'     => t('label'),
                'format'    => 'image'
            ),
            'settings'      => array(
                'file_directory'        => 'photos', // save inside "public://photos"
                'max_filesize'          => '4M',
                'preview_image_style'   => 'thumbnail',
                'title_field'           => TRUE,
                'alt_field'             => FALSE,
            )
        );
        field_create_instance($field_instance);
        drupal_set_message("Field created successfully!");
    }

```

Hope that works

Muhammad.
> 3 votes

---
Tags: 7, entities
---


# Question
Title: Email send action fails: Cron has been running for more than an hour and is most likely stuck
I am maintaining a Drupal 6 installation. The task was to send an email to all registered users. I was using a rule set containing one rule with a default action: "send email to all users of a certain role". The rule set has been scheduled, was executed and deleted from the schedule (automatically like expected), but the task seemed to restart forever in the background: all (or probably a lot) users got the email every hour (6 times until I stoped cron). I use poormans-cron.

Please help with to answer this questions:

1. I suppose the mails could not be sent (~300 users) in the 60 minutes before the next cron (1h) decided that the job was still not complete and restarted it. Correct?
2. 300 mails in 1 hour should not be a problem, but I saw somewhere, but cannot remind where, that one can set a wait time between sending mails. Is that correct? Please tell if you know where.
3. Can you think of something else than 1. for the reason? (I used out of the box drupal 6 functions).

The log shows:

```
error   cron    18/02/2012 - 12:04  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 11:08  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 11:04  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 10:07  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 10:03  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 09:07  Cron run exceeded the time limit and was aborted.
error   cron    18/02/2012 - 09:03  Cron has been running for more than an hour and is most likely stuck.
error   cron    18/02/2012 - 09:02  Cron has been running for more than an hour and is most likely stuck.
error   cron    18/02/2012 - 07:50  Cron has been running for more than an hour and is most likely stuck.
warning cron    18/02/2012 - 06:46  Cron run exceeded the time limit and was aborted.

```

**Appendix 1, 19.2.2012**
I use PHPMailer module to send the emails.

# Answer
I found the problem and changed a file in drupal core: includes/common.inc, line 2714:

```
function drupal_cron_run() {

  // Try to allocate enough time to run all the hook_cron implementations.
  if (function_exists('set_time_limit')) {
    @set_time_limit(240); // will return a fatal error, if the script runs more than 4min
  }
...

```

I changed the set\_time\_imit(240) line to:

```
    @set_time_limit(2400);

```

because sending all mails lasts about 14min.

Thanks anyone for your time. Spikey
> 0 votes

# Answer
I think that your PHP configuration is not letting cron finish. Turn off poormanscron, then delete your cron entries in your MySQL database:

```
DELETE FROM `variable` WHERE name = 'cron_semaphore';
DELETE FROM `variable` WHERE name = 'cron_last';

```

Then go to admin/reports/status and click on your PHP version to see the output of phpinfo(). What is the max execution time? What is the memory limit? You'll want to change those values to higher numbers, then verify that they are indeed different on this page, then run cron manually at admin/reports/status.

To change these 2 values in PHP, create (or edit) php.ini in the webroot of your site and add (or modify):

```
max_execution_time = 300
memory_limit = 256M

```

Obviously feel free to try whatever numbers you'd like here. Ideally you don't want to leave the memory limit very high if you don't need to.
> 1 votes

---
Tags: rules, emails, cron, actions
---


# Question
Title: Create a kind of coupon with a entity references or node reference and no autocomplete
I should create a webform with a field which is related to a node. With webform seems no possible to add a node reference, so probably I should create a content type (coupon) instead of using the webform module. Basically, when they complete the form they can fill the field "coupon" and if the coupon exists they can go through.

The most important thing is that the node reference should be a text field with ***NO AUTOCOMPLETE*** I don't want them to see the the other coupon. How do I create it?

I've already installed the module reference and entity reference and using drupal 7.12.

Thanks in advace

# Answer
> 0 votes
This is the way to avoid the autocomplete in a node reference unset($form\['MYFIELD'\]\['#autocomplete\_path'\]);

---
Tags: webforms, nodes, 7, entities
---


title: Views - Date Filtering (Panels?)

text:
# Question
Title: Views - Date Filtering (Panels?)
this is one of the most confusing tasks I've been asked to accomplish in Drupal. I have a Content Type called Latest News that has a Date field (not the creation date, a date that represent's the new itself and may be used for the filtering process).

What I need is the following page:

```
_________________________
|  _____  ____________  |
|  |   |  |          |  |
|  | A |  |    B     |  |
|  |   |  |          |  |
|  |___|  |          |  |
|         |          |  |
|  | C |  |__________|  |
|                       |
|_______________________|

```

Where A is a list of Latest News nodes' titles, B is the node itself (smells like Panels), and C is a menu that contains dates spanning from 2004 to now (dynamic preferably), that acts as a filter to view A.

Whenever a user clicks on a date on C, the titles in A are filtered (much like an exposed filter), and the node display on B should change to the topmost item of the currently filtered list on A.

The current displaying node's title should be highlighted.

If the user has filtered A to display news from 2011, clicking on one of them should retain the filter, and simply display that node.

How would you go about doing this? I will be editing this question if more clarification is needed. Thanks in advance.

# Answer
Thanks to Tommi Forsstrom's answer I got lead in the right direction:

I created a panel with A,B and C being 3 regions in it.

In A I used 2 view panes, one that showed the latest 15 news and none that showed all the news according to one of the panel's arguments. If the argument was a prefixed value ("all" for example) I'd show the first view, if not, I'd show the second one that would get filtered by the argument (if it's not "all" it's a year (2012 for example) and it's valid for filtering).

In B I used 2 view panes that displayed full content, with the only difference that one of them had an extra contextual filter (the date). Both of them had the NID of course.

On C I have a static menu (will need updating on 2013 sadly) that leads to the panel/year url. So that covers the date filtering as well (and leads me to the second view).

As far as the "stuff staying selected" I had to write some correctional javascript to do that. On document.load I check the url and add "active" classes to whatever should be active.

At the moment this is the best I could do. If anyone has a better solution I'll gladly pass the green checkmark along :)
> 1 votes

# Answer
Here's what I would do.

First I'd enable the CTools Page Manager and Views content panes and create a page (admin/structure/pages) for that display that has arguments in it's path.

Then I'd create three views with display type "content pane": one that lists nodes based on a contextual filter (A), one that shows only one node (B) and one that lists dates (C).

Then I'd create the column layout in the page's content and would provide the arguments with Page Manager.

Here's a really nice tutorial from NodeOne that addresses most of the tricky parts here: http://dev.nodeone.se/en/learn-page-manager-part-5-views-content-panes-basics
> 1 votes

---
Tags: 7, views, panels
---


title: Saving form after altering it

text:
# Question
Title: Saving form after altering it
I'm altering the "Edit menu link" form

```
function module_name_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
    $form['html_content'] = array(
        '#type' => 'textarea',
        '#title' => t('HTML Content'),
        '#maxlength' => 180,
        '#required' => FALSE,
        '#description' => 'Put here the HTML code of the menu'
    );
}

```

The text area is showing fine, but it's not saving the information I put into. How can I solve that?

# Answer
> 3 votes
Generally speaking, only the form builds with system\_settings\_form() automatically saves the form field content of all the form fields present in the form. This is because its form submission handler (system\_settings\_form\_submit()) contains the following code.

```
  foreach ($form_state['values'] as $key => $value) {
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
      $value = array_keys(array_filter($value));
    }
    variable_set($key, $value);
  }

```

The form you are altering has a different form submission handler, menu\_edit\_item\_submit(), which doesn't contain similar code. The function that is called for saving the menu item, menu\_link\_save() saves the fields it knows of, and which are defined in the database schema for the table used for this purpose.

```
  if (!$existing_item) {
    $item['mlid'] = db_insert('menu_links')
      ->fields(array(
      'menu_name' => $item['menu_name'],
      'plid' => $item['plid'],
      'link_path' => $item['link_path'],
      'hidden' => $item['hidden'],
      'external' => $item['external'],
      'has_children' => $item['has_children'],
      'expanded' => $item['expanded'],
      'weight' => $item['weight'],
      'module' => $item['module'],
      'link_title' => $item['link_title'],
      'options' => serialize($item['options']),
      'customized' => $item['customized'],
      'updated' => $item['updated'],
    ))
      ->execute();
  }

```

```
db_update('menu_links')
  ->fields(array(
  'menu_name' => $item['menu_name'],
  'plid' => $item['plid'],
  'link_path' => $item['link_path'],
  'router_path' => $item['router_path'],
  'hidden' => $item['hidden'],
  'external' => $item['external'],
  'has_children' => $item['has_children'],
  'expanded' => $item['expanded'],
  'weight' => $item['weight'],
  'depth' => $item['depth'],
  'p1' => $item['p1'],
  'p2' => $item['p2'],
  'p3' => $item['p3'],
  'p4' => $item['p4'],
  'p5' => $item['p5'],
  'p6' => $item['p6'],
  'p7' => $item['p7'],
  'p8' => $item['p8'],
  'p9' => $item['p9'],
  'module' => $item['module'],
  'link_title' => $item['link_title'],
  'options' => serialize($item['options']),
  'customized' => $item['customized'],
))
  ->condition('mlid', $item['mlid'])
  ->execute();

```

In your case, you need to alter the form, adding the form field, and a form submission handler that saves your data in your own database table.
As there are more than one button on that form, I prefer associate a new form submission handler to the specific button, such as with the following code.

```
$form['actions']['submit']['#submit'][] = 'mymodule_menu_edit_save_submit';

```

You could also be interested in doing something when the menu item is deleted (in which case, you should delete the data from your database table); the delete button is `$form['actions']['delete']`.

---
Tags: forms
---


# Question
Title: my module template_preprocess is not called
I can't figure out how to correctly implement the theme mechanism in my module. The hook just doesn't get called, after flushing registry ofc.

My mymodule.module contains a function (this function gets called, no problem, I give it just for illustration):

```
function mymodule_node_view($node, $view_mode) {
  ...
  $node->content['mymodule_tocteasers'] = array(
    '#markup' => theme('tocteasers', array('tocteasers' =>  "whatever")),
  );
}

```

As I understand the theme mechanism, in order to render `tocteasers` hook, the module should implement it. Here is my module's implementation, which is not called at all, ever:

```
function template_preprocess_tocteasers(&$variables) {
  $variables['content'] = "something!!!";
  dsm($variables); print "hello";
}

```

^^*I also tried `function mymodule_preprocess_tocteasers(&$variables)` without success*

In addition, I have a file named tocteasers.tpl.php in my module directory, containing:

```
<div>
  <?php print "!!"; ?>
  <?php print $content; ?>
</div>

```

This also does not get printed or called.

Can someone plese advise me, how to make this implementation so that the tocteasers.tpl.php file is used and gets the $content variable as intended?

# Answer
What you don't report in your question is the hook\_theme() implementation, which is necessary for Drupal to know the theme functions a module implements. In your case, the array returned from `hook_theme()` should be something similar to the following (supposing that your module defines just a theme function).

```
  return array(
    'tocteasers' => array(
      'variables' => array('content' => 'the default value'),
      'template' => 'tocteasers',

      // Use it only if the template is not in the same directory the module is located.
      // This path should be relative to the Drupal root directory.
      'path' => 'the directory where the template file is located',
    )
  );

```

Notice that:

* You call the theme function with `theme('tocteasers', array('tocteasers' => "whatever"))`, but the template file is not using `$tocteasers`.
* The template filename must be the same used for the theme name; in your case as the theme function is *tocteasers*, the reported template filename must be "tocteasers". The extension ".tpl.php" is not used, as it is automatically added by Drupal when it looks for the template file. The only allowed difference between the theme name and the template filename is that the template filename can use "-" where the theme name uses underscores. This is because the "-" character is not allowed in a theme name, which must use the same characters used in a PHP function name. (This means it cannot start with a number, for example.)
* If you are altering the code of an existing, enabled module, Drupal caches the data returned from `hook_theme()`; the result is that you had a theme function that was not using a template file, and that has been modified to use it, Drupal will not use the template file because it still referring to the old definition. `hook_theme()` is called in some specific cases, such as when a module is disabled, enabled, or updated. To force Drupal to update its cached data, you should disable and re-enable the module from the administration interface.
* `dsm($variables)` could not show anything, if it is called too late, i.e. when the messages set with drupal\_set\_message() (the function used from `dsm()`) are already rendered. For those type of debug messages it's better to use watchdog(), which saves the message in a database table. Drupal allows to see those messages in admin/reports/dblog, and defines WATCHDOG\_DEBUG for this very purpose.
* Both `template_preprocess_tocteasers()` and `hook_preprocess_tocteasers()` are used, the difference is that `template_preprocess_tocteasers()` is defined from the module implementing the theme function, and it is called before `hook_preprocess_tocteasers()`. The purpose of the preprocess functions is not printing anything, but altering the variables passed to the template file, or the theme function. As consequence, the following code doesn't work as expected (i.e. "hello" is not in the output of the theme function).

```
function template_preprocess_tocteasers(&$variables) {
  $variables['content'] = "something!!!";
  print "hello";
}

```
> 4 votes

# Answer
Definitely hook\_theme() should be implemented by your module instead of the preprocess.

To use `preprocess_tocteasers()`, you would have to call it yourself in `hook_preprocess()`.
> 0 votes

---
Tags: 7, hooks, theming
---


# Question
Title: Where is $form_state stored between form build, and form submit functions?
I assume that $form\_state data can normally be stored either in the database, or in the session.

In this code:

```
function _module_name_main_form($form, $form_state) {
  $form_state['random_extra_data'] = some_func();
}

function _module_name_main_form_submit($form, $form_state) {
  $important_data = $form_state['random_extra_data'];
}

```

I trust that there are limits to how the user can manipulate `$form_state`, which isn't true if `$form_state['random_extra_data']` is stored in the session.

Is that safe to do?

# Answer
> 4 votes
The `cache_form` table stores `$form_state`, so except for the values passed on by the client, which should be validated anyway, it is safe to trust the content in $form\_state.

---
Tags: forms
---


title: menu block with nice menu

text:
# Question
Title: menu block with nice menu
I am using the Menu Block module and the Nice Menus module. In my theme's left sidebar I have a block with that menu block (2nd level). How to use a Nice Menu in that region? If I put that Nice Menu, I get 1st level menu, but I need 2nd level menu from Menu Block module who create me 2nd level +

# Answer
> 1 votes
In the block configuration, you should be able to choose which menu it uses.

---
Tags: routes
---


# Question
Title: Comments form action points to different node
I'm having a very weird problem with comments on a node. I recently upgraded to Drupal 7.12.

Now the comments aren't working right. When a user (registered or anonymous) enters in a node page, the action call of the comment form points to the page URL. But, when the user browses to another page, the action call of the comment form of the new page remains pointing to the previous page! This happened until the browser is closed, or the user logs out.

Could anyone shed some light as to why this is happening?

\[Edited\] I just discovered that when I disable de Panel module the issue is not happening. The problem is that all the presentation layer goes to the trash :-( Anyone had a similar problem?

# Answer
> 1 votes
I think I've patched the problem clearing the cache just before the comment form render:

```
    <?php print render($page['content']); ?>
    <?php cache_clear_all('*', 'cache', TRUE); ?>
    <?php print render($content['comments']); ?>

```

As I said, seems there is a variable cache problem, and it seems to be on the Ctools module. This is only a patch until the fix comes.

Hope it will be useful.

---
Tags: comments
---


# Question
Title: How to re-render a particular field in template_preprocess_node or template_preprocess_field?
This is really really easy in Drupal 7: just use field\_view\_field or field\_view\_value. Choose the latter if you want to re-render a particular field value, or the former if you want to re-render the whole field (label and all values).

However, I couldn't figure out how to do this in Drupal 6. I resorted to implementing hook\_nodeapi and changing the node content before it was rendered. This approach cannot be implemented from the theme, though, I'm looking for a theme solution.

# Answer
> 1 votes
In `template_preprocess_node($vars)`, you can do:

```
$node=$vars['node'];

```

and then all the fields of the node are available to you, and a quick

```
drupal_set_message('<pre>' . print_r($node,true) . '</pre>');

```

will show them to you. So if you had a text field called `field_description` you can access it via:

```
$node->field_description[0]['value'];

```

and you can then modify to your heart's content, eg:

```
$node->field_description[0]['value']='What I really wanted to say was....';

```

and then at the end:

```
$vars['node']=$node;

```

sets it on its way.

---
Tags: 6, theming
---


# Question
Title: Can't drupal_execute('filter_admin_format_form') on hook_install?
I'm attempting to configure an input format on hook\_install() with the following code:

```
module_load_include('inc', 'filter', 'filter.admin');
$form_state = array(
  'values' => array(
    'name' => 'Full HTML',
    'format' => '2',
    'roles' => array(
      1 => 0,
      2 => 0,
      3 => 1,
    ),
  ),
);
$arg = filter_format_load(2);
drupal_execute('filter_admin_format_form', $form_state, $arg);

```

However this produces the error:

```
Filter format names need to be unique. A format named Full HTML already exists.

```

However if I run the same code on hook\_init(), then it runs without error.

# Answer
You can execute that code, but you need to give a unique name for the input format being saved.

As alternative, if you want to be sure there is an input format called *Full HTML*, you can save the input format in the database using db\_query(), and using the code of filter\_admin\_format\_form\_submit(), the form submission hander for the form you are executing, as guideline.
The involved database tables are two: filter\_formats, and filter\_formats; the first contains the data about the input format, and the latter contains the data about the input filters associated with an input format. The relevant executed queries are the following ones.

```
  if (!$format) {
    $new = TRUE;
    db_query("INSERT INTO {filter_formats} (name) VALUES ('%s')", $name);
    $format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_formats}"));
    drupal_set_message(t('Added input format %format.', array('%format' => $name)));
  }

```

```
db_query("DELETE FROM {filters} WHERE format = %d", $format);

```

```
  foreach ($form_state['values']['filters'] as $id => $checked) {
    if ($checked) {
      list($module, $delta) = explode('/', $id);
      // Add new filters to the bottom.
      $weight = isset($current[$id]->weight) ? $current[$id]->weight : 10;
      db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $format, $module, $delta, $weight);

      // Check if there are any 'no cache' filters.
      $cache &= !module_invoke($module, 'filter', 'no cache', $delta);
    }
  }

```

In Drupal 7, it would be easier, as you can call filter\_format\_save(), which always save the input format passed as argument, and eventually merge the format you passed as argument with the existing one.

The function that shows the error you are noticing is the form validation handler, filter\_admin\_format\_form\_validate(), which contains the following code.

```
if ($result) {
  form_set_error('name', t('Filter format names need to be unique. A format named %name already exists.', array('%name' => $name)));
}

```

As the form validation handlers, and the form submission handlers are executed when you call drupal\_execute(), the same error is returned, even when `drupal_execute('filter_admin_format_form', $form_state, $arg)` is called from `hook_init()`; it just happens that the error message shown with form\_set\_error() is not immediately visible when `hook_init()` is invoked, but the input format is not saved. To notice that `filter_admin_format_form_submit()` executes the following code.

```
  $format = isset($form_state['values']['format']) ? $form_state['values']['format'] : NULL;
  $current = filter_list_format($format);
  $name = trim($form_state['values']['name']);
  $cache = TRUE;

  // Add a new filter format.
  if (!$format) {
    $new = TRUE;
    db_query("INSERT INTO {filter_formats} (name) VALUES ('%s')", $name);
    $format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_formats}"));
    drupal_set_message(t('Added input format %format.', array('%format' => $name)));
  }
  else {
    drupal_set_message(t('The input format settings have been updated.'));
  }

```

Supposing that the form validation handler doesn't return an error, the form submission handler is not saving any data in the "filter\_formats" table, if the input format is not new; in such case, the function executes the `else` part of the control statement, which just output a message.
> 1 votes

---
Tags: 6, installation
---