# Question
Title: Having duplicate entry error with Panelizer module
I installed the Panelizer module and enabled it for a specific content type. When trying to add new content, I get a duplicate entry error as follows :

> PDOException: SQLSTATE\[23000\]: Integrity constraint violation: 1062 Duplicate entry 'node-196-197-page\_manager' for key 'PRIMARY': INSERT INTO {panelizer\_entity} (entity\_type, entity\_id, revision\_id, no\_blocks, css\_id, pipeline, did, view\_mode, css\_class, title\_element, link\_to\_entity) VALUES (:db\_insert\_placeholder\_0, :db\_insert\_placeholder\_1, :db\_insert\_placeholder\_2, :db\_insert\_placeholder\_3, :db\_insert\_placeholder\_4, :db\_insert\_placeholder\_5, :db\_insert\_placeholder\_6, :db\_insert\_placeholder\_7, :db\_insert\_placeholder\_8, :db\_insert\_placeholder\_9, :db\_insert\_placeholder\_10); Array ( \[:db\_insert\_placeholder\_0\] =\> node \[:db\_insert\_placeholder\_1\] =\> 196 \[:db\_insert\_placeholder\_2\] =\> 197 \[:db\_insert\_placeholder\_3\] =\> 0 \[:db\_insert\_placeholder\_4\] =\> \[:db\_insert\_placeholder\_5\] =\> standard \[:db\_insert\_placeholder\_6\] =\> 0 \[:db\_insert\_placeholder\_7\] =\> page\_manager \[:db\_insert\_placeholder\_8\] =\> \[:db\_insert\_placeholder\_9\] =\> H2 \[:db\_insert\_placeholder\_10\] =\> 1 ) in drupal\_write\_record() (line 6888 of /Library/WebServer/Documents/www/jkl/includes/common.inc).

Any insight?

# Answer
Looks like a known bug: unable to edit nodes with default panelizer state.

Try the patches in the above issue. Looks like it might be useful to chip in there with your issue also!
> 1 votes

# Answer
Thanks Chapabu. I've been through those, and tried merlinofchaos's #7 patch and get this in my apache error log : Fatal error: Declaration of PanelizerEntityNode::get\_default\_display() must be compatible with that of PanelizerEntityInterface::get\_default\_display() in /Library/WebServer/Documents/www/jkl/sites/all/modules/contrib/panelizer/plugins/entity/PanelizerEntityNode.class.php on line 12 The other patches there don't work at all. :/
> 0 votes

---
Tags: 7, panels
---


# Question
Title: Populate second node reference field based on what first node reference field is selected
I have 2 content types. "ABC" content type and "DEF" content type. In "DEF" content type i give reference to "ABC" node reference.

I am building another content type called "XYZ" where i give node reference to "ABC" and along with it i give node reference to "DEF" content type.

My problem is that i need to filter out the "DEF"(node reference to "DEF") drop down based on what "ABC" is selected from previous "ABC" drop down.

How to achieve this.

Any help is appreciated.

# Answer
> 0 votes
You can use custom coding to achieve this, here the idea

1. Add a script to call a ajax call back on change your first node reference select list.
2. Define the menu callback in your custom module.
3. On change of first select list, get the selected node id and pass to above defined function
4. Write the query to get depended node ids
5. Output it as

$options .= "nid." ".$selected." \>".$data-\>node\_title.""; echo $options;
6. In your jquery ajax success part, add it eg: success: function(data) {
f(data){$('#your-second-noderefernced-field').html(data);}

Hope this idea help you to proceed on

---
Tags: 7
---


title: Twitter-like follow button

text:
# Question
Title: Twitter-like follow button
I'm trying to make a twitter-like "following" system for a content-type I have.

Users have an entity reference to the content-type.

What I want is a user to go onto the content and click the "follow" button. The user's entity ref field would then be populated with this content and the follow button would turn to followed.

Users can follow multiple content.

Can anybody point me in the right direction for accomplishing this please?

## Update

I've now got Button and Rules and am trying to set this up, however, I've immediately hit a sticking point: I can't find my content-type in Rules. Shouldn't it be `entity:MyContentType`?

## Update 2

See my answer.

# Answer
> 1 votes
It turns out I was going about this the wrong way.

To create a Twitter-like follow button the best thing to use is the module Flag.

Create a Flag called "Follow Me" (follow\_me)

Create a Content-pane View which has:

* Sort Criteria: Content: Type (=MyContent)
* Context Filters: Content: Nid
* Relationships: Flags: follow\_chapter (by current user)

This content pane then can be used with Panels.

You can then create another view with the relationship with Flags: follow\_me to get a list of content followed by the user.

# Answer
> 0 votes
I think that you should try something like this:

You create, with hook\_menu, a custom callback that responds on a path like add-follow/%content\_type.

In the callback you get the %content\_type variable, so you can load the user with user\_load and add the reference to the content type, and then save the user.

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


title: Add a file field to a block

text:
# Question
Title: Add a file field to a block
I have a problem concerning the blocks in drupal.

I need to create a block that has additional fields, image and files, I am currently using the add block feature in Home » Administration » Structure and I just need to add two fields there so I can upload pdf's and images.

I was thinking that there must be a way to add those fields from the admin panel, without programming it by hand or installing modules? Is it possible ?

# Answer
No.

Blocks aren't entities in Drupal 7, so there's no real way to add fields to them.

If you want fields on blocks, then take a look at the awesome Bean module.

> Beans were driven by the API first. This means that you can create block types (bean types) all in a plugin class turning off the UI. The entire configuration in code. No worry about feature reverts.
> 1 votes

---
Tags: entities, blocks
---


# Question
Title: Need advice on how to setup a Drupal site on a given scenario
I need ideas/help on how to setup a drupal website with following given scenario. I just come up with the scenario this is not real but if I get the answers then I think I can apply on real poject.

I have two content-type **Movies** & **Celebrities**.

Movies content type will list all the movies information like... "Movie story overview", "movie review" and "movie cast"

Similarly I have Celebrities content type which will Celeb information like Movies acted, Bio, awards etc.

Now what I want...

**First Objective:**

* When I add a new celebrities node to site, how can I create/add multiple pages automatically Example: I added a new celebrity named “kate winslet” by using “Add Content”-\>Celebrities content type. Now when I save it there should be 4 urls created in one go.

a. Domain.com/celebrity/kate-winslet
b. Domain.com/celebrity/kate-winslet /movies-acted
c. Domain.com/celebrity/kate-winslet /bio
d. Domain.com/celebrity/kate-winslet /awards

Similarly while adding a Movies content type it should generate multiple pages like

* a. Domain.com/movies/titanic/overview
* b. Domain.com/movies/titanic/cast
* c. And more like this.

Note: I don’t want to create pages manually. Only one main landing page for each type should be created manually and rest of the pages should be added itself.

Now...

**Second Objective:**

* On the “domain.com/movies/titanic/cast” page, how can I have functionality to look-up all the celebrities page titles & url and link both, a movie with its casts or an actor/actress with movies.

**Example:** I added a new movie “titanic”, now the movies content type may have a custom filed (CCK) named as “movie cast” where I will be adding actor/actress full name like “kate winslet”, “leonardo dicaprio” etc.

Now what I want is these names should be link to their corresponding celebrity pages like

a. “kate winslet” shoule be linked to Domain.com/celebrity/kate-winslet

b. And “leonardo dicaprio” should be linked to Domain.com/celebrity/ Leonardo-dicaprio

Any idea or help is highly appreciated.

# Answer
This is multiple questions, really, but here's a quick answer for you:

Part 1: Using Views, you can accomplish having multiple "pages" for a given node. You'll have all the data for those pages on the one "kate-winslet" node. Then you'll create a view that takes an argument from the URL. The path of the view will be entered something like this: /celebrity/%1/movies-acted. You will need to add the fields you want to each view or view display. Then you'll add a contextual filter, using the node id. If this doesn't make sense to you, you just need to learn how to use Views, and particularly how to use contextual filters in Views.

Part 2: Yeah, you just need to view a tutorial on how to use Views. This is a simple View, but you'll need to use the views\_attach module, too probably.
> 0 votes

---
Tags: entities, views
---


# Question
Title: Drupal 7 Is the a way to programmatically know the Fields in a Content Type?
In Drupal 7, i need to `Programmatically` create the nodes, by using:

```
$node = new stdClass();
$node->type = "movie";

```

After, just this codes above, and lets assume i don't know what are the fields for it.

* How can i get to know the `fields` and that field's `structure` for this Content Type?
* (or) Can i echo out the `fields` inside a Content Type and its `relations` ?

# Answer
> 5 votes
`field_info_instances();` will get you a list of all field types on a specific entity/bundle.

For example:

```
$fields = field_info_instances('node', 'movie');
print_r($fields);

```

Will give you a list of all available fields on the node type of movie.

---
Tags: entities, nodes
---


# Question
Title: Drupal 7 Does “New Node Creation” initiate/prepare the Fields for different Content Types?
In Drupal 7, i need to `Programmatically` create the Nodes. As usual, there are `Different Fields` set for `Different Content Types`.

For very simple example:

```
Content Type: "car"
Fields: "Model", "Engine", "GearType"

Content Type: "article"
Fields: "Title", "Author", "Media"

```

What i want to be confirmed here is, `while` i am creating a new node, for e.g by using:

```
$node = new stdClass();
$node->type = "car";

```

Then..

* Is that (currently creating) new `$node` has been initiated/loaded with its related/corresponded fields, already before get saved?
* To be more clear, if i just suddenly Save a node `node_save($node)` (without filling any other related fields) will that `node` be still having (following) its proper Content Type structure?

# Answer
The node can have fields attached to it. If any are required and not provided then I believe your save() will fail with an error message. If your fields provide a default value that value will be used for those fields.

If there are no required fields. The basic node information (nid, type, title?) will be the only values set on your new node (and timestamps, owner uid).

I believe it's up to you the developer to assure the fields have the data you want when you save the node (and meet the Requirements of the node/fields configuration) from the Field UI.
> 2 votes

---
Tags: entities, nodes
---


# Question
Title: Is there a way to globally redirect taxonomy paths -- on a pattern?
I know there is url alias but what I need to happen is the taxonomy path be redirected to a view. The itemization will be from a tag. This tag basically controls a views output. I want to have that terms URL be redirected to that view page.

# Answer
> 0 votes
You can simply create the view and make its path "taxonomy/term/%". That will take care of the redirect of the default taxonomy pages for you. Then you'll need to use a contextual filter to provide the argument of the taxonomy term id to the view.

# Answer
> 1 votes
As i understand - you want to show some view on taxonomy term page. This view will take term as argument (contextual filter) and display list of nodes related to it.

For this purpose you can use module Taxonomy Views Integrator:

> The TVI (Taxonomy Views Integrator) module allows selective overriding of taxonomy terms and/or vocabulary with the view of your choice. Using TVI you can easily create custom views to output all terms in X vocabuarly.

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


# Question
Title: Take 2 fields in a content type with php
I have a content type with the following fields: Name, Language, Date, Photo, Text associated with the following names for internal use: title, language, field\_date, field\_photo, body

I created instances. One of these is called "Mondovi." I would like to see only the fields field\_data and body of this instance. I want to use php to put them within the content or within a block. What to do?

# Answer
Let assume that you are using Drupal 7

You need to know nid of node "Mondovi".

Then you can use following code:

```
$node = node_view(node_load(NID_OF_NODE));

// print value of body field without field label
print render($node['body'][0]);

// or print body value with field label and all div wrappers
print render($node['body']);

// print value of field_data without field label
// if field can have multiple values - use cycle to dipslay all of them
print render($node['field_data'][0]);

```
> 2 votes

---
Tags: views, 7
---


# Question
Title: Can I give a role permission to configure one (and only one) block?
Right now, I see that the administrator role has a premission called `administer block`. I would like to offer that permission to another role, but only for a specific block, not all of them. Is this at all possible?

# Answer
> 0 votes
try the content access Module for drupal 7.x might be exactly what you need

---
Tags: 7, users
---


title: Functions in template.php not working

text:
# Question
Title: Functions in template.php not working
So I am new to Drupal and I am trying to create a new theme for a site. I am trying to create a page template for a specific custom content type. Research has led me to adding this to my template.php file:

```
function yourthemename_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

```

However, it is not working. I know the template.php file itself is being pickup up because a simple echo test works, but putting one in the function above does not fire. So I have to assume this function is not being called. I changed the 'yourthemename' to what I think is my theme's machine name. The folder name and .info name is FWMurphy. I tried that and fwmurphy and neither worked. I am stumped.

# Answer
Okay. I ended up figuring out what was wrong. Given what I needed done and the info given here, there is no way anyone could have helped me with this, so sorry and thank you to all who tried.

Come to find out my .info file was named wrong. It was named theme.info instead of fwmurphy.info so it was throwing off the machine readable name for my theme. Once I renamed it and replied the theme, everything worked as it should.

Again thanks everyone.
> 2 votes

# Answer
In your instance the hook should be (based on what you said your theme name is):

```
function FWMurphy_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

```

After you implement that, clear the drupal cache. For drupal to pickup your `page--{node type}.tpl.php` , you need to make sure your theme also contains a default `page.tpl.php`
> 2 votes

---
Tags: theming
---


# Question
Title: When is using --package-handler=git_drupalorg appropriate with drush?
In which situations are using

```
drush pm-downlaod --package-handler=git_drupalorg ...

```

appropriate?

For example, if I am developing a normal site and want to version it with git, I assume it just best to just use the normal drush commands and version it outside of git?

Would using the git package handler, especially when combined with submodules, be most appropriate with sandbox environments where I may want to contribute patches and/or push changes back to git.drupal.org?

# Answer
> 4 votes
The second half of your question is easiest to answer: yes, if you are planning on creating a patch for drupal.org, --package-handler=git\_drupalorg is a good option to use, as you may then easily create patches with `git diff`. For an additional tool to help create and apply patches, see drush\_iq.

The answer to the rest of your question is more subjective. How you download projects for inclusion on a production site depends on your strategy for managing your code. There are many options, but it's important to pick one that will work for you, because Drupal will commonly WSOD on you if you miss-match your code and your database -- that is, you must use any particular database snapshot with the version of the code that created it. If you ever end up with an older database with newer code, you can just run updatedb; however, you can never use a newer database with older code.

Sometimes, I check in my entire Drupal source code tree into git. When I do this, I do not use --package-handler=git\_drupalorg to download modules; I just update them with `drush pm-updatecode`, and commit the result to my repository after testing. When I do this, sometimes I deploy with git (git pull on production), and sometimes I keep my .git files on dev/stage only, and push just the code to production with `drush rsync`, leaving the .git files behind.

Using submodules might be a viable option. There is a project to help manage Drupal submodules in your repository: see Drupal on Git, aka "dog". I don't really use submodules or dog myself yet.

Another option is to build an installation profile from your code, and commit just that to your repository. The advantage here is that there's less in your repository, and it is easier to understand how versions change by tracking a makefile than trying to parse and understand the history of an entire Drupal tree committed to a repository. See http://drupal.org/node/1368242. I am just starting to use this, and have not really adopted it as a standard practice yet.

---
Tags: drush, version-control
---


# Question
Title: Set default value of Search form block to be searched terms
So I have the Search form block in my template, but after performing a search it doesn't show the query in the form field.

How do I set the default value on search results to be the query?

i.e if I search "cats"..on the search results box, I want "cats" to remain in the search box.

Just like it does on Drupal Answers :)

