# Question
Title: Is it possible to create multiple submission forms for one content type?
I want to allow my users to submit different type of content using different types of templates (like in tumblr.com where you get a specific template/form for each content)

At first, I was thinking about creating custom content types, but this is a workaround because I dont really want to make different content types (all nodes are blog posts). I just want to create different forms for the content submission.

What is the proper "Drupal way" of doing that?

# Answer
> 1 votes
The proper way to do this in Drupal is using multiple content types, but if you want (for whatever reason) to still stick to your solution, you can write a custom module, and modify that one before rendering.

Here's an example using the default page content type and hiding the body. Use the Devel module, and `dsm()` to inspect the form.

```
function mymodule_menu() {
  $items['mymodule/add'] = array(
    'title'=> 'mymodule add',
    'description' => 'add content',
    'page callback'=>'mymodule_form',
    'access arguments' => array('add content'),
    'type'=>MENU_NORMAL_ITEM,
  );

  return $items;
}

function mymodule_form() {
    global $user;
    $node = new stdClass();
    $node->uid = $user->uid;
    $node->type = 'page';
    node_object_prepare($node);

    module_load_include('inc', 'node', 'node.pages');
    $form = drupal_get_form("page_node_form", $node);
    hide($form['body']);
    dsm($form);
    return drupal_render($form);
}

```

# Answer
> 0 votes
1. Create roles for your specific users
2. Create node form templates like this by exmaple **myform-node-form.tpl.php** and copy it to your themes template folder.

`<?php
 ?>

 <?php print drupal_render($form['mydesiredfied1']); ?>

 <?php print drupal_render($form['mydesiredfied2']); ?>

 <?php print drupal_render($form['mydesiredfied3']); ?>

 <?php print drupal_render($form['mydesiredfied4']); ?>

 <?php echo drupal_render_children($form)?>

`

Then Write a small module and assign the node form templates based on your roles. I wrote something where a assigned a node form template to my forms in hook\_theme. You just have to check the user roles and assign your templates. Examplecode for assigning node-form templates:

```
function mymodul_theme() {
    return array(
      'myform_node_form' => array(
        'arguments' => array('form' => NULL),
        'template' => 'templates/myform-node-form',
        'render element' => 'form',
      ),
}
```

# Answer
> 0 votes
Well I took a different approach -

I created some templates for the WYSIWYG editor (supported for ckeditor and tinymce) and let the users pick their preferred layout (template) for submitting via RTE. In my opinion this solution is less complicated and much more flexible and easy to implement.

thanks for the help!

---
Tags: nodes, forms
---


title: Inline block confirm messages

text:
# Question
Title: Inline block confirm messages
I have a contact (web)form in my sidebar on my site and I would like to display a custom confirm message when a users submits the form. However, this message should replace the contact form.

I've tried with Inline Messages or with the form-settings (no-redirect), but every solutions just redirects the entire website to the node and displays the message inline. So, that not what I want, obviously...

So, is there a solution where the content of the page remains unchanged, but when submitting the form in the sidebar, only the sidebar refreshes and shows the confirmation message?

