# Question
Title: Getting the user ID of the user who created a taxonomy term
I need to get the user information of the user who created a taxonomy term. How can I get it?

# Answer
> 1 votes
try to do this:

1. Add a field called 'Author' like a entity reference
2. alter the form to prepopulate this field

```
function customodule_form_alter(&$form, &$form_state, $form_id){
print_r($form_id);
if( $form_id == 'taxonomy-form-term' && isset($form['field_author']) ){

  print_r($form['field_author']['nid']['nid']['#value']);
  global $user;
  $form['field_author']['nid']['nid']['#value'] == $user->uid;

  }
}

```

I put some print\_r so you can debug this code fast.

# Answer
> 0 votes
Only nodes have author information attached, not taxonomy terms.

If you need to access author information you may be better off making a content type to store your data as opposed to a taxonomy vocabulary.

# Answer
> 0 votes
Taxonomy terms are actually entities, to which you can add fields from "Manage fields."

Add a user entity reference field, and make it mandatory. Whenever you add a new term, associate the user ID to to the taxonomy term using the field you just created.

You can also hide the field using `hook_form_alter()`, and populate the field using the entity pre-save technique.

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


# Question
Title: Is there an hook to react to custom entity updates?
I need to react to updates of custom entities wich are using Entity API (Redhen organization in my case).

I tried using hook\_entity\_update($entity, $type) but it does not seem to be fired when updating said entity.

Thank you for your time.

# Answer
> 0 votes
If it can help other people :

hook\_entity\_update is working fine as long as it is declared in the .module file.

I putted it int an inc file so it was never fired !

---
Tags: 7, hooks, entities
---


# Question
Title: How is drupal able to see a module even when I renamed it
I ran down into a serious issue with mediabox module. After spending some time I realized its because the update has broken some functionality. I just wanted to revert back to older version. I did it by copying my local folder which is older version to the production. However it looks like drupal is still taking the older version. This I confirmed by observing the html code which is different for two versions.

I cleared cache, restarted apache. But it still somehow is getting it from the bugged code. **I even removed the folder.** But surprisingly it is still reading it from somewhere. I made sure I removed the cache and rebooted apache. I did this in my local machine which actually broken my site which was expected but I am wondering why its still not throwing any error even after I renamed the folder name

# Answer
> 1 votes
Drupal stores information about where to find module files in the system and registry tables. If you want to revert an update, you'll have to replace the updated version with the old version. If you ran database updates to update the module, you'll have to disable and uninstall it first, and then re-enable it after you've replaced the module files.

If you've removed the module without disabling it, the site should break. If it's still running with the updated module, there must be another copy of it somewhere.

If you want to know where drupal's reading the files from you can run the following SQL on the db:

```
SELECT filename FROM system WHERE name = 'mediabox';

```

---
Tags: 7, updating
---


# Question
Title: How to link two content types from each other
I have content type A and content type B. Users need to be able to link between them while creating either content type (A or B). When they link them up I would like it to be saved in one table. Currently using something like node reference would put it in two different tables. Know of any module or functionality that can do that?

Clarifying I want a user to be able to go into content A and save a reference to content B. We also need a user to go into content B and save a reference to content A. Ideally both references would be stored in one table as a many to many relationship.

# Answer
> 0 votes
You can save it to a single table by creating one entity reference field and invoking it on both content types.

---
Tags: nodes
---


# Question
Title: Importing Content Without Including `nid`
I have this site I develop, and the way the process works is that I have three versions of the same site: Production, Staging, and Development.

I've been working on some new features on Development, but over time, new content has been added to the Production version. Now that I'm done with the development for now, I'd like to copy the new Content Types + Nodes I've created in Development to Staging, which I've turned into a clone of Production, but I keep running into this issue: when I import content, it always includes the nid, so it overwrites content that has been created on the live site, which I can't have.

I've tried Features, Data Export Import, etc, but they all include the Node ID with the information, so existing content is always getting overwritten when I import.

What solutions are there for importing nodes WITHOUT also importing the Node ID with it? I essentially need to use Node Clone's functionality, except instead of creating the cloned node locally, it exports it to be created on the Staging site.

# Answer
I think you should use Features and Universally Unique IDentifier.

When you update an existing node, thanks to UUID, it will be updated in production site because they should have the same UUID (but can have different IDs). If the UUID doesn't exist, then it will create a new node.
> 1 votes

---
Tags: nodes, importing-exporting
---


title: Trigger #states via custom jQuery

text:
# Question
Title: Trigger #states via custom jQuery
I have a form using #states which is great, but once a hidden field is made visible I would like the user to be able to hide it again by clicking a close button, rather than deselecting the original checkbox - hopefully by triggering the original states function. Is there a Drupal way to do this?

# Answer
> 2 votes
If "#edit-radiobutton" should launch the state, just do:

```
jQuery('#edit-radiobutton').click().trigger('change');

```

# Answer
> 0 votes
What I understand is that you unhide a field using #states, and want the end user to hide it again. If thats the case, there is no way you can do this in drupal. You can use Jquery to do so, use .hide() function to hide that particular div.

---
Tags: javascript
---


# Question
Title: Adding a link to download the original image to a view
I would like to add at the end of the description a link like saying "Download HiRes Image" at the end of the caption of the image in this view, but I don't know how. I did try with the module DownloadFile but there is no documentation about it.

http://www.nellens.com/home/photos-full/segunda-serie

# Answer
You can use the DownloadFile module, which allows you to download Files or Images, and it's usable in views.
> 1 votes

---
Tags: views, theming, media
---


# Question
Title: General architectural approach to Drupal for a new project
Thank you for taking your time to answer. Her is the edited version:

I am developing a sport social networking website. I come from WordPress cms and for this particular project I've choosen Drupal Commons that seems more suited to me compared to wordpress solution "Buddypress".

This sport social network revolves around 3 points, along with all the features of a social network which the distribution offers(wall, comment, follow an user...)

1. Manage an activity: (nutrition/exercice program)

* User can add/edit/delete their own activity
    * User can save an existing public activity as its own activity
2. Display of activities flow on each user wall (eg User create a training program that appears on all others users wall)

* User can filter the display (own flow, all users flow, user groups flow)
3. Graph/summary generation of some activities and display for each user on his backend

My questions are as follows:

1. What would be the best approach for this type of project ?
2. Should I create a module for 2 activities (nutrition and programs) ?
3. Create taxonomy + custom content type ? (What would be criteria that guide to the choise of fields on taxonomy rather than custom content type?)

I see it as follows, taxonomy to structure data types and then custom content type to create custom forms that will retrieve the data entered by the users content.

Thanks in advance for your answers.