# Answer
> 2 votes
For the regular search block, the preprocessing function **template\_preprocess\_search\_block\_form**() runs (you can find it in the **search.module** file of the core search module), which assigns the search terms you've entered to the $key variable which is used by the function building the search form.

You should include your own preprocessing function (named appropriately to run before your own template file) which performs a similar task to initialize any variables you need/use (you can even grab the code from the one cited above). Since it sounds like you want to have the keywords printed, make sure the $key variable is actually set... If you have a custom theme, you can just include the preprocessing function in your theme's template.php file.

Does that help? Let us know if that works!

=========== ANSWER ADDITION ====================

OK, so here's what I've just tested that *does* work. I've added a search preprocessor to my custom theme in the template.php file. If you just copy this (with your own theme's name prefixed), it should work after you clear your cache.

I actually had to bang my head against the wall for a little bit. At first I just copied the preprocessing function exactly from the search module, with the exception of setting the field's value to the search term in that first line (since it doesn't do that be default)... But nothing rendered. Then I realized I had to add that second line I've commented on to set the '#printed' property to false, so that drupal\_render() will render them again. Soooo... I don't know if this is a good solution or not. There may be a better way, but this is all I can think of and it works...

Again, in short, this is my copying the search module's preprocessing function and making the two line edits I've commented on by saying 'ADDED THIS LINE' to get the extra functionality. Hope that makes sense.

```
function YOUR_THEME_preprocess_search_block_form(&$variables) {
// ADDED THIS LINE -- get the search term from the URL, so you can use that as the value of the search box text field
  $variables['form']['search_block_form']['#value'] = arg(2);

  $variables['search'] = array();
  $hidden = array();
  // Provide variables named after form keys so themers can print each element independently.
  foreach (element_children($variables['form']) as $key) {
    $type = $variables['form'][$key]['#type'];
// ADDED THIS LINE -- these fields have already been rendered by the search module's preprocessing function, so they won't render again here unless you do this...
    $variables['form'][$key]['#printed'] = FALSE;
    if ($type == 'hidden' || $type == 'token') {
      $hidden[] = drupal_render($variables['form'][$key]);
    }
    else {
      $variables['search'][$key] = drupal_render($variables['form'][$key]);
    }
  }
  // Hidden form elements have no value to themers. No need for separation.
  $variables['search']['hidden'] = implode($hidden);
  // Collect all form elements to make it easier to print the whole form.
  $variables['search_form'] = implode($variables['search']);
}

```

p.s. The above would obviously make the change for all search block forms on your site...

---
Tags: 7, search
---


# Question
Title: How to process a textarea as an html list?
Is it possible to process a textarea line by line and turn it into an HTML list, and how would you go about it?

# Answer
This is pretty easy to accomplish with hook\_preprocess\_field in your theme:

```
function YOURTHEME_preprocess_field(&$vars) {
  if (array_key_exists('element', $vars)) {
    $element = $vars['element'];
    if (array_key_exists('#object', $element) && isset($element['#object']->type) && ($element['#field_name'] == 'field_test')) {
      $output = '';
      foreach (explode("\n", $vars['element'][0]['#markup']) as $line) {
        $output .= '<li>' . check_plain($line) . '</li>';
      }
      $vars['items'][0]['#markup'] = '<ol>' . $output . '</ol>';
    }
  }
}

```

This presumes that you have created a field called 'test' and set its type to 'long text' / 'textarea'. Adjust the code above as desired to match your field name(s) and desired formatting. For more information on altering render arrays, see The Scary Render Array.

With additional work, you could add additional flexibility by converting the above preprocess function into a Drupal field formatter. See Creating Custom Formatters with the Field API. The Custom Formatters project might also be particularly helpful here.
> 0 votes

# Answer
Either use the text-field and choose "list" style. Another way is to simply use filtered HTML as your text-format for your text-area. Once you select filtered HTML. use \< ul \> or \< li \> in front of each line of text to turn it into a list-item. This can also be accomplished using "Views"
> 0 votes

---
Tags: entities
---


# Question
Title: Drupal Migrate - Link fields from an XML Source
I am using the Migrate (v7.x-2.2) module to migrate records from an XML source into Drupal 7.9.

I've also installed the popular link field module (v7.x-dev).

So far, in my migration class, all built-in fields work well during the migration, but I have not figured out how to migrate link fields from my XML source with their title.

I have two XML source fields (xpaths):

```
/record/organization/name  <-- I want to migrate this into the link title
/record/organization/url   <-- I want to migrate this into the link url

```

I am able to get the URL to import using this line in my Migration file (had to use link v7.x-dev module, not 7.x-1.0):

```
   $this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url');

```

...but I have no idea how to inject the `/record/organization/name` into the title argument:

```
   $this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url')->arguments(array('title' => [WHAT GOES HERE?]);

```

# Answer
> 3 votes
So, the solution is to not use arguments, but instead, fix up the record using the prepare() method:

In the constructor:

```
//IMPORTANT - DO this source mapping without a destination mapping (NULL)
$this->addFieldMapping(NULL, 'organization_title')->xpath('/record/organization/title');

$this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url');

```

Then, create a method named prepare():

```
function prepare($node, $rec) {
      $node->field_organization[LANGUAGE_NONE][0]['title'] = $rec->organization_title;
}

```

As of today (Nov 30, 2011), you must have the 7.x-dev version of the link module installed, not the "stable" 1.0 version, in order for link fields to work at all!

Whew!

# Answer
> 1 votes
I found a working MigrateLinkFieldHandler here:

http://drupal.org/node/1004066

I uploaded the latest 'patch' from there, which is basicly a single class definition (\*), to a file called 'link.inc' in my migratemodule, and added a reference to that file in my module.info there. Cleared caches et voila:

```
 $arguments = MigrateLinkFieldHandler::arguments(
      array('source_field' => 'url_title')
 );
 $this->addFieldMapping('field_link', 'url')
        ->arguments($arguments);

```

(\*) ofcourse, since its a patch, i had to remove all the ++++ and superfluous lines to get a nice working php class )

---
Tags: 7, navigation, migrations
---


# Question
Title: How to do load testing that simulate adding a node with a drupal site?
I know we can use apaceh workbench to do some load testing and provide some statistics. However, how would I go about finding out how many logged in users can perform certain action (adding a node, comment, or submitting a custom form)? An idea was that to create a script that perform the action and use apache workbench to execute the script.

# Answer
Create a script that does the stuff that you want logged in users to be able to perform, then run `ab` against it:

```
ab -n <no: of requests> -c <concurrency> http://mysite.com/user_action.php

```

One thing you could do is have user\_action perform various actions in random. So each time ab hits it, it might to a node creation, or a form submit or a comment entry etc..This would simulate a closer scenario to real world actions.
> 1 votes

---
Tags: testing
---


title: Delete/create nodes programmatically

text:
# Question
Title: Delete/create nodes programmatically
I created a custom module that uses the Taleo Web API to get data from the external Taleo database and make nodes from this data. This works great.

But now I want to run this update script every night... The script works great whem I logged in into Drupal.

What would be the safest way to allow deleting and adding nodes programmatically when logged out?

```
function taleo_menu() {
  $items['taleo-update'] = array(
    'title' => 'Taleo Update page',
    'description' => 'Taleo Update page',
    'page callback' => '_taleo_update',
    'access arguments' => array('view content'),
        'type' => MENU_NORMAL_ITEM,
  );
    return $items;
}

function _taleo_insert($jobs) {
    foreach ($jobs as $job_object) {

        $node = new stdClass();
        $node->type = 'job';
        $node->title    = $job_object->title;
        $node->language = LANGUAGE_NONE;

        node_object_prepare($node);
        $node = node_submit($node); // Prepare node for a submit
        node_save($node); // After this call we'll get a nid
    }

    drupal_set_message(t('Added %count jobs.', array('%count' => count($jobs))));
    return array();
}

```

# Answer
> 0 votes
If you are looking for the *safest* way, I would say your current approach is not how most of us get things done in Drupal.

Basically, you can make use of a hook that wakes up your module, check last run's status and if suitable, start its next run.

Check out hook\_cron. You can check last run status easily from a variable\_get (you need to set the value first using variable\_set). Cron runs anonymously regardless of a specific page call. Even if the cron runs frequently, you can use some condition to check last run timestamp and compare it to current system time. If it has exceeded the interval (1 day), you can now run the "create nodes" function.

If nodes are saved correctly, you will see a $node-\>nid set. use that as a condition and if all given jobs are done, you can set the last run variable to the current time.

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


title: change region block in module

text:
# Question
Title: change region block in module
I want when a node saved,one block region be change.

for example: when a node be save,"user-login block" move to the content region.

please help me for resolve this problem.

thank you

# Answer
try the context module and use node as the context and blocks as the reaction. you should be able to figure out the rest :)
> 1 votes

---
Tags: 7, blocks
---


# Question
Title: How to disable "all" option from contextual filter?
While debugging some slow running queries I came across a "hidden feature"? in views. When I have a "uid" contextual filter and pass "all" as the value it will show all users.

# Answer
> 6 votes
Ok, found it. In the contextual filter there is an "Exception" option that you can expand. "all" seems to be added by default for all contextual filters.

---
Tags: 7, views
---


# Question
Title: Which is the leading facebook module for Drupal 7 a complete site integration?
There are 3 main FB integration modules for Drupal 7;

There are tons of discussion threads around the net and drupal.org describing the pros and cons of each module. From all these threads, this is what I've gathered. If all you want is FB login capabilities for your users. Then FBoauth is your best bet. FBconnect does a few of the 'other' features pretty well but requires some bug fixes to be stable. FB is great if you want APP integration for your site. But my question is;

If you wanted your site to do;

* User Registration
* Content Posting to Wall Stream
* Comment Stream
* Friend Inviting

Which is the best module to be able to have those features built into your drupal site?

# Answer
You need FB. It offers all what you need.

I've been in the same dilemma and went with that one.

I suggest to try all of them and see for yourself though. Don't waste time with modules which offer third party integration - they rely on registration on those websites and usually paying a fee to them. I think it's silly registering and paying for a third party service in order to use another (free) third party service.
> 2 votes

---
Tags: social-network
---


# Question
Title: In hook_form_alter, when adding a custom field, control the order in which the field appears?
Question: When adding a field via `hook_form_alter`, how do you control the order in the HTML which the field is rendered?

Meaning, this is my current `hook_form_alter`:

```
function ccom_validations_form_challenges_node_form_alter(&$form, &$form_state, $form_id) {
  $form['my_field'] = array (
    '#type' => 'hidden',
    '#value' => 'schweet'
  );
  dpm($form);
}

```

...which adds the hidden form element to the end of the renderable array. That's cool. However, this is what my HTML looks like...

