title: drupal 7 comment moderation modules

text:
# Question
Title: drupal 7 comment moderation modules
I am looking for modules that can extend drupal 7 comment admin. For example, I want to be able to set different statues for comments, like Approved, pending, spam and unapproved. And maybe comment moderation history, in comment admin it should show a log of who changes the text, who changes status of a comment. the only module i can find is for drupal 6.

# Answer
> 3 votes
You should be able to "set different statuses for comments, like approved, pending, spam and unapproved" using Flags, which are D7 only.

I could not find anything that adds revisions to comments, or comments to flag changes.

The workflow module allows you to assign states to nodes, and comment each state change, but the comment\_workflow module is available only for D5. Hopefully someone else might have better news.

# Answer
> 1 votes
I suspect that what you are looking for is actually a D7 port of Nodecomments which is unavailable. This module effectively uses nodes for comments thereby giving you access to everything that is possible with a node such as revisioning and so on. While there is no D7 port of nodecomments yet, it might be worth taking Advanced Forum out for a test ride to see what features it supports as it integrates with nodecomments (amongst other things) in D6.

As amateur barista mentioned, the Flags module is currently your best (limited) bet for D7.

# Answer
> 1 votes
This may not do everything you want but Antispam is useful as:

* It connects to Akismet, TypePad AntiSpam or Defensio
* Can use its own rules
* Holds spam in a queue
* Gives stats and even some pretty charts
* Notifications of spam

# Answer
> 1 votes
I believe the best answer to this question is now Workflow module.

Since version 2.0, this module supports defining a workflow for any Entity type. This means you can define different workflows for Nodes (content types), comments and even users. Not only this module is multi-purpose which covers all entity types, but also it is a very flexible and powerful in defining different states, transitions, and permissions.

It also have great integration with Views so you can query things like current entity state, time of last state change, the user who made the last state change, etc. etc. in Views.

Here is general steps to setup a workflow:

1. Install Workflow 2.x
2. Enable **Workflow Access** and **Workflow Field** submodules
3. Add a Workflow field to the entity type you want (comment in your case)
4. Define states for that entity type (e.g. `Approved`, `Pending`, `Spam`, `Unapproved`)
5. Specify which roles have which access permissions (view/edit/delete) at each state. (See the below figure)
6. For each role, define the permitted transitions between states (e.g. author can switch from Draft to Review state but cannot go back, while Editor can do both). (See the last figure)

Note that Workflow Fields is a different module which provides field-level permissions (e.g. making a field read-only or hidden in some states). So don't confuse **Workflow Field** submodule (which is integrated in Workflow) with the **Workflow Fields** module (which is a separate module developed for a different purpose).

# "Access" page:

(Open image in a new window and zoom for a better view)

# "Transitions" page:

(Open image in a new window and zoom for a better view)

---
Tags: 7, comments, users
---


# Question
Title: How to position an element using jQuery UI .position method?
I'm going on about 20 hours trying to get jQuery UI to work, and fortunately, I'm still not frustrated. I just really want it to work. I would like to use the .position method to position an element in the top right corner relative to #page, (http://api.jqueryui.com/position/).

I'm not sure which version of jQuery this method requires, so I'm using the newest version, 1.10.2. It wasn't so hard to implement. I'm using the jQuery Multi module, and my script uses the alias as per instructions. (I tried using the jQuery Update module, but that just seemed to break everything, so I found jQuery Multi).

This part seems to be working. The file, jquery-1.10.2.min.js, shows up in the head of my HTML parallel to Drupal 7's 1.4.4 version. I'm getting an alert message when I write a test alert so it seems to be finding the function. If I delete the jquery-1.10.2.min.js file, the alert quits working and when I add it back it works again, (after clearing caches).

I've added the jquery.ui.core and jquery.ui.position libraries from Drupal core (both versions are 1.8.7) using drupal\_add\_library() in a preprocess page function. Like this...

```
function marigold_zen_preprocess_page(&$variables, $hook) {
  /* Add jQuery UI libraries - http://jqueryui.com/ */
  drupal_add_library('system', 'ui');
  drupal_add_library('system', 'ui.position');
}

```

Both of these files show up in the head of my HTML also.

Now I add the code to test out positioning the submit button in the top right corner of the page...

```
(function ($, Drupal, window, document, undefined) {
  $(document).ready(function() {
  //  alert("This is working");
    $( "#edit-submit" ).position({
      my: "right top",
      at: "right top",
      of: "#page"
    });
   });

})(jq1102, Drupal, this, this.document);

```

Nothing happens, and I get no errors in the console. Nothing is positioned differently. Again, if I uncomment the alert, it shows when I refresh the page, so I think that means that it's reading the function, yes?

If anyone can help me out here, I'd be so incredibly grateful. I was up till past 4am yesterday, woke up about 8am, and I've been at it all day again today. It's nearly dinner time, and I'm still stuck.

P.S. - Drupal 7.24

# Answer
I think the problem is that you need to also load the UI libraries using the newer jQuery version. jQuery UI is a jQuery plugin, so it attaches to jQuery itself. Within your function `$` refers to jQuery 10, while the UI plugin is loaded for Drupal's jQuery.

To fix this you have to use jQuery Multi to also load the libraries with the newer jQuery. You can use `hook_jqmulti_files()`:

```
function mymodule_jqmulti_files() {
  return array(
   'path/to/file.js',
   'another/full/file/path.js',
  );
}

```

You'll need to specify the file paths, which you can put together using `drupal_get_path()` or get using `drupal_get_library()`. Once you do that jQuery Multi will automatically load those files in the newer jQuery context and then `.position` should be available to you in your function.
> 1 votes

---
Tags: javascript
---


title: Auto increment using serial variable

text:
# Question
Title: Auto increment using serial variable
In this code i want to incerment the value by 4 and not by one . How Can i do it ?

```
    select_id' => array(
          'description' => 'TODO: please describe this field!',
          'type' => 'serial',
          'not null' => TRUE,
       ),

```

# Answer
> 2 votes
Auto-incrementing by a value other than one is not an easy task. Drupal's Schema API allows you to supply the mysql\_suffix property to supply mysql specific properties as explained in this comment.

The problem is that there is no mysql TABLE CREATE option which allows you to change the auto increment amount. There is a MySQL variable auto\_increment\_increment but it can only be set globally.

In this similar question a solution has been posted using MySQL triggers. AFAIK this is the best SQL solution that exists.

The best solution would probably to find a way to not need to auto\_increment with a value other than one or use an INTEGER type and do the incrementation manually through PHP.

---
Tags: 7, database
---


title: How do I use Viz.js?

text:
# Question
Title: How do I use Viz.js?
Viz.js is GraphViz converted to JavaScript. There is a demo at http://webgraphviz.com.

What I would like to do is send a string (dot syntax) created by a PHP function to Viz.js to produce svg output for display as "content". I know zilch about JavaScript and my trial and error attempts with `drupal_add_js()` and `Drupal.behaviors` are getting me nowhere.

Hoping someone can guide me through this. (The string from my PHP function is valid - it displays correctly if I paste it into the demo site).

Some background:

I have a working system using locally installed GraphViz and the PEAR Image\_GraphViz class. The problem is shared hosting providers don't want to install GraphViz -- so this js conversion could get around that.

I have a link on a Views display that calls a function to build a chart through calls to methods in Image\_GraphViz. At the end of the function I do

```
<?php
return $gv->fetch();
?>

```

which opens a page displaying the chart in the site theme content area.

In my attempt to use Viz.js I have first placed `scripts[] = Viz.js` in my .info file -- that seems correct to me and does get Viz.js into the html header. According to the author I only need one line of javascript like `svg = Viz("digraph { a -> b; }", "svg");`.

My problem is: where do I put it? Obviously, I need to pass a string to replace the 1st parameter and that is easily obtained by

```
<?php
$gvdata = $gv->parse();
?>

```

Pasting such a string into the demo site produces correct results.

Does the one-liner need to be in a separate file or can it be tacked on to the main function?

I tried this:

```
<?php
$gvdot = $gv->parse();
$gvdata = array('gvdata' => $gvdot);
drupal_add_js(array('ftree' => $gvdata), 'setting');
return drupal_add_js('jQuery(document).ready(function () {
Viz(Drupal.settings.ftree.gvdata, "svg"); });', 'inline');
?>

```

gives a blank screen.

I also tried calling a separate file:

```
<?php
$gvdot = $gv->parse();
$gvdata = array('gvdata' => $gvdot);
drupal_add_js(array('ftree' => $gvdata), 'setting');
drupal_add_js('dot2viz.js');
return;
?>

```

that contained:

```
(function ($){
  Drupal.behaviors.ftreeBehavior = {
    attach: function (context, settings) {
      var gvdata = Drupal.settings.ftree.gvdata;
      document.body.innerHTML += Viz(gvdata, "svg");
    }
  };
})(jQuery);

```

also returns a blank screen.

And that's where I am -- hoping someone can explain what I'm missing and/or doing wrong.

p.s. a better formatted version is at https://drupal.org/node/2153353

# Answer
I have managed to coerce the system into providing the desired result, but I'm not entirely happy with the method. I have the main function listed in my module's .info file as previously stated. The function that builds the dot script is a "menu callback", triggered from a views display. I have mimicked the method found here.

After the dot script is built, the function returns:

```
 <?php
 $gvdata = $gv->parse();
  $return = '<div id="svgarea"> </div>';
  $return .= '<textarea id="dotscript" rows="20" cols="80" width="100%" wrap="off">';
  $return .= $gvdata."\n\n";
  $return .= '</textarea>';
  return $return;
?>

```

I get the javascript into the output using the js\_injector module to put the following into the footer:

```
    jQuery(document).ready(function () {

  var svg_div = jQuery('#svgarea');
  var graphviz_data_textarea = jQuery('#dotscript');

  function UpdateGraphviz() {
    svg_div.html("");
    var data = graphviz_data_textarea.val();
    // Generate the Visualization of the Graph into "svg".
    var svg = Viz(data, "svg");
    svg_div.html("<hr>"+svg);
  }

  // Startup function: call UpdateGraphviz
  jQuery(function() {
      UpdateGraphviz();
  });

});

```

It seems to me there should be a more elegant way to do this.
> 1 votes

---
Tags: 7, javascript
---


title: Block file downloads for user

text:
# Question
Title: Block file downloads for user
**Problem**

I have a series of file fields on a user account where users can upload files. These files need to be attached to emails (by the system with drupal\_mail) and removable by the user.

But they don't actually need to be downloadable. And it would be a nice extra level of security if they can't download the files, only upload, remove and upload again.

Has anyone ever tried this (admittedly fairly niche) idea before?

# Answer
As it turns out this functionality was possible with only one extra module, the Content Access module.

Select the file field on the user account. You can find them at the following path:

`/admin/config/people/accounts/fields`

Edit the field and under permissions select, custom permissions. You'll need the Content Access module installed for this to work.

Then in permissions you can set custom permissions for the field. To allow a user to upload and not download, you give them only the ability to create or edit their field. You don't give them the permission to view it.
> 1 votes

---
Tags: 7, files
---


title: Features reset without drush

text:
# Question
Title: Features reset without drush
In Drupal 7, my commons wiki gives an error when editing.

> EntityMetadataWrapperException: Unknown data property field\_target\_nodes. in EntityStructureWrapper-\>getPropertyInfo() (line 339 of /home/content/44/11622944/html/sites/all/modules/entity/includes/entity.wrapper.inc).

According to Drupal, the problem is that when commons is installed, it doesn't reset features because it might cause the user to loose work. So the solution is to reset features.

So I go `/admin/structure/features/commons_wikis` here and reset all I can, but I'm still having issues. My `FIELD INSTANCES` and `MESSAGE TYPE` are "stuck" in overridden. I've tried clearing the cache too.

I can't install or use drush because I'm on a hosted solution and SSH isn't an option.

**How can I reset `FIELD INSTANCES` and `MESSAGE TYPE` without drush?**

# Answer
You can revert features in an update hook

e.g, in `MYMODULE.install`:

```
/**
  * Revert the 'field' component in my_feature_module
  */
function MYMODULE_update_7001(&$sandbox){

  features_revert(array('my_feature_module' => array('field')));

}

```

http://drupalcontrib.org/api/drupal/contributions!features!features.module/function/features\_revert/7

Note, if you have manual access to the code, you can check in the wrapper if the field isset first prior to use, preventing that EntityMetadataWrapperException:

e.g:

```
// Check if field is set prior to use, avoid EntityMetadataWrapperException
if (isset($wrapper->field_target_nodes)) {
  drupal_set_message('<pre>'. $wrapper->field_target_nodes->value(). '</pre>');
}

```
> 1 votes

# Answer
If you did want to try this with **drush** you could do so locally, as long as your site could live with a few minutes of restricted user interaction.

I would recommend testing this out first (steps 1,3) to avoid disruption to users.

1. download site (inc db via backup\_migrate) and setup on local development server (eg acquia dev desktop, which includes drush)
2. block users on live site (take care with notifications)
3. run drush features-revert-all to resolve your features issue - test
4. unblock users on local site
5. create backup of local db using backup\_migrate (to avoid mysql timeouts etc on upload)
6. overwrite remote site db
> 1 votes

# Answer
Not sure if this will work for you with the wiki commons editor, but something you might want to take a look at is features tools (https://drupal.org/project/ftools). Mainly the feature to look at is:

> Revert them all Adds a "Revert Them All" button on the main features page, which let you (as it says), revert all features in one click. Especially useful for Dev and Prod environments, where there no drush around.

Again, not sure if this will work for you, but it's worth a shot. Also, as always, if your monkeying around with your site, make sure you back up your DB before doing anything too drastic incase something gets fouled up.
> 0 votes

# Answer
The Features module has, in the past, refused to revert (without any useful errors) if it meant removing a field instance. It has also been tripped up by trying to revert a content type that was already created before the feature was enabled, but was missing field instances.

As far as I am aware, those two specific problems got fixed. Or I could just have been lucky and never run into them again!

You're going to have to remove whatever hangups the Feature might be having by doing one of the following. I find that when Features is giving me trouble the solution can boil down to trying to make it do its job easier:

1. Add the missing field to the type that won't revert, by hand. The field is clearly not there yet, so simply adding a field named 'field\_target\_nodes' and then try to revert might do the trick. Fields can be added (if the Field UI core module is enabled) at *Administer \> Structure \> Content types \> Content-type-name*.
2. Completely delete the offending content type and try to revert the feature, afterward. Consider even going as far as deleting each field from the type beforehand, to make sure everything is totally removed and anything that Features might be getting hung up on are out of the way. **This will remove all data saved in the content type, all data saved in those fields, etc.**

Alternately, if you can understand PHP, you can go a step further in #1 and pretend you're the features module. All of the settings options you'll need are all wrapped up in the features include file(s), and they're actually quite easy to read and understand. If you set the fields up the way they're "supposed" to be initially, it should remove any future revert issues.

Additional side questions: What version of Features are you running? What version of wiki commons? Following up on goron's question in the comment would be helpful, too.
> 0 votes

---
Tags: features, 7
---


# Question
Title: Showing icons to represent content types
Is there a simple way to have the site display a content type icon just before the "Submitted by..." function? I know I can do this conditionally in node.tpl.php like

```
if ($type==blog_post) echo '<img src=blog_post.png />';

```

etc. But this seems cumbersome. I have seen this done as part of Drupal Commons and others. Is there a module that can handle this or any other systematic changes to how the metadata is displayed?

# Answer
> 3 votes
This is set up by the node.module via preprocess()ing in variables:

```
// Display post information only on certain node types.
if (variable_get('node_submitted_' . $node->type, TRUE)) {
  $variables['display_submitted'] = TRUE;
  $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
  $variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';
}
else {
  $variables['display_submitted'] = FALSE;
  $variables['submitted'] = '';
  $variables['user_picture'] = '';
}

```

These are then used like this in (the standard core) node.tpl.php:

```
<?php if ($display_submitted): ?>
  <div class="submitted">
    <?php print $submitted; ?>
  </div>
<?php endif; ?>

```

So, it would be pretty easy to do something along these lines in your theme's `template.php` file:

```
function YOURTHEME_preprocess_node(&$variables) {

  if ($variables['display_submitted']) {
    $variables['submitted']='<img class="submitted-node-type" src="' . $variables['node']->type . '.jpg">' . $variables['submitted']; // or whatever/however you want to do this
  }

  // any other preprocessing goes here

}

```

# Answer
> 1 votes
All content types have CSS classes (in body tag if you are viewing the node or in container tag of the teaser). You can use them to add background image to whatever you want.

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


# Question
Title: Disable autofill username & password on drupal
How can tell the browser not to save drupal usrrname and password? I am newbie. So having difficulty understand many functions. Any easy way to configure drupal for this? Thanks

# Answer
> 3 votes
Auto-completion of common fields (text, password, select, textarea, date-related, time-related, numeric, email, and uri controls) is a browser feature but you can tell browsers to turn off auto-completion on form fields by using the autocomplete attribute.

You can use hook\_form\_alter or hook\_form\_FORM\_ID\_alter to add this attribute to your fields.

Example:

```
/**
 * Implements hook_form_alter().
 */
function example_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'YOUR_FORM_ID') {
    $form['YOUR_FIELD']['#attributes']['autocomplete'] = 'off';
  }
}

```

Example altering the log-in forms:

```
function example_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login_block': // Log-in block form.
    case 'user_login': // Log-in form.
      // Username
      $form['name']['#attributes']['autocomplete'] = 'off';

      // Password
      $form['pass']['#attributes']['autocomplete'] = 'off';
      break;
  }
}

```

You can check out these posts for more info on module development - Module Developer's Guide and Creating Drupal 7.x modules. You can also download the excellent Examples module for reference.

---
Tags: 7
---


# Question
Title: theming nodes as forms - any advantage using drupal_render?
I need to theme a node content type as a form. For example, the node has fields:

```
field_body = a question, e.g. "What is your favourite color?"
field_answers = field collection ------------------> these will become radio buttons
    field_content = an answer, e.g. "Blue"
    field_internal = internal value for the radio button
    field_points = how many points for this answer ---------> this will become an html attribute
    field_additional = "some additional info about this answer ---------> this will become an html attribute

```

and so on, each question has 3 answers to choose. This is a questionnaire, the editor adds questionnaires dynamically. I don't want Webform module in this case.

So far I've written a `mymodule_theme()` function (in a custom module) for the whole node with answers, and themed it as a form using raw html output, something like this:

```
$output = '<form>';
... loop
$output .= '<input type="radio" name="myquestion" value="' . $field_internal_value . '"> . $field_content_value .'<br>'
...

```

But Drupal has form API. I could as well build a `$form` render array in `mymodule_theme()`, instead of raw html and then use:

```
$output = drupal_render($form)

```

**The question:**

in the above example, is there any real advantage of building a form array and rendering it using `drupal_render`, instead of building the output from raw html as shown? For example, advantage with using ajax later, or submitting, or validating "the Drupal way" etc. (I think not because form API applies only to static forms which are defined in a module, but I'm not sure).

# Answer
> 1 votes
Using the Form API instead of doing things in the theme layer (rendering the node as a form) will give you all the advantages that the Form API has to offer (e.g. custom validation, submit handlers, form alters, etc.)

I would do things differently by creating a menu item with drupal\_get\_form as the page callback and the node as the parameter.

```
/**
 * Implements hook_menu().
 */
function example_menu() {
  $items = array();

  $items['custom/%node'] = array(
    'title callback' => 'node_page_title',
    'title arguments' => array(1),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('example_custom_form', 1),
  );

  return $items;
}

/**
 * Form constructor that takes a node as a parameter and creates a form based
 * on its values.
 */
function example_custom_form($form, &$form_state, $node) {
  $form['#node'] = $node;

  // Start generating the form...

  return $form;
}

```

Although subjective, this feels a little less hacky and might be easier to maintain in the future.

---
Tags: 7, forms
---


# Question
Title: Drupal 7 - Exposed form block also inside results
In Drupal 7 I created a view with an exposed form in a block. The view has a "page" display.

Users can make their searches using the exposed form in the pages where I placed the block.

I would like to put the filter also in the results page, but it is placed always after the results, while I would like to have that between the page title and the results.

Example:

**what happens**

PAGE TITLE

VIEWS RESULTS

EXPOSED FORM

**what I would like to do**

PAGE TITLE

EXPOSED FORM

VIEWS RESULTS

Any idea? thank you in advance

---

As I write below, I found the solution:

I had to:

1) Create the view 2) Expose the form 3) Add a "Global PHP" in the view header with the following code:

```
$block = block_load('views', '-exp-myview-page');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

```

Surely it can be done also using template instead of the php in the header.

# Answer
I found the solution to my own question.

I had to: 1) Create the view 2) Expose the form 3) Add a "Global PHP" in the view header with the following code:

```
$block = block_load('views', '-exp-myview-page');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;

```

Surely it can be done also using template instead of the php in the header.
> 0 votes

# Answer
You can override View tpl file and do the arrangement as per requirement. Also check the setting for exposed for under view.
> 0 votes

# Answer
Prashant's answer won't work because you use an exposed block to filter results. The default views template for exposed filters is the same way as you want it, eg, Title -\> filters -\> results. The block submit button directs you to the page where the results are. Where, if I am correct, you have also put this block in.

The solution: You shouldn't expose the filters in a block, this way they will be shown on the search-page, and by default, are on top of the page and stay there, and results will be below them.

Or: put your exposed-block in a different region, or duplicate the view.
> 0 votes

---
Tags: views
---


# Question
Title: How to i programatically change the page thats loaded from hook_init?
I am in the process of building a drupal module that will block access to certain IP addresses, i've built the whole thing and it works a treat except from one area of functionality; i would like to be able to redirect blocked users to a node.

The code that i have does everything except display the node:

```
if (variable_get('lock_denied_response_type') == 2){
  $node_id = variable_get('lock_denied_node');
  $node = node_load($node_id);
  $node_view = node_view($node, FALSE, TRUE);
  drupal_render_page($node_view);
  exit;
}
else{
  echo variable_get('lock_denied_html');
  exit;
}

```

I've scanned google, stack overflow etc but not much luck. So far as i can tell, it appears my approach is wrong and rather than triggering my own render page, i should just change which node the standard rendering process uses, something like this:

```
if (variable_get('lock_denied_response_type') == 2){
  $node_id = variable_get('lock_denied_node');
  /* insert awesome node override code here */
}
else{
  echo variable_get('lock_denied_html');
  exit;
}

```

Suggestions?

Cheers!

# Answer
> 2 votes
you can do somthing like this:

```
function MY_MODULE_init() {
    global $user;

    // or you can also use ip_address() function
    if($user->hostname == 'MY_BLOCKED_IP') {
      drupal_goto('node/NID_OF_IP_BLOCKED_NODE');
    }
  }

```

2-aproach (this is a recommended way. Because hook\_init() will be removed from drupal v8):

```
// in template.php
function MY_THEME_preprocess_page(&$variables) {
  if($variables['user']->hostname == 'BLOCKED_IP') {
    drupal_goto('node/NID_OF_IP_BLOCKED_NODE');
  }
}

```

# Answer
> 1 votes
httpbl has a similar concept and it seems that it's using hook\_boot.

So you might have something similar to:

```
/**
 * Implements hook_boot()
 */
function example_boot() {
  $result = example_check_ip(); // Check IP immediately upon access
  if ($result) {
    if ($_GET['q'] == '<URL_TO_NODE_YOU_WANT_TO_DISPLAY_IF_IP_IS_BLOCKED') {
      return;
    }

    drupal_goto('<URL_TO_NODE_YOU_WANT_TO_DISPLAY_IF_IP_IS_BLOCKED');
  }
}

```

---
Tags: nodes, hooks
---


# Question
Title: Checkboxes options with class in form api
I need something like a filter on checkboxes #options in my form built via Form API. Is there a way to group checkboxes or add a class to filter them via js front side?

In the documentation options are simply 'value' =\> 'label'. Can I filter or group them?

# Answer
To modify how drupal outputs checkboxes, override the default `theme_checkbox` function found in `includes/form.inc`. This allow to you add classes and all other stuff. I simply copied the function and changed the last 8 lines:

```
/* Override theme_checkbox to display titles as facebook-style beautytips  */
function MYTHEME_checkbox($variables) {
  $element = $variables['element'];
  $element['#attributes']['type'] = 'checkbox';
  element_set_attributes($element, array('id', 'name', '#return_value' => 'value'));

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
    $element['#attributes']['checked'] = 'checked';
  }
  _form_set_class($element, array('form-checkbox'));

  if (substr($element['#name'],0, 13) == "field_MYFIELD") :
    $element['#attributes']['class'][] = 'beautytips';
    return
      '<input title="' . $element['#title'] .'" ' .
      drupal_attributes($element['#attributes']) . ' />';
  else: // Return the regular value
    return '<input ' . drupal_attributes($element['#attributes']) . ' />';
  endif;
}

```

Thanks @clive for the inspirtation.
> 1 votes

# Answer
If you want to display check boxes options as `optgroup`, then `Drupal` already provide this functionality. You need to set `multidimensional` array for `#options` field.

Example:

```
$options = = array (

   'parent1' => array(
      3 => 'child1',
      4 => 'child2',
      5 => 'child3',
    ),
    'parent2' => array(
      8 => 'child1',
      9 => 'child2',
    ),
);

$form['FIELDNAME'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Checkbox'
    '#options' => $options,
);

```
> 0 votes

---
Tags: forms
---


# Question
Title: How to bulk delete content of a given type?
I need to delete all content of a content type. I'm allowed to select up to 50 node per deletion process. My problem is that I have 900 nodes then I need to repeat this 18 times.

Anyway to select all nodes to mass delete them?

# Answer
> 5 votes
Check the Views Bulk Operation module. This allows you to create list for exactly this purpose and gives you some other interesting functions.

# Answer
> 0 votes
I dont see any modules, Try adding a custom page and put this code

```
<?php
$node_type = 'MYTYPE';
  //fetch the nodes we want to delete
  $result = db_query("SELECT nid FROM {node} WHERE type='%s'",$node_type);
  while ($row = db_fetch_object($result)){
    set_time_limit(20);
    node_delete($row->nid);
    $deleted_count+=1;
  }
  //simple debug message so we can see what had been deleted.
  drupal_set_message("$deleted_count nodes have been deleted");
?>

```

Edit Accordingly

# Answer
> 0 votes
Enable the Devel generate module, then use Drush, one command does it all, easy.

```
drush genc 0 --kill --types='your_content_type_name'

```

# Answer
> 0 votes
Can you try Delete all module, navigate to 'admin/content/delete\_content' and you will be presented with a form for deletion of content belonging to certain content types. I tend to agree that this solution is more suitable for this use-case compared to the accepted answer (which is also a viable solution).

Regards

# Answer
> 0 votes
If you want to perform bulk operations, then I would recommend Administration Views module.

> **Features**
>
> * Filter all administrative views via AJAX.
> * Perform any kind of bulk/mass operations on items in administrative views.
> * Filter content by title, node type, author, published status, and/or vocabulary.
> * Filter comments by title, author, node title, or published status.
> * Filter users by name, ban/blocked status, or user roles.

---
Tags: nodes
---


# Question
Title: How to host and play videos in a drupal site?
Just that, I need to host and play videos in a drupal site. I mean not using vimeo, youtube...

# Answer
Something along the lines of the Video module?

> Video module allows you to upload video in any format, play video in any format, transcode video to H.246, Theora, VP8 using Zencoder or FFMPEG automatically creates video thumbnails, stream videos from cloud, HTML5 videos with mobile device playback compatibility. Very reliable API for converting videos and auto thumbnail, embed video to node body using WYSIWYG module (D7 only) and many more.
> 12 votes

# Answer
Another viable option is the MediaElement.js module. I've had great success with it, and it's HTML5 too! If your site is on Drupal 7 of course. This module also does sound files as well.
> 6 votes

# Answer
You can host and play video using Kaltura module

> Kaltura is the world's leading Open-Source Video Platform, providing video management, publishing, authoring, distribution and monetization solutions for media companies, enterprises, educational institutions and service providers. Our customers include HBO, ABC, Disney, Best Buy, Texas Instruments, NYU, MIT, Cornell, and many others.