# Answer
> 1 votes
I think you need to decide what the best method to store each content type will be.

You main options are Content Types, Taxonomies or custom entities.

If your data needs revisions, author information or comments that creating a custom content types would be ideal. (think articles, blogs, etc.)

If you don't need that much bolted on functionality, and just want to store a list then a taxonomy vocabulary may be more appropriate. Taxonomy terms are still easy to integrate with the views module and can also be stored with a hierarchy structure.

If you need to store something entirely different to either of these 2 options (think till data, site adverts or vehicles) then a custom entity may be more suitable. This option is more work initially however the module Entity Construction Kit (ECK) makes things easier. This would be more work to integrate with Drupal views.

It is worth spending some time making sure you make the right decisions about this before you start as in the long run can save lots of time.

This is a great article that builds further on what I've said.

It sounds like quite a lot of what your building will require some fairly custom functionality so I would look down the custom entities path...

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


# Question
Title: I'm new to object oriented php. Trying to query database but not getting any results
I am trying to query a table in my DB and am not able to get any results back. Here is the code I am using:

```
function get_agent_info($agent) {
        $query = db_query("SELECT * FROM tls_connect_stage_timer WHERE '".$agent."' IN ('start_processing_agent' || 'end_processing_agent')");
        $rows = array();
        foreach ($query as $result) {
            $rows[] = array(
                $result     -> applicant_id,
                $result     -> stage,
                $result     -> event_start,
                $result -> event_end,
                $result     -> start_processing_agent,
                $result     -> end_processing_agent,
                $result     -> start_request_ip,
                $result     -> end_request_ip,
                $result     -> gwf,
            );
        }
        print_r($rows);

    }

```

I have already used a method like this to get info:

```
$results = db_query("SELECT * FROM tls_active_applicants WHERE `".$searchParams."`='".$input."'");
$rows = array();
                 foreach($results as $result){
                    $rows[] = array(
                        $result -> first_name,
                        $result -> last_name,
                        $result -> gwf,
                        $result -> visa_type,
                        $result -> current_stage,
                    );
                 }

```

The second one works fine, where with the first one, if I print\_r($rows) it returns an empty array. Why is the foreach loop starting in the first example but not the second? I've tested the query, and it works fine. Also any links that could help me understand how the foreach loop is working would be greatly appreciated. I assumed that since it's saying $query as $result, I would be able to pull a single value saying something like $query-\>stage but that didn't work. I'm assuming because there are several entries I would need to do something like $query\[0\]-\>stage but I don't really know how that works when it comes to calling properties..

# Answer
> 3 votes
I won't address your question specifically...because you're doing it wrong, and that should stop here :)

This is very, very bad:

```
db_query("SELECT * FROM tls_connect_stage_timer WHERE '".$agent."' IN ('start_processing_agent' || 'end_processing_agent')");

```

You should never concatenate data into an SQL string, you'll leave yourself ripe for injection attacks. This one is even worse:

```
db_query("SELECT * FROM tls_active_applicants WHERE `".$searchParams."`='".$input."'");

```

As you're liable to injection attacks from both the field name *and* the argument.

If you want to use dynamic field names you should use the `SelectQuery` class, accessible via `db_select()`. E.g.

```
$values = array('start_processing_agent', 'end_processing_agent');
$query = db_select('tls_connect_stage_timer', 't')
  ->fields('t')
  ->condition($field_name, $values);

$rows = $query->execute()->fetchAll();

```

You'll need to make some changes to the above for your specific query, but that's the general idea.

# Answer
> -1 votes
You are messing things up. Build a query with db\_select. https://drupal.org/node/310075

# Answer
> -1 votes
You are using the IN statement wrong.

If $agent has to be considered as a value, you should use the '=' like for the second query.

If $agent is a field name of your table instead, the query should be like this

```
"SELECT * FROM table WHERE $agent IN ( SELECT field FROM table)"

```

On a side note, when you create a string using the double quotes, you can directly use simple variables inside, like in the example above, as opposed to:

```
" WHERE ".$agent." IN "

```

About your use of foreach instead, it seem that what you are trying to do can be achieved using

```
$rows = $query->fetchAll();

```

---
Tags: database
---


# Question
Title: Problem with updating modules (check updates)
I have Drupal 7.26 with Commons 7.x-3.9. Recentyl manual update of modules is not working. When going to "Modules" - "Update" I'm getting something like:

`Last checked: 4 days 58 min ago (Check manually)`

and this is the last time I've been able to check updates (just before Durpal core update).

When I use "Check manually", the page with progress bar appears where progress bar is always "100%" and messages say:

`Trying to check available update data ...
Checking available update data ...`

After short while it returns to "Update" page with:

`Last checked: 8 hours 5 min ago (Check manually)
There was a problem getting update information. Try again later.`

No updates visible, no errors in log.

Any ideas?

# Answer
Problem solved through cleaning cache\_update table (execute SQL query "delete from cache\_update;" through phpmyadmin or mysql workbench)
> 3 votes

---
Tags: updating
---


title: Run D6 and D7 instance on same domain?

text:
# Question
Title: Run D6 and D7 instance on same domain?
Client wants to have their D6 and D7 site run under the same domain. They're not ready to upgrade. Each has a similar theme so linking to the D6 site will 'look' seamless. How can this be done?

# Answer
Put the D7 site under the root web directory. You should be able to go the site and see the D7 site. Then, put the D6 site under the root web directory in a new directory called 'd6' or whatever you want. Then, in the settings for the D6 site, put the root path as webdirectory/d6.

Then you can reference the d6 site from the d7 by directing users to the link "something.com/d6/someNode"

Otherwise, you really can't have both running under the same web root. It has to choose one or the other.
> 3 votes

---
Tags: multi-sites, subsites
---


# Question
Title: What trigger menu_rebuild flag in semaphore table?
Well, this question appear to be simple, but my problem is a little bit more complex. I'll try to explain my situation.

I have a site with customized template and a bunch of modules (all 3rd party from Drupal contrib site). When **any content** needs to be updated, which means include, update or delete a node, page or panel causes a slow down in entire site. The site practically stops. For everyone (anonymous and logged users).

I began an investigation and I realized that **menu\_rebuild flag in semaphore table** is taking too long (~5 minutes) to disappear. This is causing trouble for every user who wants to navigate on the website, because menu\_rebuild is locking down the site.

One side effect of this menu\_rebuild lock is the queue of apache processes in the server. This leads the server to be overloaded (100% CPU).

My conclusion after this investigation is simple. Something (a module maybe) is firing the menu\_rebuild many times causing the site lockup. I tracked down the function in Drupal core that activate menu\_rebuild. See:

**includes/menu.inc**

```
/**
 * Populates the database tables used by various menu functions.
 *
 * This function will clear and populate the {menu_router} table, add entries
 * to {menu_links} for new router items, and then remove stale items from
 * {menu_links}. If called from update.php or install.php, it will also
 * schedule a call to itself on the first real page load from
 * menu_execute_active_handler(), because the maintenance page environment
 * is different and leaves stale data in the menu tables.
 *
 * @return
 *   TRUE if the menu was rebuilt, FALSE if another thread was rebuilding
 *   in parallel and the current thread just waited for completion.
 */
function menu_rebuild() {

  if (!lock_acquire('menu_rebuild')) {
    // Wait for another request that is already doing this work.
    // We choose to block here since otherwise the router item may not
    // be available in menu_execute_active_handler() resulting in a 404.
    lock_wait('menu_rebuild');
    return FALSE;
  }

  $transaction = db_transaction();

  try {
    list($menu, $masks) = menu_router_build();
    _menu_router_save($menu, $masks);
    _menu_navigation_links_rebuild($menu);
    // Clear the menu, page and block caches.
    menu_cache_clear_all();
    _menu_clear_page_cache();

    if (defined('MAINTENANCE_MODE')) {
      variable_set('menu_rebuild_needed', TRUE);
    }
    else {
      variable_del('menu_rebuild_needed');
    }
  }
  catch (Exception $e) {
    $transaction->rollback();
    watchdog_exception('menu', $e);
  }

  lock_release('menu_rebuild');

 return TRUE;
}

```

When I comment the `lock_wait('menu_rebuild');` / `lock_release('menu_rebuild');` calls, my site runs smoothly and fast. But I can't do that. This affects the generation of new content.

I disabled all modules that I could without breaking the template. If you need to know what modules that I have installed, please ask.

I am using Drupal 7.23. My server configuration:

* Ubuntu 12.04 LTS
* 4 cores / 8GB RAM
* Apache 2.2.22;
* PHP 5.3.10 / FastCGI;

If you need information about apache configuration or PHP configuration, please let me know.

Update:

Here are all active modules in my site:

**\[CORE\]**

* Block
* Contact
* Content translation
* Contextual links
* Dashboard;
* Field;
* Field SQL Storage;
* Field UI;
* File
* Filter;
* Image;
* List;
* Locale;
* Menu;
* Node;
* Number;
* Options;
* Overlay;
* Path;
* RDF;
* Shortcut;
* System;
* Taxonomy;
* Text;
* Toolbar;
* Update Manager;
* User;

**\[FIELDS\]**

* Entity Reference;
* Link;
* Select(or other);

**\[ACCESS CONTROL\]**

* ACL;

**\[SPAM CONTROL\]**

* CAPTCHA;
* Image CAPTCHA;

**\[DATE/HOUR\]**

* Date;
* Date API;
* Date Popup;
* Date Views;

**\[EMAIL\]**

* Newsletter;
* SMTP Authentication Support

**\[USER INTERFACE\]**

* CKEditor;
* Options element;
* Pagestyle;

**\[META TAGS (QUICK)\]**

* Meta tags (quick);

**\[LOCALIZATION\]**

* Localization update;

**\[INTERNATIONALIZATION\]**

* Block languages;
* Contact translation;
* Field translation;
* Internationalization
* Menu translation;
* Multilingual contant;
* Multilingual select;
* Path translation;
* String translation;
* Synchronize translations
* Taxonomy translation;
* Translation redirect;
* Translation sets;
* Variable translation;

**\[MEDIA\]**

* File entity;
* IMCE;
* IMCE Mkdir;
* Media

**\[OTHERS\]**

* Entity API;
* Pathauto;
* Profile2;
* Profile2 pages;
* Token;
* Transliteration;
* Vocabulary Permissions Per Role;

**\[PANELS\]**

* Panels;

**\[SUITE CHAOS TOOLS\]**

* Chaos tools;
* Page manager;
* Views content panes;

**\[VARIABLE\]**

* Variable;
* Variable realm;
* Variable store;
* Variable views;

**\[VIEWS\]**

* Embed Views Display;
* Views;
* Views UI;

**\[WEBFORM\]**

* Webform;
* Webform validation;

**\[WEBFORM DYNAMIC SELECT\]**

* Webform options;

**\[WORKBENCH\]**

* Workbench;
* Workbench access;
* Workbench Media;
* Workbench Profile;

**\[XML SITEMAP\]**

* XML sitemap;
* XML sitemap engines;
* XML sitemap internationalization;
* XML sitemap menu;
* XML sitemap node;
* XML sitemap taxonomy;

# Answer
> 2 votes
After a long wait, we finally figured out what is the real problem. This can be splitted in two parts: the custom template that we use and the Chaos Tools Module.

1. The template **was really bad coded**. Had functions accessing the database all the time and making unnecessary I/O. We refactored the template;
2. Chaos Tools is a really nice module, but it really slow down my site. Not all Chaos Tools, but specifically the **Page Manager**. I don't know why, but there is a loop in file `/sites/all/modules/ctools/page_manager/page_manager.module` causing all the trouble when I was trying to save a new page, for example. **This loop trigger menu\_rebuild** semaphore and the **page manager** take an eternity to remove this flag from semaphore table.

Open the file page\_manager.module and **scroll down to line ~148**

```
// And for those that provide subtasks, provide menu items for them, as well.
foreach (page_manager_get_task_subtasks($task) as $subtask_id => $subtask) {
   // Allow the task to add its own menu items.
   if ($function = ctools_plugin_get_function($task, 'hook menu')) {
      $function($items, $subtask);
   }
}

```

I commented this entire loop to solve this problem. I don't know all the impact this action can cause to my site, but now, when I save a new content, the speed increased and the `menu_rebuild` is not triggered.

```
// And for those that provide subtasks, provide menu items for them, as well.
// foreach (page_manager_get_task_subtasks($task) as $subtask_id => $subtask) {
//   Allow the task to add its own menu items.
//   if ($function = ctools_plugin_get_function($task, 'hook menu')) {
//      $function($items, $subtask);
//   }
// }

```

I believe **this is not a bug on Chaos Tools**, but maybe this can be improved.

# Answer
> 0 votes
To figure out an issue like this, you should enable XHProf, which is a tool that will profile your CPU (and memory) usage and will show you how the trace of calls through the system that calls this function. From that you can find out what module or section of code that is causing the issue.

There is a great page documenting how to set up Drupal and XHProf, and let us and the module owners know what you find.

---
Tags: routes, performance
---


title: XSS in Drupal 7 Views Replacement token