```
<div><input type="hidden" name="changed" value="">
<input type="hidden" name="form_build_id" value="form-ToT93ljrNzFudWQnMVF0Ti4-RLmTXPt8AhusXxR2Tcc">
<input type="hidden" name="form_token" value="RXnp5FVFnZgTcRn_lsDfBDzze6IcOnEwx_7ok6J70Z4">
<input type="hidden" name="form_id" value="challenges_node_form">
<input type="hidden" name="my_field" value="schweet">
<div class="field-type-taxonomy-term-reference field-name-field-reporting-period field-widget-options-select form-wrapper" id="edit-field-reporting-period"><div class="form-item form-type-select form-item-field-reporting-period-und">
  <label for="edit-field-reporting-period-und">Reporting Period <span class="form-required" title="This field is required.">*</span></label>
 <select id="edit-field-reporting-period-und" name="field_reporting_period[und]" class="form-select required"><option value="1342" selected="selected">2012 December</option><option value="56">2012 June</option></select>
</div>
</div><div class="field-type-text-with-summary field-name-body field-widget-text-textarea-with-summary form-wrapper" id="edit-body"><div id="body-add-more-wrapper"><div class="text-format-wrapper"><div class="text-summary-wrapper text-summary-wrapper-processed" style="display: none; "><div class="form-item form-type-textarea form-item-body-und-0-summary">
  <label for="edit-body-und-0-summary">Summary </label>
<div class="description">Leave blank to use trimmed value of full text as the summary.</div>
 <div class="form-textarea-wrapper resizable textarea-processed resizable-textarea"><textarea class="text-summary form-textarea text-summary-processed" id="edit-body-und-0-summary" name="body[und][0][summary]" cols="60" rows="5"></textarea><div class="grippie"></div></div>
</div>
</div><div class="form-item form-type-textarea form-item-body-und-0-value">
  <label for="edit-body-und-0-value">Description of Challenges <span class="form-required" title="This field is required.">*</span><span class="field-edit-link">(<a class="link-edit-summary" href="#">Edit summary</a>)</span></label>
 <div class="form-textarea-wrapper resizable textarea-processed resizable-textarea"><textarea class="text-full form-textarea required" id="edit-body-und-0-value" name="body[und][0][value]" cols="60" rows="20"></textarea><div class="grippie"></div><div class="wysiwyg-toggle-wrapper"><a id="wysiwyg-toggle-edit-body-und-0-value" href="javascript:void(0);" style="display: none; ">Disable rich-text</a></div></div>
</div>
<fieldset class="filter-wrapper form-wrapper" id="edit-body-und-0-format"><div class="fieldset-wrapper"><div class="filter-help form-wrapper" id="edit-body-und-0-format-help"><p><a href="/filter/tips" target="_blank">More information about text formats</a></p></div><div class="form-item form-type-select form-item-body-und-0-format">
  <label for="edit-body-und-0-format--2">Text format </label>
 <select class="filter-list wysiwyg form-select wysiwyg-processed" id="edit-body-und-0-format--2" name="body[und][0][format]"><option value="progress_report_field" selected="selected">Progress Report Field</option><option value="markdown">Markdown</option><option value="filtered_html">Filtered HTML</option><option value="full_html">Full HTML</option><option value="plain_text">Plain text</option></select>
</div>
<div class="filter-guidelines form-wrapper filter-guidelines-processed" id="edit-body-und-0-format-guidelines"><div class="filter-guidelines-item filter-guidelines-progress_report_field" style="display: block; "><h3 style="display: none; ">Progress Report Field</h3><ul class="tips"><li>No HTML tags allowed.</li><li>Lines and paragraphs break automatically.</li><li>Web page addresses and e-mail addresses turn into links automatically.</li></ul></div><div class="filter-guidelines-item filter-guidelines-markdown" style="display: none; "><h3 style="display: none; ">Markdown</h3><ul class="tips"><li>Quick Tips:<ul>
      <li>Two or more spaces at a line's end = Line break</li>
      <li>Double returns = Paragraph</li>
      <li>*Single asterisks* or _single underscores_ = <em>Emphasis</em></li>
      <li>**Double** or __double__ = <strong>Strong</strong></li>
      <li>This is [a link](http://the.link.example.com "The optional title text")</li>
      </ul>For complete details on the Markdown syntax, see the <a href="http://daringfireball.net/projects/markdown/syntax">Markdown documentation</a> and <a href="http://michelf.com/projects/php-markdown/extra/">Markdown Extra documentation</a> for tables, footnotes, and more.</li></ul></div><div class="filter-guidelines-item filter-guidelines-filtered_html" style="display: none; "><h3 style="display: none; ">Filtered HTML</h3><ul class="tips"><li>Web page addresses and e-mail addresses turn into links automatically.</li><li>Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd></li><li>Lines and paragraphs break automatically.</li></ul></div><div class="filter-guidelines-item filter-guidelines-full_html" style="display: none; "><h3 style="display: none; ">Full HTML</h3><ul class="tips"><li>Web page addresses and e-mail addresses turn into links automatically.</li></ul></div><div class="filter-guidelines-item filter-guidelines-plain_text" style="display: none; "><h3 style="display: none; ">Plain text</h3><ul class="tips"><li>No HTML tags allowed.</li><li>Web page addresses and e-mail addresses turn into links automatically.</li><li>Lines and paragraphs break automatically.</li></ul></div></div></div></fieldset>
<div class="description">Use this field to document any challenges or obstacles you have experienced whilst working on your research.  This should be a relatively in-depth description.  Use the Summary field to provide highlights.</div></div>
</div></div><h2 class="element-invisible">Vertical Tabs</h2><div class="vertical-tabs clearfix"><ul class="vertical-tabs-list"><li class="vertical-tab-button first selected" tabindex="-1"><a href="#"><strong>URL path settings</strong><span class="summary">Automatic alias</span><span id="active-vertical-tab" class="element-invisible">(active tab)</span></a></li><li class="vertical-tab-button" tabindex="-1"><a href="#"><strong>Revision information</strong><span class="summary">New revision</span></a></li><li class="vertical-tab-button" tabindex="-1"><a href="#"><strong>Comment settings</strong><span class="summary">Closed</span></a></li><li class="vertical-tab-button" tabindex="-1"><a href="#"><strong>Authoring information</strong><span class="summary">By lpeabody</span></a></li><li class="vertical-tab-button last" tabindex="-1"><a href="#"><strong>Publishing options</strong><span class="summary">Published</span></a></li></ul><div class="vertical-tabs-panes vertical-tabs-processed"><fieldset class="path-form form-wrapper vertical-tabs-pane" id="edit-path" style=""><legend><span class="fieldset-legend">URL path settings</span></legend><div class="fieldset-wrapper"><div class="form-item form-type-checkbox form-item-path-pathauto">
 <input type="checkbox" id="edit-path-pathauto" name="path[pathauto]" value="1" checked="checked" class="form-checkbox">  <label class="option" for="edit-path-pathauto">Generate automatic URL alias </label>

<div class="description">Uncheck this to create a custom alias below. <a href="/admin/config/search/path/patterns">Configure URL alias patterns.</a></div>
</div>
<div class="form-item form-type-textfield form-item-path-alias">
  <label for="edit-path-alias">URL alias </label>
<div class="description">Optionally specify an alternative URL by which this content can be accessed. For example, type "about" when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.</div>
 <input type="text" id="edit-path-alias" name="path[alias]" value="" size="60" maxlength="255" class="form-text" disabled="">
</div>
</div></fieldset>
<fieldset class="node-form-revision-information form-wrapper vertical-tabs-pane" id="edit-revision-information" style="display: none; "><legend><span class="fieldset-legend">Revision information</span></legend><div class="fieldset-wrapper"><div class="form-item form-type-checkbox form-item-revision">
 <input type="checkbox" id="edit-revision" name="revision" value="1" checked="checked" class="form-checkbox">  <label class="option" for="edit-revision">Create new revision </label>

</div>
<div class="form-item form-type-textarea form-item-log">
  <label for="edit-log">Revision log message </label>
<div class="description">Provide an explanation of the changes you are making. This will help other authors understand your motivations.</div>
 <div class="form-textarea-wrapper resizable textarea-processed resizable-textarea"><textarea id="edit-log" name="log" cols="60" rows="4" class="form-textarea"></textarea><div class="grippie"></div></div>
</div>
</div></fieldset>
<fieldset class="comment-node-settings-form form-wrapper vertical-tabs-pane" id="edit-comment-settings" style="display: none; "><legend><span class="fieldset-legend">Comment settings</span></legend><div class="fieldset-wrapper"><div class="form-item form-type-radios form-item-comment">
  <label class="element-invisible" for="edit-comment">Comments </label>
 <div id="edit-comment" class="form-radios"><div class="form-item form-type-radio form-item-comment">
 <input type="radio" id="edit-comment-2" name="comment" value="2" class="form-radio">  <label class="option" for="edit-comment-2">Open </label>

<div class="description">Users with the "Post comments" permission can post comments.</div>
</div>
<div class="form-item form-type-radio form-item-comment">
 <input type="radio" id="edit-comment-1" name="comment" value="1" checked="checked" class="form-radio">  <label class="option" for="edit-comment-1">Closed </label>

<div class="description">Users cannot post comments.</div>
</div>
</div>
</div>
</div></fieldset>
<fieldset class="node-form-author form-wrapper vertical-tabs-pane" id="edit-author" style="display: none; "><legend><span class="fieldset-legend">Authoring information</span></legend><div class="fieldset-wrapper"><div class="form-item form-type-textfield form-item-name" role="application">
  <label for="edit-name">Authored by </label>
<div class="description">Leave blank for <em class="placeholder">Anonymous</em>.</div>
 <input type="text" id="edit-name" name="name" value="lpeabody" size="60" maxlength="60" class="form-text form-autocomplete" autocomplete="OFF" aria-autocomplete="list"><input type="hidden" id="edit-name-autocomplete" value="https://intranet.webdev.ccom.nh/user/autocomplete" disabled="disabled" class="autocomplete autocomplete-processed">
<span class="element-invisible" aria-live="assertive" id="edit-name-autocomplete-aria-live"></span></div>
<div class="form-item form-type-textfield form-item-date">
  <label for="edit-date">Authored on </label>
<div class="description">Format: <em class="placeholder">2012-10-11 17:23:38 -0400</em>. The date format is YYYY-MM-DD and <em class="placeholder">-0400</em> is the time zone offset from UTC. Leave blank to use the time of form submission.</div>
 <input type="text" id="edit-date" name="date" value="" size="60" maxlength="25" class="form-text">
</div>
</div></fieldset>
<fieldset class="node-form-options form-wrapper vertical-tabs-pane" id="edit-options" style="display: none; "><legend><span class="fieldset-legend">Publishing options</span></legend><div class="fieldset-wrapper"><div class="form-item form-type-checkbox form-item-status">
 <input type="checkbox" id="edit-status" name="status" value="1" checked="checked" class="form-checkbox">  <label class="option" for="edit-status">Published </label>

</div>
<div class="form-item form-type-checkbox form-item-promote">
 <input type="checkbox" id="edit-promote" name="promote" value="1" class="form-checkbox">  <label class="option" for="edit-promote">Promoted to front page </label>

</div>
<div class="form-item form-type-checkbox form-item-sticky">
 <input type="checkbox" id="edit-sticky" name="sticky" value="1" class="form-checkbox">  <label class="option" for="edit-sticky">Sticky at top of lists </label>

</div>
</div></fieldset>
<input class="vertical-tabs-active-tab" type="hidden" name="additional_settings__active_tab" value="edit-path">
</div></div><div class="form-actions form-wrapper" id="edit-actions"><input type="submit" id="edit-submit" name="op" value="Save" class="form-submit"><input type="submit" id="edit-preview" name="op" value="Preview" class="form-submit"></div></div>

```

Really the most important part is that even though the element appeared last in the array, it shows up as the last hidden element at the very top of that code, on line 5 to be specific.

It is very important that this field get's rendered after all other fields. How can this be done "the Drupal 7 way"? Using DOM manipulation via JavaScript is not an option (and shame on you if you think it is).

# Answer
> 3 votes
You can use the `#weight` property to control the display order of elements in a form (or any render array as it happens).

Elements with lower weight will appear first (and vice versa) so

```
$form['my_field'] = array (
  '#type' => 'hidden',
  '#value' => 'schweet',
  '#weight' => 1000
);

```

will make sure your element is right at the bottom, for example.

You can also alter the `#weight` of any other elements in the form so you should be able to rearrange it exactly as you need.

# Answer
> 3 votes
Give the form element a weight. Also to make sure it shows up after all the fields make sure you set the weight greater than all the fields using field\_info\_max\_weight. This will make sure it will show up at the very end even if you add new fields in the future.

So it might look something like this

```
function ccom_validations_form_challenges_node_form_alter(&$form, &$form_state, $form_id) {
  $form['my_field'] = array (
    '#type' => 'hidden',
    '#value' => 'schweet'
    '#weight' => field_info_max_weight('node', 'challenges', 'form') + 10,
  );
}

```

Let me know if it works.

---
Tags: 7, theming, forms
---


# Question
Title: Need help or idea on how to setup a Drupal site on a given scenario
I need ideas/help on how to setup a drupal website with following given scenario. I just come up with the scenario this is not real but if I get the answers then I think I can apply on real poject.

I have two content-type **Movies** & **Celebrities**.

Movies content type will list all the movies information like... "Movie story overview", "movie review" and "movie cast"

Similarly I have Celebrities content type which will Celeb information like Movies acted, Bio, awards etc.

Now what I want...

**First Objective:**

* When I add a new celebrities node to site, how can I create/add multiple pages automatically Example: I added a new celebrity named “kate winslet” by using “Add Content”-\>Celebrities content type. Now when I save it there should be 4 urls created in one go.

a. Domain.com/celebrity/kate-winslet
b. Domain.com/celebrity/kate-winslet /movies-acted
c. Domain.com/celebrity/kate-winslet /bio
d. Domain.com/celebrity/kate-winslet /awards

Similarly while adding a Movies content type it should generate multiple pages like

* a. Domain.com/movies/titanic/overview
* b. Domain.com/movies/titanic/cast
* c. And more like this.

Note: I don’t want to create pages manually. Only one main landing page for each type should be created manually and rest of the pages should be added itself.

Now...

**Second Objective:**

* On the “domain.com/movies/titanic/cast” page, how can I have functionality to look-up all the celebrities page titles & url and link both, a movie with its casts or an actor/actress with movies.

**Example:** I added a new movie “titanic”, now the movies content type may have a custom filed (CCK) named as “movie cast” where I will be adding actor/actress full name like “kate winslet”, “leonardo dicaprio” etc.

Now what I want is these names should be link to their corresponding celebrity pages like

a. “kate winslet” shoule be linked to Domain.com/celebrity/kate-winslet

b. And “leonardo dicaprio” should be linked to Domain.com/celebrity/ Leonardo-dicaprio

Any idea or help is highly appreciated.

# Answer
For the second objective instead of adding the actors to the movie, since you already are going to add movie appearances to each actor, make those movies taxonomy terms. Then when you want to make a cast page for a movie, just display all of the actors that have that taxonomy term (the movie name) associated with it.
> 0 votes

---
Tags: views
---


# Question
Title: Can't get values from $form in submit handler?
Using Drupal 7 and a custom form generated with the Webform module, I'm trying to get info from the submitted form to save in additional SQL tables.

I know my submit handler is being called because putting `dpm('This is great news, our submit handler is being called!');` inside the submit handler gives the expected output. So does `dpm($myvariable);` (after setting a value for `$myvariable`).

But `dpm($form);` not only doesn't return anything, but also seems to preven the other dpm() functions from working. There are no errors logged, and the page loads otherwise normally.

I should also mention that if I put the `dpm($form)` in the `hook_form_alter()` function instead of the submit handler, it does show up, but all values appear to be default or empty, after the form is submitted.

# Answer
Please check your submit handler signatures once ... Ideally submit function should be something like below... You can try using drupal set message for same like code given below !