* Drupal 7 compliant (Kaltura also offers a module for Drupal 6)
* Easy upload of video, audio and image, with automatic transcoding
* Import video directly to your site or record from a webcam
* User Engagement - allow users to add video and audio comments on any page
* Reach your users anywhere and on any device (including iPhone and iPad, web, and set-top boxes
* Full control of the player and content – play your own ads and create your own related content
* Hosting, streaming and automatic transcoding of media - all seamlessly performed on the Kaltura cloud (or on your local Kaltura installation)
* Easy skinning, theming and integration with other Drupal modules
* Flexibility and granularity - Each media file is created as a Drupal Video Field
* Drupal permissions integration – Administrators decide who can view/edit content and metadata, with granular permissions at field level
* Full integration with Drupal Views - including predefined views
* Full synchronization of content, metadata and tags between Drupal and the Kaltura system
> 2 votes

---
Tags: files
---


title: Webform - Multilingual Support

text:
# Question
Title: Webform - Multilingual Support
I have a webform which is built in English. I need to add two more languages. Is that possible to display many languages in webform?

# Answer
Take a look at Webform Localization module

> The Webform Localization module provides multilingual features to the Webform Module. Special options in the webform and component configuration let you enable different ways to manage translation of forms and questionnaires.
> 0 votes

---
Tags: nodes, webforms, i18n-l10n, forms
---


# Question
Title: changing display depending on fields value
I want to change how a field value can be displayed to the front-end user,

For example I have an Article content type which have a priority fields, this priority can be either low or high as a value...

so I want when the priorty is high, my displayed view show me an image icon instead of the high value.

# Answer
Another approach is to use `MY_THEME_preprocess_node(&$variables)` in template.php and build your logic according to $variables array elements (e.g. $variables\['field\_priority'\]). Example:

```
function MY_THEME_preprocess_node(&$variables) {
  if($variables['type'] == 'page') {
    $priority = $variables['field_priority'];

    if($priority > 0 && $priority < 2) {
      // do_first_logic()
    }
    elseif($priority > 2 && $priority < 4) {
      // do_second_logic()
    }
    // .... so on
  }
}

```
> 1 votes

# Answer
I think you are looking for Field conditional state module.

> With field conditional state module you can set #state form field attribute based on value selected in other form fields. Module splits fields into two types:

* control field - field which set #state attribute based on the value from that field,
* controled field - field for which #state attribute is set based on the value from the control field.

(or)

You can try Conditional Fields module which ability to modify fields appearance and behavior on certain conditions when viewing content.
> 0 votes

---
Tags: views, theming
---


# Question
Title: View to display the comments of the curent user nodes
Please how to create a simple view to display the comments of the curent user nodes, only comments, Thank you.

# Answer
When you add a new view (/admin/structure/views/add), you have the possibility to select Comments. It will list all comments.

Then you need to set a Contextual Filter and a Relation in order to get the comments of the current logged in user.
> 4 votes

---
Tags: views, comments
---


# Question
Title: Creating dynamic pages for content-type/taxonomy-term
I have two content types:

* news
* review

I have a taxonomy vocabulary attached to them with following terms

* tech
* entertainment
* other
* (More may come)

I need to have a listing of these contents in following format:

* tech/news (or news/tech)
* tech/reviews (or reviews/tech)
* other/news (or other/news)
* other/reviews (or other/reviews)

..and so on.

I could create a page for every required URL pattern and create a separate view for each. But is there any dynamic way to do it in views?

At least, can I add a drop down filter for content type on term pages?

I'm using Drupal 6.

Thanks for any help. :)

# Answer
> 0 votes
I think you can do something like this:

1. Create one page view and give him a path like: `%/%`
2. Add contextual filters
3. Create a module
4. Implement hook\_menu.

..

```
function test_menu() {
  $items['test/%term_name/%node_type_name'] = array(
    'title' => 'My test page',
    'page callback' => 'test_page_callback',
    'access callback' => TRUE,
    'page arguments' => array(1,2),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function test_page_callback($term_name, $node_type_name) {

  /**
   * here we are getting arguments from _to_arg() functions and processing them to
   * get $tid and $SECOND_ARGUMENT
   */

  return render(views_embed_view('test_veiw', 'test_display', $tid, $SECOND_ARGUMENT));
}

function term_name_to_arg() {
  // return term_name as argument
}

function node_type_name_to_arg() {
// return node_type_name as argument
}

```

---
Tags: views, nodes, taxonomy-terms, 6
---


title: content type form doesn't save data?

text:
# Question
Title: content type form doesn't save data?
I have a content type that want to display it's form in block to any user types but when putting the form fields in my custom form style the form doesn't save any data although there are the required render items inside my custom form .tpl file

```
<?php print drupal_render($form['form_build_id']); ?>
<?php print drupal_render($form['form_id']); ?>
<?php print drupal_render($form['form_token']); ?>

```

All of the form configuration to appear to the has been added but the problem in form saving.

```
<h3>
    <i class='sprite blue-circle'></i>

</h3>
<!-- -->
<div class="row">
  <div class="calc-header">

  </div>
  <div class="installment">
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <label >
              <input type="radio" id="edit-field-installment-car-state-und-" name="field_installment_car_state[und]" value=""  >
            </label>
            <label >
              <input type="radio" id="edit-field-installment-car-state-und---2" name="field_installment_car_state[und]" value="" checked="checked"  >
            </label>
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
              <label>
                <input type="radio" id="edit-field-installment-process-type-und-" name="field_installment_process_type[und]" value=""  >
              </label>
              <label>
                <input type="radio" id="edit-field-installment-process-type-und---2" name="field_installment_process_type[und]" value="" checked="checked" >
              </label>
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="car_type" type="text" name="field_installment_car_type[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
              <input id="manf_year" type="number" name="field_installment_manf_year[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="car_value" type="number" name="field_installment_value[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
              <input id="period" type="number" name="field_installment_period[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
  </div>
</div>
<br />
<br />
<div class="row">
  <div class="calc-header">

  </div>
  <div class="installment">
    <!-- First row -->
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="name" type="text" name="field_installment_name[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
           <!-- <span>
            <label >
              <input type="radio" name="field_installment_gender[und]" value="" checked>

            </label>
            <label >
              <input type="radio" name="field_installment_gender[und]" value="">

            </label> -->
           </span>
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="nationality" type="text" name="field_installment_nationality[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="age" type="number" name="field_installment_age[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="comm_record_num" type="text" name="field_installment_location[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="source" type="text" name="field_installment_source[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>

    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="work_palce" type="text" name="field_installment_work_destinatin[und][0][value]" value="" placeholder=" " required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="job_name" type="text" name="field_installment_job_name[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>

    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="service_period" type="number" name="field_installment_service_period[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">
                             </label>
          </td>
          <td>
             <input id="total_salary" type="number" name="field_installment_total_salary[und][0][value]" value="" placeholder="">
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>

    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
            <input id="mobile" type="tel" name="field_installment_mobile[und][0][value]" value="" placeholder="" required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="total_salary" type="number" name="field_installment_total_salary[und][0][value]" value="" placeholder=" ">
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>

    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input type="checkbox" name="field_installment_income" value="" checked>
             <?php  //print render($field_installment_income); ?>
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="income" type="text" name="field_installment_remember[und][0][value]" value="" placeholder=" " required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>

     <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
              <label >
                <input type="radio" id="edit-field-installment-maritul-status-und-" name="field_installment_maritul_status[und]" value="" >

              </label>
              <label >
               <input type="radio" id="edit-field-installment-maritul-status-und---2" name="field_installment_maritul_status[und]" value="" checked="checked" >

              </label>
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="col-sm-6 car-price calc-wrapper">
      <table border="true" cellpadding="0">
        <tr>
          <td class='table-form-lable'>
            <label for="">

            </label>
          </td>
          <td>
             <input id="family_num" type="number" name="field_installment_family_num[und][0][value]" value="" placeholder=" " required  >
          </td>
          <td class='required-cell'>
            <img src="<?php print base_path().path_to_theme().'/'; ?>images/required-field-icon-red.png">
          </td>
        </tr>
      </table>
    </div>
    <div class="clearfix"> </div>
  </div>
</div>
<br>
<br>

<div class="row">
  <hr>
  <label class='checkbox'>
    <input type="checkbox" name="field_installment_validation[und]" value="" required >
    <?php  //print render($field_installment_validation); ?>

  </label>
  <br>
  <br>
  <div class="field pull-right span2"> <!-- <div class="pull-right"> -->
    <!-- <input id="submit" type="submit" name="submit" value="" class="btn"> -->
    <?php print drupal_render($form['form_build_id']); ?>
    <?php print drupal_render($form['form_id']); ?>
    <?php print drupal_render($form['form_token']); ?>
    <?php  //print render($actions); ?>
    <?php  print render($actions); ?>
  </div>
</div>

```

# Answer
I would suggest that you call the drupal node form (as described here)

You can use hook\_form\_alter to unset the form elements you do not wish to appear, or set them to hidden.

You may wish to add a condition to assess the context of the form based on path or by testing for a configured context if you are using the context module. This will mean you can still get the full form on the node edit page.
> 0 votes

# Answer
It's now working. I have followed the instructions related to theming a form in Drupal as follows:

1. In template.php, I added all the form elements and removed all the input fields prefix and suffix, and used the following code

```
function THEME_preprocess_[form_id]_form(&$variables) {
  // Send all the form elements to the custom form file.
}

```
2. in \[form\_id\].tpl.php, I rendered the fields that I need by using the following code

```
<?php print render($[field_name_sent_by_the_template_file]); ?>

```
> 0 votes

# Answer
I think you should use `print drupal_render($form['actions'])` instead of `print render($actions);`, I hope it helps.
> -1 votes

---
Tags: forms, nodes
---


title: Drupal7/Search Module & Pagination

text:
# Question
Title: Drupal7/Search Module & Pagination
1. I am looking for a People directory Search Module. Something like what they used on top of the link: http://wws.princeton.edu/directory
2. Also in the link above, they have pagination on the top and bottom of the page. In my case when I set the 'Pager' in Drupal Admin, it adds the pagination block to the bottom of the page. How would I move it to the top instead?

Thanks. Boutros.

# Answer
> 1 votes
**Filter :**

A views module will do the same with few tweaks on exposed filters

