# Question
Title: Language Block customization: I need to display either English link or the other language link (not both)
I have a bilingual project and the language is being switched from the language block. It actually displays now: English and Spanish.

I need to have just one language link displayed: English when on Spanish language and Spanish when English.

Thank you!

# Answer
Usually the current language link gets an "active" class. You can use CSS to hide all other links and display only the active link.

This can also be done by overriding theme template files or functions.
> 1 votes

---
Tags: i18n-l10n
---


title: drupal_mail() is formatting my body

text:
# Question
Title: drupal_mail() is formatting my body
drupal\_mail() is formatting my email body. Before: http://pastebin.com/LbBy04BZ (note 1 line) After: http://pastebin.com/nEx7AFwU (note multiple lines)

It should not, because Line 23 in /modules/system/system.mail.inc is the following one:

```
$message['body'] = implode("\n\n", $message['body']);

```

How can I prevent the reformatting of my mail content?

# Answer
> 2 votes
Have a look at the API documentation for drupal\_mail\_system(), there you'll have code to override the default MailSystemInterface.

For an exemple of how to override it, have a look at the Postmark module.
You can then redefine the `format()` function:

```
class YourModuleMailSystem implements MailSystemInterface {

public function format(array $message) {
  //remove this formatting.
  //$message['body'] = implode("\n\n", $message['body']);
  return $message;
}

//...
}

```

---
Tags: 7, emails, entities
---


title: How can I learn the Views 3 API?

text:
# Question
Title: How can I learn the Views 3 API?
Where can I learn the views 3 API? I can use the ui to make views but I would like to create views using the API in my modules. I would settle for the views 2 API at this point. I looked at the docs and did not get very far. Anyone know of a good tutorial?

# Answer
Not sure what exactly you mean with "creating" views.

First, if you have custom tables/data, you can use hook\_views\_data() and custom plugins and handlers to tell views how to access these tables. Some Tutorials/examples: http://treehouseagency.com/blog/neil-hastings/2010/01/19/views-handler-easy-way (Drupal 6) and http://larsolesen.dk/node/273 (Drupal 7). But again, you only need this if you want to expose your own tables to views.

Then, there are a number of pre-render and alter hooks, which allow you to alter some things that you can't do in the user interface. List of views hooks in Drupal 6.

That said, there is no "API" to create actual views (that I know of). I think everybody uses the views UI for that (After all, it's a great UI now in Drupal 7). What you can do is export the views you created in the UI to distribute them with your module or as a new module. This is also useful for contributed/standard modules to not only expose their tables to views but also provide example views, which can be customized/extended for a specific site.

Instead of exporting them manually, you can also use the Features module, which allows you to export all kinds of configuration (views, content types, fields, permissions, ...) into so called features (which is basically an automatically generated module). That is especially useful when moving configuration like views from a development to a production installation, or re-using the same views/configuration on multiple sites.
> 7 votes

# Answer
I was able to make views using Views UI, then I added the exported view into `hook_views_default_views()` and also created `hook_views_api()` and it works! This is the best way to do this.
> 3 votes

# Answer
A good way to figure out where to start with the Views 3 API is by looking at the hooks and their execution order. There's a diagram somewhere (unfortunately I can't find it), but this post is a good substitute: It does a good job on explaining the life cycle of a view showing the order in which hook events happen.
> 2 votes

# Answer
Have a look at the book Drupal building blocks from the author of views Earl Miles, it contains both examples with Views 2 and Views 3.
> 0 votes

---
Tags: 7, views
---


# Question
Title: Remove jQuery and find out what is asking it to be included
I'm using drupal 7 and I simply don't want jQuery included at all. It seems like most people are advocating modify the js in a theme hook. That's fine I suppose, but it seems like this is dangerous and a little silly.

If we're removing jQuery after something has requested it, won't that break whatever requested? How can I find out what is requiring jQuery?

Related to that is all the system CSS files that are included by default. I've also found that using a theme hook to get rid of them is the way to go. It seems like Drupal has a lot of "features" like this that require you to add more code to remove things. It seems like there should be a more efficient way to handle things like this. (forgive me if I'm mistaken, I'm coming from years of work with frameworks and not a full stack CMS).

In the end, what I want is a theme that has NOTHING in it except what I explicitly say should be there. Right now I'm considering just writing the html.tpl.php to not use the dynamic drupal variables.

# Answer
I think that it is pretty safe to assume that any module using JS is going to assume that jQuery is present. Yes they should feature detect this, but its availability in Drupal is pretty much assumed by everyone. There is no real way to get a list of all of the jQuery dependencies.

CSS can be aggregated and minified if the worry is file count.

If you truly want to manage these yourself, your best bet is to remove the `$scripts` and `$styles` variables from html.tpl.php and manage your own, eg `$myscripts` and `$mystyles`. You could also unset/reset them in your own template\_process\_html.

Drupal is built on hooks. Don't think of it as having to add code to remove something. You add code (implement hooks) as a way to modify or extend the default behavior.

Now that I have answered your question, you are really going out of your way to bypass a lot of the power of Drupal. You should start by looking into what Drupal calls starter themes or base themes. The Omega and Zen themes are two popular ones.
> 3 votes

---
Tags: javascript, theming
---


# Question
Title: Install a PDF maker to the panel of a WYSIWYG editor?
After installing WYSIWYG and CKeditor how can I install some kind of PDF maker to the panel of the editor?

# Answer
I don't know of a pre-built solution for this. I assume you want a PDF icon similar to what there is in MSWord or OpenOffice.

There is no PDF generation capability with client-side Javascript that I am aware of, so it would be difficult to implement something like this in the browser.

There are plenty of server-side PDF solutions, however, but you'd have to send the editor content back to the server somehow (AJAX), and then have the PDF generated and sent back to the client.

There looks to be some discussion of this at the CKSource forums.

It might be easier to just use the Print module.
> 1 votes

---
Tags: 6, wysiwyg, files
---


title: Image Display (Content) View

text:
# Question
Title: Image Display (Content) View
Drupal 7

I created an Image Display (Content) View for a different image to display on each page of my site in the second sidebar. When I created the view and uploaded an image to Basic Page...the photo now appears on every page of my site.

How do I modify the view that each page (Basic Page) can have a unique image?

# Answer
very block has a "visibility setting". Select "Only the listed pages" and enter the pages where you want this block to show.
> 2 votes

---
Tags: views
---


# Question
Title: How can I setup a template for displaying all nodes of a given type?
When I enabled the Blog module in D7 it allows a "/blogs/" page to show all blogs and then the standard blog view underneath that for single blog entries; how can I do this with my own content type?

I want to create a list of my image gallery content types that is tailored to my needs, and then have a view for individual galleries, while still keeping items in those galleries as separate nodes.

I've worked out what seems to be a decent way to reference everything, I just can't figure out how to setup a group view for the galleries. I could just make a custom article that uses PHP to query the nodes and do it all through custom articles, but I thought perhaps the Drupal themes setup allows something more eloquent.

# Answer
> 1 votes
You can create your content type and add fields to it to create sorting criteria.

Use taxonomy to define a vocabulary to plug into your content field.

Use pathauto to set up custom URL alias paths for your content.

Define a view to read your fields, filter all content to find what you want, sort and display it. YOu can refine your searches using contextual filters, that will read the URL and extract information from it.

Sounds simple enough, but if you are unfamiliar with the modules it takes a bit of work to master them.

---
Tags: 7, nodes
---


# Question
Title: Sending email only to active (unblocked) users of the site
How can I send email and notifications to the active (unlocked) users of the site? What modules do I need for that? Could you explain it clearly?

Already I'm using messaging, notifications and the Mass contact module. If I send mail through the Mass contact module, the blocked users also receive mails.

# Answer
Add a category in Mass Contact

http://localhost/sitename/admin/config/system/mass\_contact/add

and "Roles to receive e-mail" , just check "authenticated user" and save configuration.

And "authenticated user" are active user not the blocked user.
> 1 votes

# Answer
You could use hook\_mail\_alter to check the emails before they go out and filter the users on your conditions before they actually send to anyone.
> 0 votes

# Answer
You can use the Rules and VBO modules.
> 0 votes

---
Tags: 7, emails
---


# Question
Title: Embedding the s3slider jQuery plugin in a block
How can I add a custom image slider similar to this one in a block?
I tried integrating it in a block, but it doesn't work.

What is the best image slider for Drupal 7, excluding the View Slideshow module? I tried using it, but it only displays the last image of the slideshow.

# Answer
> 2 votes
I would use in D7 the Fields Slideshow module.

If you still want to use the s3 slider, these are some general steps to make.

1. Make a content type with an imagefield.
2. Add nodes for each slide in your slider.
3. Create a view that has the fields you need.
4. Set the field stye of the imagefield to none for all the items (label and wrapper too).
5. Set the body field style to span and set none to label and wrapper. Trim the field to your desired length and remove any html.
6. Go to 'Theme information' in your view. You need to copy the name of the templates of the views you will be replacing. You need to get the list template (views-view-list--MYVIEWNAME.tpl.php).
7. Go to the themes folder in the views module and copy the views-view-list.tpl.php into your theme and rename it to what you figured out in the first step.
8. Change the content of the template with something like this, remember to change MYTHEMENAME to the name of your theme and remember to flush your theme registry so it recognizes the new template file.

# Answer
> 1 votes
Not sure how you tried that, there are many ways to achieve it in Drupal. Often they are displayed in blocks. See this question What are the available image sliders?. Links referred there could take you to various slideshow modules available for Drupal but in my experience it is always more than installing and configuring modules.

---
Tags: 7, blocks, media, javascript
---


# Question
Title: How do I add an Organic group to my main menu?
I have read the documentation for Organic Groups Version 7.x.1.x (is there any more/better?) and created a group type "group content" and a group.

Question (and it may not be an OG question because I am a total n00b) - how do I add a top level menu "Groups" to my main menu? Specifically, what do I add for "path? ?