```
function form_example_tutorial_7_submit($form, &$form_state) {
  drupal_set_message("I am inside submit handler. Printed form values below");
  drupal_set_message("<pre>" . print_r($form_state['values'], 1) . "</pre>");
  // $form_state['values'] is used to extract submitted values !
  drupal_set_message("Printing Form Structure Below !");
  drupal_set_message("<pre>" . print_r($form, 1) . "</pre>");
}

```
> 1 votes

---
Tags: webforms, forms
---


title: Adding multiple fields in node_save()

text:
# Question
Title: Adding multiple fields in node_save()
Its possible to add a node using the code below, but how do i add multiple fields?

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

node_save($node);

```

Singles custom field, we can use:

```
$node->field_my_custom_field['und'][0]['value'] = 'my value';

```

But what if I want to add multiple entries for one field?

# Answer
> 1 votes
Second index after 'und' is used for delta of values. You can make it 1 , 2, 3 etc to add multiple values... Something like below...

```
$node->field_my_custom_field['und'][0]['value'] = 'my value one';
$node->field_my_custom_field['und'][1]['value'] = 'my value two';
$node->field_my_custom_field['und'][2]['value'] = 'my value three';
$node->field_my_custom_field['und'][3]['value'] = 'my value four';

```

---
Tags: entities, nodes
---


title: Authored by lookup

text:
# Question
Title: Authored by lookup
Right now the when I want to change 'authored by' there is a look up by username. Is there an easy way to change that to enter the users email address?

# Answer
To change 'authored by' autocomplete with email, In your form alter change the auto complete path as follows,

```
if ($form_id == 'test_node_form') {
    $form['author']['name']['#autocomplete_path']= 'user/autocomplete/email';
 }

```

Originally this path is \[#autocomplete\_path\] = user/autocomplete

In your module define the menu path, hook\_menu

```
function example_menu() {
  $item[] = array(
  'path' => 'user/autocomplete/email',
  'callback' => 'example_autocomplete',
  'access' => user_access('access example autocomplete')
  );
}

```

Define the call back

```
function example_autocomplete($string=''){
  //your query to get email
  //return the output as $mathes
   drupal_json_output($matches);
   exit();
 }

```

Hope this may helps you
> 0 votes

---
Tags: 7, forms
---


# Question
Title: I cannot add node links to primary links
I have a problem that is driving me crazy. I've been trying to solve it for a week now without luck. The problem is, I can't add any internal (node/xxx) links to primary-links. After I add one, it appears, but I cannot edit or add any nodes until I delete that menu item. If I try to edit a node, i get the message **"username admin does not exist"**. It looks like this triggers an effect that is causing admin user to lose permisson for node\_access. After I delete the created menu item, everything is back to normal... until I add another menu item.

Here's a summary:

* I can add external links to primary-links, no problem
* I can add internal links to seconday-links, no problem
* It doesn't matter if I add the menu item manually or by specifying one on the node edit page, the effect is the same
* The language, weight and position of the menu item doesn't matter, as long as I add an *internal* link to primary-links, the above problem appears
* I tried to rebuild the menu, disable modules, clear the cache, rebuild permissions, no luck
* I double checked the menu\_links table, there were some orphan items (had no parents) which I deleted, but otherwise everything is fine

I am using Drupal 6.19 with only one user (the admin), a bunch of modules and 11 languages. I **must** solve this problem soon as we need to add another language and it'll definately need some internal links in the menu.

Edit: Here are the modules currently enabled:

CCK

* Content 6.x-2.8
* Content Copy 6.x-2.8
* FileField 6.x-3.7
* FileField Sources 6.x-1.2
* Node Reference 6.x-2.8
* Number 6.x-2.8
* Option Widgets 6.x-2.8
* Text 6.x-2.8

Location

* IP to Locale 6.x-1.0-rc1
* Smart IP 6.x-1.3

Meta tags

* Nodewords 6.x-1.11
* Nodewords - basic meta tags 6.x-1.11

Multilanguage

* Block translation 6.x-1.7
* CCK translation 6.x-1.7
* Content type translation 6.x-1.7
* Internationalization 6.x-1.7
* Menu translation 6.x-1.7
* String translation 6.x-1.7

Other

* Custom Page 6.x-1.17
* Custom Page Admin UI 6.x-1.17
* GeoIP 6.x-1.4
* Global Redirect 6.x-1.2
* Menu attributes 6.x-2.0-beta1
* Menu breadcrumb 6.x-1.3
* Page Title 6.x-2.3
* Path redirect 6.x-1.0-rc2
* Token 6.x-1.15
* Webform 6.x-3.14

I can provide any information if you can help, just ask!

Thanks in advance

# Answer
Issue solved.

Looks like that with the large menu tree, Mysql packet size was exceeded.

I just added the following to mysql config (my.ini) and the issue resolved:

```
[mysqld]
max_allowed_packet = 16M

```
> 1 votes

---
Tags: 6, navigation
---


title: How to create content type Drupal 7

text:
# Question
Title: How to create content type Drupal 7
I need to add a new content type to the node/add page. How can I go about doing this?

# Answer
> 1 votes
You should try Google before posting questions like this here.

One of the first few results is the following video:

Drupal 7: Creating Content Types

You might find the following videos useful as well:

Getting Started with Drupal 7 Tutorials

---
Tags: 7, nodes
---


# Question
Title: How do I add an OR expression between two ->addExpression() in Drupal 7
I am trying to return flagged content that is either flagged as a favorite or flagged as visited. I can get them to return but i believe Drupal is doing an **and** between the 2 `addExpression()` in the query because it is only showing results if either both are flagged. Not one or the other.Here is my code. This is being used for the Drupal Services module to return some values. Any help would be greatly appreciated.

```
$query->leftJoin('flag_content', 'flag', "n.nid = flag.content_id AND flag.uid = $user->uid");
$query->addExpression("flag.fid is not null AND flag.fid = 2", "is_flagged");
$query->addExpression("flag.fid is not null AND flag.fid = 3", "is_visited");