like: Name filter operator (starts with) and show all (a-z) characters with link each character accordingly.

**Pagignation :**

You can have pagination on top and bottom by overwriting that views template. just print `print $pager;` where ever you required.

Its better to not load another modules help for something that can be achieved with small changes. :)

---
Tags: search, paging
---


title: Adding Manual Code to Front Page

text:
# Question
Title: Adding Manual Code to Front Page
I have written HTML code which includes some JQuery code and some CSS. It basically gives me the Advanced Search button (some select button, text box and submit button). I have tested it outside Drupal and it is working perfectly. I have written whole code in one file. When I tried to copy that code and put it in the blocks, it messed up the front page. I removed it. All the CSS, styling of Front page was messed up.

How do I add that code in Drupal so that it shows me that advanced search block on the content region of the Front Page?

I have attached the Output. I hope you will understand the code now.

**CODE**

```
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#less").hide();
  $("#more").click(function(){
   $(".views-widget_before").hide();
    $("#panel").slideDown("slow");
    $("#more").slideUp();
    $("#less").slideDown();
  });

 $("#less").click(function(){
    $("#panel").slideUp("slow");
    $(".views-widget_before").show();
    $("#less").slideUp();
   $("#more").slideDown();

  });
});

</script>

<style type="text/css">
#panel,#flip
{

//padding:15px;
//text-align:center;
//background-color:#e5eecc;
//border:solid 1px #c3c3c3;
}
#panel
{
//padding:50px;
display:none;
}
</style>

<style>

.views-widget
{
display:inline;
float:left;
padding: 0.5em 1em 0 0;
}
div
{
margin:0;
border:0;
outline:0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
display: inline;
}

.form-submit {
    background-image: url(http://etraining-dev.esc.rl.ac.uk/Apply.jpg);
    background-position:  0px 0px;
    background-repeat: no-repeat;
    width: 48px;
    height: 25px;
    border: 0px;

}
.form-submit:hover{
//      background-position:  0px -52px;
}

.form-submit:active{
      background-position:  0px -104px;
}

A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {font-size:32; font-weight:bold; color: red;}

.font-family
{
//font-family: "Lucida Sans Typewriter", "Lucida Console", Monaco, "Bitstream Vera Sans Mono", monospace;
font-family: 'Droid Sans',arial,serif;
line-height: 1.5em;
color:#333
}
.advanced
{
display:inline;
}

</style>
</head>

<body>
<form action = "advanced_search_dev" method= "get" id = "views-exposed-form-advanced-search-dev-page-11" accept-charset="UTF-8"><div><div class = views-exposed-form1">
<div class = "views-widget_before">
<div class = "font-family">
<b> Keyword </b> <br>
<input title="Enter the terms you wish to search for." type="text" id="edit-keys" name="keys" value="" size="15" maxlength="128" class="form-text">
</div>
</div>
 <div class = "views-widget_before" style = "display:inline">
<input type="submit" id="edit-submit-advanced-search-dev" name="" value=" " class="form-submit">
</div>
</form>
<div class = "font-family">

<div id="more"><a href = "#" style = "font-size:18px; ">More Option</a></div>

<div id="less"><a href = "#"><b>Less Option</b></a></div>
</div>
<div class = "advanced">
<div id="panel">
<form action="advanced_search_dev" method="get" id="views-exposed-form-advanced-search-dev-page-1" accept-charset="UTF-8">
<div class = "font-family">
<div class="views-exposed-form">
<fieldset>
<legend><b>Search for Training</b></legend>
<div class = "views-widget">
<div class = "type">
<b>Type</b><br>
<select id="edit-type" name="type" class="form-select">
<option value="All" selected="selected">- Any -</option>
<option value="event">Events</option>
<option value="online_training">Materials</option>
<option value="training_resources">Resources</option>
<option value="webinar">Webinars</option>
</select>
</div>

<div class = "views-widget">
<div class = "country">
<b>Country</b><br>
<select id="edit-tid" name="tid" class="form-select">
<option value="All" selected="selected">- Any -</option>
<option value="10909">Afghanistan</option>
<option value="10910">Albania</option>
<option value="10911">Algeria</option>
<option value="10912">American Samoa</option>
<option value="10913">Andorra</option>
<option value="10914">Angola</option>
<option value="10915">Anguilla</option>
<option value="10916">Antarctica</option>
<option value="10917">Antigua</option>
<option value="10918">Argentina</option>
<option value="10919">Armenia</option>
<option value="10920">Aruba</option>
<option value="10921">Australia</option>
<option value="10922">Austria</option>
<option value="10923">Azerbaijan</option>
<option value="10924">Bahamas</option>
<option value="10925">Bahrain</option>
<option value="10926">Bangladesh</option>
<option value="10927">Barbados</option>
<option value="10928">Belarus</option>
<option value="10929">Belgium</option>
<option value="10930">Belize</option>
<option value="10931">Benin</option>
<option value="10932">Bermuda</option>
<option value="10933">Bhutan</option>
<option value="10934">Bolivia</option>
<option value="10935">Bosnia and Herzegovina</option>
<option value="10936">Botswana</option>
<option value="10937">Brazil</option>
<option value="10938">British Virgin Islands</option>
<option value="10939">Brunei</option>
<option value="10940">Bulgaria</option>
<option value="10941">Burkina Faso</option>
<option value="10942">Burma</option>
<option value="10943">Burundi</option>
<option value="10944">Cambodia</option>
<option value="10945">Cameroon</option>
<option value="10946">Canada</option>
<option value="10947">Cape Verde</option>
<option value="10948">Central African Republic</option>
<option value="10949">Chad</option>
<option value="10950">Chile</option>
<option value="10951">China</option>
<option value="10952">Colombia</option>
<option value="10953">Comoros</option>
<option value="10954">Congo</option>
<option value="10955">Congo (Zaire)</option>
<option value="10956">Cook Islands</option>
<option value="10957">Costa Rica</option>
<option value="10958">Cote d'Ivoire (Ivory Coast)</option>
<option value="10959">Croatia</option>
<option value="10960">Cuba</option>
<option value="10961">Cyprus</option>
<option value="10962">Czech Republic</option>
<option value="10963">Denmark</option>
<option value="10964">Djibouti</option>
<option value="10965">Dominica</option>
<option value="10966">Dominican Republic</option>
<option value="10967">Ecuador</option>
<option value="10968">Egypt</option>
<option value="10969">El Salvador</option>
<option value="10970">Equatorial Guinea</option>
<option value="10971">Eritrea</option>
<option value="10972">Estonia</option>
<option value="10973">Ethiopia</option>
<option value="10974">Falkland Islands</option>
<option value="10975">Federated States of Micronesia</option>
<option value="10976">Fiji</option>
<option value="10977">Finland</option>
<option value="10978">France</option>
<option value="10979">French Guiana</option>
<option value="10980">French Polynesia</option>
<option value="10981">Gabon</option>
<option value="10982">Gaza Strip and West Bank</option>
<option value="10983">Georgia</option>
<option value="10984">Germany</option>
<option value="10985">Ghana</option>
<option value="10986">Gibraltar</option>
<option value="10987">Greece</option>
<option value="10988">Greenland</option>
<option value="10989">Grenada</option>
<option value="10990">Guadeloupe</option>
<option value="10991">Guam</option>
<option value="10992">Guatemala</option>
<option value="10993">Guinea</option>
<option value="10994">Guinea-Bissau</option>
<option value="10995">Guyana</option>
<option value="10996">Haiti</option>
<option value="10997">Honduras</option>
<option value="10998">Hong Kong</option>
<option value="10999">Hungary</option>
<option value="11000">Iceland</option>
<option value="11001">India</option>
<option value="11002">Indonesia</option>
<option value="11003">Iran</option>
<option value="11004">Iraq</option>
<option value="11005">Ireland</option>
<option value="11006">Israel</option>
<option value="11007">Italy</option>
<option value="11008">Jamaica</option>
<option value="11009">Japan</option>
<option value="11010">Jordan</option>
<option value="11011">Kazakhstan</option>
<option value="11012">Kenya</option>
<option value="11013">Kiribati</option>
<option value="11014">Kuwait</option>
<option value="11015">Kyrgyzstan</option>
<option value="11016">Laos</option>
<option value="11017">Latvia</option>
<option value="11018">Lebanon</option>
<option value="11019">Lesotho</option>
<option value="11020">Liberia</option>
<option value="11021">Libya</option>
<option value="11022">Liechtenstein</option>
<option value="11023">Lithuania</option>
<option value="11024">Luxembourg</option>
<option value="11025">Macau</option>
<option value="11026">Macedonia</option>
<option value="11027">Madagascar</option>
<option value="11028">Malawi</option>
<option value="11029">Malaysia</option>
<option value="11030">Maldives</option>
<option value="11031">Mali</option>
<option value="11032">Malta</option>
<option value="11033">Marshall Islands</option>
<option value="11034">Martinique</option>
<option value="11035">Mauritania</option>
<option value="11036">Mauritius</option>
<option value="11037">Mayotte</option>
<option value="11038">Mexico</option>
<option value="11039">Moldova</option>
<option value="11040">Monaco</option>
<option value="11041">Mongolia</option>
<option value="11131">Montenegro</option>
<option value="11042">Montserrat</option>
<option value="11043">Morocco</option>
<option value="11044">Mozambique</option>
<option value="11045">Namibia</option>
<option value="11046">Nauru</option>
<option value="11047">Nepal</option>
<option value="11048">Netherlands</option>
<option value="11049">Netherlands Antilles</option>
<option value="11050">New Caledonia</option>
<option value="11051">New Zealand</option>
<option value="11052">Nicaragua</option>
<option value="11053">Niger</option>
<option value="11054">Nigeria</option>
<option value="11055">North Korea</option>
<option value="11056">Northern Mariana Islands</option>
<option value="11057">Norway</option>
<option value="11058">Oman</option>
<option value="11059">Pakistan</option>
<option value="11060">Palau</option>
<option value="11061">Panama</option>
<option value="11062">Papua New Guinea</option>
<option value="11063">Paraguay</option>
<option value="11064">Peru</option>
<option value="11065">Philippines</option>
<option value="11066">Pitcairn Islands</option>
<option value="11067">Poland</option>
<option value="11068">Portugal</option>
<option value="11069">Puerto Rico</option>
<option value="11070">Qatar</option>
<option value="11071">Reunion</option>
<option value="11072">Romania</option>
<option value="11073">Russia</option>
<option value="11074">Rwanda</option>
<option value="11075">Saint Kitts and Nevis</option>
<option value="11076">Saint Lucia</option>
<option value="11077">Saint Pierre and Miquelon</option>
<option value="11078">Saint Vincent and the Grenadines</option>
<option value="11079">Samoa</option>
<option value="11080">San Marino</option>
<option value="11081">Sao Tome and Principe</option>
<option value="11082">Saudi Arabia</option>
<option value="11083">Senegal</option>
<option value="11084">Serbia</option>
<option value="11085">Seychelles</option>
<option value="11086">Sierra Leone</option>
<option value="11087">Singapore</option>
<option value="11088">Slovakia</option>
<option value="11089">Slovenia</option>
<option value="11090">Solomon Islands</option>
<option value="11091">Somalia</option>
<option value="11092">South Africa</option>
<option value="11093">South Korea</option>
<option value="11094">Spain</option>
<option value="11095">Sri Lanka</option>
<option value="11096">Sudan</option>
<option value="11097">Suriname</option>
<option value="11098">Swaziland</option>
<option value="11099">Sweden</option>
<option value="11100">Switzerland</option>
<option value="11101">Syria</option>
<option value="11102">Taiwan</option>
<option value="11103">Tajikistan</option>
<option value="11104">Tanzania</option>
<option value="11105">Thailand</option>
<option value="11106">The Gambia</option>
<option value="11107">The Holy See</option>
<option value="11108">Togo</option>
<option value="11109">Tonga</option>
<option value="11110">Trinidad and Tobago</option>
<option value="11111">Tunisia</option>
<option value="11112">Turkey</option>
<option value="11113">Turkmenistan</option>
<option value="11114">Turks and Caicos Islands</option>
<option value="11115">Tuvalu</option>
<option value="11116">Uganda</option>
<option value="11117">Ukraine</option>
<option value="11118">United Arab Emirates</option>
<option value="11119">United Kingdom</option>
<option value="11120">United States of America</option>
<option value="11121">United States Virgin Islands</option>
<option value="11122">Uruguay</option>
<option value="11123">Uzbekistan</option>
<option value="11124">Vanuatu</option>
<option value="11125">Venezuela</option>
<option value="11126">Vietnam</option>
<option value="11127">Western Sahara</option>
<option value="11128">Yemen</option>
<option value="11129">Zambia</option>
<option value="11130">Zimbabwe</option>
</select>
</select>
</div>

<div class = "views-widget">
<b>Project</b><br>
<select id="edit-tid-1" name="tid_1" class="form-select">
<option value="All" selected="selected">- Any -</option>
<option value="16110">CERN</option>
<option value="16111">CLARIN</option>
<option value="16112">DARIAH</option>
<option value="16113">EGI-InSPIRE</option>
<option value="16114">EMI</option>
<option value="16128">ENVRI</option>
<option value="16115">EPSRC</option>
<option value="16116">EUDAT</option>
<option value="16129">GridPP</option>
<option value="16117">HMRC</option>
<option value="16118">LSGC</option>
<option value="16119">MeDIA</option>
<option value="16120">NAG</option>
<option value="16121">NSCCS</option>
<option value="16122">PRACE</option>
<option value="16123">Scalalife</option>
<option value="16124">SeIUCCR</option>
<option value="16125">SSI</option>
<option value="16126">STFC</option>
<option value="16127">WeNMR</option>
</select>
</div>

<div class = "views-widget">
<b>Research Community</b><br>
<select id="edit-tid-2" name="tid_2" class="form-select">
<option value="All" selected="selected">- Any -</option>
<option value="16064">Agricultural Sciences</option>
<option value="16065">-Agricultural biotechnology</option>
<option value="16066">-Agriculture, forestry, and fisheries</option>
<option value="16067">-Animal and dairy science</option>
<option value="16068">-Veterinary science</option>
<option value="16069">Engineering and Technology</option>
<option value="16070">-Aerospace engineering</option>
<option value="16071">-Bioengineering and Biomedical engineering</option>
<option value="16072">-Chemical engineering</option>
<option value="16073">-Civil Engineering</option>
<option value="16074">-Electrical, electronic and information engineering</option>
<option value="16075">-Environmental biotechnology</option>
<option value="16076">-Environmental engineering</option>
<option value="16077">-Industrial Biotechnology</option>
<option value="16078">-Materials engineering and science</option>
<option value="16079">-Mechanical engineering</option>
<option value="16080">-Nano-technology</option>
<option value="16081">Humanities</option>
<option value="16082">-Arts</option>
<option value="16083">-History and Archaeology</option>
<option value="16084">-Languages and literature</option>
<option value="16085">-Philosophy, ethics and religion</option>
<option value="16086">Medical and Health Sciences</option>
<option value="16087">-Basic medicine</option>
<option value="16088">-Clinical medicine</option>
<option value="16089">-Health sciences</option>
<option value="16090">-Medical biotechnology</option>
<option value="16091">Natural Sciences</option>
<option value="16092">-Biological sciences</option>
<option value="16093">-Computer sciences</option>
<option value="16094">-Earth sciences</option>
<option value="16095">-Information sciences</option>
<option value="16096">-Mathematics</option>
<option value="16097">-Space Science</option>
<option value="16098">Physical Sciences</option>
<option value="16099">-Chemical sciences</option>
<option value="16100">-Physics</option>
<option value="16101">Social Sciences</option>
<option value="16102">-Economics, finance and business</option>
<option value="16103">-Educational sciences</option>
<option value="16104">-Law</option>
<option value="16105">-Media and communications</option>
<option value="16106">-Political Science</option>
<option value="16107">-Psychology</option>
<option value="16108">-Social and economic geography</option>
<option value="16109">-Sociology</option>
</select>
</div>

<div class = "views-widget">
<b> Keyword </b> <br>
<input title="Enter the terms you wish to search for." type="text" id="edit-keys" name="keys" value="" size="15" maxlength="128" class="form-text">
</div>

 <div class = "views-widget" style = "display:inline">
<input type="submit" id="edit-submit-advanced-search-dev" name="" value=" " class="form-submit">
</div>
</fieldset>
</form>
</div>
</body>
</html>

```