text:
# Question
Title: XSS in Drupal 7 Views Replacement token
I am working on a Drupal 7 site that uses a replacement pattern %1 inside a View header to generate a URL with the Organic Group id(og\_group\_ref).

The view header markup is

```
<a class="ct" href="/node/add/post?og_group_ref=%1">Create Convo</a>

```

Example URL of a page is site/b\_posts/2, so the link created would be /node/add/post?og\_group\_ref=2.

This is vulnerable to XSS, since accessing the URL site/b\_posts/%22%20onmouseover=%22alert%28559%29%22%20test=%22/2 would result in a JS alert getting executed on mousing over the link. How to protect against this? I used the latest version of Views and this is still happening.

# Answer
You must enable validation on your contextual filter.

More information found here:

https://drupal.org/node/1578564

http://nodeone.se/en/learn-views-with-nodeone-part-23-validation-of-contextual-filter-input
> 1 votes

---
Tags: views, tokens
---


# Question
Title: When editing a node, some markup disappears
I'm using Drupal 7 and my page loads and looks fine when I add a new node and insert HTML markup. When I edit the page, some of the markup either disappears or it's replaced.

For example, if I add `<h3 class="landing">`, the node saves and it's displayed fine. When I edit the node, `<h3 class="landing">` is replaced by `<h3>`. If I add `<iframe>`, `<iframe>` is replaced by `<p>`.

Do you know why this would happen? How can I fix it?

# Answer
> 1 votes
I have the same issue, and this is caused by the WYSIWYG editor: When you try to edit a node created with a input format with WYSIWYG enabled, the HTML markup will be changed by the editor.

To solve it, you have two options.

1. Disable the WYSIWYG editor by default, unselecting the checkbox as shown in the screenshot.

>
2. Create a node using an input format that doesn't use the WYSIWYG editor (for example Full HTML, or Filtered HTML). If the *Full HTML* format is already associated with a WYSIWYG profile, try to create a custom format from /admin/config/content/formats, and use it to create new nodes. Remember to not associate a WYSIWYG profile.

---
Tags: nodes
---


title: How do I make an event calendar?

text:
# Question
Title: How do I make an event calendar?
Im on D7. I have been pulling my hair out trying to get this working.

Im using these modules:

I have tried to use the calendar dev version but I get the same problem.

When ever I try and create a calendar view, all I see is a blank calendar. Meaning nothing shows up in the calendar cells even though I have fields assigned. I am "Adding a view from template" and selecting the template that has my date field (I have also tried the one that uses the content creation date, but no luck). Has anyone else had this problem? Why would it not be working? I can make a view of a simple list of nodes that have the date field, so why not a calendar view?

Here is my view:

```
    $view = new view();
$view->name = 'calendar';
$view->description = '';
$view->tag = 'Calendar';
$view->base_table = 'node';
$view->human_name = 'Calendar';
$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['use_more_always'] = FALSE;
$handler->display->display_options['link_display'] = 'page_1';
$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['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['row_plugin'] = 'calendar_entity';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: Content: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_date']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['field_date']['settings'] = array(
  'format_type' => 'short',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_repeat_rule' => '',
);
$handler->display->display_options['fields']['field_date']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_date']['delta_offset'] = '0';
/* Sort criterion: Content: Date (field_date) */
$handler->display->display_options['sorts']['field_date_value']['id'] = 'field_date_value';
$handler->display->display_options['sorts']['field_date_value']['table'] = 'field_data_field_date';
$handler->display->display_options['sorts']['field_date_value']['field'] = 'field_date_value';
/* 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'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Month */
$handler = $view->new_display('page', 'Month', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['row_options']['colors']['legend'] = 'type';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/month';
$handler->display->display_options['menu']['type'] = 'default tab';
$handler->display->display_options['menu']['title'] = 'Month';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['tab_options']['type'] = 'normal';
$handler->display->display_options['tab_options']['title'] = 'Calendar';
$handler->display->display_options['tab_options']['weight'] = '0';

/* Display: Week */
$handler = $view->new_display('page', 'Week', 'page_2');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'week';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'week';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'week';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/week';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Week';
$handler->display->display_options['menu']['weight'] = '2';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Day */
$handler = $view->new_display('page', 'Day', 'page_3');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'day';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'day';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'day';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/day';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Day';
$handler->display->display_options['menu']['weight'] = '3';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Year */
$handler = $view->new_display('page', 'Year', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'year';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'year';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: Content: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_date']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['field_date']['settings'] = array(
  'format_type' => 'short',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_repeat_rule' => '',
);
$handler->display->display_options['fields']['field_date']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_date']['delta_offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'year';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-date/year';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Year';
$handler->display->display_options['menu']['weight'] = '4';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'mini';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '1';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);

/* Display: Upcoming */
$handler = $view->new_display('block', 'Upcoming', 'block_2');
$handler->display->display_options['display_description'] = 'Upcoming events block';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* 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'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Date: Date (node) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'node';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['operator'] = '>=';
$handler->display->display_options['filters']['date_filter']['default_date'] = 'now';
$handler->display->display_options['filters']['date_filter']['add_delta'] = 'yes';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
  'field_data_field_date.field_date_value' => 'field_data_field_date.field_date_value',
);

```

And here are some pictures of my view:

And the contextual filter settings:

# Answer
I have an Event Calendar on my website,

Import this view and see if it works for you.