And then how do I add a group or two as sub-items to that menu?

Thanks a 1,000,000 in advance

# Answer
I love the new screeencast for OG, it explains it really well.

When you install OG it creates a few "views" that you can use. "OG list" view shows you a list of all the groups (you might have to enable the view if it's disabled).

Then create your menu item "groups" and use "group-list" as the path.

You can add specific "group nodes" to a sub-menu by editing the nodes and using the "provide menu link" feature. I believe not every theme uses submenus, for example Bartik doesn't by default.
> 1 votes

---
Tags: 7, routes, organic-groups
---


# Question
Title: How do I let my users create organic groups?
\[n00b apologies\] I have installed Organic Groups but am apparently too dumb to understand it.

How do I let me users create and administer their own groups? What do I need to do on the admin pages, and how do I add something on the main page to let them administer & join groups.

Sorry if this sounds dumb

---

Update: if they can't, and I have to - how do I add a "groups" item to the man menu and a sub-menu for each group?

# Answer
> 1 votes
once you have enabled a "content type" as "group type" you can just let your users add new content of that type and it will create new groups.

It's explained very well in this screen cast.

# Answer
> 1 votes
see documentation for Drupal 6 http://drupal.org/documentation/modules/og or Drupal 7 http://drupal.org/node/1114852.

---
Tags: organic-groups
---


# Question
Title: Views3 - Is there are feature in Views3 that allows for authenticated users to change the fields in a view?
I'm using Drupal 7 to display a particular content type as a table view. This particular content type has the possibility of 15 columns, but I want to give users the option of displaying fields that are interesting to them. Does Views3 allow for users to select which fields he or she is interested in and save that to the profile?

Drupal 6 has a module based on Views - Control field display, which seems to have this feature.

# Answer
> 1 votes
you can allow users acces to the views UI but you couldn't limit that just to "fields". It wouldn't be end user friendly either.

You might want to show all fields in your view and then hide the fields dynamically with css.

If you want it more robust you can use a hook like hook\_views\_post\_execute to remove fields dynamically.

# Answer
> 0 votes
Field permissions. You can fine grained decide which fields you want to display to a specific role.

You can give permission to let users edit the permissions for fields. It is off course not designed for exactly what you want. But it can be a good starting point to think about.

http://drupal.org/project/field\_permissions

There is also flags and rules modules that can be used to achieve such a functionality.

---
Tags: views
---


title: Theming Block Contents in Drupal 7

text:
# Question
Title: Theming Block Contents in Drupal 7
I can change the overall layout of a block editing the `block.tpl.php` file. I can modify the way `subject` looks, but what I want to take control over `contents` of the block which is accessible by single line of code:

```
<?php print $content ?>

```

Now, How can I theme **contents** of the block, i.e. list items etc?

*If I've failed to clarify myself, please mention it in your comments. Thanks :)*

# Answer
> 8 votes
Before blocks get to the theme layer, they can be altered. Blocks are represented as "render arrays", which means you can manipulate them with the Render API.

You can use `hook_block_view_alter()` to change the contents of a block.

Any module or theme can implement this hook. For example, a theme named YOURTHEME would have code like this:

```
function YOURTHEME_block_view_alter(&$data, $block) {
  // Remove the contextual links on all blocks that provide them.
  if (is_array($data['content']) && isset($data['content']['#contextual_links'])) {
    unset($data['content']['#contextual_links']);
  }
  // Add a theme wrapper function defined by the current module to all blocks
  // provided by the "somemodule" module.
  if (is_array($data['content']) && $block->module == 'somemodule') {
    $data['content']['#theme_wrappers'][] = 'mymodule_special_block';
  }
}

```

Or, if you know in advance the module and delta you'd like to alter, you can use `hook_block_view_MODULE_DELTA_alter()` like this:

```
function YOURTHEME_block_view_MODULE_DELTA_alter(&$data, $block) {
  // This code will only run for a specific block. For example, if MODULE_DELTA
  // in the function definition above is set to "mymodule_somedelta", the code
  // will only run on the "somedelta" block provided by the "mymodule" module.

  // Change the title of the "somedelta" block provided by the "mymodule"
  // module.
  $data['subject'] = t('New title of the block');
}

```

# Answer
> 1 votes
You can use Views to generate a block which you can exactly theme the way you want.

# Answer
> 0 votes
In short, you cannot. `$content` is the minimal piece of information known to the block module.

---
Tags: 7, blocks, theming
---


# Question
Title: Is there a nicer way of getting my nodes language and text direction?
My site is almost entirely in English, but with individual pages in different languages. There's one extra page per language other than English, as a single page "this is a summary of the sites information in your language" sort of deal.

I've used the Drupal "language" module to set up some languages and give some nodes a language other than English. I don't really want anything more complicated than this. Specifically I don't want:

* To translate the entire site to any other language.
* To allow users to pick their language.
* To translate anything other than node (single page) content. Menus, site slogan, etc, will always be in English.

When viewing the pages for those nodes, I want to set some CSS classes and in some cases the text direction (rtl for Arabic / Urdu / Hebrew) based on the nodes language.

For some reason, the global $language variable is always set to English, regardless of the node language.

I can get the nodes language from `$node->language` and work out my CSS classes and text direction with the following code in my page.tpl.php:

```
<?php
    $node_lang = 'en';
    if (isset($node) && isset($node->language)) {
        $node_lang = $node->language;
        $rtl = ($node_lang == 'ar' || $node_lang == 'ur' || $node_lang == 'he');
    }
    $en = ($node_lang == 'en' || $node_lang == 'und');
?>
<div id="content"
    class="primaryContent <?php if($rtl){print "rtl";}?>"
    <?php if ($rtl) { print "dir='rtl'"; } ?>
    <?php if (!$en) { print "lang='$node_lang' xml:lang='$node_lang'"; } ?> >
...content...
</div>

```

Is there a simpler or "more recommended" way of doing the above? Doing my own detection of rtl / ltr feels fairly brittle.

# Answer
> 2 votes
If `$node` is the variable containing the node object, you can use code similar to the following one:

```
$languages = language_list();
if (isset($languages[$node->language])) {
  $rtl = $languages[$node->language]->direction == LANGUAGE_RTL;
  // $direction = $languages[$node->language]->direction ? 'rtl' : 'ltr';
}

```

If you need to use the string "rtl" or "ltr" basing on the direction associated with the language, then you can use `$direction`, instead of `$rtl`.

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


# Question
Title: Comment subject field too large breaks the page layout
I activated a contributed theme and I am doing some little customization. At the moment I have a 2 columns layout (content + second sidebar). Originally the theme was designed with a much larger content column hence after reducing its size I realized the comment subject field was too large for the content column.

Looking in the theme style.css file was of no help. I am trying to reduce the `size` of the comment subject field from 60 to 40 in the following portion of HTML code:

```
<input id="edit-subject" class="form-text" type="text" maxlength="64" size="60" value="" name="subject">

```

but I do not understand where/what part of drupal php code generates it. I am also afraid I will meet the same problem once the contact form is enabled.

Any help?

# Answer
> 2 votes
All right I got it. I fixed it in the `style.css` file

WAS:

```
.form-text {
    border: 1px solid #ACACAC;
    border-radius: 3px 3px 3px 3px;
    color: #949494;
    padding: 4px 5px;
}

```

IS

```
.form-text {
    border: 1px solid #ACACAC;
    border-radius: 3px 3px 3px 3px;
    color: #949494;
    padding: 4px 5px;
    width: 75%;              /* <-- added line */
}

```

---
Tags: 7, comments, emails
---


# Question
Title: db_select() ignores condition() when used with join
I want to select all rows from 'ha' table, which access column are \>= 0 and node type of that nid is equal $this-\>ctype.

```
  protected function queryAlter() {

    if(isset($this->ctype)) {

        $this->query->leftJoin('node', 'n', 'n.nid = ha.nid');
        $this->query->conditions(
                db_and()
                ->condition('ha.access', 0, '>=')
                ->condition('n.type', $this->ctype));
        //dpr($this->query);
    }
    else {
        $this->query->condition('ha.access', 0, '>=');
    }
  }

```

$this-\>ctype is set and equal to 'ad'. And I have not any nodes with that type. But db\_select() ignores condition('n.type', $this-\>ctype) and returns all rows from ha (which NID's are not ad type).

Why this happens? And how to debug db\_select() in general?

# Answer
`HearthbeatStream::$query` is an object of the class `PagerActivity` which extend the class `SelectQuery`; this is evident from the code for HeartbeatStream::createQuery(), where the value of the property is initialized with the following line.

```
$this->query = db_select('heartbeat_activity', 'ha')->extend('PagerActivity');

```

The fact `PagerActivity` is an extender of `SelectQuery` means that every method implemented by `SelectQuery` is also implemented from `PagerActivity`.

SelectQuery::conditions() is a getter method, not a setter method. The only method to set the condition associated with a `SelectQuery` object is SelectQuery::condition().

The code should be re-written as:

```
  protected function queryAlter() {
    if (isset($this->ctype)) {
      $this->query->leftJoin('node', 'n', 'n.nid = ha.nid');
      $this->query->condition(('ha.access', 0, '>=')
        ->condition('n.type', $this->ctype));
    }
    else {
        $this->query->condition('ha.access', 0, '>=');
    }
  }

```

To make a comparison, this is the code executed from blog\_page\_user():

```
  $query = db_select('node', 'n')->extend('PagerDefault');
  $nids = $query
    ->fields('n', array('nid', 'sticky', 'created'))
    ->condition('type', 'blog')
    ->condition('uid', $account->uid)
    ->condition('status', 1)
    ->orderBy('sticky', 'DESC')
    ->orderBy('created', 'DESC')
    ->limit(variable_get('default_nodes_main', 10))
    ->addTag('node_access')
    ->execute()
    ->fetchCol();

```

There are some similarities with your code:

* in both the cases, the value returned from `db_select()` is passed to the `extend()` method
* in both the cases, more than one condition is applied

Using the value returned from `db_and()` with `SelectQuery::condition()` is not necessary, as the constructor of `SelectQuery` initializes the value of `SelectQuery::$where` (used by SelectQuery::condition()) with the following code:

```
  $this->where = new DatabaseCondition('AND');

```

The returned value is the same returned by db\_and().

```
function db_and() {
  return new DatabaseCondition('AND');
}

```
> 5 votes

---
Tags: 7, database
---


# Question
Title: CCK migration From Drupal 6 to Drupal 7: Which tables can I delete?
After migrating the CCK fields from Drupal 6 to Drupal 7, which tables can I delete?

# Answer
> 1 votes
As far as I can see, the tables that are safe to be removed (if they are not removed from an update function) are the ones matching the content\_\* pattern, which are not used anymore in Drupal 7.

---
Tags: entities, migrations
---


title: List fields for a content-type?

text:
# Question
Title: List fields for a content-type?
> **Possible Duplicate:**
> Listing entity fields

Is there a function or technique anywhere in the Drupal API to list fields for a particular content type?

# Answer
> 2 votes
About list your fields for your content type, I guess that you can use `node--NAMECONTENTTYPE.tpl.php` in your directory template.

to be more detailed, you can copy/paste to your theme directory the file node.tpl.php (located in `modules > node` or already located inside your theme directory) and rename it according your content type. for example, if the Content Type is `Article` the name will be `node--article.tpl.php`

already inside in `node--article.tpl.php` you can list the fields with the variable `$content` using `print_r($content);` to see the list of the fields that you can use to your node (or if you use Devel module, is best use `dsm($content);`)

**to call each field you can use:**

for example I have a field called `field_demotext1`, then:

```
print render($content['field_demotext1']);

```

here is the example of zone in the `node--article.tpl.php` using `dsm($content);` to print list of fileds:

```
  <div class="content clearfix"<?php print $content_attributes; ?>>
    <?php
      hide($content['comments']);
      hide($content['links']);
      print render($content);
      dsm($content);
    ?>
  </div>

```

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


# Question
Title: How do you print the view name on a "view page"?
I have set up a custom template for my new view and need to print the views title at the top of the page. What is the best way to do this?

# Answer
> 1 votes
This should normally just work. What do you mean by "custom template", did you make a .tpl.php file? What .tpl.php did you use?

---
Tags: views, 7
---


# Question
Title: Use Views to display unpublished nodes to authors, but not to other users
Say \[User A\] creates, but does *not* publish \[Node 1\]. \[Views V\] aggregates all of the content type that \[Node 1\] belongs into. \[User B\] should not be able to see \[Node 1\] listed on \[Views V\], but \[User A\] should be able to see his *own* unpublished \[Node 1\], all through \[Views V\] which lists out the specific content type.

Currently, if I change the Filter to not filter for Published or Unpublished nodes, then regular members can see the *title* of unpublished Nodes through the view, despite not having permission to access it (if the user clicks on it, then access denied message is shown). I do not wish for this to occur. However, I can't explicitly filter out unpublished nodes, since I want authors of said nodes to be able to see them (and access/edit them before publishing).

So is it possible to have Views filter out nodes based on the access permission of the current user?

I am using Drupal 7, and Views 3.

# Answer
Just to save anyone else some time and trouble, there's a filter under Views called, "Content: Published or admin." This will do precisely what is needed.
> 6 votes

---
Tags: 7, views, users
---


# Question
Title: How do I set "has_title = false" for an existing node?
I understand how to set the node attribute 'has title' via the `hook_node_info()` when creating a node programmatically. However, I struggle to edit this attribute for a node that has been created with the built in Drupal node designer. Can anyone please give me advice on how to modify this attribute, for example on a node such as "article"? Which hook do I use and when? Could I even modify this attribute directly in the database and therefore get this changed permanently?

# Answer
> 3 votes
There is good comment in source:

```
// title_label is required in core; has_title will always be true, unless a
// module alters the title field.
$type->has_title = ($type->title_label != '');

```

So, you can alter the form and customize it. I have created a simple example, because I found it interesting.

```
/**
 * Implements hook_form_FORM_ID_alter().
 * Alter 'node_type_form'
 */
function nodetitle_off_form_node_type_form_alter(&$form, &$form_state) {

    $type = $form['#node_type'];
    $default_value = $type->has_title;
    // Create simple flag
    $form['submission']['nodetitle_off'] = array(
        '#type' => 'checkbox',
        '#title' => t('Has title'),
        '#default_value' => $default_value,
        '#weight' => -1,
    );

    $value = !empty($form_state['input']) ? isset($form_state['input']['nodetitle_off']) : $default_value;
    if (!$value) {
        // Make field not required and empty
        $form['submission']['title_label']['#required'] = FALSE;
        $form_state['values']['title_label'] = '';
    }

}

```

# Answer
> 0 votes
The Automatic Nodetitles module could be useful to you.

---
Tags: 7, nodes
---


# Question
Title: Views Block's machine name is being "hashed" (?)
A Drupal newbie, so correct me if my understand is wrong, but normally, when a Block is created by Views, the machine name of the block is appended to the Views' machine name.

i.e. "article\_listing\_view-block\_1"

When using block\_load($module, $block\_id) function, the way I've been doing it is to call it thus: $block = block\_load("views", "article\_listing\_view-block\_1");

However, for some *very* odd reason, one particular Block with the machine name:

"flag\_comments\_as\_offensive-block\_1"

has a hashed machine ID of:

"92a591f5a81d13a3dd5492f073f9e135"

I say "hashed" because the machine ID changes based directly on the machine-name of the block. If I change it from block\_1 to block, it will change, and when I revert back from block to block\_1, it will revert the machine ID back to the above. So there's a direct correlation between the machine name and the "hashed" ID it generates.

Instead of calling block\_load("views", "machine name"), I have to use the hashed machine ID, which isn't a problem but it did take me a *long* time to figure out. The way I figured it out was to go into Structure -\> Blocks and hover over the "Configure" link and look at the URL. I noticed that *all* my other Blocks have a URL that included its machine ID, but for this particular block, it was the hashed machine ID. Once I put in the machine ID into block\_load, viola, it worked like a charm!

So I guess the question boils down to: What's going on, and why is Drupal hashing my machine name? Is this a bug, or an error on my part?

# Answer
> 22 votes
This is because the block module expects a 'delta' (block id) up to 32 characters long. But a view block display can have up to 65 characters: up to 32 characters from the view name and 32 characters from the display name and an hyphen '-' between them.

When the delta exceeds the 32 characters limit, Views will hash it through md5 — it is not a random string. You can safely use it for CSS and jQuery selectors.

# Answer
> 4 votes
Views machine names are only hashed if the name is over 32 characters in length.

---
Tags: 7, views
---


# Question
Title: Add rule for a webform checkbox to autosend email after specified time
Im running D7 with webform. I have a multstep form, on the last step the user is asked to participate in a future survey. If they enter their email and check the box to agree, they should receive an email reminder with a link to a new survey I have created in two weeks from when they agreed.

Im planning to use webform rules, rules, and token modules to create this feature.

Am I going to be able to verify the condition and generate a scheduled email using these modules? Or do you think I should focus my efforts on a custom module?

# Answer
> 1 votes
You will also need Webform Rules, but once you can react to the submission, you should have no problem getting this going. You'll need to schedule the rule to run in the future and will probably need to add a Rules Component containing the actions to run at that time.

In your triggered rule that reacts to the Webform submission, you need a condition checking if that checkbox was checked and an action that runs the Rule Component you defined earlier. You will want to pass the user object to it (or uid, or email address, or Webform submission - whatever you need) to make sure it works correctly.

I am using Drupal 7 terminology here, but this is achievable in Drupal 6 as well. Just replace "Rule Components" with "rule sets."

---
Tags: webforms, rules, tokens
---


# Question
Title: How to right align text in custom form textfield in Drupal 7?
I have a custom form with a textfield that takes numeric values (temperature). I want to right-align the text typed in textfield. Should I use CSS or is there a Drupal attribute to do this?

Here's the present code:

```
$form['temperature'] = array(
            '#type' => 'textfield',
            '#title' => 'Answer',
            '#description' => 'Enter temperature in ° Fahrenheit',
            '#required' => TRUE,
            '#size' => 6,
            '#maxlength' => 6,
            '#field_suffix' => '° Fahrenheit',
            '#element_validate' => array('_myform_temperature_validate'),
        );

```

# Answer
There is no Form API property to align the text. You will have to resort to CSS, 'text-align: right' will do it.
> 1 votes

# Answer
Yes, add a custom class, or use an existing one. You can add custom CSS styles to your form using #attached.
> 2 votes

# Answer
If I understand well, I guess that you can use the "settings" array to control your alignment. I found this example: Drupal 7 Field API Simple Example - Digging Deeper.

```
'settings' => array(
              'container' => array(
                  'float' => 'right',
                  'class' => '',
                  'inline_style' => '',
                  array('background' =>
                      array('image' => ''),
                  ),
              ),
...

```
> 1 votes

---
Tags: 7, forms
---


# Question
Title: Look up nodes that reference a given node
I'm using the references module (not grounded to it, but it seems to work well enough) however I don't know how in a custom PHP block/etc I would be able to do a query that can look up all the nodes of a given type that reference the current node.

What sort of query would accomplish this?

For just looking up by type I've used this previously:

```
<?php
    foreach(node_load_multiple(array(), array('type' => 'homepage_image')) as $node){
    //code
    }
 ?>

```

# Answer
Well, you know, this is one of the problems that gave birth to relation. Nonetheless, an `EntityFieldQuery` with a `fieldCondition('name_of_the_reference_field', 'nid', $nid)` is what you want.
> 3 votes

---
Tags: 7, nodes, database
---


# Question
Title: When I change theme, I can't see my sidebars
I am a total n00b, just trying to set up my first site.

I got something nice with the Bartik theme, then realized that I wanted drop-down menus on the main menu, so decided to try another theme.

I tried both Corolla and Martinelli, but when I set them as default theme I can't see my sidebars or footers.

The are still set up as they were for Bartik and if I switch back to that then I see them again.

Obviously, this is just some stupid n00b thing, like not knowing to rebuild the front page or something. Can anyone tell me what I am doing wrong? Thanks.

# Answer
Because themes haven't the same region names, after changing your theme you must go to *admin/structure/block* and re-assign blocks to regions.
> 2 votes

# Answer
Go to Admin/structure/blocks. The tabs at the upper right of the form allow you to select your theme. arranging the blocks in one them does not change them in every theme so you must Verify their location in the new themes. You should find the missing blocks at the bottom of the form in the 'Disabled' category.
> 1 votes

---
Tags: 7, theming
---


# Question
Title: Is there a module for saving current block setup?
Would be handy to be able to save the current block setup, so after one changes around blocks, it could be reset to a previous state.

# Answer
> 2 votes
You can try either of these modules (quotes included are from their project pages):

* Features Extra:

> ... provides faux exportables (via Features) of several site-building components.
>
> To export a block, install FE Block, edit your block, give it a "machine name," export it with Features. You can export block settings (region settings, visibility settings, ...) of any block, and the content of blocks created with the Block module from Drupal core. The D7 version supports the Block Class, i18n block and Block Cache Alter modules.
* Boxes:

> ... a reimplementation of the custom blocks (boxes) that the core block module provides. It is a proof of concept for what a re-worked block module could do.
>
> The module assumes that custom blocks are configuration, and not content. This means that it is a reasonable action to ask for all blocks at one time, this is in fact exactly what the core block module does.

---
Tags: blocks
---


title: best WYSIWYG editor from the UX side?

text:
# Question
Title: best WYSIWYG editor from the UX side?
There are a bunch of WYSIWYG edirtors available. I've tried CKEditor so far (and tinyMCE with wordpress). CKEditor is a very fancy one but fairly complex and weights 6Mb including source files.

What is in your experience the most buggless and stable?

It needs to have a support for IMCE bridge module to be able to get images from disk.

# Answer
I personally use tinyMCE on my sites, it's not heavy, and you can use the IMCEbridge.

This module will install the **WYSIWYG API**, then follow **these instructions** for adding TinyMCE or any other you want.

The IMCE Bridge module can be found **here** and is compatible with *CKEditor*, *FCKeditor* and *TinyMCE*.
> 1 votes

---
Tags: wysiwyg, files
---


title: Embed form inside a block

text:
# Question
Title: Embed form inside a block
I am using a module (donate) that produces a form at a specific URL, for example, http://example.com/donate. I would like to put this form inside a block and display it on another page. Do you guys know the best way to do this? Thanks for reading.

# Answer
> 2 votes
If you switch to 'donation' module and 'simple\_paypal' You can create a block with the content:

```
<?php
require_once(drupal_get_path('module', 'donation') .'/donation.module');
print donation_form();
?>

```

Make sure to set input format to PHP code

# Answer
> 1 votes
```
<?php
print drupal_get_form('my_form'); //my_form is the function that returns the $form array
?>

```

Just put the above code in the block to display the respective form in a block. Any callback that returns HTML will work instead of `drupal_get_form()`.

# Answer
> 0 votes
I don't know if it will work in your case but you can test Blockify module.

---
Tags: forms, nodes
---


# Question
Title: How can I add Support module's tickets to the homepage?
I am trying out the Support module to create a client support ticketing system. Out of the box it seems to be configured so that I need to navigate to mysite.com/support to view the table of support tickets. How can I change this so that the support tickets appear on the homepage? Drupal version is 7.9

# Answer
You could change the default front page for your site in the admin section at example.com/admin/config/system/site-information. Enter `support` and it will now be your front page.
> 2 votes

---
Tags: nodes
---


# Question
Title: Adding a field to users from a module.install file
Is it possible to add a custom field to users from a module.install file, as it would be done from admin/config/people/accounts/fields?

# Answer
It is possible, in the same way forum\_enable() adds a new field to the "forum" content type; the only difference is that "entity\_type" and "bundle" are both set to "user."

```
// Create the 'taxonomy_forums' field if it doesn't already exist.
if (!field_info_field('taxonomy_forums')) {
  $field = array(
    'field_name' => 'taxonomy_forums',
    'type' => 'taxonomy_term_reference',
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);
}

// …

// Create the instance on the bundle.
$instance = array(
  'field_name' => 'taxonomy_forums',
  'entity_type' => 'node',
  'label' => $vocabulary->name,
  'bundle' => 'forum',
  'required' => TRUE,
  'widget' => array(
    'type' => 'options_select',
  ),
  'display' => array(
    'default' => array(
      'type' => 'taxonomy_term_reference_link',
      'weight' => 10,
    ),
    'teaser' => array(
      'type' => 'taxonomy_term_reference_link',
      'weight' => 10,
    ),
  ),
);
field_create_instance($instance);

```

You can implement a similar code in the `hook_enable()` implementation of your module, or in the `hook_install()` implementation; in the first case, you should check if the field doesn't already exists, or field\_create\_instance() raises an exception.

To verify the field doesn't already exist, you can use code similar to the following one, where `$instance` is the same array as used in the previous code:

```
$prior_instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
if (empty($prior_instance)) {
  field_create_instance($instance);
}

```
> 4 votes

---
Tags: entities
---


# Question
Title: How do I set my custom input type as default?
I strongly need to use my custom type as default. How do I set it as default?

# Answer
In Drupal 7, the default input format is the one the users have the permission to use, and that appears first in the list of the input formats reported in admin/config/content/formats.

In my case, Textile is the default input format that is selected for the administrator role, but if the currently logged-in user doesn't have the permission to use that input format, then the default input format will be "Filtered HTML." "Plain text" is the input format that all the roles can access; in the case none of the other input formats is accessible to the user, "Plain text" is the input format that will be used.

In Drupal 6, the default input format is the one selected as default in admin/settings/filters.
> 6 votes

---
Tags: input-formats
---


title: D7 + Views: How to hide fields labels?

text:
# Question
Title: D7 + Views: How to hide fields labels?
I have set all my fields labels as hidden in content types \> display fields.

It seems like Views overrides this by displaying labels of the filter fields.

How to hide them?

# Answer
Click on the field in the filter section, and you'll see a "Label" option.
> 3 votes

---
Tags: views, nodes
---


# Question
Title: Logo doesn't appear on the Seven theme on a fresh installation
I've got a fresh install of D7.9 and have enabled the 'Seven' theme which has an option to override the default logo in Appearance -\> Settings. I have uploaded a logo file and can see it via ftp but it does not show up on the site. Have I missed a step or does this theme not support logos out of the box?

# Answer
The logo for the theme selected is added to a php serialized array in the system table under the info column. It is advisable to not use FTP to upload the image but instead of the Admin UI under the themes section to do so.

Click Appearence \> Seven 7.8 \> Settings

Then scroll to "Logo image settings" and uncheck "Use the default logo".

Click "Choose File" and pick the logo image file.

Click "Save configuration" and your logo should show up in the site. If caching is enabled, the caches might have to be cleared.

**Edit: The page.tpl.php file for the seven theme does not have a section to display the logo. Not sure if this is a bug or just a design decision. Either way, there is no way to show a logo in the seven theme at this time.**
> 2 votes

---
Tags: 7, media
---


# Question
Title: Ubercart email notification to store owner when order submitted
I am new to Ubercart (we are installing and configuring on a Drupal 6 site) and have all of the store built out. I am attempting to set up a notification email to the store owner when an order is placed. I would think this is a built in configuration for ubercart... however for the life of me I can't find it.

Is there an Ubercart extension module which does this? Or should I configure this through Rules? I know there must be an existing and proven method for this in Ubercart somewhere.

# Answer
> 4 votes
You can use "Conditional Actions" to achieve this.

Its available under Store Administration / Conditional Actions. I believe there is a preconfigured conditional action for your request in Ubercart. Maybe you just need to enable it.

If not just create your own.

# Answer
> 0 votes
Also, take a look at the UC Rules module for Drupal 6.

---
Tags: 6, ubercart, rules, emails, notifications
---


title: Email marketing in Drupal 7

text:
# Question
Title: Email marketing in Drupal 7
I have a site with articles which has an RSS feeds. I 'd like visitors to be able to subscribe to those articles using their email. They ll give their email and then new articles will be sent to their email.

I m using feedburner to email right now, but I dont like it at all.

How this can be done in using Drupal modules and an SMTP server?

What technology is stackexchange.com using for the email notifications?

# Answer
> 1 votes
See Messaging and Notifications framework.

# Answer
> 1 votes
Here is a module for an SMTP Email Relay Service Elastic Email: Elastic Email.

---
Tags: 7, notifications
---


# Question
Title: Export exposed fields into a block with Views
I'm trying to create a **search box from the exposed fields** from a view. Is that possible? If I add a block display I also get the results.. I want only the fields, not both.

I also tried embedding a view with exposed filters inside a node, however, when I click "search" I'm not redirected to the view (the url is not constructed correctly: instead of website.com/**view**?exposed\_field=test I get website.com/?exposed\_field=test).

Any help is appreciated. Thank you

# Answer
> 1 votes
This functionality is now built into Views itself. See How To Display Views' Exposed Filter In A Block And Theme It for details.

---
Tags: blocks, search, views
---


title: How do you negate a rule in Rules 2?

text:
# Question
Title: How do you negate a rule in Rules 2?
I'm working with a Drupal 6 tutorial (but building in Drupal 7) that uses the Rules module, and I notice that some of the rules the presenter is building rely upon negation (e.g. "if NOT blah-blah") Am I missing something, or is this possibility not available in the Drupal 7 version of the module?

# Answer
**Rule conditions** may be negated by checking the Negate checkbox ("If checked, the condition result is negated such that it returns TRUE if it evaluates to FALSE.") You can't negate a rule event or an action.
> 4 votes

---
Tags: rules
---


# Question
Title: How can I change the text: "Images must be larger than 200x200" in the image field for a specific content type?
How can I change or replace the text: "Images must be larger than 200x200" in the image field for a specific content type?

I have created a image field CCK and I have put the Minimum resolution for Images of 200x200. When I put this restriction appears the text: Images must be larger than 200x200. I need to replace or change this text by: Minimum size for images: 200x200, in some content types. Is it possible?

I am working with Drupal 6.x.

Thanks.

# Answer
According my test you can use two ways:

**1)** rewrite theme\_filefield\_widget\_file() function inside your template.php of your theme, to replace the $element\['#description'\] value, for example:

```
function phptemplate_filefield_widget_file($element) {
  $output = '';

  switch ($element['#name']) {
    case 'NAME_FIELD'://name of field in $element['#name']
        $element['#description'] = 'Images must be larger than 200x200';
        break;
    }

  $output .= '<div class="filefield-upload clear-block">';

  if (isset($element['#field_prefix'])) {
    $output .= $element['#field_prefix'];
  }

  _form_set_class($element, array('form-file'));
  $output .= '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. $element['#id'] .'" size="'. $element['#size'] ."\" />\n";

  if (isset($element['#field_suffix'])) {
    $output .= $element['#field_suffix'];
  }

  $output .= '</div>';

  return theme('form_element', $element, $output);
}

```

(I found very useful to change all file/image fields, but in the example the switch/case allows select an specific field that can be of your content type)

**2)** `form_alter` hook in a custom module (in this example module name is change\_form\_values\_form\_alter), and attach a function to `$form['#after_build']` array:

```
function change_form_values_form_alter($form, &$form_state) {

    if ($form['form_id']['#id'] == 'YOUR_FORM_ID') {
        $form['#after_build'][] = 'change_form_values_file_widget';
    }

}

function change_form_values_file_widget($form, &$form_state) {
    $form['GROUP_NAME_IF_EXIST']['FILE_FIELD_NAME'][0]['upload']['#description'] = 'Images must be larger than 200x200';
    return $form;
}

```

Also, seems that all help string, including other validations like max size, extensions allowed, are overwritten, so I guess that you should add the string including other texts.

I hope information be useful.
> 2 votes

# Answer
you can use string overrides module or a hook\_form\_alter and override the text with

```
$form['PHOTO_FIELD_NAME']['#description'] = 'Images must be larger than 200x200';

```
> 2 votes

---
Tags: entities, media
---


# Question
Title: How can I filter related content types in Drupal?
I'm building out a project management/project organization site with Drupal. The basic content types will be:

1. Projects
2. Milestones (which belong to a project), and
3. Tasks (which belong to a milestone)

I've built the Project content type. That was easy. I built the Milestone content type, and using the Node Reference module, I was able to access all of the Projects right in the from. Nice! But now Tasks get a bit tricky. Using the same technique, I could reference all of the Milestones in the Tasks form, but I really only want to see the Milestones that are associated with a specific Project. It seems that I would need to employ some kind of filter. How?