Please help?

# Answer
> 1 votes
This is a very broad question and it will be hard to answer it completely.

I suggest that you use a tutorial to learn to create custom blocks. Make sure you separate CSS and JS into separate files and use the `attached` property to add the CSS and JS to the output.

If needed, come back to this site and ask more specific questions.

---
Tags: theming, blocks
---


# Question
Title: 500 internal server error while installing
What is the reason for the error "500 internal server error" while trying to install drupal,

1. i have created database successfully
2. After that i have downloaded and extracted the drupal 7.22 in my desired directory.

But when i trying to install the tables in my database its showing the error and approximately more than 30 tables are storing and the installation process stops automatically with showing the above error . Can anybody tell me why the error is coming.

# Answer
As Clive says above, it's nearly impossible to help without knowing more about your particular setup and debug info.

Common pitfalls are :

* Various php.ini settings : `max_execution_time` as mentioned by monymirza above, but also `memory_limit`. This last can be raised during install and dev, then lowered for production.
* Lacking `.htaccess` at Drupal's root. Standard unix commands often don't copy hidden files, and `.htaccess` is more or less mandatory for D7 to work.
* Lousy DB connection, particularly on shared hosting.
* Misconfigured vhost : perhaps a particular setting messes up things between domains, or subdomains. Also, you have to check the `AllowOverride All` directive on Drupal directory for it to function properly.

There are others, but these should get you started.
> 2 votes

# Answer
Thanks for those hints.

In my instance, the site was installed on a Virtual Host inside Virtualmin/Webmin, which contains symbolic links in the public folder pointing to "awstatsicons".

The Drupal .htaccess file contains a directive to follow symbolic links in the installation directory:

```
# Follow symbolic links in this directory.
  Options +FollowSymLinks

```

Commenting out the Options +FollowSymLinks allowed the installation script to run:

```
# Follow symbolic links in this directory.
# Options +FollowSymLinks

```

However, I subsequently learned that Drupal needs to be able to follow Symlinks to work, so changing that to:

```
# Follow symbolic links in this directory.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

```

This needs to be repeated in the .htaccess located at sites/default/files seems to work.
> 0 votes

# Answer
Try to delete/move all of the modules to another place. Then try to move back again one by one and try to see the output. In this way bring back all the modules and try to see the output. Then most probably you will be done or atleast you may know the module which making problem.
> 0 votes

---
Tags: database, installation
---


# Question
Title: Administer Users by Role module - show users
I'm using Administer Users by Role module and I crated a view of users.
That view displays all the users.
Lets assume there is 'Admin', 'Editor' & 'Member' roles.
Admin can see all the users.
Editor can see only Members (not other Editors and not the admin).
I need that so I can use Views-Data-Export module.

How to create such a view? or any other suggestions?

# Answer
I don't know whether this is correct or not but you can try this,