```

# Answer
> 6 votes
`addExpression()` is for adding expressions to the query, (i.e. fields that will be selected), you can't use it to add conditions.

You could either use a combination of `db_and()` and `db_or()` to build up your conditions, or (and probably easier) just use the `where()` method instead:

```
$condition = '(flag.fid is not null AND flag.fid = :fid1) OR (flag.fid is not null AND flag.fid = :fid2)';
$query->where($condition, array(':fid1' => 2, ':fid2' => 3);

```

# Answer
> 0 votes
This is what I ended up doing to get my results needed. If anyone can tell me if there is a better way I would love to hear. I guess it wasn't adding an and but it was returning a record for each item in the join. Sorry my sql skills need some work.

```
$query->leftJoin('flag_content', 'flag', "flag.fid = 2 AND n.nid = flag.content_id AND flag.uid = $user->uid");
$query->leftJoin('flag_content', 'visited', "visited.fid = 3 AND n.nid = visited.content_id AND visited.uid = $user->uid");
$query->addExpression("flag.fid is not null", "is_flagged");
$query->addExpression("visited.fid is not null", "is_visited");

```

---
Tags: database
---


# Question
Title: How to limit term reference autocomplete to a certain branch in hierarchical vocabulary (D7)?
I would like to add a term reference field in my user registration form, where the users should enter or select the organization they are from.

Tags vocabulary:

```
  - Organizations
   -- Orga1
   -- Orga2
    -- Orga3
    -- etc.
  - other parent term
  - other parent term

```

I think i remember, that in D6 i found a way to limit the term search to a certain branch of my vocabulary, so in this case, i was able to select "Organizations" and only the children terms where handled through the autocomplete.

I played around with various modules, but still there is no way to configure a parent term, but only set a hole vocabulary for the reference while creating the field.

Of course, i could set up a single vocabulary for the organizations only, but i fear that i will end up with a mess of single-use vocabs, while i would prefere to keep those things in one hierarchical vocabulary.

Did i miss something? Was there a change in the vocabulary-use-philosophy? Any hints appreciated.

# Answer
I use Workbench Access for this. I think you need to use the dev release, but for me, it is stable on a production site. It allows you to define which user roles and individual users can see which parts of taxonomy.
> 1 votes

---
Tags: taxonomy-terms
---


# Question
Title: creating child terms from a parent using fields
For a project i would like to achieve the following:

Using 2 fields in a content type field\_parent = reference to term This field references to vocabulary 'parent terms'

I have a second field called 'field\_child'. This field has to be a child term of the 'field\_parent' term

sample: field\_parent --\> apples field\_child --\> green

in taxonomy I see Apples \- green Pears \- green

How can I achieve this? Is there any module available or snippet.

# Answer
If your problem is with doing this via feeds (from your comment to me), I'd try the following:

It looks like you're already using the feeds module and that your incoming terms are mapped to your term reference. Good! It also sounds like you have a hierarchical vocabulary. Good.

Now, I'd just have one single term reference field on your node. No need to have one for the first level and one for the second level of your vocab. Just have ONE term reference field, and set that single term reference field to take an unlimited (or whatever number greater than 1) number of values in the 'Manage fields' page of your content type. (It won't just take one for the parent and one for the child, but both can be set once).

Download and install the Feeds Tamper module, which allows you to process results in various ways during the feeds import. Once your feeds tamper module is installed, when you go to /admin/structure/feeds, you should see a 'Tamper' link where you can configure your tamper settings.

For this to work properly, I'm assuming you can make your import file be in the form of '**Apples;Green**' for the hierarchical terms -- i.e. that you can provide them in one column, separated by a special character, and that that column is mapped to your one single term reference field. If you can do that, then you can set your tamper to parse them out and set both the parent and child of the vocabulary this way.

Go to the '**Tamper**' link, find the field that represents this taxonomy and select 'Add plugin'. Then select the '**Explode**' plugin and specify the special character that will separate your parent/child terms.

Test with an import, and let me know if that gets it working properly....
> 0 votes

# Answer
I used the Hierarchical taxonomy module. Now I can import feeds with parent ***/child*** taxonomy using it AND the Feeds Tamper module. It works perfect; you only need one import run.
> 0 votes

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


title: breadcrumbs not working as expected

text:
# Question
Title: breadcrumbs not working as expected
My menu looks like the following:

`defs` menu is linked to `def` view, `fghs` menu is linked to `fgh` view.

```
abcs | defs | fghs

```

Now when I click on `defs`, a view gets opened. Now my breadcrumb is the following:

```
Home >> defs >> def

```

`def` is the view. In this view there is a link to *another view*. When I click on this view, the breadcrumb is the following:

```
Home >> fghs >> fgh

```

But I want the breadcrumb in this format:

```
Home >> defs >> def >> fgh

```

How can I achieve this? I am using **Bartik** theme.

In the `page.tpl.php` file, I am using the code below:

```
<?php if ($breadcrumb): ?>
      <?php print $breadcrumb ?><?php if ($title != ""): ?><div class="breadcrumb">» <?php print $title ?></div><?php endif; ?>
<?php endif; ?>

```

# Answer
I suggest you use **Custom breadcrumbs** module for defining overriding breadcrumbs: it supports Token, which helps defining complex breadcrumbs (e.g. defining breadcrumbs from related taxonomy terms, etc.).

With this module, you can define custom breadcrumbs for the following entities: node, path, term, Views, vocabulary (on `admin/structure/custom_breadcrumbs`).
On `admin/config/user-interface/custom-breadcrumbs`, you can also set to append current page title by default too.

Its admin interface is really simple.

---

In your case, you should go to `admin/structure/custom_breadcrumbs/views/add`, set things like this (it's just an example):

Save, then go to `admin/config/user-interface/custom-breadcrumbs`, and check *"Append page title"*, hit "Save configuration", ready.
> 3 votes

# Answer
Hansel module can do this quite easily.

> "Breadcrumbs done right"
>
> Hansel (named after Hansel and Gretel) provides custom breadcrumbs which are build by user defined rules. These rules are independent from the menu system. Rules can have logic switches and can add links to the breadcrumbs.
> 0 votes

---
Tags: 7, breadcrumbs
---


# Question
Title: Drupal - Update Statistics label from "read" to "view" and "reads" to "views"
As the subject suggests I'm attempting to update the statistics title via a theme\_preprocess\_node function to read 'views' instead of 'reads':

```
function mytheme_preprocess_node($variables) {

  $content = $variables['content'];
  // Check the node  type to make sure
  // we have the one we want

  $content['links']['statistics']['#links']['statistics_counter']['title'] = str_replace('reads', 'views', $content['links']['statistics']['#links']['statistics_counter']['title']);
}

```

This isn't working but I cannot see why. I also don't want to use the stringoverrides module as I use 'read' and 'reads' elsewhere on the site.

Thanks

# Answer
> 2 votes
It's because you aren't accepting `$variables` by reference, so you're just changing a local variable. This will probably do what you want:

```
function mytheme_preprocess_node(&$variables) {
  $content = &$variables['content'];

  // Check the node  type to make sure
  // we have the one we want

  $content['links']['statistics']['#links']['statistics_counter']['title'] = str_replace('reads', 'views', $content['links']['statistics']['#links']['statistics_counter']['title']);
}

```

---
Tags: theming
---


# Question
Title: Why Drupal doesn't use special Memory Limit (ini_set) in Cache Clearing Script?
In Drupal 7, i have found that `CLEAR CACHE` (on the Web Panel) is using extreme high Memory resource. Giant projects like mine, needs over 350MB to that process.

* Then i set `400MB` inside `php.ini`

So as far as i have investigated, i have found that having high memory limit (Globally) is totally the `damage` to the overall Performance **because every single script is using that limit in memory**.

* Then i found, we can use separate/runtime setting as `ini_set('memory_limit',____)` only for the specific scripts.

So my question here is:

* Why Drupal by default is `NOT HAVING` this `ini_set('memory_limit',____)` separately in Cache Clearing Script (as hardcoded or in Panel Setting, etc) ?

# Answer
> Why Drupal by default is NOT HAVING this ini\_set('memory\_limit',*_*\_) separately in Cache Clearing Script (as hardcoded or in Panel Setting, etc) ?

Quite simply because Drupal doesn't know if your website has permission to change that value at runtime, so it can't be used as a generic solution. Most shared hosts won't allow you to set your own site's memory limit for example, it's locked down to a server-wide default.

As Andy already said, giving PHP a *limit* of 400MB **does not mean that every single PHP script will use 400MB**. It's a limit, PHP won't go above it, but it won't necessarily use all of it either.
> 4 votes

---
Tags: caching
---


# Question
Title: Views exposed filter for children terms when on parent term page
I have created a `views` with multiple exposed filters and I need another filter that is based on `taxonomy`.

My taxonomy structure is:

**term 1**

* child 1.1
* child 1.2

**term 2**

* child 2.1
* child 2.2

What I want is the following;

`path: site.com/taxonomy/term/1`

Exposed filter that can filter shows only;

* child 1.1
* child 1.2

How I have a filter that shows all taxonomy structure or when using depth it shows all child terms? Like this;

* child 1.1
* child 1.2
* child 2.1
* child 2.2

I'm sure there must be a way to only show the related child terms when on the parent term page.

thanks

# Answer
You could use a form\_alter hook in a custom module (or even your template.php file of your theme) to alter the filter values in the exposed view form.

as an example:

```
<?php
    function mymodule_form_alter(&$form, &$form_state, $form_id){
        //if it is the exposed filter view
        if (($form_id == 'views_exposed_form') &&
        //for the view we care about
        ($form_state['view']->name == 'your_view') &&
        //and the view display we care about
        ($form_state['view']->current_display == 'your_display') &&
        //and on a taxonomy term page
        (arg(0)=='taxonomy') && (arg(1)=='term') && (is_int(arg(2)))){
            //get the childern of the term
            if ($child_terms = taxonomy_get_children(arg(2))){
                //only care about the tids
                $child_terms_tids = array();
                foreach ($child_terms as $child){
                    $child_terms_tids[] = $child->tid;
                }

                //for the exposed filter, alter the available options
                foreach ($form['exposed_filter_name']['#options'] as $tid => $term){
                    //is is a child term?
                    if (in_array($tid,$child_terms_tids)){
                        //leave it
                    }else{
                        //remove it
                        unset($form['exposed_filter_name']['#options'][$tid]);
                    }
                }
            }
        }
    }

    ?>

```
> 0 votes

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


# Question
Title: how to publish a node content to the walll of a Facebook account?
Just wondering if is there any module to let publish a node content (title, body and images) to the wall of a Facebook account?

# Answer
> 1 votes
check Fridge for a fast solution. wont post the whole content, though. (and i wonder how that would be done)

# Answer
> 1 votes
You should be able to use Drupal for Facebook for this.

> With Drupal for Facebook, you can harness all the power of Drupal in you Facebook App. If you already have content in Drupal, you can expose it on Facebook.

The documentation is here.

> **What can Drupal for Facebook help you do?**
>
> * Add Like buttons, and other social plugins to your Drupal-powered website.
> * Let users authenticate to your site using their facebook username and password. This saves the user the trouble of registering with your site, and allows you to build additional social features, known as Facebook Connect.
> * Create applications on facebook.com. Powered by your Drupal server, these applications add features and content for your users while they visit facebook.com.
> * Publish content from your site to a user's Facebook stream (wall).
> * And more!

---
Tags: nodes, social-network
---


# Question
Title: Submitting disabled fields on content entry forms?
I need to submit content entry forms that have default values set in disabled elements. However, if I remember correctly, HTTP specifies that fields that are disabled do not have their values sent to the web server (or are dropped by the web server, I can't remember).

Specifically, I have a tag field (term reference) that is a select list, and it defaults to a particular value that is updated twice a year and it cannot be changed by users submitting the form. I want this field to appear to the user, but at the same time I want it disabled so they can't change it.

How can I submit a disabled field in Drupal 7?

# Answer
> 1 votes
As long as security is not a concern, the following can be done:

1. Use `hook_form_alter` to create an additional hidden field in the form.
2. The name attribute of this hidden field should be equivalent to the name of the disabled field. The value attribute of the hidden field should be equivalent to the currently selected value.
3. The hidden field needs to be placed at the very END of the HTML form, or at the very lease, immediately after the disabled field. The reason for this is that, according to the HTTP specification, if you submit multiple fields with the same name, the last field in the flow of the HTML has it's value submitted above all other submissions. Of course, disabled fields have their values dropped altogether, so the hidden field could technically appear anywhere in the form, but this would be "best practice".

Here's some code from my `hook_form_alter`:

```
function ccom_validations_form_challenges_node_form_alter(&$form, &$form_state, $form_id) {
  $form['my_field'] = array (
    '#type' => 'hidden',
    '#value' => 'schweet'
  );
  $defaultValue = $form['field_reporting_period']['und']['#default_value'][0];
  $form['my_field']['#attributes']['name'] = 'field_reporting_period[und]';
  $form['my_field']['#attributes']['value'] = $defaultValue;
  $form['my_field']['#weight'] = '4';
  $form['field_reporting_period']['#disabled'] = 'true';
  dpm($form);
}

```

So in the above code you can see how I've assigned the name and value to the field, adjusted the weight so it appears last in the list (using DPM I found that the the highest weight value was 3 in the form, so I used 4 so it was weighted the heaviest), and finally indicated that the original field I wanted disabled is in fact disabled. Note that you disable form fields in Drupal using the meta attribute `#disabled`, rather than specifying the disabled attribute directly in the `#attributes` array. Weird.

Now this obviously isn't secure, because anybody with any browser HTML manipulation tool like the Chrome Inspector can enable the field and move it to last in the list and then it's value would be used rather than the hidden fields. I'll revisit this later if security really becomes a concern in this area.

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


# Question
Title: How to display most recent node in different Panel
I have a magazine with two content types: Issue and Article. Regarding the Issue content type, I want one design for the most recent Issue and another design for all the past Issues. The past Issues are taken care of with Display Suite. For the current Issue I would like to use a panel/node variant. My question is, how do I display only the most recent node from the Issue content type without changing the design for all Issue nodes?

# Answer
You can use Views module to have custom content or links and show as a separate page or a block.

check this link: http://drupal.org/project/views
> 0 votes

---
Tags: 7, panels
---


# Question
Title: Check if current node meets conditions, then alter a block's contents?
In Drupal 7, how would I check whether the current node being viewed meets certain conditions, and then based on that check alter a block's contents?

To give a specific example, I want to check if the current node on my site is a blog post (like http://www.givingwhatwecan.org/blog/2012-10-04/giving-to-charity-%E2%80%93-a-pain-in-the-eye \- the conditions here are being tagged with the 'Blog' taxonomy term, or being of type 'story'). If it is, I want to add the class 'active-trail' to the 'Blog' heading in the menu block atop the page.

If need be, I'm happy to use jQuery, though I'd be interested to know the general 'Drupal way' of doing this.

# Answer
> 1 votes
You can check the content type of current node via preprocessing functions in your theme, but there might be another (simpler) way to do what you want: Drupal adds various information about the current page in the body classes, so you have more options for theming.

To select a specific menu link on all nodes of blog content type you can use the following CSS class: `body.node-type-blog` and a unique menu link ID (`#menu-1000-1`).

Add that line to the place where you define the active state of menu items. In your case this will be (in your superfish CSS file):

```
body.node-type-blog #menu-1000-1 a,
a.sf-depth-1.active, .active-trail a.sf-depth-1 {

```

---

Another quick solution would be using jQuery:

```
if ($("body").hasClass("node-type-blog")) {
  $("#menu-1000-1").addClass("active-trail");
}

```

---

Check also Context module for more complex use cases where you need to define a section on your website and apply certain theming/functional changes.

---
Tags: 7, blocks
---


title: Load a block in template?

text:
# Question
Title: Load a block in template?
Is it possible to load a block contents into a template file (say like `page.tpl.php`)? I need to extract a block which contains colophon (e.g. copyright and company information) and place it after the footer region.

Also, are there any performance problems with this approach?

# Answer
Maybe I am missing something about your question, but it seems that one of three basic techniques should work for you.

1. If you just need information from a block in the footer, place the block in the footer region and style it with css so that it is positioned where you need it to be.
2. If you need to adjust the information in a block (e.g. to place a block on a page twice), use a render hook. c.f. The Scary Render Array.
3. If you just want to put some custom content + php in your template after the footer, you can just plop it down there. If you have code in your block function that needs to be called in two locations, factor it into its own function, and call it from the template and from the block function.

It feels wrong to call the block api from a template file when one of the above more conventional techniques should work just as well.
> 3 votes

---
Tags: blocks, theming
---


# Question
Title: Redirection after certain node type creating
So far i have this code in mymodule.module:

```
function mymodule_form_alter(&$form, $form_state, $form_id) {
    //drupal_set_message($form_id);
    switch ($form_id) {

        case 'anons_node_form':
          //dpm($form);
          $form['#submit'][] = 'sex_custom_submit';

          break;
    }
}

//Custom submit handler
function sex_custom_submit($form, &$form_state) {
  $form_state['rebuild'] = TRUE;
  $form_state['redirect'] = '/video';
}

```

In a short i want this thing - when a user creates a node type 'anons' after succesfull creation of that node -\> user should be redirected to a /video page. Code above doesn't works for me.. What i am doing wrong?

# Answer
Try putting your destination as GET destination parameter, i:e $\_GET\['destination'\]. The GET destination parameter gets the highest preference
> 2 votes

# Answer
Your redirect isn't happening because you have set `$form_state['rebuild'] = TRUE;` which prevents the redirect from happening.

For appropriate documentation see drupal\_redirect\_form
> 0 votes

---
Tags: redirection
---


# Question
Title: Setting Values for TableSelect checkboxes
Is there anyway to set the default values for checkboxes? What im trying to do is set a specific value for each checkbox so it will delete the selected row in my db, however table select seems to just go off of its own value instead of the one I am trying to assign them with.

```
    function auto_form_records($form, &$form_state) {
//Table header
    $header = array(
        '',
        'First Name',
        'Last Name',
    );

//DB query
    $dbresult = db_query("SELECT * FROM {auto}");

        foreach ($dbresult as $dbrow) {

            $select_id[] = array(
            $dbrow->id
            );
            $rows[] = array(
            $dbrow->firstname,
            $dbrow->lastname,
            );
        }

//Table select Form
    $form['checkboxes'] = array(
        '#type' => 'tableselect',
        '#header' => $header,
        '#options' => $rows,
        '#empty' => 'No Records were found.',
        '#default_value' => $select_id
    );

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

//Delete row in db.
    function auto_form_delete_row($form, &$form_state){
        $id = $form_state['values']['checkboxes'];
        db_delete('autoleads')
      ->condition('id', $id)
      ->execute();
    }

//Submission
    function auto_form_records_submit($form, &$form_state){
        $data = drupal_set_message(t(dvm($form_state)));
        //auto_form_delete_row($form, $form_state);
        return $data;
    }

```

I would think that me passing the string into default\_value would atleast give me the values I am trying to pass through, but its not...

Any suggestions is appreciated.

# Answer
> 8 votes
You just need to add your id as the key for each item in your `$rows` array, e.g.:

```
foreach ($dbresult as $dbrow) {
  $rows[$dbrow->id] = array(
    $dbrow->firstname,
    $dbrow->lastname,
  );
}

```

Then in your submit handler run:

```
// Limit the checkbox ids to only those selected by the user
$selected = array_filter($form_state['values']['checkboxes']);

db_delete('autoleads')
  ->condition('id', $selected, 'IN')
  ->execute();

```

And you should be good to go :)

There's no need to use `#default_value` unless you want to pre-select some of the checkboxes for the user. If you do, just set `#default_value` to an array of the ids that you want selected initially.

---
Tags: forms
---


# Question
Title: How to use another theme's template file
I have a template file for a entity type inside my theme's folder.

How can I use the same template file in the admin area which uses the Seven theme?

Thanks. M

# Answer
> 2 votes
Since it's always bad practice to hack core, you would have to do it with a custom module. This would be done with either template suggestion overrides or with template suggestions in a preprocess hook such as template\_preprocess\_node or template\_preprocess\_page.

Unfortunately this is not enough when you place the template file (tpl) anywhere but the theme's `templates/` folder. Your custom module's template folder is not known by default so you will have to notify Drupal about. To do this, you will need to use hook\_theme\_registry\_alter. Here below is an example from one of my projects in Drupal 7 (and it's live and works).

```
/**
 * Implements hook_theme_registry_alter()
 */
function CUSTOM_MODULE_theme_registry_alter(&$theme_registry) {
  // The Templates path in your custom module you want to add...
  $mod_path = drupal_get_path('module', 'CUSTOM_MODULE') . '/includes/templates';

  // ... or the Templates path in your custom theme.
  // If you use your already existing custom theme's path, make sure you remember that this
  // function exists when you alter or disable the custom theme.
  $mod_path = drupal_get_path('theme', 'CUSTOM_THEME') . '/templates';

  $theme_registry_copy = $theme_registry;
  _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'pow', $mod_path);
  $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
  $hooks = array('node');
  foreach ($hooks as $h) {
    _CUSTOM_MODULE_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
  }
}

/**
 * Helper function for re-ordering arrays (needed by theme_registry_alter)
*/
function _CUSTOM_MODULE_insert_after_first_element(&$a, $element) {
  if(is_array($a)) {
    $first_element = array_shift($a);
    array_unshift($a, $first_element, $element);
  }
}

```

I've seen people advocate (or at least suggest) the use of `theme_hook()` instead, but I actually find the theme registry way a lot easier to handle. Especially when you add more templates at a later stage during the development process.

# Answer
> 0 votes
You have a choice.

Goto host.com/admin/appearance

Scroll down to find ADMINISTRATION THEME

And uncheck the check box "Use the administration theme when editing or creating content"

---
Tags: 7, theming
---


# Question
Title: some css of same file getting processed some not
In my custom theme I have two stylesheets; style.css and nice-menu-custom.css.

If I would change some silly old css for testing - like `body{color:lime;}` it would affect the site as normal. However, some other css changes to the same file that get uploaded just simply don't affect the site. None of the width or float properties are working I have the impression.

You would think I'm just not writing proper css, but the thing is if I make the same changes in firebug, it works fine. for instance `body{width:50%;}` does it's job when using firebug, not when uploading that same code from my stylesheet (i.e. the same stylesheet as from which I upload the changes that DO work) on the server.

I verified if the new changes actually uploaded by trying to upload the changes, shutting down the FTP program and then starting a different ftp program to see if these changes would be stored on the server. And they were.

**Made sure:**
Caches were cleared often
CSS Compression turned off

**So in short:** if I go and see in chrome developer tools, to read my stylesheet from the server, under the 'resources' tab -second from left, I can see the changes to my stylesheet that I uploaded and should work. Yet when you look at the site the changes aren't made. Plus if I made the same changes using the developer tools themselves, under the first tab 'elements', the changes would actually take effect. I just don't understand.

# Answer
It was a syntax error after all...forget one curly bracket somewhere in my stylesheet.
I never expected a syntax error in css to cause this kind of difficulties. I.o.w. I unconsciously assumed it couldn't be syntax and therefore it never crossed my mind. Lesson learned: never assume even when you don't realise you're assuming!
> 0 votes

---
Tags: 7, theming
---


# Question
Title: corresponding textbox for each user reference item
I have a special node type \[I call it **members**\] that includes a user reference field. The amount of user references that can be added to each members is unlimited.

But I need to add an extra information for each user that is added to each members node.

I am searching for a solution to put a text box input beside the node reference auto complete input. I mean each auto complete user reference field has a corresponding text box input.

Even when the manager click on **add another** button and new auto complete line is appeared at the end of rows, the new corresponding text box input must be located beside it.

Please help me

How can I do this.

# Answer
I'd use field collections. In your members content type, create a field (say members collection) with multiple values. Then proceed to the field collections admin and add:

1. the user reference field
2. the textbox field

These two fields while creating the content type will now be 'one' with an 'add more' button under each.
> 0 votes

---
Tags: users
---


# Question
Title: I am looking to export webform submissions to cck instead of typing each submission in Drupal 6?
I have close to 150 submissions on my webform but had to change to content type midway , is there a simple way to export those submissions to a cck content type and map those fields instead of typing each one out.

Thank you

# Answer
You could try: First export the data to csv.

Then, import with feeds.
> 2 votes

---
Tags: nodes, webforms
---


# Question
Title: Update new user's profile with rules, based on his webform submitted data
On my site I am using two webforms from which a user can register to the site. This feature is enabled thanks to the webform\_registration module. Of course these webforms can only be submitted by anonymous users.

What I want is, on the event of a submission, to populate the profile of the user who submitted the form with some of the data that were submitted. So I created a rule catching the event of a webform submission. Now how will I update the profile? Setting a data value on a user field does not work since the user who submitted the form was anonymous! He was created after. How can I do this? All I know about the user is just his username that can be pulled from the submission data. Any way to retrieve the user entity using his username and then writing the data to his profile?

# Answer
> 3 votes
You need to create and force-save both the User and the User's Profile before you set your data values. Your rules actions should look like the following:

1. Create Entity - User
2. Save Entity - User, Force Save
3. Create Entity - Profile, choose profile type.
4. Save Entity - Profile, Force Save
5. Set Data Value(s)

---
Tags: webforms, users, rules
---


# Question
Title: Display contact information for each car owner
I am trying to view contact information for each user who will be the car owner in this case. so in each car in car content type I want to display user info with each car he post

best

# Answer
How do you gather the contact information? Is it profile fields or a node connected to the user account?

Regardless of the method you can create a view that will use the author of the node as the argument of the view (D6) or contextual filter (D7) to bring the contact information for the user. One thing to consider is that you might have to create a relationship to the entity or method you used to collect the information.

After the view is created the next thing will be to decide how to present it, maybe you want to create a block, or attach it at the end of the car content type or make it a tab, all those options are available in views as well.
> 2 votes

---
Tags: nodes, emails
---


# Question
Title: Aggregating nodes and revisions by users in a table - "top contributors" list
I want to create a table displaying counts of users' authored nodes and revisions (we're doing some "wiki" type stuff). This is for a "top contributors" type display.

The table should be structured with three columns: Name, Posts, Revisions. The table should list users under "Name" and numbers under "Posts" and "Revisions".

I feel like I got halfway there and got stumped. Here's what I set up in a view:

(NOTE: Users are affiliated with organizations via References module and "Organization" content type, I'm trying to display users affiliated with the org on the org page.)

**Fields**:
(author) User: Name (Staff)
COUNT(Content: Title) (Title)
(revision user) User: Name (Name)
COUNT(Content revision: Vid) (Vid)

**Filter Criteria**:
Content: Type (= Resource)

**Sort Criteria**: NONE

**Contextual Filters**:
(author) User: Organization - Provide default value: Content ID from URL

**Relationships**:
Content: Author
(author) User: Organization
Content revision: User
(revision user) User: Organization

**Other**:
Use Aggregation: Yes

The result I get shows the same number of posts as revisions - even when I go throw in a few additional revisions to test.

Where am I going wrong? How do I do this properly?

**ADDED TO QUESTION**

Here's the full view export:

$view = new view();
$view-\>name = 'staff\_contributions';
$view-\>description = '';
$view-\>tag = 'default';
$view-\>base\_table = 'node';
$view-\>human\_name = 'Staff Contributions';
$view-\>core = 7;
$view-\>api\_version = '3.0';
$view-\>disabled = FALSE; /\* Edit this to true to make a default view disabled initially \*/

/\* Display: Master \*/
$handler = $view-\>new\_display('default', 'Master', 'default');
$handler-\>display-\>display\_options\['title'\] = 'Staff Contributions';
$handler-\>display-\>display\_options\['use\_more\_always'\] = FALSE;
$handler-\>display-\>display\_options\['group\_by'\] = TRUE;
$handler-\>display-\>display\_options\['access'\]\['type'\] = 'perm';
$handler-\>display-\>display\_options\['cache'\]\['type'\] = 'none';
$handler-\>display-\>display\_options\['query'\]\['type'\] = 'views\_query';
$handler-\>display-\>display\_options\['exposed\_form'\]\['type'\] = 'basic';
$handler-\>display-\>display\_options\['pager'\]\['type'\] = 'some';
$handler-\>display-\>display\_options\['pager'\]\['options'\]\['items\_per\_page'\] = '5';
$handler-\>display-\>display\_options\['style\_plugin'\] = 'default';
$handler-\>display-\>display\_options\['row\_plugin'\] = 'fields';
/\* Relationship: Content: Author \*/
$handler-\>display-\>display\_options\['relationships'\]\['uid'\]\['id'\] = 'uid';
$handler-\>display-\>display\_options\['relationships'\]\['uid'\]\['table'\] = 'node';
$handler-\>display-\>display\_options\['relationships'\]\['uid'\]\['field'\] = 'uid';
/\* Relationship: User: Organization (field\_organization) \*/
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid'\]\['id'\] = 'field\_organization\_nid';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid'\]\['table'\] = 'field\_data\_field\_organization';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid'\]\['field'\] = 'field\_organization\_nid';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid'\]\['relationship'\] = 'uid';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid'\]\['delta'\] = '-1';
/\* Relationship: Content revision: User \*/
$handler-\>display-\>display\_options\['relationships'\]\['uid\_1'\]\['id'\] = 'uid\_1';
$handler-\>display-\>display\_options\['relationships'\]\['uid\_1'\]\['table'\] = 'node\_revision';
$handler-\>display-\>display\_options\['relationships'\]\['uid\_1'\]\['field'\] = 'uid';
/\* Relationship: User: Organization (field\_organization) \*/
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid\_1'\]\['id'\] = 'field\_organization\_nid\_1';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid\_1'\]\['table'\] = 'field\_data\_field\_organization';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid\_1'\]\['field'\] = 'field\_organization\_nid';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid\_1'\]\['relationship'\] = 'uid\_1';
$handler-\>display-\>display\_options\['relationships'\]\['field\_organization\_nid\_1'\]\['delta'\] = '-1';
/\* Field: User: Name \*/
$handler-\>display-\>display\_options\['fields'\]\['name'\]\['id'\] = 'name';
$handler-\>display-\>display\_options\['fields'\]\['name'\]\['table'\] = 'users';
$handler-\>display-\>display\_options\['fields'\]\['name'\]\['field'\] = 'name';
$handler-\>display-\>display\_options\['fields'\]\['name'\]\['relationship'\] = 'uid';
$handler-\>display-\>display\_options\['fields'\]\['name'\]\['label'\] = 'Staff';
/\* Field: COUNT(DISTINCT Content: Title) \*/
$handler-\>display-\>display\_options\['fields'\]\['title'\]\['id'\] = 'title';
$handler-\>display-\>display\_options\['fields'\]\['title'\]\['table'\] = 'node';
$handler-\>display-\>display\_options\['fields'\]\['title'\]\['field'\] = 'title';
$handler-\>display-\>display\_options\['fields'\]\['title'\]\['group\_type'\] = 'count\_distinct'; /\* Field: User: Name \*/
$handler-\>display-\>display\_options\['fields'\]\['name\_1'\]\['id'\] = 'name\_1';
$handler-\>display-\>display\_options\['fields'\]\['name\_1'\]\['table'\] = 'users';
$handler-\>display-\>display\_options\['fields'\]\['name\_1'\]\['field'\] = 'name';
$handler-\>display-\>display\_options\['fields'\]\['name\_1'\]\['relationship'\] = 'uid\_1';
/\* Field: COUNT(DISTINCT Content revision: Vid) \*/
$handler-\>display-\>display\_options\['fields'\]\['vid'\]\['id'\] = 'vid';
$handler-\>display-\>display\_options\['fields'\]\['vid'\]\['table'\] = 'node\_revision';
$handler-\>display-\>display\_options\['fields'\]\['vid'\]\['field'\] = 'vid';
$handler-\>display-\>display\_options\['fields'\]\['vid'\]\['group\_type'\] = 'count\_distinct';
/\* Contextual filter: User: Organization (field\_organization) \*/
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['id'\] = 'field\_organization\_nid';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['table'\] = 'field\_data\_field\_organization';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['field'\] = 'field\_organization\_nid';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['relationship'\] = 'uid';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['default\_action'\] = 'default';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['default\_argument\_type'\] = 'node';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['summary'\]\['number\_of\_records'\] = '0';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['summary'\]\['format'\] = 'default\_summary';
$handler-\>display-\>display\_options\['arguments'\]\['field\_organization\_nid'\]\['summary\_options'\]\['items\_per\_page'\] = '25';
/\* Filter criterion: Content: Type \*/
$handler-\>display-\>display\_options\['filters'\]\['type'\]\['id'\] = 'type';
$handler-\>display-\>display\_options\['filters'\]\['type'\]\['table'\] = 'node';
$handler-\>display-\>display\_options\['filters'\]\['type'\]\['field'\] = 'type';
$handler-\>display-\>display\_options\['filters'\]\['type'\]\['value'\] = array( 'resource' =\> 'resource', );