```
$view = new view();
$view->name = 'calendar_3';
$view->description = '';
$view->tag = 'Calendar';
$view->base_table = 'node';
$view->human_name = 'Calendar Event';
$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['use_more_always'] = FALSE;
$handler->display->display_options['link_display'] = 'page_1';
$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['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['row_plugin'] = 'calendar_entity';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['exclude'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: Content: Re-Enter Event Date */
$handler->display->display_options['fields']['field_event_date']['id'] = 'field_event_date';
$handler->display->display_options['fields']['field_event_date']['table'] = 'field_data_field_event_date';
$handler->display->display_options['fields']['field_event_date']['field'] = 'field_event_date';
$handler->display->display_options['fields']['field_event_date']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_event_date']['settings'] = array(
  'format_type' => 'long',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
);
/* 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']['exclude'] = TRUE;
/* Field: Content: Rendered Node */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['exclude'] = TRUE;
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 0;
$handler->display->display_options['fields']['rendered_entity']['view_mode'] = 'full';
$handler->display->display_options['fields']['rendered_entity']['bypass_access'] = 0;
/* Field: Colorbox: Colorbox trigger */
$handler->display->display_options['fields']['colorbox']['id'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['table'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['field'] = 'colorbox';
$handler->display->display_options['fields']['colorbox']['label'] = '';
$handler->display->display_options['fields']['colorbox']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['colorbox']['trigger_field'] = 'rendered_entity';
$handler->display->display_options['fields']['colorbox']['popup'] = '<html>
<body>
<h1>[title]</h1>
<br>
<b>Description: </b> <br>[body]
<br>

<b>Date: </b>[field_event_date]
<br><br>
<b>Note: </b> For more info, Click on the title.
</body>
</html>';
$handler->display->display_options['fields']['colorbox']['gid'] = 1;
/* Sort criterion: Content: Re-Enter Event Date -  start date (field_event_date) */
$handler->display->display_options['sorts']['field_event_date_value']['id'] = 'field_event_date_value';
$handler->display->display_options['sorts']['field_event_date_value']['table'] = 'field_data_field_event_date';
$handler->display->display_options['sorts']['field_event_date_value']['field'] = 'field_event_date_value';
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->display->display_options['defaults']['use_ajax'] = FALSE;
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'mini';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '1';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);

/* Display: Upcoming */
$handler = $view->new_display('block', 'Upcoming', 'block_2');
$handler->display->display_options['display_description'] = 'Upcoming events block';
$handler->display->display_options['defaults']['use_more'] = FALSE;
$handler->display->display_options['use_more'] = TRUE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* 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'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Date: Date (node) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'node';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['operator'] = '>=';
$handler->display->display_options['filters']['date_filter']['default_date'] = 'now';
$handler->display->display_options['filters']['date_filter']['add_delta'] = 'yes';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);

/* Display: Year */
$handler = $view->new_display('page', 'Year', 'page');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'year';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'year';
$handler->display->display_options['style_options']['name_size'] = '1';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = FALSE;
/* Field: Content: Re-Enter Event Date */
$handler->display->display_options['fields']['field_event_date']['id'] = 'field_event_date';
$handler->display->display_options['fields']['field_event_date']['table'] = 'field_data_field_event_date';
$handler->display->display_options['fields']['field_event_date']['field'] = 'field_event_date';
$handler->display->display_options['fields']['field_event_date']['label'] = '';
$handler->display->display_options['fields']['field_event_date']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_event_date']['hide_alter_empty'] = FALSE;
$handler->display->display_options['fields']['field_event_date']['settings'] = array(
  'format_type' => 'short',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_repeat_rule' => '',
);
$handler->display->display_options['fields']['field_event_date']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_event_date']['delta_offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'year';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-event-date/year';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Year';
$handler->display->display_options['menu']['weight'] = '4';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Day */
$handler = $view->new_display('page', 'Day', 'page_3');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'day';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'day';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'day';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-event-date/day';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Day';
$handler->display->display_options['menu']['weight'] = '3';
$handler->display->display_options['menu']['context'] = 0;

/* Display: Month */
$handler = $view->new_display('page', 'Month', 'page_1');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'month';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['row_options']['colors']['legend'] = 'type';
$handler->display->display_options['row_options']['colors']['calendar_colors_type'] = array(
  'university_courses' => '#ffffff',
  'event_calendar' => '#ffffff',
  'event' => '#ffffff',
  'online_training' => '#ffffff',
  'new_event' => '#ffffff',
  'page' => '#ffffff',
  'panel' => '#ffffff',
  'requirements' => '#ffffff',
  'training_resources' => '#ffffff',
  'story' => '#ffffff',
  'webform' => '#ffffff',
  'webinar' => '#ffffff',
);
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);
$handler->display->display_options['path'] = 'calendar_event';
$handler->display->display_options['menu']['type'] = 'default tab';
$handler->display->display_options['menu']['title'] = 'Month';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['tab_options']['type'] = 'normal';
$handler->display->display_options['tab_options']['title'] = 'Calendar';
$handler->display->display_options['tab_options']['weight'] = '0';

/* Display: Week */
$handler = $view->new_display('page', 'Week', 'page_2');
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['pager']['options']['date_id'] = 'week';
$handler->display->display_options['pager']['options']['link_format'] = 'clean';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['style_options']['calendar_type'] = 'week';
$handler->display->display_options['style_options']['name_size'] = '3';
$handler->display->display_options['style_options']['mini'] = '0';
$handler->display->display_options['style_options']['with_weekno'] = '0';
$handler->display->display_options['style_options']['multiday_theme'] = '1';
$handler->display->display_options['style_options']['theme_style'] = '1';
$handler->display->display_options['style_options']['max_items'] = '0';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'calendar_entity';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Date: Date (node) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'node';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['date_argument']['granularity'] = 'week';
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'field_data_field_event_date.field_event_date_value' => 'field_data_field_event_date.field_event_date_value',
);
$handler->display->display_options['path'] = 'calendar-node-field-event-date/week';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Week';
$handler->display->display_options['menu']['weight'] = '2';
$handler->display->display_options['menu']['context'] = 0;

```
> 1 votes

# Answer
I'm not sure why your view isn't working, but there are a number of tutorials on building an event calendar in D7.
> 0 votes

# Answer
IMHO the Calendar module is really bad and basically abandoned (although widely adopted.) This native civicrm extension is another approach.

Also using jquery fullcalendar.
> 0 votes

---
Tags: views, datetime
---


# Question
Title: Is there a way to conditionally change the state of a collapsible field group in admin, ie without changing a template or module file?
I want to move the Metatags, keywords and edit summary into collapsible field groups at the top of the node edit page, but keep it open the first time the node is created, but collapsed in subsequent edits.

Can some CSS or Javascript be used to accomplish that? I don't want to do it in the file system code, whether are module or a template file.. I'd prefer something using the Admin even if it means applying some PHP there. If a module like the Context module can be used to test whether it is a newly created record and change some settings that will be fine.

# Answer
> 1 votes
Not sure what you mean by applying PHP 'in the Admin' but you could add a hook to template.php in your admin theme.

```
function mytheme_form_node_form_alter(&$form) {
  if (!$form['nid']['#value']) {
    $form['myfieldset']['#collapsed'] = FALSE;
  }
}

```

If you'd rather go with a JS solution the following should work.

```
(function ($){
  Drupal.behaviors.dynamicCollapsedFieldset = {
    attach: function (context, settings) {
      $('.page-node-add #myfieldset').once('dynamic-collapsed-fieldset').removeClass('collapsed');
    }
  }
}(jQuery));

```

You'd need to attach the JS in a file either in a module (which you said you want to avoid) or in your admin theme's .info file.

Unless you're using a custom admin theme I'd strongly advise against hacking core / contrib to implement either method. Either create a subtheme or a small module for this.

Edit:

Here's a version checking for a fieldset prefix