```
function mymodule_views_query_alter(&$view, &$query)
{
 global $user;
 $role=implode(', ', array_slice($user->roles, 1));//get the current user role
if ($view->name == 'your_view_name')
{
  switch ($role) {
    case 'administrator':
//  drupal_set_message("administrator");
     // $query->add_where(); put your where condition
     // $view->query->set_group_operator('OR');
        break;
    case 'editor':
//  drupal_set_message("editor");
     // $query->add_where(); put your where condition
     // $view->query->set_group_operator('OR');
        break;
    case 'Member':
    //  drupal_set_message("Member");
      // $query->add_where(); put your where condition
     // $view->query->set_group_operator('OR');
        break;
        }
    }

}

```
> 1 votes

---
Tags: views, users, importing-exporting
---


# Question
Title: MSSQL Incompatibility with Organic Group Views Filter Handlers
I have a view which filters all the organic groups for a user. I wanted to add a Views Filter to filter by OG Role, however it is not possible.

I would very much appreciate any help. Basically any OG Role filter using a Views Filter Handler cannot be used if the database is an MSSQL database. When selecting one of the filters, it errors out and then the view has to be re-created since the view can no longer be shown within the UI. I opened a drupal issue a few months ago, but no response as of yet.

The error message is as follows:

> PDOException: SQLSTATE\[42000\]: \[Microsoft\]\[SQL Server Native Client 11.0\]\[SQL Server\]Column 'og\_role.rid' is invalid in the select list because it is not contained in either an aggregate function or the `GROUP BY` clause.: `SELECT r.*, r.name AS _field_0 FROM {og_role} r GROUP BY r.name;` `Array ( )` in `og_handler_filter_user_roles->get_value_options()` (line 14 of C:\inetpub\wwwroot\sites\all\modules\og\includes\views\handlers\og\_handler\_filter\_user\_roles.inc).

I'm almost postive that I have to rewrite Line 13 to support SQLSRV database types.

Line 13: `->groupBy('r.name')`

Here is the relevant code:

```
/**
 * Field handler to provide a list of OG roles of a user.
 */
class og_handler_filter_user_roles extends views_handler_filter_many_to_one {

  function get_value_options() {
    $this->value_options = array();
    // Get all role names.
    $results = db_select('og_role', 'r')
      ->fields('r')
      ->groupBy('r.name')
      ->execute();
    foreach ($results as $result) {
      $this->value_options[$result->name] = $result->name;
    }
  }

  function query() {
    // Get the og_membership table from relations.
    foreach ($this->query->relationships as $alias => $info) {
      if ($info['table'] == 'og_membership') {
        // If there is a og_membership table present. Add some conditions.
        $rel = $this->relationship;
        $this->query->add_where_expression(NULL, $alias . '.gid = ' . $rel . '.gid');
        $this->query->add_where_expression(NULL, $alias . '.group_type = ' . $rel . '.group_type');
        break;
      }
    }

    parent::query();
  }
}

```

# Answer
> 1 votes
I fixed it by changing Line 13 to:

```
->groupBy('r.name')
->groupBy('r.rid')
->groupBy('r.gid')
->groupBy('r.group_type')
->groupBy('r.group_bundle')

```

---
Tags: views, organic-groups, database
---


# Question
Title: Dynamically change Commerce Customer profile type on checkout
I need the following in Drupal Commerce:

* On checkout, two radios should be presented (e.g. Email & Postal)
* Upon selection of one of these, a different customer profile type should be attached to the order
* Only fields related to the selected profile type should dynamically show up.

I'm perfectly able to accomplish this through FormAPI, but that wouldn't be tied to the Commerce system unfortunately.

Someone knows how the right way?

Thanks

# Answer
If you can accomplish this through the Forms API, then go for it. There's no specific Commerce way to make this happen.
> 1 votes

---
Tags: commerce
---


# Question
Title: Heartbeat - user delete comment from node -> delete also from heartbeat stream
I'm using Heartbeat to show activity on the site. When user post comment to the node Heartbeat activity stream shows that comment. But when user delete comment it does not delete it from the Heartbeat activity stream.

How to delete comment also from Heartbeat activity stream? This should be done of course automatically when user delete comment from the node.

Same thing for deleting nodes.

In the Rules there was no Heartbeat log delete possibility.

# Answer
Heartbeat module implemented `hook_user_delete()` and `hook_node_delete()` hooks itself. take a look at their implementations.. I think you can implement `hook_comment_delete($comment)` hook in your module to delete activities from `heartbeat_activity` table. Here is the documentation.
> 1 votes

---
Tags: 7, nodes, comments, heartbeat
---


# Question
Title: Add css-class based on productpages' top level taxonomy term
So I have a website (created with drupal 7) where each product is linked to a taxonomyterms. This was done so that all products can easily be divided into several different categories.

So I have a taxonomy that looks somewhat like this:

**Top level item 01**

* Level 2 item 01
* Level 2 item 02
* Level 2 item 03

**Top level item 02**

* Level 2 item 04
* Level 2 item 05
* Level 2 item 06

Every 'top level' term (or categorie) has links that need to be in their own color. For Example: The product that is linked to the term 'Top level item 01' and all linked subitems need to have 'red' links. While the product that is linked to the term 'Top level item 02' and all linked subitems need to have 'blue' links.

I was thinking of adding a css class somewhere in my theme so that I could do something like:

```
.red a { color: #f00; }

```

But I can't seem to find how I should do that. Can aynone help me with that?

# Answer
> 0 votes
Try something like this in your theme's template.php file (put it into `MY_THEME_preprocess_page(&$variables)` function):

```
if(arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $tid = arg(2);
    $term = taxonomy_term_load($tid);
    $parent = taxonomy_get_parents($term->tid);

    if(empty($parent)) {
      $variables['classes_array']['parent_cat_color'] = $term->name;
      // or $variables['classes_array']['parent_cat_color'] = 'parent_cat_color' .. it's up to you..
    }
  }

```

and open `page.tpl.php` and put `$classes` variable into your wrapper div..

# Answer
> 0 votes
Add the vid (=vocabulary id) to the classes in field.tpl.php. Then you will have unique classes for every vocabulary and their childitems.

the vid is available in the $items-array.

---
Tags: theming, taxonomy-terms, commerce
---


# Question
Title: Autofill billing Information on checkout page in Drupal Commerce
I need to autofill the billing information on checkout with Drupal commerce.

I added to drupal user a field called 'field\_commerce\_billing' like a reference to 'Customer profile' entity and I want to autofill the checkout with the customer profile fields values if an user is logged in.

# Answer
> 4 votes
This code works for me.

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

  if ($form_id == 'commerce_checkout_form_checkout' && $user->uid) {
    $user = user_load($user->uid);
    $loaded_billing = commerce_customer_profile_load($user->field_commerce['und'][0]['profile_id']);

    // For each field in customer profile, fill the form field with the $user value.
    $form['customer_profile_billing']['commerce_customer_address']['und'][0]['#address'] = $loaded_billing->commerce_customer_address['und'][0];
    $form['customer_profile_billing']['field_telephone_number']['und'][0]['value']['#default_value'] = $loaded_billing->field_telephone_number['und'][0]['value'];
  }
}

```

I tried to retrieve the *commerce\_customer\_profile* field list, but I didn't find a way to generalize an action for filling every field type in the form.

---
Tags: commerce
---


# Question
Title: How can I print render just location city in teaser view
Drupal 7

I am attempting to print just the city value within the location array.

I have created a content type with location and created a custom node template node--content.tpl.php. Inside of my if ($teaser) statement I have the following code:

```
hide($content['field_event_location']);
print render($content)

```

Which effectively hides the full field\_event\_location and renders all other content listed in the display settings of drupal 7 admin. I am attempting to render the city field with the following line:

```
print render($content['field_event_location']['und'][0]['city'])

```

I used

```
print_r($content);echo

```

to print the array with the following results:

```
[field_event_location] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [lid] => 167
                        [street] => 4501 Main Street
                        [additional] =>
                        [city] => Kansas City
                        [province] =>
                        [postal_code] => 64130
                        [country] => us
                        [source] => 3
                        [is_primary] => 0
                        [province_name] =>
                        [country_name] => United States
                        [email] =>
                        [phone] =>
                    )

            )

    )

```

I did some basic de-bugging I found from this post (How to print render Location's sub-fields?), and was able to print `render($content['body'])` as well as get the full location output from `print render($content['field_event_location'])`

# Answer
> 1 votes
The dirty way is : don't user "render".

Just print it:

```
print $content['field_event_location']['und'][0]['city'];