What's the best approach here? I have no module restrictions and am using the most current version of Drupal (7.8).

# Answer
You could populate the second list manually by using the PHP code option to generate the values, the values could be something such as ProjectNid|TaskNid|Task Title.

You could then have a javascript hook so when a project was selected from the dropdown, it reads the nid value and then filters out the tasks where the first element (Project nid) doesn't match.

The other way would be reload the page after the project has been selected, and have the PHP code which populates the task field look at the current active value for Project and pull in the related tasks, or use a view with an argument set to achieve the same result.
> 2 votes

# Answer
I am not sure precisely what you are trying to accomplish. Milestones generally relate to Projects and Tasks relate to Projects. However, in many Projects, Tasks do not have a direct mapping to Milestones. In fact, in many cases, milestones are effectively tasks of zero duration.

Milestones and tasks usually have dependencies on each other as far as completion and such.

If it were me I would tie everything to the Project. Then when displaying items, I would display in date order.

While Drupal is extremely powerful, I think you are correct in questioning whether it is an appropriate solution for a project management system. Drupal is very good for systems which are developed largely with modules out of its repository. However, to develop the kind of system in which you may be envisioning, you would need to have a very deep understanding of project management, Drupal, and PHP.

I think there are many systems already out there which might be worth a look. Quite a few are cheap or open source. Even if you eventually plan to build your own system (which I would generally recommend against), you would be able to come to a thorough understanding of the functionality.