# Answer
The Webform Ajax module will give you the functionality you describe. Here is a quote about it (from the module's project page):

> ... adds AJAX support to Webform (3.0 and above).
>
> As a first step it focusses to simply add form AJAX paging and submit. Form submissions get ajaxified including prev/next pages. Especially for multipage forms, this leads to faster loading (less data transfer), better usability and finally smaller server load.
> 1 votes

---
Tags: 7, forms, emails
---


title: Get variables of a view?

text:
# Question
Title: Get variables of a view?
im trying to access some variables of my view but i fail terribly: My modulefile looks like this:

```
$io= views_get_view('nameofmyview');
dpm($io);

```

Drupal tells me:

> Fatal error: Call to undefined function views\_get\_view()

What am i missing?

# Answer
Thanks @clive for the hint

```
module_load_include('module','views','views');

```

does the trick!
> 0 votes

---
Tags: views, hooks
---


# Question
Title: How to get image titles and source out of a view?
I'm struggling hard to understand how drupal views work. With views i assembled a new front page which takes images from certain content types.

Now i'm writing a module to get the image data out of the view.

My Problem: where can I find the images: when i write

```
views_get_view('viewsname');

```

I get an array of values but not the images.

How can i get the images out of the view properly?

# Answer
If you are wanting to get Views results to use programmatically, check out the views\_get\_view\_result() function. If you do something like:

```
$result=views_get_view_result('viewname');

```

you can then loop through $result, which is an array of objects relating to each row, and the tried and true:

```
drupal_set_message('<pre>' . print_r($result, TRUE) . '</pre>');

```

will give you all the information you are working with.
> 1 votes

---
Tags: views
---


# Question
Title: All visited urls ending with _900 in cache_page tables
I came across strange problem with drupal 7 and caching for anonymous users. After clearing cache, newly visited pages by anonymous users are stored in cache\_page with \_900 at the end of url like this www.example.com/examplepage\_900. Anybody know what can cause this behavior?

# Answer
This issue was caused by module http://drupal.org/project/resp\_img after installing the latest version, everything is ok.
> 0 votes

---
Tags: 7, caching
---


title: Caching using wget

text:
# Question
Title: Caching using wget
I use drupal 7. After clearing the cache, I use wget like this to cache all pages back.

```
wget --quiet http://xxx.xxx/sitemap.xml --output-document - | egrep -o "http://xxx.xxx[^<]+" | wget -q --delete-after -i -

```

After it is done, I check in database the cache\_page table, and all pages seems to be there. However, if I visit any page with the browser, it takes time as if it was not pre-cached. What I noticed as well is that after visiting the page in browser, the loading time on next visit is very fast as it should be.

What can the problem be? I am successfully using this method on a Drupal 6 page with no problems. Error log shows nothing except favicon.ico does not exist.

The access log for URLs looks like the following:

> www.xxx.sk 11.116.206.232 - - \[01/Jan/2013:18:09:12 +0100\] "GET /myurl HTTP/1.1" 200 31532 "-" "Wget/1.13.4 (cygwin)"

I am NOT logged in

EDIT: I updated drupal 7.14 to 7.19 version but no change. After looking into cache\_page table I noticed that all pages visited using browser are generated for some strange reason with \_900 at the end like this: www.example.com/examplepath\_900. I did not noticed it before because the paths don't fit inside the cells in database tables. So that is why pages are not cached. Also I set up fresh installation of drupal 7 on the same host where caching using wget works as expected with no problems. There can not be problem in htaccess or settings files as well. Maybe some installed module can cause this?

# Answer
This issue was caused by module http://drupal.org/project/resp\_img after installing the latest version, everything is ok.
> 1 votes

# Answer
All modern browsers send some Accept-Encoding ~ 'gzip' header, so cached entries will not be used if your spider doesn't use this one (a decent back-end generating gzipped responses adds a vary: Accept-Encoding header). You may also look into the --mirror option of wget which could assist here.
> 3 votes

# Answer
Kenny's advice is solid. One other idea is that you may have several assets that are being cached in the browser on the first load and then not the second. Instead of doing the test in the same browser, try doing the test in a Chrome Incognito window, closing that window, and then doing it again. That should help determine if it is the Drupal page cache's failure to fulfill the request (maybe because of the Gzip idea) that is responsible for slowness or if it is browser caching of files causing them not to download again which makes the second request faster.
> 3 votes

---
Tags: 7, caching
---


title: How do I find a node knowing its URL?

text:
# Question
Title: How do I find a node knowing its URL?
I need to rename the node home-care/vids into home-care/product-solutions. The trouble is that I can't find home-care/vids in the dashboard of this relatively big site.

How can I find it?

I have even done a MySQL database search but results are not helpful for me.

# Answer
The easiest way is almost always to visit the page you want to change, and hit the "Edit" button among the tabs.

However, sometimes this may not be practical for whatever reason. SQL-queries below:

**D6**

`SELECT src FROM url_alias WHERE dst = 'home-care/vids';`

**D7**

`SELECT source FROM url_alias WHERE alias = 'home-care/vids';`

You may in both version want to add `AND language =` if your site is multilingual.
> 0 votes

# Answer
Go to your theme's page.tpl.php and print the TABS, that may be ommited

and

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

```

If you have the appropriate permissions, the tabs will come up and you can visit the edit of that node
> 0 votes

---
Tags: nodes, uri
---


# Question
Title: Handling dynamic URLs through my custom module
I have written a custom module and have defined a menu inside the module as `test`. This menu uses a function named mymodule\_test() to render contents. The code written for this menu is working perfectly OK and I am getting expected output on /test page.

Now, I want to define some more menus that use the same mymodule\_test(). I understand that I can define more menu items in the `mymodule_menu()` as below.

```
$items['test-1'] = array(
  'title' => 'Test',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('mymodule_test'),
  'access arguments' => array('administer mymodule'),
  'type' => MENU_NORMAL_ITEM,
);

```

However, I am planing to use more than 100 such menu and believe this is not the best way to achieve this. Please guide me in the right direction to achieve the same.

This is to note that these menus will be dynamic in nature so I cannot hard code it in the module file.

I am using Drupal 6.

# Answer
Firstly, you should not define a callback as \['/test-1'\], instead just use \['test-1'\], without the slash - '/'. Check here - http://api.drupal.org/api/drupal/developer!hooks!core.php/function/hook\_menu/6

If you want to create 100 menus, go ahead, this is the way you can do this. If just the path is changing and nothing else, I would recommend to create an array, and then loop it, defining the value of the array item in the menu-path. something like this -

```
$arr = array('test-1', 'test-2', 'test-3', 'test-4', 'test-5');
foreach ($arr as $a) {
  $items[$a] = array(
  'title' => 'Test',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('mymodule_test'),
  'access arguments' => array('administer mymodule'),
  'type' => MENU_NORMAL_ITEM,
  );
}

```

This will be less code and quick.
> 2 votes

# Answer
If you do something like this inside your module\_menu() hook/function...

```
$items['tests/%'] = array(
  'title' => 'Test',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('mymodule_test'),
  'access arguments' => array('administer mymodule'),
  'type' => MENU_NORMAL_ITEM,
);

```

...paths such as `tests/foo`, `tests/bar`, `tests/baz` will all work and should call your form identically.

In fact, in your current implementation, calling `test-1/foo` will work, as will `test-1/bar` and `test-/baz` because drupal will try to be smart and call the best menu callback it can when it finds a partial match (for no better explanation).

Check out http://api.drupal.org/api/drupal/includes!menu.inc/group/menu/6 for all the nitty gritty.

But do note that in these simple implementations, any text will work after `tests/` or `test-1` so if you need to be more restrictive, that will require a lot more programming effort and without knowing where your users are getting these keywords and how they are stored in your module, that's a whole 'nother set of questions and answers.
> 2 votes

---
Tags: 6, uri
---


# Question
Title: Views 3 (D7) Attaching custom markup to individual view results
Ok so a bit of background first on why I want to do this, this may also spark someone to suggest a better way of doing this also. I'm always open to ideas!

Basically I have a bunch of content types, call them rooms for the moment. I am using views to sort/search these rooms, works great (as expected with views).

Now what I want is to attach some php and an jquery script to each view result itself, this script will get an ID from a field attached to the view result, this will then be sent as an ajax request get some information and then come back with some results which will then be printed underneath the view result.

How do I go about doing this? I've taken a look at a few of the different hooks available for the views api but can't really figure out which one is the one I want.

Any suggestions are greatly appreciated. Dan

# Answer
Try `hook_views_pre_render()` see docs and `drupal_add_js()`.

1. Add the correct JS using `drupal_add_js` by injecting the JS file using `hook_views_pre_render()` to fire on the correct view.
2. Your JS will have to understand the default views output to re-theme / alter HTML output accordingly. Firebug or Chrome Developer tools can help you with that.
3. you can use `$view->attachment_after` to attach like a custom blob of HTML like `<div id="mycustom_content"></div>` so you can muck with this div on your Ajax callback. You can add the view attachment in the `view_pre_render`
> 1 votes

---
Tags: 7, views
---


# Question
Title: webform + webform_entity gives empty view results :(
I am using Webform \+ Webform\_Entity to show webform results as node content used in Views on certain pages.

Here is a screenshot of 1 webform\_entity form. The form collects 2 taxonomy terms (from the same Taxonomy which happen to be parent+child) and some random textual questions.

Here is a View config that takes the 2 taxonomy terms and looks for answers to this form to show.

```
$view = new view();
$view->name = 'student_reviews';
$view->description = '';
$view->tag = 'eap';
$view->base_table = 'node';
$view->human_name = 'Student Reviews';
$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'] = 'Student Reviews';
$handler->display->display_options['use_more_always'] = FALSE;
$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'] = 'none';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Header: Global: Text area */
$handler->display->display_options['header']['area']['id'] = 'area';
$handler->display->display_options['header']['area']['table'] = 'views';
$handler->display->display_options['header']['area']['field'] = 'area';
$handler->display->display_options['header']['area']['label'] = 'Category CtoolsJumpMenu';
$handler->display->display_options['header']['area']['empty'] = TRUE;
$handler->display->display_options['header']['area']['format'] = 'full_html';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['content'] = 'No feedback found.';
$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
/* Relationship: Content: Webform submission */
$handler->display->display_options['relationships']['webform_submission']['id'] = 'webform_submission';
$handler->display->display_options['relationships']['webform_submission']['table'] = 'node';
$handler->display->display_options['relationships']['webform_submission']['field'] = 'webform_submission';
$handler->display->display_options['relationships']['webform_submission']['required'] = TRUE;
/* Field: Webform Submission: Did you open a local bank account?  Was it easy? */
$handler->display->display_options['fields']['field_eap_feedback051']['id'] = 'field_eap_feedback051';
$handler->display->display_options['fields']['field_eap_feedback051']['table'] = 'field_data_field_eap_feedback051';
$handler->display->display_options['fields']['field_eap_feedback051']['field'] = 'field_eap_feedback051';
$handler->display->display_options['fields']['field_eap_feedback051']['relationship'] = 'webform_submission';
/* Field: Webform Submission: If you did not open a local bank account, was it easy to withdraw money from the ATM?  Which banks were popular & had low ATM fe */
$handler->display->display_options['fields']['field_eap_feedback052']['id'] = 'field_eap_feedback052';
$handler->display->display_options['fields']['field_eap_feedback052']['table'] = 'field_data_field_eap_feedback052';
$handler->display->display_options['fields']['field_eap_feedback052']['field'] = 'field_eap_feedback052';
$handler->display->display_options['fields']['field_eap_feedback052']['relationship'] = 'webform_submission';
/* Field: Webform Submission: Were credit cards widely accepted? */
$handler->display->display_options['fields']['field_eap_feedback050']['id'] = 'field_eap_feedback050';
$handler->display->display_options['fields']['field_eap_feedback050']['table'] = 'field_data_field_eap_feedback050';
$handler->display->display_options['fields']['field_eap_feedback050']['field'] = 'field_eap_feedback050';
$handler->display->display_options['fields']['field_eap_feedback050']['relationship'] = 'webform_submission';
/* Field: Webform Submission: Were there ATMs on campus? */
$handler->display->display_options['fields']['field_eap_feedback053']['id'] = 'field_eap_feedback053';
$handler->display->display_options['fields']['field_eap_feedback053']['table'] = 'field_data_field_eap_feedback053';
$handler->display->display_options['fields']['field_eap_feedback053']['field'] = 'field_eap_feedback053';
$handler->display->display_options['fields']['field_eap_feedback053']['relationship'] = 'webform_submission';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Field: Survey Country (field_survey_country) */
$handler->display->display_options['arguments']['field_survey_country_tid']['id'] = 'field_survey_country_tid';
$handler->display->display_options['arguments']['field_survey_country_tid']['table'] = 'field_data_field_survey_country';
$handler->display->display_options['arguments']['field_survey_country_tid']['field'] = 'field_survey_country_tid';
$handler->display->display_options['arguments']['field_survey_country_tid']['relationship'] = 'webform_submission';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_survey_country_tid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_survey_country_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['vocabularies'] = array(
  'eap_program_list' => 'eap_program_list',
);
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['type'] = 'convert';
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['transform'] = TRUE;
/* Contextual filter: Webform Submission: Survey Program (field_survey_program) */
$handler->display->display_options['arguments']['field_survey_program_tid']['id'] = 'field_survey_program_tid';
$handler->display->display_options['arguments']['field_survey_program_tid']['table'] = 'field_data_field_survey_program';
$handler->display->display_options['arguments']['field_survey_program_tid']['field'] = 'field_survey_program_tid';
$handler->display->display_options['arguments']['field_survey_program_tid']['relationship'] = 'webform_submission';
$handler->display->display_options['arguments']['field_survey_program_tid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['field_survey_program_tid']['breadcrumb_enable'] = TRUE;
$handler->display->display_options['arguments']['field_survey_program_tid']['breadcrumb'] = 'Student Reviews for %1 - %2 on %3';
$handler->display->display_options['arguments']['field_survey_program_tid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['field_survey_program_tid']['default_argument_options']['index'] = '3';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_survey_program_tid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_survey_program_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['vocabularies'] = array(
  'eap_program_list' => 'eap_program_list',
);
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['type'] = 'convert';
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['transform'] = TRUE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* 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(
  'eap_responses_banking_' => 'eap_responses_banking_',
);

/* Display: Page: Banking */
$handler = $view->new_display('page', 'Page: Banking', 'page');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Student Reviews';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Field: Survey Country (field_survey_country) */
$handler->display->display_options['arguments']['field_survey_country_tid']['id'] = 'field_survey_country_tid';
$handler->display->display_options['arguments']['field_survey_country_tid']['table'] = 'field_data_field_survey_country';
$handler->display->display_options['arguments']['field_survey_country_tid']['field'] = 'field_survey_country_tid';
$handler->display->display_options['arguments']['field_survey_country_tid']['relationship'] = 'webform_submission';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['field_survey_country_tid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_survey_country_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_survey_country_tid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_survey_country_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['vocabularies'] = array(
  'eap_program_list' => 'eap_program_list',
);
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['type'] = 'convert';
$handler->display->display_options['arguments']['field_survey_country_tid']['validate_options']['transform'] = TRUE;
/* Contextual filter: Webform Submission: Survey Program (field_survey_program) */
$handler->display->display_options['arguments']['field_survey_program_tid']['id'] = 'field_survey_program_tid';
$handler->display->display_options['arguments']['field_survey_program_tid']['table'] = 'field_data_field_survey_program';
$handler->display->display_options['arguments']['field_survey_program_tid']['field'] = 'field_survey_program_tid';
$handler->display->display_options['arguments']['field_survey_program_tid']['relationship'] = 'webform_submission';
$handler->display->display_options['arguments']['field_survey_program_tid']['breadcrumb_enable'] = TRUE;
$handler->display->display_options['arguments']['field_survey_program_tid']['breadcrumb'] = 'Student Reviews for %1 - %2 on %3';
$handler->display->display_options['arguments']['field_survey_program_tid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['field_survey_program_tid']['default_argument_options']['index'] = '3';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_survey_program_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_survey_program_tid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_survey_program_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['vocabularies'] = array(
  'eap_program_list' => 'eap_program_list',
);
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['type'] = 'convert';
$handler->display->display_options['arguments']['field_survey_program_tid']['validate_options']['transform'] = TRUE;
$handler->display->display_options['path'] = 'student-views/%/%/reviews/banking';

```

This is a sample of the view query that is run.

```
SELECT webform_submissions_node.sid AS webform_submissions_node_sid, node.created AS node_created, 'webform_submission_entity' AS field_data_field_eap_feedback051_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback052_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback050_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback053_webform_submission_entity_e, 'student_reviews:page' AS view_name
FROM
{node} node
INNER JOIN {webform_submissions} webform_submissions_node ON node.nid = webform_submissions_node.nid
LEFT JOIN {field_data_field_survey_country} webform_submissions_node__field_data_field_survey_country ON webform_submissions_node.sid = webform_submissions_node__field_data_field_survey_country.entity_id AND (webform_submissions_node__field_data_field_survey_country.entity_type = 'webform_submission_entity' AND webform_submissions_node__field_data_field_survey_country.deleted = '0')
LEFT JOIN {field_data_field_survey_program} webform_submissions_node__field_data_field_survey_program ON webform_submissions_node.sid = webform_submissions_node__field_data_field_survey_program.entity_id AND (webform_submissions_node__field_data_field_survey_program.entity_type = 'webform_submission_entity' AND webform_submissions_node__field_data_field_survey_program.deleted = '0')
WHERE (( (webform_submissions_node__field_data_field_survey_country.field_survey_country_tid = '25' ) AND (webform_submissions_node__field_data_field_survey_program.field_survey_program_tid = '26' ) )AND(( (node.status = '1') AND (node.type IN  ('eap_responses_banking_')) )))
ORDER BY node_created DESC

```
* Some of these content types and fields end with a `_`, this is because when I made the item the title had punctuation in it and Drupal converts that an underscore. I dont believe it's necessarily breaking anything.

If I install these 2 modules on a clean D7 site with a similar setup I get results in my view. On the live site I get 0 results in the view always. But, webform\_entity is clearly collecting results properly and saving entries.

```
mysql> select * from `field_data_field_eap_feedback051`;
+---------------------------+------------------------+---------+-----------+-------------+----------+-------+-----------------------------+------------------------------+
| entity_type               | bundle                 | deleted | entity_id | revision_id | language | delta | field_eap_feedback051_value | field_eap_feedback051_format |
+---------------------------+------------------------+---------+-----------+-------------+----------+-------+-----------------------------+------------------------------+
| webform_submission_entity | eap_responses_banking_ |       0 |         1 |           1 | und      |     0 | test 2                      | NULL                         |
| webform_submission_entity | eap_responses_banking_ |       0 |         2 |           2 | und      |     0 | asdfasdf                    | NULL                         |
| webform_submission_entity | eap_responses_banking_ |       0 |      1255 |        1255 | und      |     0 | test botswana banking       | NULL                         |
+---------------------------+------------------------+---------+-----------+-------------+----------+-------+-----------------------------+------------------------------+

```

It appears as though the View is broken. I see the TIDs in the View ok, I see some magic Views placeholders `'webform_submission_entity' AS field_data_field_eap_feedback053_webform_submission_entity_e` which I understand are views placeholders ... but I *guess* aren't being processed correctly for some reason.

Can anyone help me to debug this to see my results. How do I test for conflicting modules? What can I do? .... the View runs -- but i get no results, but I should.

**EDIT 01/22/2013 14:17**

I'm specifically asking about the Reviews select list and the View page that it jumps to.

# Answer
Solution found! By myself ... The webform\_entity parent base node was created in code. Somehow the `author` field was `anonymous` on save for all 12 of my webform\_entity nodes.

Nodes with `anonymous` author dont show Views results from the following query (from Views debugging), ***EVER*** on related form submissions (using a View relation):

```
SELECT webform_submissions_node.sid AS webform_submissions_node_sid, node.created AS node_created, 'webform_submission_entity' AS field_data_field_eap_feedback051_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback052_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback050_webform_submission_entity_e, 'webform_submission_entity' AS field_data_field_eap_feedback053_webform_submission_entity_e
FROM
{node} node
INNER JOIN {webform_submissions} webform_submissions_node ON node.nid = webform_submissions_node.nid
LEFT JOIN {field_data_field_survey_country} webform_submissions_node__field_data_field_survey_country ON webform_submissions_node.sid = webform_submissions_node__field_data_field_survey_country.entity_id AND (webform_submissions_node__field_data_field_survey_country.entity_type = 'webform_submission_entity' AND webform_submissions_node__field_data_field_survey_country.deleted = '0')
LEFT JOIN {field_data_field_survey_program} webform_submissions_node__field_data_field_survey_program ON webform_submissions_node.sid = webform_submissions_node__field_data_field_survey_program.entity_id AND (webform_submissions_node__field_data_field_survey_program.entity_type = 'webform_submission_entity' AND webform_submissions_node__field_data_field_survey_program.deleted = '0')
WHERE (( (webform_submissions_node__field_data_field_survey_country.field_survey_country_tid = '25' ) AND (webform_submissions_node__field_data_field_survey_program.field_survey_program_tid = '26' ) )AND(( (node.status = '1') AND (node.type IN  ('eap_responses_banking_')) )))
ORDER BY node_created DESC

```

even though I'm only looking at `node.published = 1` and nothing regarding the author field.

I feel this is a bug somewhere in webform or webform\_entity.
> 0 votes

---
Tags: 7, views, webforms, debugging
---


title: Modules and namespaces

text:
# Question
Title: Modules and namespaces
I have strange problem or maybe I'm doing something wrong. I've create my own module. My .info file looks like this:

```
...
files[] = DdFactory.inc
files[] = ArticleManager.inc
...

```

In `ArticleManager.inc` I have class ArticleManager (no namespace). Than I would like to use DFactory (namespace Dd) class in ArticleManager.

Here is the beginning of DFactory.inc:

```
<?php

namespace Dd;

class Factory
{
...

```

In ArticleManger I have:

```
$ob = new \Dd\Factory();

```

And error:

```
Fatal error:  Class 'Dd\Factory' not found

```

I can make it work in two ways. Or I have to remove namespaces than `$ob = new Factory();` or I have to add `include 'DFactory.inc'` at top of ArticleManager.inc

Could somebody tells me how to run it with namespaces and without the include? I'm using drupal 7.

# Answer
> 3 votes
Try the xautoload (http://drupal.org/project/xautoload) module to help with autoloading. It's faster and less fragile then the D7 core code registry.

XAutoload implements the PSR-0 standard, which is how Drupal 8 will handle namespaces, so it's the most future proof way.

# Answer
> 1 votes
The code registry does not support namespaces, so far. I tried adding the following code to the classes.php a module of mine declares in its .info file.

```
class codetesting {
  protected $file;
}

namespace code;

class testing {
  protected $file;
}

```

Looking at the "registry" table, I noticed the namespace is not used. This means that when I try to create an instance of `\code\testing`, Drupal does not find the file containing its definition, as the registry contains information for the `testing` class.

What you can do is altering the registry table to include the namespace in the "name" column.

---
Tags: 7
---


# Question
Title: Let users download and set induvidual blog themes Drupal 7
I want to enable users customize their own blog appearance and theme the same way it is being done in multi-user blogging sites such as wordpress.com, tumblr.com, typepad.com, etc.

1. Users can set a theme to their blog
2. Users can manage some settings regarding ther blog appearance (background color, fonts, etc.)
3. Users can download themes or even make their own themes available for others.
4. The theme setting only affects the user blog page (but not the general site layout).

Any possible suggestions to make part of those requirements implemented quickly?

# Answer
> 0 votes
Letting them download and put up whatever theme that they want sounds like it might be a major security issue for your site, since they could put whatever PHP that they want into the theme files and it would run. I'd suggest making a specific set of themes you have picked available and letting users choose from those. There are modules like Theme key to enable using different themes: http://drupal.org/project/themekey

---
Tags: 7, users, theming
---


# Question
Title: Custom coded view not showing up under structures/admin/views
I have created a table 'Challenge'. It stores node id of some particular nodes along with the user who clicked a submit button on that page. I have written a custom form for that and insert query which works fine as i can check from my phpMyadmin. Now i want to create a view to display the user their challenges. That view should have the challenge name(in essence the node title), the challenge body in trimmed format(in essence the node body), the challenge picture(in essence the challenge picture). The 'Challenge' table has challenge id,cid (which is node-\>id), challenge title,ctitle (which is node-\>title), and the user id,uid. This insertion is happening as required. The view creation is the problem. I tried to do so with the views ui but was not able to do so. Hence i tried to custom code it. I write a custom module and it installs but when i go under structure/admin/view i do not see it. My use case is that the user should be able to see the challenges he took (nodes on which he clicked the accept button).

Here's my code

customv.info

```
name = Custom View
description = A custom view to display users and their challenges
core = 7.x

```

customv.module

```
<?php

function customv_help($path, $arg) {
  switch ($path) {
    case "admin/help#customv":
      return '<p>' . t("View for user and challenge") . '</p>';
      break;
  }
}

/**
 * Implements hook_views_api().
 */

function customv_views_api() {
  return array(
    'api' => '3.0',
    'path' => drupal_get_path('module', 'customv'),
  );
}

/**
 * Implements hook_views_default_views().
 */
function customv_views_default_views() {
  return customv_get_chal();
}

function customv_get_chal() {
    $view = new view();
    $view->name = 'user_chal';
    $view->description = 'A custom view to display users and their challenges';
    $view->tag = 'default';
    $view->base_table = 'challenges';
    $view->human_name = 'User Challenges';
    $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'] = 'User Challenges';
    $handler->display->display_options['use_more_always'] = FALSE;
    $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'] = '10';
    $handler->display->display_options['style_plugin'] = 'grid';
    $handler->display->display_options['style_options']['columns'] = '5';
    $handler->display->display_options['row_plugin'] = 'fields';

    /*
     *Field: Content: Title
     */

    $handler->display->display_options['fields']['title']['id'] = 'ctitle';
    $handler->display->display_options['fields']['title']['table'] = 'challenges';
    $handler->display->display_options['fields']['title']['field'] = 'ctitle';
    $handler->display->display_options['fields']['title']['label'] = '';
    $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
    $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;

    /*
    Field: Content: Body
    */

    $handler->display->display_options['fields']['body']['id'] = 'body';
    $handler->display->display_options['fields']['body']['table'] = 'field_data_body';
    $handler->display->display_options['fields']['body']['field'] = 'body';
    $handler->display->display_options['fields']['body']['label'] = '';
    $handler->display->display_options['fields']['body']['element_label_colon'] = FALSE;
    $handler->display->display_options['fields']['body']['type'] = 'text_summary_or_trimmed';
    $handler->display->display_options['fields']['body']['settings'] = array(
      'trim_length' => '200',
    );

    /*
     *Field: Content: blog_pic
     */

    $handler->display->display_options['fields']['field_blog_pic']['id'] = 'field_challenge_pic';
    $handler->display->display_options['fields']['field_blog_pic']['table'] = 'field_data_field_challenge_pic';
    $handler->display->display_options['fields']['field_blog_pic']['field'] = 'field_challenge_pic';
    $handler->display->display_options['fields']['field_blog_pic']['label'] = '';
    $handler->display->display_options['fields']['field_blog_pic']['element_label_colon'] = FALSE;
    $handler->display->display_options['fields']['field_blog_pic']['click_sort_column'] = 'fid';
    $handler->display->display_options['fields']['field_blog_pic']['settings'] = array(
      'image_style' => '',
      'image_link' => 'content',
    );
    $handler->display->display_options['fields']['field_challenge_pic']['delta_offset'] = '0';

    /*
     *Contextual filter: Content: Author uid
     */

    $handler->display->display_options['arguments']['uid']['id'] = 'uid';
    $handler->display->display_options['arguments']['uid']['table'] = 'challenges';
    $handler->display->display_options['arguments']['uid']['field'] = 'uid';
    $handler->display->display_options['arguments']['uid']['default_action'] = 'default';
    $handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
    $handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
    $handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
    $handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';

    /*
     *Display: Block
     */

    $handler = $view->new_display('block', 'Block', 'block_1');
    $handler->display->display_options['defaults']['hide_admin_links'] = FALSE;

}

```

SO what am i doing wrong here???

Thanks for your time because its a long question to read...sorry for that...would really appreciate some help...and yes i used view exporter to import code from an already created view (show content created by the logged in user only) and tweaked the code

# Answer
Your `customv_get_chal()` function doesn't return any value. As consequence of this, your hook is not returning any view to the Views module.

The correct code should be the following one.

```
function customv_get_chal() {
  $views = array();

  // The rest of your code

  $views['user_chal'] = $view;

  return $views;
}

```
> 1 votes

---
Tags: 7, views
---


# Question
Title: Is there a way to hide the Apply button on an Exposed Contextual Filter?
I'm using an Exposed Contextual Filter in a view. It's working nicely; however for aesthetics, we'd like to remove the Apply button and have the view change when the pull down does. How might I accomplish this?

## Follow up:

Thanks to both of you Lance and agargy below. Yes, hide the Apply button by checking 'Hide submit button'.

# Answer
> 6 votes
This is a standard feature. Go to the "Exposed Form" settings on your view and click "Settings" next to "Exposed form styles". I don't remember the correct name of the option but i think you get it when you're there.

---
Tags: views
---


title: Custom Page inside Module

text:
# Question
Title: Custom Page inside Module
I'm trying to embed custom content (custom javascript, paragraphs etc) with a Drupal Form. I'm wondering whats the best way to do it in module?

Something like this:

```
function wow_page() {
    drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
    $output = 'teasdasdst';
    $output = '<div id="test"></div>';
    $output .= drupal_get_form('wow_cake');
    return array('#markup' => $output);
}

```

# Answer
ok add hook\_menu that call this function

if you have module called wow

```
function wow_menu() {
  $items = array();
  $items['home'] = array(
    'title' => '',
    'page callback' => 'wow_page',
    'access callback' => TRUE,
  );
  return $items;
}

```
> 0 votes

---
Tags: 7, hooks
---


# Question
Title: Recording the time it takes to process a form
I have created a form that has a submission button on it. Is it possible to record the time that the submit button is pressed and then, once the form has run, display how long it took to process on the page?

# Answer
> 0 votes
I use HttpWatch to monitor load times:

http://blog.httpwatch.com/2008/05/14/using-httpwatch-to-measure-page-load-times-for-new-and-existing-users/

You should be able to get the numbers you want with the free version.

---
Tags: 7, forms
---


title: Omega theme sidebar padding

text:
# Question
Title: Omega theme sidebar padding
I've started using the Omega theme, and wanted to apply a vertical gap in between my blocks in the sidebar on the right called sidebar-second. I went into the themes settings, and added an additioanl css in "Additional region classes" but its applied it the whole of the sidebar, and I still have no gaps. I have tried inspecting in firebug, and if I amend 'region-inner' it works but applies to all regions including main content etc. I just wanted the ones in the Sidebar Second. I'm afraid I dont know enough css to - can someone point me in the right direction?

# Answer
> 0 votes
I have fixed this now by adding:-

`.region-sidebar-second .block-inner {
 background-color: white;
 border: 1px solid #CCCCCC;
 border-radius: 10px 10px 10px 10px;
 padding: 10px 20px 20px;
 position: relative;
 margin-bottom: 20px;
}`

Sorry, it was a lack of knowledge of css causing the problem.

---
Tags: theming
---


# Question
Title: Views - List of content that user (ID from URL) voted on
I want to make a list on every profile page of content that the user voted on.

I've yet only managed to show the current logged in user's votes, not the user from the profile page.

In other words, I need to pass the User ID from Contextual filters to the Filter criteria with VotingAPI.

I tried with the filter `Votes: User`, but I wasn't able to set `Is one of: %` as the username, which would've solved my problem.

# Answer
> 1 votes
Contextual filters by definition should already filter your result set on the field for an entity you choose based on the value of the URL.

Set up the contextual filter to filter on `Votes: User` and make sure you have no other filters or relationships that restrict your result for the logged in user.

---
Tags: 7, views, rating
---


# Question
Title: Why this print statement won´t print all the terms inside a specific taxonomy associated with a given node? (D7)
I´ve tried in my Drupal 7 site with this:

```
<?php print render($content['taxonomy_vocabulary_11']); ?>

```

But it doesn´t print anything at all. I´ve tried this too, and it prints out an error:

```
<?php print $node['taxonomy_vocabulary_11']; ?>

```

> The error is: Fatal error: Cannot use object of type stdClass as array in /public\_html/sites/all/themes/liga/templates/node--jornadas.tpl.php on line 30

Using Devel, I´ve get this information, and it seems that the print statement is correct:

```
... (Array, 16 elements)
taxonomy_vocabulary_6 (Array, 16 elements)
taxonomy_vocabulary_7 (Array, 16 elements)
taxonomy_vocabulary_11 (Array, 17 elements)
#theme (String, 5 characters ) field
#weight (String, 2 characters ) 10
#title (String, 4 characters ) tags
#access (Boolean) TRUE
#label_display (String, 6 characters ) hidden
#view_mode (String, 4 characters ) full
#language (String, 3 characters ) und
#field_name (String, 22 characters ) taxonomy_vocabulary_11
#field_type (String, 23 characters ) taxonomy_term_reference
#field_translatable (String, 1 characters ) 0
#entity_type (String, 4 characters ) node
#bundle (String, 19 characters ) jornadas_realizadas
#object (Object) stdClass
#items (Array, 2 elements)
#formatter (String, 28 characters ) taxonomy_term_reference_link
0 (Array, 4 elements)
#type (String, 4 characters ) link | (Callback) link();
#title (String, 8 characters ) colegios
#href (String, 17 characters ) taxonomy/term/262
#options (Array, 2 elements)
1 (Array, 4 elements)
#type (String, 4 characters ) link | (Callback) link();
#title (String, 30 characters ) derecho
#href (String, 17 characters ) taxonomy/term/543
#options (Array, 2 elements)

```

So, the print statement should show **colegios** and **derecho**, am I right?

What´s wrong with it?

## **UPDATE**

This is the output I get with `dpm($node);`

```
(object) array(
  'vid' => '5178',
  'uid' => '1',
  'title' => 'PROYECTO',
  'log' => '',
  'status' => '1',
  'comment' => '2',
  'promote' => '0',
  'sticky' => '0',
  'nid' => '155',
  'type' => 'jornadas',
  'language' => 'und',
  'created' => '1095048000',
  'changed' => '1360589684',
  'tnid' => '0',
  'translate' => '0',
  'revision_timestamp' => '1360589684',
  'revision_uid' => '1',
  'taxonomy_vocabulary_4' => array(),
  'taxonomy_vocabulary_6' => array(
    'und' => array(
      array(
        'tid' => '33',
        'taxonomy_term' => (object) array(
            'tid' => '33',
            'vid' => '6',
            'name' => 'Jornadas Gratuitas',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_6',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_7' => array(
    'und' => array(
      array(
        'tid' => '40',
        'taxonomy_term' => (object) array(
            'tid' => '40',
            'vid' => '7',
            'name' => 'Para PH',
            'description' => '',
            'format' => NULL,
            'weight' => '-10',
            'vocabulary_machine_name' => 'vocabulary_7',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_11' => array(
    'und' => array(
      array(
        'tid' => '262',
        'taxonomy_term' => (object) array(
            'tid' => '262',
            'vid' => '11',
            'name' => 'colegios',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
      array(
        'tid' => '543',
        'taxonomy_term' => (object) array(
            'tid' => '543',
            'vid' => '11',
            'name' => 'derecho',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
    ),
  ),
  'body' => array(
    'und' => array(
      array(
        'value' => "

```

...

# Answer
> 1 votes
prior to your comment you should use foreach it would be sth like this:"

```
<?php foreach ($content->taxonomy_vocabulary_11 as $key => $value): $terms = $value['#title']; ?>
    <span class="all-terms"><?php print ucwords($terms); ?></span>
 <?php endforeach?>

```

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


# Question
Title: Make phone field required if certain shipping method is selected
I use drupal 6 and ubercart 2. My aim is to make phone field in delivery address required if certain shipping method is selected. I have set up a jquery script that shows a message to the user saying that phone is needed after customer selects the shipping method. Despite of this, some customers don't fill out the phone field. I would like to add a non js check after submission of checkout page. I suppose I would need to write a small module. A need help with the start of the code

```
<?php
IF
{[mymethod] = true}
then {
  $form['panes']['delivery']['delivery_phone']['#required'] = true;
}
?>

```

Thank you very much.

EDIT: according to @Adam Balsam answer I tried to make custom module This is uc\_checkout\_phone.module

```
<?php
function uc_checkout_phone_uc_cart_checkout_form_alter(&$form, &$form_state) {
  $form['panes']['delivery']['delivery_phone']['#element_validate'] = array('uc_checkout_phone_phone_validate');
}
function uc_checkout_phone_phone_validate($element, &$form_state) {
  if (($form_state['panes']['shipping']['shipping_method']['#value'] == 'Doprava - kurier DPD') && ($element['#value'] == '')) {
   form_error($element, t('You must enter a phone number if you select XXX as a shipping method.'));
 dpm($form_state); }
}
?>

```

This is uc\_checkout\_phone.info

```
name = uc_checkout_phone
description = phone required
core = 6.x

```

The form id should be uc-cart-checkout-form. I had to write it using underscores. The shipping method is Doprava - kuriér DPD, I tried also the value which is flatrate\_3---0 but I get no warning message if I let the phone number empty. Where can be the problem? I named themodule: uc\_checkout\_phone

# Answer
You will have two functions in your custom module. The first one is hook\_form\_FORM\_ID\_alter:

```
/**
 * This function adds an additional custom validation function to the delivery phone field
 *
 * Make sure you update MYMODULE and YOURFORMID to match your circumstances.
 */
function MYMODULE_form_YOURFORMID_alter(&$form, &$form_state) {
  $form['panes']['delivery']['delivery_phone']['#element_validate'] = array('MYMODULE_phone_validate');
}

```

The second function is the custom validation function that we added using hook\_form\_FORM\_ID\_alter above:

```
/**
 * Make sure you update MYMODULE again and update the array to match your shipping method
 */
function MYMODULE_phone_validate($element, &$form_state) {
  if (($form_state['panes']['shipping']['shipping_method']['#value'] == 'THE SHIPPING METHOD') && ($element['#value'] == '')) {
    form_error($element, t('You must enter a phone number if you select XXX as a shipping method.'));
  }
}

```
> 1 votes

# Answer
Rules module is the easiest answer:

> The rules module allows site administrators to define conditionally executed actions based on occurring events (known as reactive or ECA rules). It's a replacement with more features for the trigger module in core.
> 0 votes

---
Tags: 6, ubercart
---


title: change default payment in ubercart

text:
# Question
Title: change default payment in ubercart
I have two allowed payment methods, Paypal and Credit card. When a user checks out Pay Pal is selected by default and is shown on top. How do I change the order of these with the credit card option on div on top and make the radio button for credit card, the option selected by default?

# Answer
> 0 votes
Probably with hook\_form\_alter. Change the `#weight` attribute so credit card lighter than paypal. Set the `#default` value to credit cards for the radio values.

I haven't used these modules nor have an Ecommerce site live so I cant post example code ...

***EDIT***

install Devel and implement `hook_form_alter` for your module. put `dpm($form);dpm($form_id);` in your form atler implementation ... and goto the page with the form in question. You will then see the PHP array structure for the form on the screen.

---
Tags: ubercart
---


title: Frustrating Drupal perfomance

text:
# Question
Title: Frustrating Drupal perfomance
i've started using Drupal few days ago and from the start i've noticed very slow page load, right after installation, i though it's normal and forgot for a while about this problem.
I am running Apache 2.2 and PHP 5.3 on local PC (Core2Duo 2.4, 3GB Ram) with Drupal 7.14.
I have tried using shared hosting (5% of some Xeon CPU, 256Mb Ram for PHP) - same problem, pages took ages to load, not to mention Admin pages loading for 3-5sec, sometimes - minutes. Sometimes UI and Pages are very good, sometimes it hangs for few seconds, minutes even. Always using Ctrl+R for page reload to skip caching on browser side.
Today I've installed Performance module and did the test on shared host with a little content on page and on blank installation of Drupal at local machine mentioned above.
Results on Local: http://s14.postimage.org/ij1isbh33/Drupal\_7\_Local\_default.jpg
Results on Shared: http://s11.postimage.org/asjhasu29/Drupal\_7\_shared\_content.jpg
On local - first time its default installation, second time logging disabled, caching everything, aggregation etc. Therese a phpBB3 default running on shared and local - very responsive, no hangs, page loads in a few ms.
Also, the amount of Queries, is this normal for Drupal to have 30-200 Queries?
What could be the problem with this issue?

# Answer
> 2 votes
Things to try:
http://groups.drupal.org/node/242443
http://groups.drupal.org/node/210683

But in reality we don't know until you can profile the code.
http://getmuhammad.blogspot.com/2011/08/installing-xdebug-and-webgrind-on.html

# Answer
> 0 votes
This is a known problem with MediaTemple's Grid Servers and supposedly doesn't happen with their "1 click installs" of Drupal. The issue is that Drupal's database queries are very very heavy, and their shared MySQL instance is underpowered.

Apparently the fix is to change the table type from INNODB to MyISAM for any tables who's name starts with "cache" or "variable".

# Answer
> 0 votes
Check your log, if the admin pages are taking awhile to load then it's likely a memory leak in one of the modules that are enabled.

---
Tags: performance
---


# Question
Title: how to change hierarchical taxonomy path using Pathauto
i have posted it on drupal forum also but there was no answer. Here is that:

> i am really working hard to know how i can add sub-categories in drupal 7. so i want to change the path of parent terms taxonomy path like this way:
> Category 1 - Path should be: mysite.com/category/Category 1
> \- sub category 1 - Path should be: mysite.com/category/Category 1/sub category 1
> \- sub category 2 - Path should be: mysite.com/category/Category 1/sub category 2
> Category 2 - Path should be: mysite.com/category/Category 2
> \- sub category 1 - Path should be: mysite.com/category/Category 2/sub category 1
> \- sub category 2 - Path should be: mysite.com/category/Category 2/sub category 2
> i think this can be done with URL aliases \> PATTERNS
> but as a beginner i am really confused how to do. So, some one please help as can be described.

# Answer
This pattern works for me at admin/config/search/path/patterns:

\[term:vocabulary\]/\[term:parent:parents-all\]/\[term:name\]
> 2 votes

# Answer
this work for me:

```
[term:vocabulary]/[term:parents:join-path]/[term:name]

```

this pattern generates the path: **Category-Name/Category-1/sub-category-1/Term-Name**
> 3 votes

---
Tags: path-aliases, taxonomy-terms
---


# Question
Title: site created using drush arr failing with missing index.php
I am using drush archive to copy a live site to a test environment. The test environment is on my local machine, the live site is on a hosted platform.

The arr command seems to complete successfully and the new database config is correctly appended to settings.php, the files are all restored to the appropriate directory on my local machine and the database is created and populated. So far, so good.

If I navigate to the default page `http://localhost/~drew/site2`, the home page is displayed, but it is clear that the CSS is from my theme is not available - I think that this is because the CSS was compressed and cached on the live site, so I can probably ignore that for now. If however, I try and navigate to any other page, I get an HTTP 404 saying `localhost://~drew/site2/index.php not found` yet when I check the filesystem, it's definitely there, and the web server can clearly see it because it created the home page earlier when I navigated to the default page.

I do use pathauto and have set explicit path names for my pages on the live site - could this be broken in some way when restored?

Thanks

# Answer
I think you problem is likely that you need to set the RewriteBase in the .htaccess file. Edit your .htaccess, find the line that looks like

```
# RewriteBase /

```

And add a line under it that reads

```
RewriteBase /~drew/site2

```

then clear Drupal caches, and try your site.
> 0 votes

---
Tags: drush
---


# Question
Title: How to import nodes with entity reference field through feeds?
At the moment i have 2 content types. The first (Target Communities) is a kind of category listing. These nodes already exist.

The second (Areas, many more nodes) shall be created from a csv import.

The Areas content type has a entity reference field set to the Target Community content type.

I assumed that i just attach the Target Community titles to the Area in the csv, but after import and node creation, the reference field is still empty.

Then i tried the import with the Target Community node id instead of the title, but this doesn't work eather, the entity refernce field in the created nodes remain empty.

So now, I'm quite clueless about what else to try or what other settings I may have missed.

The feed mapping is correct, all other fields work, including term references etc.

# Answer
> 1 votes
Take a look at this answer:

https://drupal.stackexchange.com/a/22043/4134

At the moment there is a very active thread on d.o about adding this functionality.

# Answer
> 0 votes
Try following this thread: How to map Feed Importer with my content type?

Which points here: http://www.zivtech.com/blog/feed-feeds-importing-referenced-rss-data#comment-1378

Very nice tutorial...very simple custom module required.

---
Tags: 7, feeds, entities, importing-exporting
---


# Question
Title: How to apply patch file to views module in Drupal 7
I have problem with my views module. In some occasions it displays this deterrent warning:

**Notice: Undefined property: views\_handler\_field\_field::$original\_value in views\_handler\_field-\>render\_text() (line 1118 of C:\wamp\www\novine\sites\all\modules\views\handlers\views\_handler\_field.inc).**

I think I found the patch that could work and save me from this buggy thing. My problem is how to apply downloaded patch to views module. I placed patch file in views folder, cached site, and nothing happened. That was obviously naive try. Can someone help me and tell all applying patch procedure? Thanks in advance!

# Answer
If it is a standard Drupal patch, you use a program named *git* (part of ambience in most Gnu/Linux configurations) to apply it. The correct procedure is to first clone the newest released version of the project, apply the patch, then install the patched version in the views folder. If the patch file is named `views-bugfix.patch` you download it, and then:

```
git clone --recursive --branch 7.x-3.x http://git.drupal.org/project/views.git
git apply -v views-bugfix.patch

```

In some cases, the patch is not for the released branch, but some other branch (this will be mentioned along with the patch). In that case you need to clone this branch instead.

Source for this info.

If you're stuck in a Microsoft environment and don't have *git* here is something that may help you: Patching in Windows (haven't tested this myself - I don't do windows.)
> 2 votes

---
Tags: views
---


# Question
Title: Undefined property: FieldCollectionItemEntity::
> Notice: Undefined property: FieldCollectionItemEntity::$field\_wa\_thick in \_get\_details() (line 385 of ...../er.module).
>
> Warning: array\_key\_exists() expects parameter 2 to be array, null given in \_get\_details()

The error is on the following line:

```
$wt = ((array_key_exists('und',$li[$li_id]->field_wa_thick))?$li[$li_id]->field_wa_thick['und'][0]['value'] : NULL );

```

What may be the reason for the following error above??

# Answer
By allowing only if the value is set the error disappeared.

```
if (isset($li[$li_id]->field_wa_thick['und']) {
  $wt = $li[$li_id]->field_wa_thick['und'][0]['value'];
}

```

Also applying the isset if the value is used elsewhere.
> 0 votes

---
Tags: 7
---


# Question
Title: Views - "Add no results behavior" not doing what I would like it to
I've selected a "Add no results behavior" option for my Views page which consists of a search form. The problem with the "Add no results behavior" feature is that it displays by default, even before I've attempted to do a search. How do I change this so that it only displays AFTER the user has attempted to do a search (for which there are no results)?

# Answer
Assuming you're using Views 3, on the Views config page under `Exposed form`, change `Exposed form style` from `Basic` to `Input required`. Optionally change the other related settings on this page. Apply the settings and save the View and it should be ok.
> 4 votes

---
Tags: views
---


title: Print module on a Views page?

text:
# Question
Title: Print module on a Views page?
Is it possible to have a print/pdf link (using the print module) displayed on a views page?

I've got it displaying in a basic page type, but view is not a content type, so how do I select the option?

# Answer
For Drupal 7 go to *admin/config/user-interface/print*, and add that page's (page created by view) path to the the list of system (non-content) pages in the Advanced Link Options tab.

This will show the link on that page. For Drupal 6 the path is *admin/settings/print*.
> 3 votes

---
Tags: 7, views
---


# Question
Title: Displaying the Drupal administration interface in the main content area
How would I go about displaying the Drupal administration interface in the main content area, instead of it taking up the whole page when the overlay module is disabled...

# Answer
If I understand you correctly you are using the Drupal core *Seven* theme as the administration theme, and you would like to use the active theme instead.

You can change this by going to `Appearance`. At the bottom of that page you have a select for `Administration theme`. Choose `Default theme` to use your site's active theme as the admin theme.
> 1 votes

---
Tags: 7
---


# Question
Title: Taking check box option and turn into select list
I want to take the value of multiple checkbox options while creating node and then when viewing the node, I want these values which were selected in a multiple checkbox to be in a select list.

Any idea how to implement this?

# Answer
> 1 votes
you could do that in your module, try to implement hook\_node\_view and get the values of the node variable, and then do your changes.

Im pretty sure you dont want to save those values from the select list, just show it in an another matter, no?

---
Tags: forms
---


# Question
Title: How do I apply different css files to different viewports with Omega subthemes?
I´m working with an Omega 3.x Subtheme in Drupal 7. I´ve been reading the handbook of Omega, specially about the layered css files.

Even if I do understand that the layer structure of the default responsive css files is (from bottom to top): global → default → narrow → normal → wide, I can´t mach that to the Grid Settings UI, and **I just can´t understand how "default" css file works, and for what layout**.

These are the css files that I´ve got:

> global.css = global
>
> yoursubthemename-alpha-default.css = default
>
> yoursubthemename-alpha-default-narrow.css = narrow
>
> yoursubthemename-alpha-default-normal.css = normal
>
> yoursubthemename-alpha-default-wide.css = wide

And these are the different default layout settings at the UI (/admin/appearance/settings/mytheme):

1. **Narrow** Layout (weight 1) --\> media query: all and (min-width: 740px) and (min-device-width: 740px), (max-device-width: 800px) and (min-width: 740px) and (orientation:landscape).
2. **Normal** Layout (weight 2) --\> all and (min-width: 980px) and (min-device-width: 980px), all and (max-device-width: 1024px) and (min-width: 1024px) and (orientation:landscape).
3. **Wide** Layout (weight 3) --\> all and (min-width: 1220px).

**How about default css file?** *I´ve also noted that all mediaqueries are set: **orientation:landscape**, so how do I manage to apply different css files for portrait viewports?*

**Example:**

I´ve got a phone (480 x 320), a Nexus 7" Tablet (1280x800), a 10" netbook (1024x600) and a 19" pc monitor (1366 x 768).

I´ve customized global, normal and wide css files, applying global.css to my phone (portrait and landscape), normal.css to my laptop and wide.css to my pc monitor.

> **cellphone orientation**: portrait and landscape ---\> css global file.

Works ok. It just takes the global file.

> **tablet orientation portrait** ---\> **css ?? file**.

It takes the global file, and it looks as the pgone, but bigger. I would like another template. I´ve tried the "default" css file, but it´s not "taken".

> **tablet orientation landscape** ---\> **css ?? file**.

I´ve copied all contents of "normal" to "narrow" css files, but that won´t work, because it´s a weird narrower result, even if its a copy of the normal css file.

> **netbook orientation landscape** ---\> css normal file

It works fine, it just takes the normal css file.

> **desktop monitor orientation landscape** ---\> css wide file

It works fine, it just takes the wide css file.

So, in other words, how do you apply the css templates to tiny viewports (cellphone), smaller ones (7" tablet), small ones (10" netbook), and bigger ones (big desktop monitor and maybe tv)?

Thanks for your help!

# Answer
> 1 votes
The way I see it you've got 2 options:

Option 1: Don't use multiple style sheets. You can have conditional elements in a single CSS file using *CSS media queries* like this:

```
// Default styles
.content {max-width:960px}

// Tablet styles
@media only screen and (min-device-width: 600px) and (max-device-width: 960px), screen and (min-width: 600px) and (max-width: 960px){
  .content {max-width:600px;}
}

// Phone styles
@media only screen and (max-device-width: 600px), screen and (max-width: 600px) {
  .content {max-width:100%;}
}

```

That will even work on a desktop PC with a small window. For more info go here.

Option 2: There is a way to include those conditions in a link tag. That way you can divide up your CSS files for easy viewing. Like this:

```
< link rel="stylesheet" type="text/css" media="screen and (max-device-width: 600px)" href="mobile-view.css" />

```

You'll have to include it manually. I don't know if drupal\_add\_css will work with media property. You might have to use drupal\_add\_html\_head.

# Answer
> 0 votes
If you'd like to do it the Omega way, look into using Context as well as Delta, as it's pretty powerful with Omega.

---
Tags: 7, theming
---


# Question
Title: How to include the Title field of a content type inside of a Group?
When creating a new content, is it possible to have the field *Title* inside a *Group* defined by me?

# Answer
> 3 votes
There is only one way I'm aware of to do this. But since this solution is structural, it may not make sense to use it since the goal here is more for admin-usability.

You could use the Automatic Nodetitles module ("ANT") create a new CCK field for the title, put it in the fieldgroup that you like, and configure ANT to populate the true title field from that new custom CCK field.

# Answer
> 0 votes
Try using the Drupal 7 module Title which creates the title as a field that you can then move around in manage display.

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


title: Create a node from XML on request

text:
# Question
Title: Create a node from XML on request
Is it possible to import XML and create a node upon request?

For example, if a user clicks a link http://www.site.com/item-1, can the corresponding XML file http://www.othersite.com/path/to/item-1/doc.xml be imported as a node at that time, and the user redirected to the new node?

(The XML file is massive, with about 200 fields I need to bring in.)

# Answer
The short answer is: "yes, it is possible".

There may be different ways of approaching this, but one approach is to use some sort of URL rewriting (e.g. Apache RewriteRule) to let Drupal pick up the external xml file, and then have a custom module that picks up and parses the XML and programatically creates a node with this data stuffed into the appropriate fields and redirects the user to this node.

I've written a custom module for a client that does exactly what I describe above.
> 1 votes

---
Tags: 6, importing-exporting, migrations, feeds
---


title: How to create fake nodes

text:
# Question
Title: How to create fake nodes
I would like to know how to fake a node in Drupal. I have a table with drawings. The drawings have non unique names. For each drawing I want to be able to create a page using the unique id of the drawing:

like so: http://mysite.com/drawing/100

I don't want to create nodes for each drawing but still be able to have a theme template to show the contents of the drawing record.

How do I do that. And if this is possible how do I access the drawing number in my template page?

Thanks a lot!

# Answer
What you are asking is rather basic module development. Setting up a page that takes an argument.

Check out the Example module, and more specifically the page\_example module and `page_example_arguments()`. That contains the base of what you need.
> 0 votes

---
Tags: nodes, theming
---


title: What is the slug of mainpage?

text:
# Question
Title: What is the slug of mainpage?
I am editing blocks in /admin/structure/block - when I click "Configure" for a block, I see:

* Show block on specific pages
* All pages except those listed
* Only the listed pages
* Pages on which this PHP code returns TRUE (experts only)

I need to show the block only on the mainpage. How to do this? I don't know what is the slug for mainpage.

# Answer
If by 'mainpage' you mean the front page, the token is simply

```
<front>

```
> 2 votes

---
Tags: uri
---


title: Add user name and content to user menu

text:
# Question
Title: Add user name and content to user menu
I'm very new to drupal, I've got a basic understanding of PHP and how it should be written but I think I'm still struggling with the concept of where to add code, at what point I need to jump in to edit things and make my own style do its thing

All I want to do is change my default user menu from:

```
User Menu

 - My Account
 - Log out

```

To

```
Logged in as:
[username]

My Account

Log Out (where both buttons have mybtn class applied to them rather than in a ul)

```

I've seen I can remove the ul function from the list that is outputted with the following code

```
function MYTHEME_menu_tree__user_menu(&$variables) {
 return $variables['tree'];
}

```

And I've also tried to add the username to the content of the username with this block

```
function MYTHEME_preprocess_block(&$vars){

  global $user;
  $block =& $vars['block'];

  if ($block->module == 'system' && $block->delta == 'user-menu') {
    if (user_is_logged_in()) {
      $block->content .= check_plain($user->name);
    }
  }

}

```

(this code was modified from someone explaining how to change the subject of the block to the username)

I'd really appreciate any help with where to go next

Kind regards

# Answer
I ended up slowly working my way towards the result, my main issue was trying to get the dpm to show me what content I can change - but that's just because I'm, still slightly unfamiliar with how the whole process runs

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

function MYTHEME_menu_link__user_menu(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  $element['#localized_options']['attributes'] = array('class' => 'my-btn');

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

function MYTHEME_preprocess_block(&$variables){
  global $user;
  $block =& $variables['block'];

  if ($block->module == 'system' && $block->delta == 'user-menu') {
    if (user_is_logged_in()) {
      $variables['content'] = check_plain($user->name) . $variables['content'];
    }
  }

}

```
> 1 votes

---
Tags: routes, users, theming
---


title: Link field type displaying '&' as '&'

text:
# Question
Title: Link field type displaying '&' as '&'
When I have a Link title field populated with '&' it will be displayed as '&' when rendered.

I have done a fair share of google searching but haven't quite nailed it down.

I was thinking this was a start in the right direction https://stackoverflow.com/a/5019423

Drupal 7.19 with a zen subtheme

visual -

rendered https://i.stack.imgur.com/0cEbj.jpg

on form https://i.stack.imgur.com/VWe9X.jpg

Any hints?

# Answer
> 2 votes
Keep in mind l() passes the text through check\_plain which escapes the HTML characters for display.

So, there's no need to double escape the link with another check\_plain later.

Pass the raw text, including the single "&" through as the link text and output it as such, that way it should be fine.

# Answer
> 0 votes
Updating the Link module fixed this for me. Although I'm sure @David Thomas' answer would fix the issue as well.

---
Tags: navigation
---


title: Adding jQuery plugin to Drupal

text:
# Question
Title: Adding jQuery plugin to Drupal
Good day

I only have access to my Drupal site's admin panel, not the ftp server. Now how can I upload a jQuery plugin, for example an image slider (with the js and css files) onto the site using the admin panel? Note that the plugin is not part of the theme.

As I understand you need to add it on your theme's .info file:

```
scripts[] = js/my_jquery_plugin.js

```

BUT, is that file only accessible via ftp?

How can I do this using the admin panel?

Thank You

# Answer
I don't think you can do it that way. You can always do it quick and dirty, depending on how it's written.

If it's your own code, wrap it in the following and throw it in a block:

```
(function ($) {
    // in this function, you can use the $ which refers to the jQuery object
}(jQuery));

```

Or you can try creating a generic file content type with a file attachment, upload the .js into the public directory, then make a new block with a PHP filter and use drupal\_add\_js() and load in that file.
> 1 votes

# Answer
Ok I see that you can actually install a module right from the admin panel. Just go to modules\>Install new module and select a url file or browse from files
> 0 votes

---
Tags: nodes, javascript
---


title: Remove an item from "menu local task"

text:
# Question
Title: Remove an item from "menu local task"
I need to remove "Create new account" from the tabs on `/user` page.

I was suggested to use `hook_menu`, but:

Further: I've found that there is also `hook_menu_alter` hook. But it does not work for me also. I created the following function for testing:

```
function cleanetica_advanced_menu_alter(&$items) {
    $items['user'] = array(
       'title' => 'blogs',
       'description' => 'Listing of blogs.',
       #'page callback' => 'blog_page',
       'access arguments' => array('access content'),
       'type' => MENU_DEFAULT_LOCAL_TASK
     );
    //$items = array();
}
```

I see no changes in `/user` page after I have added this function into the module,

# Answer
If you need the registration feature and you need to just remove the link from the default tab, then use menu\_alter hook.

```
function modulename_menu_alter(&$item) {
// Hide the "Create new account" tab
$item['user/register']['type'] = MENU_CALLBACK;
}

```
> 3 votes

# Answer
> I need to remove "Create new account" from the tabs on /user page.

Sounds like you just need to disable the ability for users to create their own account.

There's a config setting at:

**Admin \> Config \> Account Settings** *"Who can register accounts" = "Administrators only"*
> 1 votes

---
Tags: routes
---


title: Query result to display in Views

text:
# Question
Title: Query result to display in Views
i have created a custom view. its just showing nodes of a particular type. Now i want to do something with it. I am writing a SQL query:

```
global $user;
$query = db_select('challenges','c');
$query->join('node','n','n.nid = c.cid');
$query->join('field_data_body','f','n.nid = f.entity_id');
$query->join('field_data_field_challenge_pic', 'fp','n.nid = fp.entity_id');
$query->join('file_managed','fm','fp.field_challenge_pic_fid = fm.fid');
$query->fields('n',array('nid','title','created'))
      ->field('f',array('f','body_value'))
      ->field('fp',array('fm','uri'))
      ->condition('c.cid','$user->uid','=');
$result = $query->execute();

```

Where should i place this query in my custom module and how can i get my view to display this? I tried writing this code in a tpl file for the view and then did print\_r and render() but no effect. I think it should be done through views.

# Answer
> 0 votes
write code in your module like this way.

**Declaring the block**

```
function mymodule_block_info() {
  $blocks['current_posts'] = array(
    'info' => t('Current posts'), //The name that will appear in the block list.
    'cache' => DRUPAL_CACHE_PER_ROLE, //Default
  );
  return $blocks;
}

```

**Retrieving data**

```
    function mymodule_contents(){
      $query = db_select('challenges','c')
$query = db_select('challenges','c');
$query->join('node','n','n.nid = c.cid');
$query->join('field_data_body','f','n.nid = f.entity_id');
$query->join('field_data_field_challenge_pic', 'fp','n.nid = fp.entity_id');
$query->join('file_managed','fm','fp.field_challenge_pic_fid = fm.fid');
$query->fields('n',array('nid','title','created'))
      ->field('f',array('f','body_value'))
      ->field('fp',array('fm','uri'))
      ->condition('c.cid','$user->uid','=')
        ->execute();
      return $query;
    }

```

**Generating block content**

```
function mymodule_block_view($delta = '') {
  switch($delta){
    case 'current_posts':
      $block['subject'] = t('Posts');
      if(user_access('access content')){
        //Use our custom function to retrieve data.
        $result = mymodule_contents();
        //Array to contain items for the block to render.
        $items = array();
        //Iterate over the resultset and format as links.
        foreach ($result as $post){
          print $post;
        }

        if (empty($items)) { //No content in the last week.
          $block['content'] = t('No posts available.');
        }
        else {
          //Pass data through theme function.
          $block['content'] = theme('item_list', array(
            'items' => $items));
        }
      }
    return $block;
  }

}

```

---
Tags: 7, views
---


# Question
Title: Alter field collection edit form in hook_menu_alter
I need to create my own form and validation (when field collection entity is Edited).

```
function common_menu_alter(&$items) {
    //alter add(insert) - working
    $items['field-collection/field-block-id/add/%/%']['page callback'] = '_common_field_collection_item_add';
    //alter edit - not working
    $items['field-collection/field-block-id/%field_collection_item/edit ']['page arguments'] = '_common_field_collection_item_form'
}

```

`_common_field_collection_item_add()` is my own function in my common.module.

I managed to alter the entity on insert, but changing the "edit" part doesn't work. This is the path of my field collection edit: field-collection/field-block-id/%/edit?destination=node/%. I tried to put this path to `$items`, but it still doesn't not work.

In `hook_form_alter()` I did this.

```
if ($form_id == 'field_collection_item_form' && arg(3) == 'edit') {
       $form['#validate'][] = '_common_field_collection_item_form_validate';
       $form['#submit'][] = '_common_field_collection_item_form_submit';
}

```

# Answer
Better to use the Field Attach API hooks instead.

e.g:
> 3 votes

---
Tags: 7
---


title: Why my hook_menu does not work?

text:
# Question
Title: Why my hook_menu does not work?
I have this code in the module `cleanetica_advanced`.

```
function cleanetica_advanced_menu() {

    $items['ajax/content/%'] = array(
      'page callback' => 'cleanetica_advanced_ajax_load',
      'page arguments' => array(2),
      'title' => 'Ajax content load',
      'access arguments' => array('access content'),
      'type' => MENU_CALLBACK
    );

    $items['ajax/validate/form/%'] = array(
      'page callback' => 'cleanetica_advanced_ajax_validate_form',
      'page arguments' => array(3),
      'title' => 'Ajax validate form',
      'access arguments' => array('access content'),
      'type' => MENU_CALLBACK
    );

    $items['user'] = array(
       'title' => 'blogs',
       'description' => 'Listing of blogs.',
       #'page callback' => 'blog_page',
       'access arguments' => array('access content'),
       'type' => MENU_DEFAULT_LOCAL_TASK
     );

    return $items;
}
```

For some reason the item "blogs" (which I created for testing only, there are no blogs in our site) does not show in the tabs of the page `/users`. I need to show it in the `/users` tabs. What is my error?

I checked that `cleanetica_advanced` module is loaded by inserting some nonsense in the .module file and seeing that the site ceases to work with an error message. (Then I removed the nonsense.)

By the way, does `user` in `$items['user']` refer to the page where the menu should be shown or to the ID of the menu item itself?

# Answer
> 2 votes
"user" is a path already used by the User module; if your module is not executed after the User module (i.e. you are not altering the order hooks are executed), the menu item of the User module takes the precedence. (That is also the wrong way to alter the menu item defined from another module, but your purpose is not that.)

```
  // Registration and login pages.
  $items['user'] = array(
    'title' => 'User account',
    'title callback' => 'user_menu_title',
    'page callback' => 'user_page',
    'access callback' => TRUE,
    'file' => 'user.pages.inc',
    'weight' => -10,
    'menu_name' => 'user-menu',
  );

```

If you want to define a menu tab for each user account, as I think, the definition of your menu item should be similar to this, used from the User module.

```
  $items['user/%user/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_profile_form', 1),
    'access callback' => 'user_edit_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'file' => 'user.pages.inc',
  );

```

For example, something similar to the following would work.

```
  $items['user/%user/edit'] = array(
    'title' => 'Blogs',
    'description' => 'Listing of blogs.',
    'page callback' => 'cleanetica_advanced_blog_page',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_LOCAL_TASK,
  );

```
* The page callback receives an argument: the user object for the user account. It will be called from Drupal as `cleanetica_advanced_blog_page($account)`.
* Every function implemented by a module needs to be prefixed by its short name.
* The menu type is `MENU_LOCAL_TASK` since there is already a `MENU_DEFAULT_LOCAL_TASK` menu item, and there cannot be two `MENU_DEFAULT_LOCAL_TASK`; the other tab is also the tab showing the details for the user account, and it is better to keep that as default tab.

If you want to show a list of blog posts global for all the users, then you need to change the path from user, or user/%user/edit, to (for example) blogs. Adding it as tab of the user tab doesn't make any sense, since the page would list content, not a list of users; it would be also shown together user/login, user/register, and it doesn't make sense to show a list of blog posts to who is registering/logging in.

# Answer
> 1 votes
`user` path is defined by core user.module so you cannot overwrite it from `hook_menu()`.

If you want to alter default `/user` page, you need to implement `hook_form_alter`. However, note that `/user` page is the only page that works in maintenance mode and it's a little bit complicated that this page shows login page or redirects to the user's profile depending on whether the user is logged in or or not.

If you want to add a new tab in user's profile(or add a new tab and set it the default), you can (for Drupal 7):

```
$items['user/%user/blogs'] = array(
  'title' => 'Blogs',
  'page callback' => 'blog_page', // enter your own page callback here
  'page arguments' => array(1), // first argument to your page callback would be $user
  'access arguments' => array('access content'),
  'type' => MENU_LOCAL_TASK,
  'file' => 'cleanetica_advanced.pages.inc', // whatever. If your pagecallback is in the .module file, omit this line.
);

```

If you want to set this tab as the default, change `MENU_LOCAL_TASK` above to `MENU_DEFAULT_LOCAL_TASK` and implement a `hook_menu_alter()`.

```
function cleanetica_advanced_menu_alter(&$items) {
  $items['user/%user/view']['type'] = MENU_LOCAL_TASK;
}

```

---
Tags: routes
---


# Question
Title: Selecting field from all comments on a particular node
I have essentially hacked comments into reviews of a node, having a comment field of 'rating' with a fivestar widget. I was hoping it would be a trivial call to the voting API to fetch the rating of each 'review' so I could work out a nodes average rating.

However I notice that for some reason all the votes are getting saved in a database table of `field_revision_field_product_rating`, and this contains *no direct foreign key to the node it is from*, is there a 'Drupal' way of fetching the comments in manual SQL with some monster joins?

Just to confirm, review is actually a comment, and the fivestar 'rating' is a field on the comment.

Bonus points: Why, even though I'm using fivestar, are the votes not getting put into the votingAPI storage?

# Answer
> 0 votes
On the field settings screen, it is important to set the “Voting target” to “Parent node,” so that these votes will add ratings to the node; then, click the “Save field settings” button

---
Tags: 7, entities, rating
---


title: jQuery detect submit on form problem

text:
# Question
Title: jQuery detect submit on form problem
I'm trying to detect when a form is submitted so I have written this code:

```
jQuery('#formid').submit(function(event){
        console.log('submit handler');
})

```

But nothing happens and the form is submitted normally. The form is rendered as usual and the submit button is generated with this code:

```
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Enviar'),
    '#attributes' => array('class' => array('btn','pull-right')),
    '#ajax' => array(
        'callback' => 'contact_form_ajax_submit',
        'wrapper' => $result_wrapper,
        'progress' => array(
          'type' => 'none',
          'message' => NULL,
        ),
    ),
  );

```

I don't know why my jquery script doesn't intercept the submit. I've checked the form id (obviously) so I ask for help because I have no idea about what could be the problem.

Thanks

Link: http://seminolaproducciones.com/contacto

# Answer
For normal forms you need bind submit event handler to the form, something like below as Baysaa said,

```
jQuery('#formid').submit(function() {
  console.log('submit handler');
  return false;
});

```

However For Drupal AJAX forms this wont work, Because Drupal AJAX forms are submitted by Drupal in a different way when the submit button is clicked, So you need to just bind the click event to the submit button to detect the form submission, Something like below,

```
jQuery('#submit-form').submit(function() {
  console.log('Form is being submitted');
});

```

Here the restriction is you cant prevent form being submitted, even if you put return false in you custom click handler.
> 2 votes

---
Tags: forms, ajax, javascript
---


# Question
Title: Display suite's adding custom fields loads eternally
In "Manage display" page of my *product* content type, I have the custom fields tab. In that tab I have some buttons... None of these buttons works. I tried both but the popup div loads eternally there.

Anyone with the same problem with any clue?

Thanks

# Answer
> 1 votes
all these are the view modes like teaser,full content etc.whenever you create any panel ,there will be tabs of full-content etc...then u can edit the settings displayed below these tabs..here these buttons would be visible...

---
Tags: 7, entities, display-suite
---


title: Attaching workflow to node using rule

text:
# Question
Title: Attaching workflow to node using rule
Is there anyway I can set workflow dynamically using rule. Basically I need to setup workflow for given article only when someone flagged that article.

So can I setup some kind of rule that when an article is flagged, initialize workflow for that node and assign it to one of the workflow state?

-- Many thanks for your time.

# Answer
> 1 votes
Why not just set up a workflow that includes a default "no\_workflow" state? Use rules to automatically set all nodes to the "no\_workflow" state upon creation. Then, when a node is flagged, use rules to set it to the appropriate state. That way, all nodes are subject to the workflow, but by default they don't move through the states until they are flagged.

---
Tags: 7, rules, workflows
---


# Question
Title: How to show friendly url when using Facets search?
I installed the commerce\_kickstart distribution. Its products pages shows facets search blocks to filter the products.

When using these filters the url change to a not friendly url. How can change this? How to show the taxonomies terms names instead.

Look my capture below:

I mean to change this:

```
http://localhost/commerce_kickstart/es/products?f[0]=field_collection%3A81

```

to something like

```
http://localhost/commerce_kickstart/es/products/field_collection/cds

```

# Answer
I was looking for the same thing yesterday and came across Facet API Pretty Paths

> Enables pretty paths for searches with Facet API. You will likely use this module in combination with either Search API or Apache Solr Search Integration.

I haven't had a chance to try it yet but looks promising...
> 7 votes

---
Tags: commerce, search
---


title: How to sort order of menus?

text:
# Question
Title: How to sort order of menus?
I am using the sitemap module and have enabled 3 menus to display. However, I dont like the order the menus are being displayed in. Is there a way to change this?

# Answer
> 1 votes
You can use this patch http://drupal.org/node/1529708#comment-6633022 If you need something more specific you can use hook\_site\_map() to add things to your sitemap and take a look at the \_site\_map\_menus() function.

---
Tags: navigation
---