```

# Answer
> 1 votes
Have you tried to grab the data from the node? Try this:

print $node-\>field\_event\_location\['und'\]\[0\]\['city'\];

---
Tags: 7, nodes, entities, location
---


title: Remove Node Reference

text:
# Question
Title: Remove Node Reference
in the upcoming weeks my client want me change some node reference options on his page.

I got 2 content types, press release and press office. When they create a new press release, they are able to reference to a press office via the "References" Module.

Now they want me to remove some of the press offices and add some new. Thats not the problem, when I remove the old press offices the old nodes lose their references as well. But they want the old nodes keep their references, which sounds logical to me, but I've no idea how to do that.

Greetings from germany

sg

# Answer
If I'm clear, you don't actually want to remove any of the press offices because existing press releases should still be able to reference them, you just want to remove the option to associate new press releases with certain press offices (while at the same time, creating some new press offices that can be referenced).

So really, we just want to *filter* the list of press offices that can be referenced by new press releases.

I would suggest that you add a new boolean field to the press offices, something like: *"Can be referenced"*. Then create a view that filters press offices on that field. Finally, configure your Entity Reference field Mode to use *"Views: Filter by an entity reference view"* and select the view you just created.
> 0 votes

---
Tags: nodes
---


# Question
Title: How to hide 'Configuration' tab for specific user
I'm looking for a way to configure the Backend for a specific user. For example: I want to hide the 'Configuration' tab.

# Answer
This can be done easily without any coding or other modules. Just go to */admin/people/permissions* and then uncheck the box titled "Use the administration pages and help" in the System section. The user's with that role will no longer see the configuration link.

Also note that you should make sure all your permissions are set accordingly. Just because you hide the link doesn't mean one who knows the right URLs can't still use the functionality.
> 1 votes

# Answer
I would suggest you to do a hook\_menu\_alter and add an 'access callback'.

A good example here
> 0 votes

---
Tags: views
---


# Question
Title: No visible files in DIR (site/default/files) throught the IMCE
I have a problem with IMCE manager:

1. I upload my files throught CONTENT -\> FILES, all files are visible there (sites/default/files).
2. I check (Home » Administration » Configuration » Media » IMCE) for sites/default/files path and permissions. It's all OK.
3. But when I use IMCE "Add Link" button to link an uploaded file, and choose to pick it up from server... I see nothing (except 0 files using 0 bytes of unlimited quota) in file browser. Navigation tab also shows: /sites/default/files

Files folder has 0777. Uploaded files can be also opened by ULR.

Thanks!

# Answer
> Filefield sources applies a filter to the file list. It won't list files that can not be used in file field.

https://drupal.org/node/1099994

If you are using File Field sources that's your problem.
> 1 votes

---
Tags: files
---


# Question
Title: Module to turn on/off the whole block region
My client wants to turn on/off the whole region for block from the drupal menu. Is there some module that can do that?

Right now he must move the all six blocks from that region to disabled area and then he needs to find them and rearange when he want them back and it is not very efficient.

# Answer
I don't have a single great suggestions. Here are a few things that come to mind.

1. Wrap all the blocks in a single block. This way you could make a few "block groups".
2. Just don't use the block system. It's not very good. My personal favourite block handling mechanism is Panels (Everywhere) and Page manager
3. Panels Everywhere is capable of killing the *entire* block system. A peek into it's codebase could probably reveal how to do it on a region by region basis.
> 2 votes

# Answer
If you want to do this *before* the blocks are rendered, then hook\_block\_list\_alter() is your friend.

```
/**
 * Implements hook_block_list_alter()
 *
 * Hides the right sidebar on some pages.
 */
function THEME_NAME_block_list_alter(&$blocks) {
  if (!$fancy_condition) {
    return;
  }

  // Go through all blocks, and hide those in the 'sidebar_second' region.
  foreach ($blocks as $i => $block) {
    if ('sidebar_second' === $block->region) {
      // Hide this block.
      unset($blocks[$i]);
    }
  }
}

```

Note: Interestingly, this hook seems to work no matter if you have it in your theme or in a module. (Please correct me if I'm wrong)

The $fancy\_condition is obviously a placeholder.

In your case, you want to do this based on a setting. Maybe you can provide an administration form somewhere, where this setting can be toggled. Or you could add an option to the theme settings.
> 1 votes

# Answer
There is a sandbox D7 Port of the D6 module Region Visibility which allows you to set role or page specific visibility settings for regions.

> It does only what it says - allows regions to be toggled off per-path. (and also per-role)
>
> This is handy if you want to, eg,
>
> * toggle some pages to be super-wide and have no sidebars on a path-by-path basis.
> * toggle header and footer off to present a 'bare' display ... based on paths alone.
>
> For anything more advanced, I suggest you upgrade soon to the 'context' module, with allows you to build full logical display conditions, like "if user is not admin and content-type is 'article' and path is under 'archive/*' but not 'archive/index/*' then hide sidebar-left"
> 0 votes

---
Tags: blocks
---


# Question
Title: How to automatically install civicrm extensions in drupal+civicrm installation profile?
We are building a Drupal distribution / installation profile similar to CiviCRM Starter Kit. This will install Drupal 7 and CiviCRM 4.3 while installing the distribution.

We want to add some CiviCRM Extensions like "Extended Reports for CiviCRM" etc. in our distribution so that whenever user will install the distribution, these CiviCRM Extensions also gets installed by default.

We have added these CiviCRM Extensions in drupal-org.make file like below,

```
libraries[nz.co.fuzion.extendedreport][download][type] = get
libraries[nz.co.fuzion.extendedreport][download][url] = "https://github.com/eileenmcnaughton/nz.co.fuzion.extendedreport/archive/master.zip"
libraries[nz.co.fuzion.extendedreport][destination] = "extensions"

```

and these get downloaded/unzipped when we run drupal packaging script (drush make). But we are not sure how to enable them as part of the distribution installation.

We know we can add the Drupal modules in profile.info file like below,

```
dependencies[] = civicrm

```

but don't know how and where to add CiviCRM Extensions so that they get installed as part of distribution / installation profile setup.

Please suggest how can we install CiviCRM Extensions automatically as part of installation profile setup.

# Answer
> 10 votes
The current API call requires more than just the key. To enable modules as part of an install profile, you simply need to include this code somewhere in the process when it's possible to initialize CiviCRM...

```
  if (!civicrm_initialize()) {
    drupal_set_message(t('Failed to initialize CiviCRM'));
    return;
  }

  require_once 'CRM/Extension/Manager.php';

  $params = array(
    'version' => 3,
    'sequential' => 1,
    'key' => 'org.civicrm.volunteer',
  );

  $result = civicrm_api('Extension', 'install', $params);

```

As long as the Extensions Directory and ResourceURL are set in the civicrm.settings.php, you should be set. I've been setting the Extensions Directory for Pantheon users, but still need to dynamically configure the ResourceURL https://drupal.org/node/1980088.

Rather than create a "Drupal distribution / installation profile ***similar*** to CiviCRM Starter Kit", PLEASE consider building on the CiviCRM Starter Kit by using it as the base distribution and contribute to maintaining it. Take a look at this patch and how the latest version of OpenAtrium builds on Panopoly.

https://drupal.org/comment/6117722#comment-6117722

http://drupalcode.org/project/openatrium.git/blob/refs/heads/7.x-2.x:/drupal-org-core.make

We really need more developers working to push the patches that are still requires back into CiviCRM to keep this stable. I hardly have time to figure out the changes with each CiviCRM release. It has taken several years to get to the point we can install and run CiviCRM from the /profiles directory, package CiviCRM w/ drush make, and rebuild the required libraries.

The CiviCRM Starter Kit was always designed to remain a base install to build other use case specific distributions on, but I've really been maintaining this on my own so far and would love some help.

**UPDATE:** I went ahead and created https://drupal.org/project/civicrm\_extension\_enabler since troubleshooting code in this queue is difficult. That module enables the CiviVolunteer extensions and works a site running https://dashboard.getpantheon.com/products/civicrm\_starterkit/spinup once CiviVolunteer is uploaded to sites/all/extensions

I've started an issue to change the specific extensions hard coded in the .install to be an array of extensions populated by the distribution https://drupal.org/node/2159317

# Answer
> 1 votes
I haven't done this exactly (using Drupal install-profiles), but there are two key ingredients that have helped me automate setup in other contexts:

1. Traditionally (with Civi 3.x =\> 4.2 inclusive), one needed to create an extension directory and then set configuration options so that Civi would scan that directory. This is no longer necessary. Beginning in 4.3, you can put extension files anywhere in the CiviCRM source tree -- I'm partial to $civicrm\_root/tools/extensions. Beginning in 4.4, you can also put extensions in $drupal\_root/vendor.
2. To activate the extension, you can call CiviCRM's Extension API. The call needs to come after CiviCRM's core platform has been installed and bootstrapped.

Some examples of using the API

```
## PHP
$result = civicrm_api('Extension', 'install', array('key' => 'my.extension.name'));

## PHP
$result = civicrm_api('Extension', 'install', array(
  'keys' => array(
    'my.extension.num1',
    'my.extension.num2',
    'my.extension.num3',
  ),
));

## CLI
drush cvapi extension.install key=my.extension.name

## CLI
drush cvapi extension.install keys=my.extension.num1,my.extension.num2,my.extension.num3

```

---
Tags: 7, civicrm
---


title: Theme output of submenu

text:
# Question
Title: Theme output of submenu
I have a menu that should look like this:

```
<ul class="subpagemenu">
<li><a href="xx">xx</a>
  <ul>
  <li><a href="xx">xx</a></li>
  </ul>
</li>
<li><a href="xx">xx</a></li>
</ul>

```

You can see, that the first ul has a class and the submenu ul doesn't have.

I am using this code to add class to the ul.

```
function mytheme_menu_tree__menu_mymenu($variables) {
    return '<ul class="subpagemenu">' . $variables['tree'] . '</ul>';
}

```

But it adds that class to the all submenus.

```
<ul class="subpagemenu">
<li><a href="xx">xx</a>
  <ul class="subpagemenu">
  <li><a href="xx">xx</a></li>
  </ul>
</li>
<li><a href="xx">xx</a></li>
</ul>

```

Is there any way to theme the sub menu? Thank you.

# Answer
```
function mytheme_menu_tree__menu_mymenu($variables) {
  return '<ul class="subpagemenu">' . $variables['tree'] . '</ul>';
}

function mytheme_menu_tree__menu_mymenu_second($variables) {
  return '<ul>' . $variables['tree'] . '</ul>';
}

function mytheme_menu_link__menu_mymenu($variables) {
  $element = $variables['element'];

  $submenu = '';
  if ($element['#below']) {
    // You can set a theme wrapper here or put an empty array() only
    // and theme the second level directly by adding <ul></ul> one line below.
    $element['#below']['#theme_wrappers'] = array('menu_tree__menu_mymenu_second');
    $submenu = drupal_render($element['#below']);
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $submenu . "</li>\n";
}

```
> 1 votes

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