Also, I might point out that Drupal has almost 9000 modules--several of which relate directly to project management. Depending on your specific needs, you may be able to use existing Drupal modules to accomplish your objectives.

A great place to start is http://drupalmodules.com.
> 1 votes

---
Tags: nodes
---


# Question
Title: Unable to uninstall an incompatible module
I have 6.22 core and by mistake added the folder for quicktags 7.x-3.0 to the modules folder.

I deleted the folder, replaced it with 6.x but nothing seems to allow me to enable the quicktabs module under "Home » Administer » Site building » Modules."

All I get against the quicktab folder is:

> This version is incompatible with the 6.22 version of Drupal core.

How can I install the correct version of the module?

# Answer
Install drush, and type

```
drush cc all

```

to clear the cache, then

```
drush en quicktags

```

to enable the module; sometimes drush saves my day, when the admin\>\>modules throws errors.
> 1 votes

# Answer
The only quicktags module I found doesn't have a version for Drupal 6 and Drupal 7; the module is for Drupal 4.7 (the development snapshot 4.7.x-1.x-dev) and for Drupal 5 (the development snapshot 5.x-3.x-dev, and the official release 5.x-3.1-dev).

If you copied one of those versions, the module is rightly reported not to be compatible with Drupal 6.

If you installed Quick Tabs, which effectively has a 7.x-3-0 version, then it is probable that you have two copies of the files of that version in two different directories, one of which is the directory of another module. Suppose that you copy the files of the Quick Tabs module in the directory "cck," those files will be found first the files contained in the directory "quicktabs"; if the files copied in "cck" are for Drupal 7, then you see the error you are seeing because those files are the first ones that are retrieved.
> 0 votes

# Answer
I know that is an *old* question.

besides of clear cache and/or remove files, I find useful to review `.install` file of incompatible module to see in detail changes inside database, so you can detect respective changed data in database. Is just an opinion.
> 0 votes

---
Tags: 7
---


# Question
Title: Change a Node Reference field value with VBO
I'm having trouble setting a Node Reference field using VBO. If I select Integer as the parameter type it doesn't change the field value, and if I set it to Node Reference it has a "Data selector \*" field for the input and no value seems to satisfy it.

Any suggestions?

# Answer
Ok what worked out was having 2 parameters. One the node I'm altering, the other an integer field to input the node ID. Then I set up a "Fetch entity by id" action using the integer parameter. I use the entity variable provided by the fetch action to set the node reference field.
> 2 votes

---
Tags: 7, rules, views
---


title: Webform send multiple email

text:
# Question
Title: Webform send multiple email
I have created a webform. There is one field "Send invitation to your friends" . In this field user can enter their friends email ids (Comma seperated) For example A@gmail.com,B@yahoo.com,C@hotmail.com etc. I want to send a common email "Welcome and join us" to all these people. Can anyone help me, how can I proceed?

# Answer
> 5 votes
You can send custom emails to addresses submitted in the form. When creating the form, you have to select 'email' for the field type. Once you've done that, go to the 'Emails' tab in the webform, and add a new email using the 'Component value' menu; you should see your Email field in there (you can add as many of these as you want). This sets it up to send an email to the email address entered in the form, in your case the friends' email addresses.

From there you can customise the email options.

Edit: Whoops, this answer is for Drupal 7 specifically, but (if I remember correctly) the option exists in Drupal 6 as well.

---
Tags: 6, webforms
---


# Question
Title: How can I alter the HTML output of a specific content-type in display mode via a module, without creating the node type in a module?
I have a specific node-type: resource. The default display of a resource node is not quite what I want, so I need to over ride the themeable output - so far so good. The problem is, I've created my resource node-type through the Drupal 7 GUI. How do I write a module that just over rides the HTML output for this one content-type?

...and, in piggyback to that question - I will have many other node-types that I've created through the GUI, but need custom output for. Is there a way to create just a single module that will handle the custom output for all of these types?

Thanks.

# Answer
I would use a template override on node.tpl.php for the resource type. Just copy it to node--resource.tpl.php and make your changes. Here is a good tutorial.
> 1 votes

# Answer
IMO, a very good approach would be using Display Suite to generate the basic markup/layout and then add the appropriate styling to the theme.
> 1 votes

# Answer
You can use hook\_view() and `hook_node_view()` in your module to customize your node display, or `hook_field_prepare_view()` to alter individual fields.

On your module within `hook_view()` and `hook_node_view()`, you should use a control statement like `switch` to place the code for each type:

```
switch ($node->type) {
  case 'resource':
    ...
    break;
  case 'other':
    ...
    break;
}

```

To see what is inside `$node`, you can use the Drupal 7 debug() function, like this:

```
debug($node);

```
> 1 votes

# Answer
To answer the question about managing the display of all the content types, you may also want to look into adding custom view modes. Display Suite itself may give you what you need, but keep view modes in mind if you need to display several of the node types in a certain fashion or want to display different fields on different tabs in conjunction with Panels or Display Suite.
> 0 votes

---
Tags: 7, nodes
---


title: Form state redirect to previous page

text:
# Question
Title: Form state redirect to previous page
I have a custom form which can be accessed from different places inside the website. The form itself is inside the admin overlay.
When the form is submitted, I want the user (administrator) to return to the place where he accessed the form. The form can also be accessed from within the overlay.
Inside the submit handler I use a form redirect to return but I don't have a clue how to determine the url of the previous page to return to.

```
// $_SERVER['REDIRECT_URL']?
$redirect = 'set redirect url'
$form_state['redirect'] = $redirect;

```