/\* Display: Block \*/
$handler = $view-\>new\_display('block', 'Block', 'block');
$handler-\>display-\>display\_options\['defaults'\]\['hide\_admin\_links'\] = FALSE;

# Answer
> 0 votes
I'm assuming that your view is set up to display content revisions (you have to select what it's displaying on the first screen when setting up a view).

Try selecting '\**Count DISTINC*\*T' in the aggregation settings! That should do it. Otherwise, even if your view is outputting something like

```
user: user1
nid: 510
vid: 1

user: user1
nid: 510
vid: 2

user: user1
nid: 510
vid: 3

```

It would be counting those nids at '3' rather than '1' if you don't count the DISTINCT instances. Does that make sense?

Hope this gets you in the right direction...

============================ RESPONSE ADDITION ==============

Just wanted to add that if you can't get quite the right view with what the View's UI provides (because it's not quite as flexible as writing your own SQL), you can always choose to write a tiny custom module that overrides the SQL of your view.

Something like this: http://eureka.ykyuen.info/2010/11/27/drupal-customize-the-views-query/

I just wanted to add that in case it helps too. :-)

# Answer
> 1 votes
Here's what I ended up doing - it worked like a charm:

I installed the Userpoints module and the Userpoints Nodes and Comments module.

Site users like recognition/credit, but aren't quite looking to rack up points or compete, so I just changed the "Points" branding (under configuration \> points \> points settings \> branding) to "Contributions".