```
function mytheme_form_node_form_alter(&$form) {
  if (!$form['nid']['#value']) {
    foreach ($form as $key => $value) {
      if (strpos($key, 'group_metatags_') === 0) {
        $form[$key]['#collapsed'] = FALSE;
      }
    }
  }
}

```

# Answer
> 1 votes
If you want it to be open on page creation, you can target the page using the node-add-CONTENTTYPE class on the body. Using some jQuery in document ready you can set it open.

Something like:

```
jQuery('body.page-node-add-<YOUR-CONTENT-TYPE> fieldset.#YOUR-ID-HERE').removeClass('collapsed').children('.fieldset-wrapper').show();

```

---
Tags: entities
---


title: Remove the Argument from a views URL

text:
# Question
Title: Remove the Argument from a views URL
I have a view with an exposed filter using the hierarchical select module for taxonomy.

`/browse?category=12345`

On the same view, I have an argument which does the same thing.

`/browse/12345`

I want my users to navigate using only the select filter, but this doesn't support breadcrumbs and page titles like the argument does. I wrote a bit of code to inject the filter value into the argument, and that works fine, but the next time I change a filter and refresh the view, the URL changes to that previous value while showing the new value.

`/browse/(term id of last selection)?category=(term id of new selection)` aka `/browse/111?category=333`

How can I discard this url change and keep things how they work the first time?

```
function MODULE_views_pre_view(&$view, &$display_id, &$args) {
  switch ($view->name) {
    case 'resources':
      if ($display_id == 'page_1') {
        if ($_GET['category']) {
          $args = array($_GET['category']);
        }
      }
    break;
  }
}

```

# Answer
The exposed filter form is always going to add a query string to the current URL as it's a simple GET form.

You need a form with a submit handler that redirects to the argument based path. You could do this to the existing exposed filter with `hook_form_FORM_ID_alter` or create a custom form and expose it in a block.

To make the existing form redirect you'd need to do something like:

```
function mytheme_form_views_exposed_form_alter(&$form, &$form_state) {
  $form['#method'] = 'POST';
  $form['#submit'] = array('mytheme_redirect_taxonomy');
}

function mytheme_redirect_taxonomy($form, &$form_state) {
  $form_state['redirect'] = '/browse/' . $form_state['values']['category'];
}

```
> 0 votes

---
Tags: views, hooks
---


title: "Add to cart" form tweaks

text:
# Question
Title: "Add to cart" form tweaks
I am setting up a very simple Drupal commerce site for a few courses with 3 product variations for different price levels. I created a product type "Course Registration" and gave it these payment options:

* DEP|Deposit
* EB|Early Bird
* FULL|Full Price

I have a content type "Course Display". On the bottom of a product display page I get this:

Payment Option
o Deposit
o Early Bird
o Full Price
\[Add to Cart\]
$250

From what I've been able to figure out the radio buttons and submit button are displayed part of the "Add to Cart form" widget for 'product' field. The price is coming from the 'Product: Price" field. I would like have the price show above the submit button like this:

Payment Option
o Deposit
o Early Bird
o Full Price
$250
\[Add to Cart\]

I assume this means getting the "Add to Card form" to show the price? I'm at a loss for how to proceed.

# Answer
> 4 votes
You can add the rendered field into the add to cart form like this:

```
function mytheme_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state, $form_id) {
  $product = $form_state['default_product'];
  $view_mode = $form_state['context']['view_mode'];
  $form['price'] = field_view_field('commerce_product', $product, 'commerce_price', $view_mode);
}

```

---
Tags: commerce
---


# Question
Title: How do I modify Drupal so that ONLY relative URLs are used through the whole site?
I have a client who says that he is unable to view his company's website from inside his company's building. Their network engineers have asked to make sure that DOMAIN.COM is not included in any of the URLs generated by Drupal.

They want only relative paths everywhere in the code. Any insights?

# Answer
> 1 votes
You can alter all Drupal generated URLs to make them root relative using hook\_file\_url\_alter

```
function mymodule_file_url_alter(&$uri) {
  global $base_path;

  $scheme = file_uri_scheme($uri);

  if (!$scheme || $scheme == 'public') {
    if (!$scheme) {
      $path = $uri;
    }
    else {
      $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
      $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
    }

    // Clean up Windows paths.
    $path = str_replace('\\', '/', $path);

    $uri = $base_path . ltrim($path, '/');
  }
}

```

For links in content you can apply the filter supplied by Pathologic

# Answer
> 0 votes
Dan, I believe this can be achieved within apache and the .htaccess file under mod rewrite. http://httpd.apache.org/docs/2.0/rewrite/rewrite\_guide.html

---
Tags: uri
---


# Question
Title: Duplicated results using fields from relation File Usage: file
I have a content type with a field image and a field file. I made a simple view to get all items of that content. I included in my view a relation ¨File Usage: File¨ to get some data like file size, upload date and uri of file field and for using VBO to download all files.

Now Im getting duplicate results, all data (file size, upload date, vbo) for image field and the same for file field when I just want to get the information for the file field, the image is just a thumbnail. Any ideas of how to get real results over duplicates?

# Answer
You need to add a File relationship for a specific field, not a File Usage relationship.

In the options for 'Add relationships' select the 'File' filter and you should see an option for each field e.g. 'File: Content using My Field'. Use this and it will give you the same data (file size etc.) but just for files attached to that field.
> 1 votes

# Answer
You can use aggregation settings to yes.

1. Go and edit your view
2. In FIELDS or FILTER CRITERIA section, select and apply Aggregation settings for which fields you want to group by or distinct.
> 1 votes

---
Tags: views
---


# Question
Title: How do I make link act like a view or a view look like a link?
Good morning!

I want to create a link that displays a node, the most recently created for example. What is the best way to do that in Drupal?

I have a menu link that does what I want with: moneymap/Pro/EURUSD/Day?sort\_by=field\_map\_id\_value&sort\_order=DESC but I don't know how that works or how to make that work in an HTML link.

I've made a few views but still a beginner? How should I proceed?

Thanks!

# Answer
> 0 votes
* Easiest way to achieve above is using Views
* Create a new view with block view

* Sort Content by Post Date
* Select fields as Content Display and show only one item
* Enable the block by Navigating to blocks list page "admin/structure/block"

Please find the view code which you can simply import using "admin/structure/views/import"

```
$view = new view();
$view->name = 'latest_node';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Latest Node';
$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'] = 'Latest Node';
$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'] = '1';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* 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';
/* 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;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');

```

---
Tags: views, routes, navigation
---