# Answer
> 1 votes
If I'm not wrong by default the form redirect the user in the page where it was generate. But, if you want change it you can use the function drupal\_get\_destination and add it to your `action=""` simply by changing the `$form['#action']` in your code.

---
Tags: 7, forms
---


# Question
Title:  Modules to extend the Display Suite module?
Just that. I find the Display Suite module really useful for my projects.

Are there more modules to extend its functionality in any way?

Thanks.

# Answer
> 4 votes
I really like the combination of Display suite with Custom Formatters - http://drupal.org/project/custom\_formatters & with the Omega Theme, with these tools you can almost entirely skip having to use tpl.php files to theme your site's layout and content.

Also listed on the Display suite page you have Field Group - http://drupal.org/project/field\_group & Rendable elemenets - http://drupal.org/project/rel However Rendable elements doesn't seem to work that well quite yet but it looks promising.

---
Tags: display-suite
---


# Question
Title: What's the best module to serve mp3 or audio files securely? Problem with jPlayer, etc
I'm trying to protect (in this example) audio files from being downloaded. I'm currently using jPlayer because it is supposed to provide download protection (which it supposedly does, but it breaks when I enable it).
Surely there is a way to prevent leeching and downloading of files. The Drupal private file system, as I understand it, only restricts access per user role. Creating a path `system/files/file.mp3`. Which tells Drupal to check if the user has permission to download the file. So if I set that up - with the file storage outside my public root - when i type `http://site.com/system/files/file.mp3`, Drupal just serves up the file and it starts downloading. Its a public file system by default, the audio file is a private file field. If I turn on protection in the jPlayer module then it wont play.

In the reports, immediately when viewing the node that the audio is on I get that the file cannot be accessed - twice in a row. Clicking on play gets me this:

> PDOException: SQLSTATE\[23000\]: Integrity constraint violation: 1062 Duplicate entry '1-30-1318255859' for key 'PRIMARY': INSERT INTO {jplayer\_denied} (uid, fid, hostname, timestamp) VALUES (:db\_insert\_placeholder\_0, :db\_insert\_placeholder\_1, :db\_insert\_placeholder\_2, :db\_insert\_placeholder\_3); Array ( \[:db\_insert\_placeholder\_0\] =\> 1 \[:db\_insert\_placeholder\_1\] =\> 30 \[:db\_insert\_placeholder\_2\] =\> {my ip address here} \[:db\_insert\_placeholder\_3\] =\> 1318255859 ) in drupal\_write\_record() (line 6868 of /var/www/html/drupal/includes/common.inc).

Can anyone steer me in the right direction here?

EDIT:

Well I finally got the private serving working actually - kind of. It will serve up the file once when the page is first loaded and will only serve it again if I almost immediately try and hit the URL again. Then after a couple seconds it will block it like it's supposed to. This works good enough for now I suppose.

# Answer
> 1 votes
For a real good private file protection use the Private Files module.

---
Tags: users, files
---


# Question
Title: How do I disable the "Group activity" tab on the organic groups page
I've got organic groups setup in Drupal 6 and have been asked to remove the "Group activity" tab from the groups page (example.com/og). I suspect that this is being driven by one of the views, but I can't seem to find one that is powering it. Is it possible to disable this tab or control its output at least?

This tab appears to have been removed from the Drupal Groups site: http://groups.drupal.org/og

# Answer
The Tab tamer module is a quick and easy way to hide or disable extra tabs.
> 1 votes

---
Tags: views, 6, organic-groups
---


# Question
Title: Views Module "Page" and Contextual Filters
I have a /press-releases section of my site. The /press-releases url shows a summary of all articles (press-release content types) and there is a block on that page that is generated by a view which displays the latest press releases by release date. That part works great.

When a user clicks on one of the listed articles, I need it to go to the full article, but use a special "View" for press releases (articles). I think I need to use some combination with the page view's "Path" field along with the Contextual Filters, but I can't figure out the correct combination.

In other words, how do I show my Press Release (article) Page View when the url is /press-releases/anyarticle ?

# Answer
> 0 votes
You are close. Remove the "Global: Null" contextual filter and configure your "content: nid" contextual filter this way:

WHEN THE FILTER VALUE IS NOT IN THE URL =\> Display all results for the specified field WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED =\> Specify validation criteria, content, type: press releases

To get the press release links changed, you need to: \- add field "content: nid", exclude from display, and rearrange on top, above title \- edit title and remove "Link this field to the original piece of content". In "Rewrite results" check "Output this field as a link" and enter "press-releases/\[nid\]".

# Answer
> 0 votes
Ben & Mototribe. I am following this question. I thought that Blocks did not read the URL directly and you have to direct the block to read the URL. In that case, in WHEN THE FILTER VALUE IS NOT IN THE URL you should set 'Provide Default Value' checkbox and select 'Content ID from URL' to tell the block where to look. This should take you to whatever press release is in the URL.

---
Tags: 7, views
---


title: User URLs based on the usernames

text:
# Question
Title: User URLs based on the usernames
Is there a module that changes the user URL from "user/1" to "user/username"?

# Answer
Pathauto does exactly that.

All new user aliases generated after enabling the module will look like `users/[user:name]` (obviously this could be changed in module configuration - Configuration / URL aliases / Patterns).

You can use "Bulk update" to generate aliases for already existing users (and other type of content).
> 14 votes

# Answer
You can use the PathAuto module to create an alias for every user.Your alias pattern would be able to include the username in its pattern. If you want the aliased path to be the primary url then you can also use GlobalRedirect to make user/id redirect to user/username
> 4 votes

# Answer
You can always use the Me Aliases module. It doesn't matter what user is logged in; they can use "user/me" to access their own accounts.
> 1 votes

# Answer
I am not sure if there's an individual module for that purpose, but I guess you could take a look at Drupal's url() method or hook\_url\_inbound\_alter() to help your purpose.
> 0 votes

---
Tags: 7, users, uri
---


title: drupal 6 NOT showing php notices

text:
# Question
Title: drupal 6 NOT showing php notices
I am trying to make php show error notices, but it doesn't work. For my error settings I have write errors to screen and log.

I tried this: (in page.tpl.php)

```
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$abc = array();
echo $abc['test'];

```

# Answer
> 3 votes
To enable error messages, add the following to your *index.php*:

```
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

```

# Answer
> 2 votes
Answer is already accepted, but editing index.php isn't the greatest idea. It is a core file and will get replaced when you apply an update.

There are two ways you can go about this.

One is to put the code in settings.php, along with the other php variable overrides.

```
error_reporting(E_ALL);
ini_set("display_errors", TRUE);
ini_set("display_startup_errors", TRUE);

```

The other way (assuming Apache) is to put the statements in your .htaccess or your Apache config for the host. .htaccess may get replaced when you update, so Apache config is the better option here. The only thing to be aware of is that E\_ALL is a constant in PHP, and you have to use the numeric value.

When I execute

```
<?php print E_ALL; ?>

```

I get the value 30719. You can then use

```
php_value error_reporting 30719
php_flag display_startup_errors on
php_flag display_errors on

```

Note that the value of E\_ALL may be different on your machine, depending on the version of PHP you are using and vanilla Apache/PHP vs Zend Server.

Then restart Apache. You can verify these by making a file with

```
<?php phpinfo(); ?>

```

in your DOCROOT and browsing to it and viewing the settings section. Remember to remove it when you go live, or lock it down by IP or password.

# Answer
> 1 votes
Check this article for the code to add to your index.php.

# Answer
> 0 votes
I have an article on this subject: http://groups.drupal.org/node/170339

---
Tags: 6
---


title: Content type menu links?

text:
# Question
Title: Content type menu links?
I'm making a site that has three different content types. I would like a Main-Menu link to each content type. Additionally, I would like each of these three pages to list recent nodes for that content type, with a link to to that node. I would think this is pretty standard.

So I've created the content types, and I can click directly to each content type, but I do not know what the "best practice" would be to create these pages. I could create an override of node--*mycontenttype*.tpl.php but is this the right way to go? How would I link to the general page (instead of the specific node)?

# Answer
There are many ways to do this. A simple way would be to create a view for each content type and then create menu items for each of them.
> 2 votes

---
Tags: routes, nodes
---


# Question
Title: Why doesn't this Views 3 contextual filter work?
I have expanded the article content type to include a few more fields and want to display an article node as a page. Each article node (content) I give an alias with the following pattern: press-releases/\[name-of-article\]

I've set up A "Press Releases" view which has three displays. Two of the displays are block displays and these work perfectly. I also want to make a page display with this view, and that's where I'm running in to problems. I want this view to be active for any node (content) that has the url press-releases/\[name-of-article\] and so I set up the view like this:

And the Contextual Filter has these settings for the Node ID:

But when I visit any press-releases/\[name-of-article\] it's like the Contextual Filter is completely being ignored and I just get the node spit out all the default fields as determined by the content type, and not according to the View's Page display. Why is this, and how can it be corrected?

# Answer
In order to play nicely with other modules, views will not override any aliases that point to something already. You're trying to make a view show up on an alias that is already pointing to a standard drupal full page node. This simply will not work.

Options:

1. Stop giving aliases to press release nodes so they are only available at `node/nid`
2. Use a different path for your view so it doesn't conflict with your nodes
3. Use Panels to override your full node page and show that view

**Some other things to consider**
A view is really useful for display a list of things, you should probably consider not using it as a node page in this way. You can get a lot of control over your page layout using the standard display tools Drupal 7 gives you.

Using `Content: Nid` as a contextual filter will not recognize a url in the form of `press-releases/name-of-article`. You would need to use `Content: Title`. You also don't need to specify the raw url value as a default value or add `%` in your view path. The order in which the contextual filters are configured are the order in which they are pulled from the URL.
> 5 votes

---
Tags: 7, views
---


# Question
Title: Create a page filter with the last article of each category
My articles are grouped in 6 categories (created by taxonomy)