Set the system to add one point for creating one node, creating one revision, creating one comment, etc. Then set the userpoints categories (under structure \> taxonomy) to "Resources"(node contributions), "Revisions", "Comments", etc.

Set default user points category for each content type (structure \> content type)

User profiles now show how many resource posts, revisions, comments, etc they've respectively contributed:

To show top users, just create a view with the User:Name field and Userpoints:Total Current Points field, and adjust the points field title to "Site Contributions" (near bottom of pic):

Using relationships and aggregation I was able to create a "Top Organizations" view as well:

@Boriana - I'll still try the SQL approach. Need to learn it.

Thanks!

---
Tags: views, css-js-aggregation
---


title: Flow player problem

text:
# Question
Title: Flow player problem
I am using flow player on my site. I am providing all possible fields but flow player is not playing any audio and video format. please help.

# Answer
> 0 votes
**Answer for Video format:** As flow player does not support flash so that's why .wav extension's video can not play by flow player.

**Answere for audio format:** Flow player mostly support mp3, ACC audio format.

---
Tags: 7, files
---


title: Use drush make to load only modules?

text:
# Question
Title: Use drush make to load only modules?
I have a dev site with many modules. I have another dev site on a different server that I'd like to populate with the same modules. I can zip 'em up and move the file, or use rsync, but I wanted to see if drush-make would do it faster.

I can create only modules without core using: "drush make --no-core makefile.make" within the module directory but this creates the sites/all/modules directory hierarchy.

How can you use drush make to just build the modules in the modules directory without that structure?

# Answer
If you run `drush make --contrib-destination=sites/mysite`, then modules will be placed in sites/mysite/modules. rsync is going to be faster than Drush make. (**Edit:** This speed comparison presumes roughly equal transfer speeds between the endpoints. I can see how make might be faster if you have a fast connection from the target to d.o, but a slow connection between the source and the target.)

If you want to create a makefile for an existing site, you may use `drush generate-makefile`, or build a whole installation profile with drush generate-profile.
> 8 votes

---
Tags: 7, drush
---