# Question
Title: Show links only to sub menus items, not to parent menu
I added some links to Main menu and created sub links for it. Now the problem is that I've to give url to the parent menus of sub links. I want it to be disabled. Links should be for sub menus only. How can I do it. Please help. In the pic, I don't want link for 'Contact us

>

# Answer
Use Menu item container module, containers have no URL path associated with them. So they are not links, just regular text

> By default, the Drupal menu system only allows you to add menu items that are links. With this module, you can add menu items that are simply containers, and not links.

also look into Special menu items and Menu Firstchild modules.
> 0 votes

---
Tags: routes, theming, navigation
---


# Question
Title: How to create webform according to user rules
I wanted to create a "Contact Us" webform, which should have following fields-

1. Name
2. Email Address
3. Contact No
4. Message

For an anonymous user, all of these fields should display.However for logged in user, field 1, 2 and 3 should not be displayed.

I don't see any option in webform to set a filed in such a way, so that only anonymous user can see it.

I tried to create two webform and assigned different-2 submission access but unknowingly now the website is having two menu items.

# Answer
> 1 votes
You can do it with Webform Component Roles, this module provides a way to allow access to each webform component to only selected roles.

> This module will allow webform creators to restrict which roles can use webform components per webform.

# Answer
> 2 votes
you need to try this coding

```
function _form_edit_module_form_alter(&$form, &$form_state, $form_id) {
 if($form_id =='webform_form_id') {
  //check login user enter in site
  global $user;
  if ($user->uid) {
     $form['component_name']['#attributes']['disabled'] = true;
  }
 }
}

```

and also you need check **Webform Conditional module**

---
Tags: webforms
---


# Question
Title: hook_preprocess_node() or hook_node_view() for html altering the field
What's the best way to alter html of an image field? I have imagefield and i want to rewrite it's html from scratch.

# Answer
> 3 votes
hook\_preprocess\_HOOK will do the job,

You may also take a look at writing your own `theme_image_formatter()`

It could work in a node\_view() but you want to alter the FIELD's HTML.In node\_view you would alter the order of fields, hide/show new contents NOT control how they look.. you could absolutely do it, but it will not be the best/Drupal way.

Drupal divides functionality (node\_view()) and looks (theme)

In a hook\_preprocess\_node() you would alter the node template variables, not the field's ones.You would need it to add a class to a node wrapper, to change node templates etc... you have to go deeper in the theme for this one.

**Examples:**

```
// ALL IMAGES get rounded class.
function YOURTHEME_preprocess_image(&$variables) {
  $variables['attributes']['class'] = array('rounded');
}

```

and for field

```
// If field_images in FULL view mode of a node, add/edit variables and choose template
function YOURTHEME_preprocess_field(&$variables) {
  if ($element['#field_name'] == 'field_images' && $element['#bundle'] == 'YOUR_NODE_TYPE' && $element['#view_mode'] == 'full') {
 $variables['theme_hook_suggestions'][] = 'field__field_images_YOUR-file-name';
  // Add more variables available in template...
  $variables['toggle'] = 'Read the story';
  $variables['some_text'] = 'Some text';

}

```

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


# Question
Title: custom block's BLOCK_VISIBILITY_LISTED not working on profile installation hook_install()?
Why this cannot work in my profile installation?

```
array(
  'module' => 'views',
  'delta' => 'views-block',
  'theme' => $default_theme,
  'status' => 1,
  'weight' => 0,
  'region' => 'map_region',
  'visibility' => BLOCK_VISIBILITY_LISTED,
  'pages' => '<front>',
  'cache' => -1,
),

```

Is just a copy of standard's profile hook\_install() and i add a views block installed with the profile in $blocks array.

All is set right except block only visible in front page ("front" is set correctly in the block config 'pages' but the visibility setting is stuck to 'All pages except those listed')

Looks like the system module re-sets them upon install.

# Answer
> 0 votes
I had to do this in a module that gets installed after all other modules installation in the profile using

> hook\_install\_tasks()

and in the the new task's callback i enable the module with module\_enable

---
Tags: blocks, installation, installation-profiles
---


# Question
Title: Content subscriptions/notifications from multiple terms?
I have a clothing site where multiple taxonomy vocabularies are used for content. For example, there are "Boys" and "Girls" terms, and clothing size terms such as "2" "4" "6" etc., as well as "Seasons" and "Sport" vocabularies.

A user only wants to be alerted when "Boys" "4" "Basketball" new content is posted.

I am aware that modules such as Notifications, Subscriptions, Simplenews, etc. exist -- but these only allow for new content notifications based on a single taxonomy term.