I need to output a view page that contains 6 sections each one displays in a block or div the latest article of the category it belongs.

I have a solution how to do that by creating 6 views for each category filtered desc and displaying the last article and a 7th view to hold all the 6 view blocks. The only thing I don't like it about this is if the editor enters a new category I need to manually update the view.

Is there a way to display the 6 cell grid with the categories as I mentioned before?

# Answer
> 1 votes
I managed to figure out based on Daniel Wehner clue. There is an obvious bug in the views handlers that has already been submited to the Views development team and got already fixed in the development snapshot.

**Step1. Fix the bug** First you need to check your Apache's log and notice the line:

> PHP Fatal error: Call to undefined method views\_handler\_relationship\_groupwise\_max::view\_aliased() in ...\sites\all\modules\views\handlers\views\_handler\_relationship\_groupwise\_max.inc on line 200

If you get an Ajax error, you should see the error in a modal window.

Now you need to find out views\_handler\_relationship\_groupwise\_max.inc, and at line 200 replace the line:

```
$temp_view = $this->view_aliased();

```

with

```
$temp_view = $this->get_temporary_view();

```

Step2. **Create a taxonomy view of the categories**. Once you have the categories display you create a relationships of type: Representative node with the node title, sorted DESC and then add all the fields needed in the main view settings.

# Answer
> 1 votes
Yeah that's possible.

* Add a new taxonomy view
* Add a relationship: Representative node.
* There configure to sort by node created DESC.

That's it

---
Tags: views
---


# Question
Title: How to get exposed filter dropdown option selected value in drupal hook
I'm trying to get exposed filter selected value in hook\_form\_alter().

```
myModule_form_alter(&$form, $form_state, $form_id) {
     if ($form['#id'] == 'views-exposed-form-view-id-display-id'){
          var_dump($form['exposed_element']['#options']);
     }
}

```

i tried with also

```
$form['exposed_element']['values'],
$form['values']['exposed_element']
$form['exposed_element']

```

But none of them giving me selected option value.

Any help/suggestion would be greatly appreciated.

**EDIT**

For more clarification

```
function myModule_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
        case 'views_exposed_form':
            switch($form['#id'])
            {
                case 'views-exposed-form-soldproduct-page-1':
                       var_dump($form['exposed_element']['#options']);
                break;
            }
        break;
    }
}

```

Where soldproduct is my view name and page-1 is the view display id.

# Answer
> 3 votes
First of all, look up the exact filter's name. To do that open your view's builder UI and go to this exposed filter's settings page; look for the "Filter identifier" text field.

After that, you can get the filter's currently selected value in `hook_form_alter()`:

```
function myModule_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == 'views_exposed_form'){
        $view = &$form_state['view'];
        if ($view->name == 'your view name' && $view->current_display == 'page_1') {
            var_dump($view->exposed_input['your filter identifier']);
            // OR
            var_dump($form_state['input']['your filter identifier']);
        }
    }
}

```

---
Tags: views, 7
---


# Question
Title: How do I show username & email address of currently logged in user on a page he is viewing?
I want the logged in user to see his name and email address in the text of a paragraph on a given page, how to I extract that information from the currently logged in users account, and show it in the body of the page?

# Answer
You can create a block with the **PHP code** format (don't forget to activate the PHP filter module) and put inside:

```
<?php
  //Retrieve the global variable for the connected user
  global $user;
  echo 'Hello ' . $user->name;
  echo 'Your email is :' . $user->mail;
?>

```

Then you set up this block to show only for authenticated users and you place it in a region.

See Drupal global variables documentation.
> 2 votes

# Answer
You can also look into Token Filter \- you add this as a processor on the text format and can then use tokens right within your content without having to enable the PHP module. Much more elegant. It may or may not work for your user tokens according to the project page, but definitely worth a shot.
> 2 votes

# Answer
A simple way would be to create a view for those fields with a contextual filter "userid from logged in user". Use the block display and show it anywhere on your site.

Please specify if you have more specific layout requirements. As with anything in Drupal there many different ways of getting to the same results ;-)
> 1 votes

---
Tags: users, tokens
---


# Question
Title: Stop Drupal from encoding '&' as '&' in YouTube URLs
I embedded a YouTube video inside a "News" node. The input format in use is Full HTML.

When node is saved, the ampersand symbol in `&wmode=Opaque` is substituted for `&wmode=Opaque`.

Is it possible to prevent the ampersand in the URLs of embedded YouTube videos is encoded as HTML entity?

# Answer
> 2 votes
Try disabling the HTML corrector on the text format. Also, though, I don't think URL-encoding amphersands in URLs actually breaks them. & should work as a query string parameter separator as well. If not, though, see my suggestion :)

# Answer
> 1 votes
I haven't tried yet but I can give you a clue. This could be a ckeditor issue or what editor may use (tinymce etc..): try to make sure you have a button like view source added to your editor button grid. Then paste the youtube link in view source mode.

Ampersands in HTML are encoded as `&` That is, this is correct HTML.

If you think this won't work you need to go one step further and to display the content as plain text.

You need to edit your Full HTML input format: config/content/formats or from Configuration \> Content Authoring \> Text Formats \> Configure and check Display any HTML as plain text or Convert URLs into links

---
Tags: uri, theming, nodes
---


# Question
Title: How to find the list of 'paths' on my site?
I recently became the administrator of a Drupal site. I am attempting to configure various blocks on the page, and have so far only succeeded in removing them altogether. The configuration menu tells me to enter the 'path' for where I want the block to appear. How do I find the list of path names available for entry? The site has a blog, but entering "blog" or even "blog/\*" did not make the block appear on the block.

# Answer
> 8 votes
To get all the paths you can use, you can use the following code to get all the paths defined from modules:

```
$items = module_invoke_all('menu');
drupal_alter('menu', $items);
foreach ($items as $path => $info) {
  print preg_replace('/%([a-z0-9_]*)/i', '*', $path);
}

```

The code will show the path as you enter in the block settings; this means it will change `node/%node` in `node/*`, and `node/%node/edit` in `node/*/edit`.

About your specific issue, the block could not appear because the block has not been assigned to any theme section, the theme doesn't define the section where the block should appear, or the block is empty. In most cases, modules don't output empty blocks.

# Answer
> 4 votes
If you have the Path module (core) enabled, there will be a page that lists all URL aliases on the site.

If using Drupal 7: example.com/admin/config/search/path

If using Drupal 6: example.com/admin/build/path

---
Tags: uri
---


# Question
Title: Permissions / Roles / Taxonomy / Workbench -- combination?
Hello dear Drupal enthusiasts,

I'd like to hear your opinion - how to organize mentioned modules/functionality to achieve nice permission granularity.

1. After user is logged in we have a list of his e-groups (outside structure, we have its names).
2. I want to build drupal inner hierarchy where I organize user e-groups to tree structure.
3. I would like to divide nodes to groups, to allow people who are members of some e-groups to edit some nodes (gathered in group).

What comes to my mind it's to organize page structure in one vocabulary, and allow admin to add a e-group name to some taxonomy.

Example:

* Main Site admin \[taxonomy: egroup-main\]

+ Department A admin \[taxonomy: egroup-department-a\]
    + Group 1 \[taxonomy: egroup-group-one\]
    + Group 2 \[taxonomy: egroup-group-two\]

    - Subgroup 1 \[taxonomy: egroup-students\]
    + Group 3 \[taxonomy: egroup-group-three\]

And now, after somebody logs in first time, and we know he is part of egroup-main, we give this user taxonomy egroup-main, which is the same we set to Main Site Admin term in vocabulary shown in example.

1. Is there any better way to organize this? I need fine, good grained control over users by egroups, to access, create and delete nodes.
2. What about workflow management? I mean - module like Workbench is nice to control workflow, let beginner users to edit, and let admins to publish stuff after review.

I know there's a module called Taxonomy Access but it seems it bases on Drupal Roles which means apart from taxonomy we would have to create dynamically user roles (depending on e-groups), attach permissions to them and assing users to these roles...

Waiting for your hints people!

Confused Drupal developer

# Answer
http://tutr.tv/t4991?list=4948 is a video from Drupal Con London where they talk about the Workbench Modules and will answer most of your questions/concerns.

If you have Workbench Moderation you can have users submit content for review. Then a content moderator will publish the content or return it as a draft for changes.

Workbench Access will limit users to what content a user can create/edit. You just need to create a role, assign the role to a Workbench Access Section of the site, and then when they create a new account you can assign them to the correct role.

I have this on my site and have created a rule to email me whenever someone logs in for the first time so I can assign them a role.
> 2 votes

---
Tags: taxonomy-terms, users
---


# Question
Title: Grant/refuse access permission on the fly
Is there some kind of hook or callback that will allow me to do some fancy checks before granting or refusing permission?

I have an Application content type which references another content type that contains a list of users that are allowed to view it. I need to load up the list of users and check to see if the current user is in the list.

# Answer
> 2 votes
Yes. Look into this topic: Node access rights.

That's what you should do if you want the permissions to be respected in all contexts, including DB queries (except your own if you don't use db\_rewrite\_sql).

Another potential solution, assuming that you can get your existing setup to work with it, is Content Access. It can do per-user access control. The way I would do this is implementing hook\_nodeapi's update operation and then programmatically configuring Content Access to match the list of users. Basically, the list of users would become a simplified admin interface in this approach. You would of course have to look at how Content Access manages this specifically (I know it uses the ACL module).

This approach should have all the benefits of the previous one, i.e. low-level security.

The poor man's way to do this would be to use hook\_menu\_alter and change `access callback`/`access arguments` to your own, where you'd load the nodes and do your fancy checks. This would only help on viewing, though, not on data retrieval. But it is probably easier than the other two ways if you don't need a perfect solution.

---
Tags: 6, users
---


# Question
Title: Do I need to optimise images for smaller file sizes?
Im adding images to my content through Drupal eg as a CCK field and im normally displaying them through image cache.