Could this be done with Rules (e.g. content type that contains each users' subscribed terms)? Or some other way, perhaps using Flag?

# Answer
> 1 votes
I have a similar use case for my site. What I do is utilize views loops. I create a view rule that accepts multiple taxonomy terms (I use AND rather than OR. I think you would too). Any user who has all the items in their profile is then sent a PM when on Create New Content. It's not terribly elegant but it works. I think it may be a bit too restrictive. But Them's the breaks.

# Answer
> 0 votes
you can use my module for this Total Subscription.

> Total Subscription provides functionality which would allow the user to subscribe to node pages, taxonomy terms, etc. The main feature which distinguishes it from other subscription modules is that it allows subscription for Anonymous along with Authenticated users.

---
Tags: taxonomy-terms, rules, notifications
---


# Question
Title: how to notificate users about new created referenced nodes
I have a content type called "A" and content type called "B". When a user creates node "A" other users can create node "B" referenced to node "A". How can i notify user which created node "A" about newly created nodes of type "B" referenced to his node "A"? I've tried notifications module but as i can understand there's no such options for that.. Tried this solution: how to create rules to send email notification for node reference content? but it's not working on D7

# Answer
I think you can accomplish it by creating a custom module. Whenever users create nodes of type *B*, you can mail and notify those users who created nodes of type *A*.

You can get the list of users who created nodes of type *A* with a SQL query like the following.

```
SELECT DISTINCT uid FROM node WHERE type = 'goals'

```

In order to send mails when users create nodes of type *B*, you will have to implement `hook_node_insert()`, so that you can send notifications after nodes are successfully created. You could also use `hook_node_presave()`; the only difference is that the latter will send mails before nodes are created.

```
function MODULE_NAME_node_insert($node) {
  if ($node->type == "B") {
    $params = array();
    $from = variable_get('site_mail', 'admin@example.com');
    $send = TRUE;
    $language = language_default();

    // It is assumed that array od users who created node of type "A" is returned
    // by the following function.
    $users = _list_of_user_created_A_node();
    foreach ($users as $key => $value) {
      $uid = $key;
      $mail = $value;
      $params['node_title'] = $node->title;// The node title of the created node B
      $params['userID_A'] = $uid;
      $params['mail_of_user_A'] = $mail;
      drupal_mail('MODULE_NAME', 'notify_mail', $mail, $language, $params, $from, $send);
    }
  }
}

```

See `hook_mail()` on how sending mails.

You could also save the node titles in a database table, and send mails during cron task's execution.
> 3 votes

# Answer
you can use my module for this Total Subscription.

> Total Subscription provides functionality which would allow the user to subscribe to node pages, taxonomy terms, etc. The main feature which distinguishes it from other subscription modules is that it allows subscription for Anonymous along with Authenticated users.
> 0 votes

---
Tags: 7, notifications
---


title: Email Subscriptions with Verification

text:
# Question
Title: Email Subscriptions with Verification
I feel like I'm missing something, because I can't find a module that does this, but it seems like it should be really common.

I would like users to be able to simply enter their email address to subscribe to my site so that I can send them an email whenever I post a new Article. I don't want to require them to create a full drupal account, just a simple email address and then click a verify link.

I've tried Simple Subscription and it provided a simple form block which provides essentially what I'm looking for on the front end:

However, when a user enters their email address this module doesn't provide a verification email. So, I need something more complicated that Simple Subscription.

Any suggestions?

# Answer
Simple subscription validates email address. It did work for me. I used the latest version of the module.
It also provides a hook `hook_simple_subscription` which allows modules to do something with the simple subscription form results such as sending email for subscription verification.
> 3 votes

# Answer
you can use my module for this Total Subscription.

> Total Subscription provides functionality which would allow the user to subscribe to node pages, taxonomy terms, etc. The main feature which distinguishes it from other subscription modules is that it allows subscription for Anonymous along with Authenticated users.
> 1 votes

---
Tags: 7, notifications
---


# Question
Title: What is the proper way of using existing fields?
I'm a Drupal beginner. I'm a bit confused about adding fields to content types.

**Case 1:** Suppose if I have three content-types `Book`, `Article` & `White Paper`. I created `Authors` vocabulary which contains list of all Authors.

1. Now, Should I create "Written by" field (term-reference to Authors) for each content-type or create the field for one content-type and use it in other content types?
2. What are advantages/disadvantages of either methods?
3. What happens if I delete a reused-field from one content-type? Does it get deleted in all others?

**Case 2:** I've follwing content-types: (with specified field requirements)

```
+--------------+----------------------+
| Content Type | Field Required       |
+--------------+----------------------+
| Book         | Year of publication  |
+--------------+----------------------+
| Presentation | Date of Presentation |
+--------------+----------------------+
| Article      | Date of Publication  |
+--------------+----------------------+
| Event        | Held On              |
+--------------+----------------------+

```

What should I do? Should I create a single field for one content-type & use it for all other content-types or create field for each content-type?

Help me understand clearly when & how to appropriately re-use existing fields.

# Answer
> Should I create "Written by" field (term-reference to Authors) for each content-type or create the field for one content-type and use it in other content types?

If you need to collect the same information for different content types, you should use a single field. Your "Written by" field sounds like the perfect case for that. If you had different vocabularies for your authors, say "Book author", "Article author", etc, you'd want (and need) to use separate fields for each.

> What are advantages/disadvantages of either methods?

One advantage is that you can query all content types by the one field. So if you find yourself wanting to view all content written by a single author, or even all content written by all authors, it will be easy to create a view to do that. But that's only useful if you need it, obviously. I suppose the main point is that the use case of the field itself will actually dictate the relative advantages/disadvantages of either method.

Also, whenever you create a field, you create two database tables (one for current data, one for revision data). There are, shall we say, "mixed" feelings about whether this method of storage is the best idea from a performance standpoint, and some people prefer to keep the number of tables down. When you attach an existing field to another content type, the same database table is used for all of them, so that box gets ticked. Again though, this only makes sense when your data can be separated.

> What happens if I delete a reused-field from one content-type? Does it get deleted in all others?

The field will only be deleted once it has been detached from all content types. Data that belongs to the content type from which you detached the field will be moved into a deleted data table, and purged during cron runs.

On to case 2, and just ask ask yourself this...

Keeping in mind that you can have different labels for each content type's instance of the same field, will that give you enough of a visual (or data-led) cue to let you know the differences between the data?

If so, use a single date field to gain the advantages mentioned above. If not, then it makes more sense to your data design to have separate fields.

It all comes down to what's appropriate for your particular website, but hopefully the above will give you some sort of way forward.
> 8 votes

---
Tags: entities, nodes
---


# Question
Title: How to have a node which displays & interacts differently with different type of users?
Title might not be very clear. But to clarify my question, I'll take example of a Book Content Type.

I've 3 different types of users: Authors, Reviewers, Admin. Now this is what I want to achieve:

On the Book Page \[a display which is shown to even unauthenticated user\], Registered Reviewer submits a review for a book which should appear in `Approve Reviews page` of Admin, When the admin approves it should Appear in respective Author's `Reviews for my books page` and when finally the Author approves, it should be displayed on the Book Page.

And the reviewer must have a `Submitted Reviews page` which should list all the reviews he submitted each showing its present status like:

"Waiting for Admin's Approval", "Waiting for Author's Approval", "Approved"

I don't know how to achieve this.

# Answer
> 1 votes
What you are talking is called a workflow. For `Review` content-type you need to setup a workflow. You can use `workflow` module for that. It needs a bit of training. Search Google/Youtube for "Workflow module drupal"

# Answer
> 1 votes
There are many ways to accomplish this but here's one:

1. create content type Book
2. create content type Review
3. add a custom status field to Review (select list) and add the three states (admin approval, author approval, approved)
4. download and enable references module (also enable submodule node reference)
5. download and enable rules module (also enable rules ui submodule)
6. add a node reference field to Review (e.g. autocomplete widget)
7. create roles admin\_reviews, author, reviewer
8. create view lists for reviews content and set permissions per role for admin\_reviews, author and reviewer pages. Filter on field status of review for each role
9. use field permissions module to show / hide fields per role
    1. create rules to set status of review (After saving new content -\> set data value)

---
Tags: users, comments
---


title: sign-up pop-up on webform

text:
# Question
Title: sign-up pop-up on webform
I'm going to make a sign-up website. When the user has clicked on Sign-up link it will take them to this pop-up window on the browser itself giving them one option (to input mail) then a submit button. I know how to setup the thing in webform but how do I make a sweet pop-up window for the user to enter the value? Is there any module for this?

Any suggestions are welcome

thanks

# Answer
> 1 votes
The Modal Form Module supports modal window for `webform`, you can also use shadowbox module which creates a modal window for anything.

---
Tags: webforms, javascript
---