I want the images to be compressed for a smaller file size as sometimes the originals can be massive without looking that much sharper. Note, im not talking about resolution here, but the quality of the image.

Do I need to first do this with a graphics program like Photoshop or will Drupal automatically do this for me? If it does it automatically, are the results fairly good or is it still best to do it manually?

Thanks

# Answer
Drupal does this for you; check your ImageCache settings (look for it under `admin/settings`), since it basically runs ImageMagick or uses GD in the background to do the image conversions. There is a quality setting that should do what you need.

IIRC, ImageMagick does a good job. The external GD library when called from PHP apparently aren't as reliable, but the built-in GD also does a good job, I think. Ultimately, you have to test this to see if it meets your own standards.
> 1 votes

---
Tags: media
---


# Question
Title: Views_embed_view fatal error in views.inc
I'm getting this error when I embed a view on a page. It doesn't happen when I preview the view in views UI.

"recoverable fatal error: Object of class stdClass could not be converted to string in views\includes\view.inc on line 728."

This is my embed code:

```
<?php print views_embed_view('list_applications_for_reviewer', 'block_1', array(85, 229)); ?>

```

I don't have this problem in any of the other views on my site, of which there are many doing similar things.

Any ideas what I might need to fix?

# Answer
> 1 votes
First thing I would try is using instead of passing the arguments as an array. I recall hitting this issue because `views_embed_view()` uses `func_get_args()` to process view arguments and behaves oddly if an array of them is passed.

If that doesn't work, your best bet is to step through the code with Xdebug and see if you can find the difference between that variable when it works (all other times) and when it doesn't (this time).

---
Tags: views, 6
---


# Question
Title: 'Show block on specific pages' wraps url in paragraph tags
I have a Drupal 6 site and I want to add a block to a page. This block is generated from a custom module, from the `hook_block` function.

Under the blocks admin section, under `Page specific visibility settings` header, there is the setting for `Show block on specific pages`. I've entered my url under `Pages` and selected `Show on only the listed pages.`

When I click save, Drupal wraps my path in `<p>` tags. I don't have anything in my module that would be overriding the default drupal behavior. Why is this happening and how can I get it to stop?

# Answer
> 1 votes
We have CK Editor enabled on our site. In order to fix this, I had to go under CK Editor and change the profile for my role. Under `Visibility Settings`, there was a place to specify paths of textareas *not* to affect. I put in the path and I'm good to go!

---
Tags: 6, blocks
---


# Question
Title: Log where permissions are being refused?
When not logged in as admin my view is returning no results. I believe it to be a permissions issue but everything appears to be configured correctly.

Is there a way to get a log of what permissions are being attempted and then rejected, and by what?

# Answer
No. Permissions usually are checked by a function call to `user_access` and for performance reasons there is no way to override that (not that D6 was so big on overrides like D7 is -- still that function can't be overridden in D7). You can set use devel to see the query if one is run or Views can display the query. As a last resort, you can add `error_log(4, $string);` into `user_access` itself to send the permissions into Apache error log or similar.

Note that it can be a node access issue, in this case the query log will help you.
> 2 votes

---
Tags: 6, users
---


# Question
Title: For multilingual sites, do I set up a separate taxonomy?
If I decide to set up an additional language for my site, do I need to manually set up a translated version of my existing taxonomy, or is there a module that can manage that process for me (not the translating part, obviously)?

# Answer
The I18N project gives you multiple ways to deal with multi-language taxonomies:

* Assign a vocabulary a language, making it specific for that language only
* Translate Terms into different languages
* Assign each term a language, so that you can have different terms based on the chosen language, but still a common vocabulary.
> 1 votes

---
Tags: 6, taxonomy-terms, i18n-l10n
---


# Question
Title: How to modify Drupal configuration programmatically?
How can I modify the Drupal settings found on /admin/config/people/accounts (and other configuration pages) using a custom module?

For example, how do I rename the Anonymous user and change 'Who can register accounts' setting from 'administrator' to 'visitor' programmatically with a custom module?

# Answer
> 9 votes
Most of these configuration settings tend to be controlled by a variable, so Drupal uses `variable_get()` and `variable_set()` to retrieve and modify these values.

To find out the variable name and value you can have a look at the source page. For example:

```
<label for="edit-user-register">Who can register accounts? </label>
<div id="edit-user-register" class="form-radios">
  <input type="radio" id="edit-user-register-0" name="user_register" value="0" class="form-radio">
  <label class="option" for="edit-user-register-0">Administrators only </label>

  <input type="radio" id="edit-user-register-1" name="user_register" value="1" class="form-radio">
  <label class="option" for="edit-user-register-1">Visitors </label>

  <input type="radio" id="edit-user-register-2" name="user_register" value="2" checked="checked" class="form-radio">
  <label class="option" for="edit-user-register-2">Visitors, but administrator approval is required </label>
</div>

```

Here you can see that in order to change the *"Who can register accounts?"* option, you need to change the value of the `user_register` variable. You can set it to `1` for visitors, so putting this code in your module will do the trick:

```
variable_set('user_register', 1);

```

Of course, this is if you're too lazy to open the source code :) . The other way is to find out which callback generates this form, and inspect `user.module`:

```
function user_menu() {
  //snip...
  $items['admin/config/people/accounts'] = array(
    'title' => 'Account settings',
    'description' => 'Configure default behavior of users, including registration requirements, e-mails, fields, and user pictures.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_admin_settings'),
    'access arguments' => array('administer users'),
    'file' => 'user.admin.inc',
    'weight' => -10,
  );

```

Then find the callback function `user_admin_settings()` in `user.admin.inc`:

```
$form['registration_cancellation']['user_register'] = array(
  '#type' => 'radios',
  '#title' => t('Who can register accounts?'),
  '#default_value' => variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL),
  '#options' => array(
    USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
    USER_REGISTER_VISITORS => t('Visitors'),
    USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'),
  ),
);

```

So there you have your variable and in fact there's some constant to set up the values: `USER_REGISTER_VISITORS`.

---
Tags: 7
---


# Question
Title: drupal_set_message is visible only to those with permissions for the operation?
API about drupal\_set\_message read: "Set a message which reflects the status of the performed operation. If the function is called with no arguments, this function returns all set messages without clearing them."

Does that mean, if the operation is not permitted for authenticated user or anonymous, then they cannot see the message but only visible to who has the permission to perform the operation?

# Answer
No, it doesn't. It means that if you want to get the list of the messages set from other modules, you just call the function without any argument; this is what drupal\_get\_messages() does to get the list of messages set by the modules.

```
function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
  if ($messages = drupal_set_message()) {
    if ($type) {
      // …
    }
    // …
  }
  // …
}

```

If the message should be visible to users with a specific role, it is the caller that needs to first check the user's permissions with `user_access()` as in the following code, executed from comment\_form\_submit():

```
  if (!user_access('administer comments')) {
    drupal_set_message(t('Your comment has been queued for review by site administrators and will be published after approval.'));
  }

```

This doesn't need to be done in a form submission handler, if who uses the form is already restricted to who has that permission.
> 2 votes

---
Tags: users
---


title: D7 Related Nodes within a Content Type

text:
# Question
Title: D7 Related Nodes within a Content Type
Please forgive me if this is a total noob question, but here it is anyway.

I have a content type 'person'. One of the fields I want to add to the 'person' is a relatives field and I want it to either be an autocomplete or a drop down list. I'm pretty sure I can figure that part out. The question is, how can I populate the drop down list (or the autocomplete) with the names of all 'person' content that is already created?

Also, I am using the persons full name for my title field.

I'm also running drupal 7 and I've installed the CTools and Views modules.

EDIT:

After some more thought on this, what I'm really trying to do is have a field that links to a related content node. That way if a person is ever deleted they would also be removed from those who claim to be related to them.

Does drupal have a way to do this? I have so many ideas on how to use drupal, but most of them involve relating nodes to one another in a heirarchal format.

# Answer
> 3 votes
I would look at the references module, this will allow you to manually set relationships between your "people".

---
Tags: entities, nodes
---


# Question
Title: CCK text field does not appear in views fields nor filters
I have a CCK text field in my TOC. However, it is not displayed for selection under the views fields nor the views filters.

I tried clearing cache and refreshing the module list with no luck.

Any hint of what could be happening?

# Answer
> 0 votes
The problem was that I had in Views -\> Tools the option "Disable views data caching" unchecked. Fixed now, thanks for your help!

---
Tags: 6, entities, views
---


# Question
Title: Displaying all sub-menu items even when not "expanded"
I'd like a menu structure that is something like the following to be placed into a page's sidebar.

Insects
Animals
----Mammals
--------Bears
--------Whales
----Reptiles
--------Snakes

I'd like it to be set up so that if a user is on the bears page, the animals and mammals menus will be expanded...but the user COULD click an arrow next to reptiles to have that menu expand, and see the snakes option. When I checked the $page\['sidebar'\] render array, however, child menu items that are not expanded are not even included in the array. So, if I am on bears, there is nothing below $page\['sidebar'\]\[whatever number reptiles is\]

I thought about writing a module that builds this through the DB, but at that point I'd be pretty much re-writing and implementing the menu modulem since I'd need to also include the html output of this new data on the page. What's the best way to approach this?

# Answer
> 1 votes
The jQuery Menu module gives you that functionality.

---
Tags: 7, routes
---


# Question
Title: A menu block won't show up for second language
I have 3 separate menus in my header. They are not connected. I don't used secondary menus.

My site is bilingual: english + spanish.

All 3 are created using menus and placed in the same region using blocks. They are all translatable: checked Make this block translatable. And they all have translated strings edited already.

However, when I switch to Spanish one of the menu dissapears and won't show up. I check in the DOM and is not build at all.

Another mention: the menu that won't show up is a category menu: it points to the a page that display article based on the specific category.

Can someone give me a clue?

# Answer
> 0 votes
In the specific menu edit mode: structure/menu/manage/your-menu/edit alter the Translation Mode.

---
Tags: routes, blocks
---