# Question
Title: Tools to create registration site with calendar and jQuery/ajax
I belong to a volunteer organization that uses a painful .NET site for signing up for shifts (for example, you can change registrations for anyone, not just yourself), so I'm looking to create a Drupal site that can handle this process much easier and also allow admins to make changes without having to pay someone to make changes when needed.

You can see the current site below. Each column is a day, the numbers (140, 148, etc.) are the stations, and the second column is the position. At one glance, you can see who is signed up on a given day and at which station. This is just one small part of the entire page, which is a calendar view of a whole month.

What I would like to do is create a "Register" button for each slot that uses ajax when clicked that would register the user for the shift and replace the button with the user's name (after doing some validation, such as making sure the user isn't signed up for another slot at the same time, they have permission for that slot, etc.).

The trickiest part is creating the custom form and then displaying it in the calendar. As with any Drupal site that needs a calendar, I'm looking at the Calendar and Full Calendar modules. Both seem to require nodes with date fields and Views displays to show a calendar, so I'm guessing I would need to create something like a Shift entity with a date field and then create the node via the ajax code. The bigger question is how to create the custom form and display it in the appropriate date in the calendar. Is it a matter of creating a custom Views display handler for the form, or is there a simpler way? Once I figure that part out, the rest will be pretty easy.

Thanks.

# Answer
> 0 votes
For the sake of answering this question, I spoke with Tim Plunkett (creator of the Full Calendar module), and after explaining my use case, he said there really wasn't anything to be gained by using Views, especially with all of the custom work I would need to do to get my signup links inside a calendar. I've decided to just go with a custom module that will give me the control I need, both over the node creation and the calendar display.

# Answer
> 0 votes
Creating the form should be as easy as simply as creating a content type and populate it with your needed fields. This content type will have the date, the stations, etc etc.

Then, using views will be as easy as list your nodes. If you need to display them in a calendar you can customize your view using third modules, calendars or customizing your own view.

Good luck :-)

---
Tags: ajax, datetime, users, javascript
---


title: Set value field before submit

text:
# Question
Title: Set value field before submit
I'm trying to set a value before the form is submitted. The field is calculated by two other fields. One of them is a property of an entity reference. This is what I do:

```
function nodeoverlay_node_submit($node, $form, &$form_state) {
    if($node->type == 'zoekertje')
    {
        $korting = $form['field_field_korting']['und'][0]['value']['#value'];
        $node = field_get_items('node', $node, 'field_product_zoekertje');
        $node = node_load($node[0]['target_id']);
        $aankooprijs = $node->field_aankoopprijs['und'][0]['safe_value'];
        $price = floatval($aankooprijs - (($aankooprijs/100)*$korting));

        $form['field_verkoopprijs']['und'][0]['value']['#value'] = $price;
        $form['field_verkoopprijs']['und'][0]['value']['#default_value'] = $price;

        $form_state['field']['field_verkoopprijs']['und']['instance']['default_value'] = $price;
        $form_state['values']['field_verkoopprijs']['und'][0]['value'] = $price;
    }
}

```

I've tried different things to set my value of the field `field_verkoopprijs` but the result is always empty (and yes, my $price variable contains a float variable).

What can I do?

# Answer
From hook\_node\_submit():

> This hook is intended for adjusting non-field-related properties

I think the proper place for this will be hook\_node\_presave() . To change field there you need to set, for example:

```
$node->some_field_name[LANGUAGE_NONE][0]['value'] = 'your value';

```

If you want to set reference field then:

```
$node->some_reference_field_name[LANGUAGE_NONE][0]['target_id'] = 'your value';

```

You may also want to consider using computed\_field module for this.
> 1 votes

---
Tags: entities, forms, nodes
---


title: styles unlimited value image fields

text:
# Question
Title: styles unlimited value image fields
I use unlimited values for image field in a content type, then the images displays one below the other :

Is there a way to render this field differently? For example every line show me only three images.

Im using `display_suite` module to display the node content.

# Answer
> 1 votes
CSS. Your fieldset should be wrapped in one big div, with each field-item wrapped in it's own div. I see no reason you couldn't do this with CSS alone.

Unless there's a specific reason you need each line to be exactly three images. In that case you would have to override the field template: https://drupal.org/node/1089656

Then you would have to write some basic PHP logic that counts the number of field items and print those out in a 1X3 display.

# Answer
> 0 votes
You can do this by adding CSS for the row

.class-of-the-row { display: inline-block; width: 33.3333%; }

---
Tags: 7, media
---


# Question
Title: Maintain same node ID's when importing nodes
I am using Node Export with Features module, and then importing content while installing my profile. All works fine, but I want the node ID's to be retained while importing. I want it to be in same order as the source site.

Can I do this?

# Answer
> 1 votes
I think more detail here would clarify the question and help generate better answers.

* Are you moving to a new server?
* Importing content to another site that already has other content?
* Why are you worried about preserving the NIDs? External dependencies?
* Is order the only concern, or the actual NIDs themselves?

A couple of thoughts here that may help:

1. A core-rsync/sql-sync or sql-dump using drush and import would maintain node IDs and machine names for all items. This does not involve 'features' in any way, and is more of a core operation which would would clone your install, overwriting any differences on site #2. Beware.
2. If you're only doing this once (and are only concerned about the NIDs), an `ALTER TABLE node
AUTO_INCREMENT = XXX;` (where XXX=your first old NID) statement in mySQL on your target Database BEFORE you import your nodes might help. This would not work, however, if you're not exporting a non-sequential NID list of nodes (i.e. 64, 65, 68). It also would most likely fail/destroy your target site if it already has NIDs that are greater than the first NID of the source (or any matching NIDs).

# Answer
> 1 votes
In short no (not easily/safely anyway).

If you're looking for specific content ID's, you may want to look into putting the UUID module on your source/destination site. As far as I'm aware, this will allow you to keep a unique identifier on your nodes that match across sites, even though the node ID's will be different.

# Answer
> 1 votes
Yes, with a little work.

First, disable auto increment on node.nid & node\_revision.vid. Details an exercise for the reader.

Second, create a custom module w/ one function in it, say mymodule\_ns($node).

copy and paste the contents of node\_save from api.drupal.org into your function.

then (this current as of drupal 7.28) change the line in the else for

```
if($node->is_new)

```

that says

```
drupal_write_record('node', $node, 'nid);

```

to

```
drupal_write_record('node', $node);

```

Then change the line in the else under the

```
if($!empty($node->revision))

```

that says

```
_node_save_revision($node, $user->uid, 'vid');

```

to

```
_node_save_revision($node, $user->uid);

```

Enable the module.

Finally, create your nodes programmatically as usual with these changes:

1. set $node-\>nid = $node-\>vid = whatever you want on your object.
2. set $node-\>log to something non empty, say "imported node" or whatever you want.
3. call mymodule\_ns instead of node\_save.

Don't forget to turn auto increment back on on node & node\_revision tables, and set the auto increment value to something greater than the highest nid you imported.

Happy hunting.

---
Tags: 7, nodes, features, importing-exporting
---


# Question
Title: How does Strongarm decide which variables need to be included in a feature
When you enable Strongarm on a site that is already using Features, do these two modules work together to determine which Strongarm variables need to be included in a Feature, or is there additional work that needs to be done to ensure that the correct Strongarm variables are included?

If more work is needed, what needs to be done?

# Answer
> 0 votes
Strongarm provides a component to features where you can manually select the relevant variables to export with that feature.

Some variables may be included by default, e.g node\_type variables when exporting a node type, others may need to be manually checked and exported with the feature module.

---
Tags: 7, features, strongarm
---


title: Weird behaviour when using dsm

text:
# Question
Title: Weird behaviour when using dsm
I am using Drupal 7 on a CentOS 6.5 box. I am trying to debug some code which produces the following error:

> User error: ImageMagick error 1: convert: no decode delegate for this image format `/tmp/thesis-163.OBJ.xml' @ constitute.c/ReadImage/503.
>  convert: missing an image filename` jpg:/tmp/thesis-163.OBJ.PREVIEW.jpg' @ convert.c/ConvertImageCommand/2800. in \_imagemagick\_convert\_exec() (line 519 of /var/www/html/sites/all/modules/imagemagick/imagemagick.module).

I can see that the problem is caused by the fact that ImageMagick is trying to make jpg out of a xml file. What the error is about, isn't really the issue. The issue is that, when I insert a dsm statement to check what is going and run the program again, the error goes away. If I comment out the dsm statement and run the program again the error returns. I have never seen this type of behaviour before and can't explain it.

Unfortunately, I can't reproduce this behavior with a small snippet of code otherwise I would post it here.

Can someone explain why this is happening so that I can fix it?

# Answer
> 1 votes
You may be experiencing a Krumo side effect:

https://drupal.org/node/1855468

The problem is that PHP handles references to array elements in a risky way, see this article: PHP: References To Array Elements Are Risky

I haven't read the post deeply, and can't assure you have this problem, but you may try the workaround to see if it works: use Krumo NG.

Another way is to use dd to dump your traces to a file, see functions documentation: https://api.drupal.org/api/devel/devel.module/function/dd/7

# Answer
> 0 votes
May want to try one of these or some combination of them. Sometimes dsm gives me weird behavior and I have to resort to one of these.

```
print '<pre>' . print_r($your_item) . '</pre>';

print '<pre>' . dsm($your_item) . '</pre>';

drupal_set_message('<pre>' . print_r($your_item,true) . '</pre>');

```

---
Tags: 7, debugging
---


# Question
Title: Why does advancing/retreating the month remove all events from the calendar in FullCalendar?
http://bit.ly/1jrzpIx

1. Visit the link noted above. See the calendar. See the calendar events.
2. Now advance to the next month using the arrow buttons near the top left.
3. Now go back to the current month. Observe that the calendar events have disappeared. This is not expected behaviour.
4. Now change the view so that you are in week or day mode.
5. Now return to the month mode and observe that the events have re-appeared on the current month.

Objective: Fix this calendar so that it retains its current functionality but does not lose the events when the months are paged through.

More information: This is Drupal v. 7.26. (latest)

And you can find the Drupal FullCalendar module here: https://drupal.org/project/fullcalendar

And here is a bug report that I think deals with this issue, at least they seem to be related. My post is near the bottom of this thread. I've turned off AJAX so I don't think that's the problem.

https://drupal.org/node/1864992

Here is an answer on StackOverflow on (maybe) how to fix it. I don't know how to run the eventsRender method after fullCalendar instantiates in Drupal.

https://stackoverflow.com/questions/2665469/fullcalendar-cannot-display-the-new-event-when-switch-month-back

Here is another one (maybe): https://stackoverflow.com/questions/20195156/when-switching-months-i-want-to-stop-fullcalendar-from-removing-events

# Answer
Looking at your calendar now it looks like you have it fixed. I was gonna' offer the solution that I was told: Make your site's short date format to use "2014-5-19 17:30" Unfortunately it had to be in military time, not 12 hour or it didn't work. That is only an issue when looking at the "upcoming events" that I have listed at the bottom of my calendar in another block. I was going to go the ajax method if I can get 12 hour time to work with ajax, using the fix offered for Ajax at the drupal posts on this issue; haven't tried it yet.

So what solution did you get to work for you?

Dave N
> 1 votes

---
Tags: javascript
---


# Question
Title: How Do You Make a 'Rules Link' Work in a Custom Content Pane?
I'm struggling to get a Rules Link set in a Custom Content Pane to trigger a Rules Link and work. I've done many tests and using the URL path provided by the Rules Link Edit page, (ie domain/content/post-new-content) all I get is a 404 despite my many trials and viewing/reading of info docs online.

Put simply, I want a link set on a Custom Content Pane to show a link which the user clicks, this will then trigger a Rules set to check: a) the user has valid auth/role; B) and then redirect to a Post page; if not authorised then redirect to a 'Subscription' page. Through my testing, a 'standard' link to an Add Content page works fine, so I presume it is something within the Rules/Rules Link framework I working within the D7.2x

Can someone please provide some generalism how this (assumed simple flow) should work. HELP!

# Answer
> 0 votes
To render a Rules link programmatically use the following:

```
<?php
    print render(rules_link_render('RULES_LINK_NAME', $node->nid));
?>

```

---
Tags: rules
---


# Question
Title: how to map comments in drupal migrate module
So im migrating comments from a different database to Drupal 7 but i cant understand why this wont work. Im successful with migrating nodes, i only mapped the node fields and somehow its node\_revision seemed to have automatically updated too.

But in comments it doesnt work, i know to add a comment these tables are affected in drupal:

1. comment
2. field\_data\_comment\_body
3. field\_revision\_comment\_body

am i missing some mapping here in my code?

```
$this->addFieldMapping('cid', 'id');
    $this->addFieldMapping('is_new')->defaultValue(TRUE); // i dont know what this thing does

    $this->addFieldMapping('nid', 'mainthread');
    $this->addFieldMapping('pid', 'parent')
         ->sourceMigration('ForumComment')
         ->description('Parent comment.');
    $this->addFieldMapping('comment_body', 'body');
    $this->addFieldMapping('subject', 'subject');
    $this->addFieldMapping('hostname', 'host');
    $this->addFieldMapping('created', 'date');
    $this->addFieldMapping('changed', 'last');
    $this->addFieldMapping('name', 'author');
    $this->addFieldMapping('status')
         ->defaultValue(COMMENT_PUBLISHED);
    $this->addFieldMapping('comment_body:format')
        ->defaultValue('full_html');

    /*$this->addFieldMapping('uid', 'accountid')
         ->sourceMigration('WineUser')
         ->defaultValue(1); */

    //optional
    //$this->addFieldMapping('tid', 'category_id');
    //$this->addFieldMapping('comment_count', 'hits');

    // Unmapped destination fields
    $this->addUnmigratedDestinations(array('uid', 'thread', 'mail', 'homepage', 'language', 'comment_body:language'));

      $this->addUnmigratedSources(array('category_id'));

```

and is my destination correct? here it is:

```
$this->destination = new MigrateDestinationComment('comment');

```

based on my code only the comment table is mapped, i just assumed that the body and its revision will automatically map too like in my migration of nodes.

Help please

# Answer
I got it, you need to add another class for the mapping of the body of the comment

and the destination should be 'comment\_node\_forum'
> 1 votes

# Answer
You have to follow a format here:

so instead of

```
$this->destination = new MigrateDestinationComment('comment');

```

It should be

```
$this->destination = new MigrateDestinationComment('comment_node_article');

```

Where comment\_node\_'nodetype' is a format and above the node type that I have used is "article".
> 0 votes

---
Tags: migrations
---


title: how to add conditional styles?

text:
# Question
Title: how to add conditional styles?
How can I insert the following:

```
<!--[if lte IE 9]>
    <style type='text/css'>
  #page{display: none;}
    </style>
<![endif]-->

```

I tried it in page.tpl.php but not worked.

# Answer
> 0 votes
Put it in `html.tpl.php` also it work in `page.tpl.php` but I think you did not clear cache , please dont forget this, clear cache after `templates` changes.

also you can use conditional css this link help you

https://drupal.org/project/conditional\_styles

---
Tags: 7
---


# Question
Title: Cannot figure out what's wrong with my schema
It keep saying

```
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

```

Here is my Schema:

```
function artx_partner_schema() {
  $schema = array();

  $schema['artx_partner'] = array(
    'description' => 'The base table for artx_partner.',
    'fields' => array(
      'partner_id' => array(
        'description' => 'The primary identifier for a partnership.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'User identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'Node identifier.',
        'type' => 'int',
        'not null' => FALSE,
      ),
      'product_id' => array(
        'description' => 'Identifier for a product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'reqtime' => array(
        'description' => 'time stamp of the request',
        'type' => 'datetime:normal',
        'mysql_type' => 'datetime',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'restime' => array(
        'description' => 'time stamp of the response to request',
        'type' => 'datetime:normal',
        'mysql_type' => 'datetime',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'status' => array(
        'description' => 'the status of the request, pending(0)/AC(1)/Rej(2)',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('partner_id'),
    'unique keys' => array('unique' => array('uid', 'nid', 'product_id')),
    'foreign keys' => array(
      'owner' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
      'product_display' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
      'product' => array(
        'table' => 'commerce_product',
        'columns' => array('product_id' => 'product_id'),
      ),
    ),
  );

  return $schema;
}

```

# Answer
> 3 votes
Unsigned attribute is not supported with datetime. Following code will create table for you.

```
function artx_partner_schema() {
  $schema = array();
  $schema['artx_partner'] = array(
    'description' => 'The base table for artx_partner.',
    'fields' => array(
      'partner_id' => array(
        'description' => 'The primary identifier for a partnership.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'User identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'Node identifier.',
        'type' => 'int',
        'not null' => FALSE,
      ),
      'product_id' => array(
        'description' => 'Identifier for a product.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'reqtime' => array(
        'description' => 'time stamp of the request',
        'type' => 'datetime:normal',
        'mysql_type' => 'datetime',
        'not null' => FALSE,
      ),
      'restime' => array(
        'description' => 'time stamp of the response to request',
        'type' => 'datetime:normal',
        'mysql_type' => 'datetime',
        'not null' => FALSE,
      ),
      'status' => array(
        'description' => 'the status of the request, pending(0)/AC(1)/Rej(2)',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('partner_id'),
    'unique keys' => array('unique' => array('uid', 'nid', 'product_id')),
    'foreign keys' => array(
      'owner' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
      'product_display' => array(
        'table' => 'node',
        'columns' => array('nid' => 'nid'),
      ),
      'product' => array(
        'table' => 'commerce_product',
        'columns' => array('product_id' => 'product_id'),
      ),
    ),
  );
  return $schema;
}

```

# Answer
> 2 votes
Contrary to what others have said, your use of `'mysql_type' => 'datetime'` is OK (and will work as you intend, provided the database is MySQL).

What triggers the PDOException is the use of the `unsigned` attribute. This was first pointed out in the answer *Pushpinder Rana* \- +1 from me for that. However, I would not use his suggested schema verbatim: The line `'type' => 'datetime:normal'` is not portable and *will* trigger a PDOexception if the code is ported to a site that uses a database engine that does not support `datetime`. (The fact that `datetime` is not supported by all is the reason for the change in Drupal 7.)

Use of the fallback type `datetime:normal` for the case when the DB is not MySQL will not work as you intend for *all* database engines. For portable code, you should use a fallback. I recommend that in this case, you provide a fallback type `varchar` for the case that the database is *not* MySQL.

(While this page suggests one uses `text` as a generic fallback, I prefer `varchar` for `datetime`. Both are variable length generic fields. On PostgreSQL they're equivalent, but on some other database engines, `varchar` is slightly faster for short strings such as datetime.)

I.e.: replace the relevant part of your schema with the following:

```
  'reqtime' => array(
    'description' => 'time stamp of the request',
    'type' => 'varchar',
    'mysql_type' => 'datetime',
    'not null' => FALSE,
  ),
  'restime' => array(
    'description' => 'time stamp of the response to request',
    'type' => 'varchar',
    'mysql_type' => 'datetime',
    'not null' => FALSE,
  ),

```

# Answer
> 0 votes
Below field in your schema definition is causing problem...

```
  'reqtime' => array(
    'description' => 'time stamp of the request',
    'type' => 'datetime:normal',
    'mysql_type' => 'datetime',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ),
  'restime' => array(
    'description' => 'time stamp of the response to request',
    'type' => 'datetime:normal',
    'mysql_type' => 'datetime',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ),

```

Try removing type attribute.. It should support mysql\_type attribute..

Drupal doesn't support field of type datetime. It's removed from Drupal 7.

Find more information below..

https://drupal.org/node/159605

---
Tags: database
---


title: show the rate of tax in order

text:
# Question
Title: show the rate of tax in order
I've create Tax Rate of 20% in VAT type of tax.

It is now displayed in the checkout process and in order view.

What I want now is to show the rate i have created, which is 20%, in the checkout and in order?

Any help will be greatly appreciated.

Thank you!

# Answer
> 1 votes
Not sure if this is what you want to do but could you just not rename the display name of your tax to 20%?

Go to admin/commerce/config/taxes click edit on your tax and under display title enter 20% tax or what you wish the display name to be.

---
Tags: commerce
---


title: Drupal webform with sortable report

text:
# Question
Title: Drupal webform with sortable report
I want the **webform** submitted **report** to be **sortable** (or filtered), suppose there is the "Country" field in the form with **selectlist** of Countries,

I must be able to filter the reports with specific value,suppose "USA" or something else.

Thank you.

# Answer
> 0 votes
You could use Views to render a table view of fields (for Country, etc) and set the content filter of that view to pull only submitted webforms.

# Answer
> 0 votes
You can do it easily with Webform Report module, using filters.

* Install and configure the Webform Report module
* Go to content \> add new content \> webform report
* Select a webform which you want to extract a report of submissions
* In "Report Criteria" section, select all the components (fields) from the webform that you want to display on your report.
* select the fields you want to use to create a filter, In your case choose:

Type de filtre= equal, and Filter Value= USA

---
Tags: forms, webforms
---


# Question
Title: How to add a dynamic select field to a content type form?
I would like to add a dynamic select field where options change from time to time. New options will be added along with old options in future. I know i can add form element using hook\_form\_alter and save values using node api in custom table created using install file of a module.

Is there any inbuilt mechanism where i can create a field and avoid dealing with schema and schema related queries ? My only concern is field should support dynamic options in future... Something like select field values will be pulled using a query.

PS: I hope above questions is not primarily opinion based. I believe many Drupalers might have faced above situation :-) Please do add a comment if form alter approach is the right one !

# Answer
You can probably do that using the field API and setting an `allowed_values_function` for the list field.

e.g:

```
/**
 * Implements hook_form_alter
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id){

  if ($form_id == 'field_ui_field_settings_form') {
    // Make the allowed_values_function editable as a textfield
    // Possible to inspect $form or $form_state to vary by field
    if(isset($form['field']['settings']['allowed_values_function'])) {
      $form['field']['settings']['allowed_values_function'] = array(
        '#type' => 'textfield',
        '#title' => t('Allowed value function'),
        '#description' => t('Returns an array of allowed values'),
        '#default_value' => $form['field']['settings']['allowed_values']['#field']['allowed_values_function']
      );
    }
  }

}

```

The `allowed_values_function` then returns an array of values for the field.

e.g:

```
/**
 * Allowed values callback
 */
function MYMODULE_custom_field_allowed_values($field){

  if(CONDITION){
    return drupal_map_assoc(array('A1','B1','C1'));
  }elseif(OTHER_CONDITION){
    return drupal_map_assoc(array('A2','B2','C2'));
  }

}

```
> 2 votes

---
Tags: nodes, database
---


# Question
Title: Problems rendering drupal 7 user registration form with ajax in BootStrap 3 Modal
I have a subtheme based on bootstrap 3 and am trying to load user registration form(user\_register\_form) on front--page.tpl.php, I am adding #ajax to the submit button using form\_alter

```
     $form["actions"]["submit"] = array(
        '#type' => 'submit',
        '#ajax' => array(
            'wrapper' => "user-register-form", "effect" => "fade",
            'effect' => 'fade',
            'callback' => 'my_form_submit_handler',
            'method' => 'replace',
        ),
        '#value' => t("Sign-up"),
        '#id' => 'user_register_form'
    );

```

I am rendering the form in two places on the same page (a) in a div which is a regular div and (b) in a bootstrap modal div as mentioned here http://getbootstrap.com/javascript/#modals

```
     <?php
            if (user_is_anonymous()) {
                $form = drupal_get_form('user_register_form');
                 print drupal_render($form);
            }
     ?>

```

in case (a) the ajaxified form works very well, however in case (b) the form is no longer ajaxified , the submit button does not have the "ajax-processed" class attached.

I intend to open all my application forms using bootstrap modal and ajax however i am not able to do this as of now. I want to know the right way to load any ajax form in bootstrap modal dialog I know this is a fairly common problem with modal dialogs and drupal forms, but i am yet to understand what the reason behind this behaviour, any help or direction will be highly appreciated.

There is one more similar question that is unanswered here Drupal load form with ajax callback in Bootstrap modal

# Answer
> 0 votes
By rendering the user registration form twice, duplicate form id's were being created. After recreating the second form with a different ID, things are good.

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


title: Checkboxes not rendering

text:
# Question
Title: Checkboxes not rendering
All the other form elements render properly. Radios and Checkboxes do not. The title and descriptions show up, but not the boxes or radios.

```
$options7 = array();
foreach ($resqry1 as $option)
{
  $options7[$option->id] = $option->id;
}

$form = array();
$form['lis'] = array(
  '#type' => 'checkboxes',
  '#options' => $options7,
);

return $form;

```

Please help me out. Thanks

# Answer
> 0 votes
I faced similar situation while trying to inject checkboxes to user\_register\_form. I think checkboxes type is not valid type for typical rendering. Form elements of type checkboxes get totally reformatted within form\_builder after form\_alter hooks have executed. Make sure that form builder runs after you place your field.

---
Tags: 7
---


# Question
Title: how to migrate a multi-value term reference field?
I am setting up a drupal migration where the destination node contains a multi-value taxonomy term\_reference field, called `'field_features'`. The machine name of the drupal taxonomy vocabulary of the field is called `'voc_features'`.

My field mapping for this field is configured like this:

```
$this->addFieldMapping('field_features:create_term')->defaultValue(true);
$this->addFieldMapping('field_features:ignore_case')->defaultValue(true);

//i don't have tid's in the source, so i leave the source_type for what it is
$this->addUnmigratedDestinations(array('field_features:source_type'));

//i link the drupal vocabulary to the multivalue field.
$this->addFieldMapping('voc_features', 'field_features')->separator('|');

```

The terms are added in the `'voc_features'` vocabulary, but not in the `'field_features'` field.

When i add the field mapping like i do with all the other fields:

```
//my source fields have the same name as my destination fields
$this->addFieldMapping('field_features', 'field_features')->separator('|');

```

i get the following error:

*strtolower() expects parameter 1 to be string, array given File ...\sites\all\modules\migrate\plugins\destinations\fields.inc, line 402*

Other single value term\_reference fields import just fine. What am i missing?

# Answer
> 4 votes
Yes. The migration of term doesn't allow to migrate multi-value. You have to process the source ahead.

1. Create a new migration and import the data to terms of vocabulary named `'voc_features'` at first.
2. Add a dependence to your current migration using previous migration. Such as `$this->dependencies = array('MigrateXXXMigration');`.
3. The field mapping should be like this,`$this->addFieldMapping('field_features', 'Features')->arguments(array('source_type' => 'tid'));`
4. In the `function prepareRow($row)`, you should prepare the `Features` field and put it into your `$row` variable. `$row->Features=array(tid1,tid2,tid3);`. The 'tid1','tid2' and 'tid3' should be replace the live tid from your term tables.

# Answer
> 0 votes
Looking at the code for migrate module it seems to be a bug in the module.This issue happens when ignorecase is set to true while migrating multivalue fields. You may want to open a new issue in ALB migrate module.

# Answer
> 0 votes
I'm working on a migration also at the moment. I agree with Tony that you could write something using prepareRow() that would achieve what you want . Could you post your full extension class of RcnMigrateMigration, I'll see if I can make any sense of it.

---
Tags: taxonomy-terms, migrations
---


# Question
Title: Why file field button disappeared while uploading file?
I have installed fresh drupal-7 and create file upload field with manage field with 8M Maximum upload size. when i upload a file 25MB then it is showing error message and file field missing. **Before upload:** **After Upload:**

After long search i got some links "exceeded the maximum file size" error even when uploading small files File upload error "Files must be less than x MB" despite file being smaller than x By these link my problem sorted out but my question. **why the file upload field button disappeared?**. **My php.ini settings are**

post\_max\_size = 24M upload\_max\_filesize = 512M

# Answer
> 1 votes
its a default bug in drupal.

you can try this patch ! your problem will be solved

https://drupal.org/node/1489692

# Answer
> 1 votes
Don't set `upload_max_filesize` larger than `post_max_size` if you are not using any library that takes care for such cases. Plupload integration with FileField Sources Plupload can get it managed for you.

Currently you are confusing your Drupal by allowing file upload larger than allowed data size. Given that data posted is file size + metadata size, both always equal to or greater than 0, it makes no sense and Drupal may fail.

Specifically, button disappeared because Form or Field API crashed, and it crashed because you mismatched sizes without providing appropriate handler.

---
Tags: 7, hooks, files
---


# Question
Title: VBO action 'Modify OG user roles' does not show custom OG roles on the 'Add roles' list
I have added new OG roles like 'tutor' or 'contributor'. I am using the view og\_members\_admin that comes with drupal commons, which uses view bulk operations 'Modify OG user roles' to give an admin the ability to add or remove certain roles. However, the only role selectable that I can add or remove is the default 'administrator member', despite the fact that I am user 1. Is there any further configuration that needs to be done to expose those custom added roles to that list?

Edit: when I try to add a user (through group/node/%/admin/people/add-user) the only role shown in there is also 'administer member', so this must be some site-wide configuration that is missing?

# Answer
> 0 votes
It turns out that new roles are not visible to already created groups. When I create a new group I can see the added roles. However there should be a way to make existing groups 'see' newly added roles...

---
Tags: organic-groups, users, 7
---


title: The right way to validate fields

text:
# Question
Title: The right way to validate fields
Rather than creating a new field via the Field API, and as a quick workaround, I've added a simple text field to a content type that I'm now attempting to validate via `hook_node_validate()`. Unlike previous versions of Drupal, the value for this field is not simply available as `$node->field_name` or `$form['field_name']`, but instead as a nested array containing a variety of other information.

My question then is this: what is the 'correct' and therefore most future proof way to retrieve the value for this field?

Am I supposed to be using the likes of `field_view_value()` or `field_view_field()`, or is it acceptable to simply reference `$node->field_name['und'][0]['value']` for example.

# Answer
field\_get\_items() is the one you're looking for.

```
$items = field_get_items('node', $node, 'field_FIELD_NAME');
$first_value = $items[0]['value'];

```

It also takes care of language selection for you, so no need to worry about that one any more.
> 1 votes

---
Tags: views
---


# Question
Title: Unable save/update any content after migrating from local to production
This is the first time I have made my Drupal site live on a production server (Ubuntu ls 10.04).

These are the steps I did:

1. Zip the entire webroot folder
2. Upload to the production server
3. Extract the contents into the webroot
4. Take db dump from local server
5. Dump into the production server
6. Update the production's Drupal admin password

I do not have a problem viewing the contents, but I am unable to save any content including the configuration settings such as Site information. It doesn't throw any error message or update the content.

What other steps might I have missed?

# Answer
Check mod\_rewrite (server module) and .htaccess (configuration files in Drupal installation, which easily can be left behind when copying) which take care of lot of the URL and path functionality.

Read more from https://drupal.org/getting-started/clean-urls

Credits to this question: Can't save settings after copying site to new server
> 1 votes

# Answer
Find these lines in your .htaccess and uncomment RewriteBase /

\# If your site is running in a VirtualDocumentRoot at http://example.com/, \# uncomment the following line: RewriteBase /
> 0 votes

---
Tags: migrations
---


# Question
Title: hook_update_N - expose new field to views after module update
I've added new field to existing table with hook\_update\_N. Now, is it possible to expose this new field to views? I want it to be exposed when module is updated...

Possible?

# Answer
Yep, you can use `hook_views_data_alter()`:

> Alter table structure.
>
> You can add/edit/remove existing tables defined by hook\_views\_data().
> 1 votes

---
Tags: updating, views
---


# Question
Title: How do I get the username of the logged-in user?
I am working on a site where on a page I am querying some data related to my project.

Here I have many clients and I have given all of them access to project search page. On search page I run a query according to the fields selected by the user and display the result as a table on the page itself. But my query is as such that it is not user dependent.

I just want to ensure that each user has a specific set of output for itself (i.e not all the table would be displayed to all users).

How do I get the username or user ID of the logged-in user?

# Answer
> 3 votes
You can use the global `$user` object:

> An object representing the user currently visiting the site.
>
> Contains preferences and other account information for logged-in users. When a user is not logged-in, the $user-\>uid property is set to 0.

e.g.

```
global $user;
$name = $user->name;
$id = $user->uid;

// or
$name = $GLOBALS['user']->name;
$id = $GLOBALS['user']->uid;

```

# Answer
> 0 votes
You can use:

```
   global $user;
   if (!empty($user->uid))
   {$id = $user->uid;} //$id will only have a value if user is logged in

```

---
Tags: users
---


# Question
Title: How to show comments for an unpublished node
this is my problem,

* A node is in unpublished state
* The "View own unpublished content" permission is set
* The node author posted a comment on the node, but the comment is not getting rendered in the node page
* The super admin user though can see the comment.

Is this normal in Drupal 7? If so, how can I make those comments visible for the node author?

Hope I can explain my problem, thanks...

# Answer
I vaguely remember I had once an issue with viewing unpublished content and the view\_unpublished module offered me a better granularity that solved my issue.

Otherwise I would say creating a view showing comments in relation with the node, using a contextual filter nid, and without the filter "content: published" might help.
> 1 votes

---
Tags: 7, entities, comments
---


# Question
Title: Passing Settings from Drupal Module to Javascript: Uncaught TypeError: Cannot read property
In my module I have the following code.

```
$my_settings = array(
    'basePath' => '/',
    'my_locs' => $my_locs // Array of numbers
);

drupal_add_js(array('my_module' => $my_settings), 'setting');

```

In the JavaScript I am supposed to retrieve settings as follows.

```
var my_locs = Drupal.settings.my_module.my_locs;

```

From Goggle Chrome console, I get the following error.

> Uncaught TypeError: Cannot read property 'my\_locs' of undefined google\_elev.js

These are the various output I obtain from the console.

```
>my_locs
undefined

```

```
>Drupal.settings.my_module.my_locs
[41, 9, 42, 9]

```

```
>my_locs = 2
2

```

```
>var my_locs
undefined

```

```
>my_locs = Drupal.settings.my_module.my_locs
[41, 9, 42, 9]

```

```
 >my_locs
[41, 9, 42, 9]

```

All the rest in the JavaScript file works perfectly; variables are readed, computed, snd used. Settings are loaded in Drupal.settings before loading the JavaScrip file with `drupal_add_js()`.

I don't know what to try. I don't understand if it is a syntax problem, if I must define the var to be an array before, or if something tricky in the order of callings have to be accomplished.

# Answer
Try this

```
(function($) {
  Drupal.behaviors.myModule_someJS = {

    anotherFunction: function() {
      console.log(this.vars.initial_page);
    },

    attach: function(context, settings) {

      this.vars = {
        initial_page  : Drupal.settings.myModule.initial_page
      }

      this.anotherFunction();

    }
  }
})(jQuery);

```

Drupal.settings won’t contain the custom stuff sent through from my module until the attach function is called, so therefore every settings variable can only be called inside attach()
> 0 votes

# Answer
For future readers who will have the same problem.

My call for retrieving Drupal settings variables was made in the declaration part of the JavaScript:

```
var my_locs = Drupal.settings.my_module.my_locs;

```

I supposed this would be correct, since the Drupal settings object is already created, and since Javascript allows, like Java, the creation of new objects at declaration time. But for some reason it didn't work.

I solved leaving the declaration

```
var my_locs;

```

and passing the object inside an *initialize()* method.

```
function initialize() {
    my_locs = Drupal.settings.my_module.my_locs;
    [...]

```

I hope it can be useful, since I lost lot of time on this.
> 0 votes

---
Tags: javascript
---


title: Commerce Kickstart subtheme?

text:
# Question
Title: Commerce Kickstart subtheme?
Hi I'd like to alter some of the CSS on the Commerce Kickstart theme, but when I try to create a sub theme by following these instructions https://drupal.org/node/819170 I end up with an unformatted theme. This isn't what I want, I want to alter the current Kickstart theme but from the sites/all/themes subfolder.

I've created a subtheme based on omega, omega\_kickstart, but these leave me with no css formatting at all.

I've copied the profiles\commerce\_kickstart\themes\omega\_kickstart folder to my sites/all/themes, renamed the info file etc.. this left me with partial formatting.

one thing I noticed from the dom entries is css come from various folders, i.e. alpha, omega.

anyone know how to create a successful subtheme here?

# Answer
> 2 votes
I followed all 10 steps at this article in detail to get a fully functional boilerplate subtheme for the Commerce Kickstart Theme in just a couple of minutes.

In case the article goes offline, you can find a mirror here.

Info :

> **How to subtheme the Omega Kickstart Theme**
>
> Posted by sja1 on August 4, 2013 at 12:31pm
>
> Hi guys, first off thanks for the all the work you've put into make Commerce Kickstart such an oustanding platform. I wanted to create this issue in order to help those who are having trouble creating a subtheme of the commerce kickstart theme. There is good documentation for subtheming omega, but I had a harder time finding information on subtheming a subtheme of omega (Commerce Kickstart is a subtheme of Omega Kickstart, which is a subtheme of Omega). With some trial and error I have come up with the following procedure which is working for me, and thought I'd present it to the community for others to benefit from and hopefully improve upon. All comments welcome.
>
> **Steps to subtheme Commerce Kickstart theme**
>
> *\[ For the detailed 10 steps, go to one of the two provided links \]*

# Answer
> 1 votes
This is the only solution I've found so far, feel free to add a new answer to improve on this answer.

create your new css file in

```
drupalinstall\profiles\commerce_kickstart\themes\omega_kickstart\css\customcss.css

```

edit this file:

```
drupalinstall\profiles\commerce_kickstart\themes\omega_kickstart\omega_kickstart.info

```

Add this detail (below the similar global.css entry):

```
css[customcss.css][name] = 'custom Css file'
css[customcss.css][description] = 'All my stuff'
css[customcss.css][options][weight] = '12'

```

now add this to the same file(again below the similar global.css entry):

```
settings[alpha_css][customcss.css] = 'customcss.css'

```

now within your drupal site, clear your cache (Site settings\>configuration\>performance) now engage your new css file in the `appearance>settings>toggle styles`, from here you should see your new css file entry. tick this. and you're good to go.

This answer was discovered with the help of this question/answer How to add custom css file to subtheme of omega kickstart theme?

---
Tags: commerce
---


# Question
Title: How to add custom css file to subtheme of omega kickstart theme?
I have created a subtheme of "omega kickstart theme" and I want to add some custom css files to it. I searched and got some solution(which didn't worked for me), the solution is as follows:

1. create your custom css file and place it in css folder of your subtheme.
2. edit your subtheme.info file(edit under optional css code of info file) as follows:

```
css[yourthemename.css][name] = 'Your custom products styles'
css[yourthemename.css][description] = 'This file holds all the product page CSS of your theme.'
css[yourthemename.css][options][weight] = '12'

```

The other Solutions were as follows:

1. Specify your custom css path file in info file as

```
stylesheets[all][] = mycustomcss.css

```
2. Make use of "drupal\_add\_css" function in template.php as follows

```
function MYTHEMENAME_preprocess_node(&$variables) {
  if ($variables['view_mode'] == 'full') {
    $path = drupal_get_path('theme', 'MYTHEMENAME');
    drupal_add_css($path . 'MY-THEME-PATH');//PUT UR CSS FILE PATH
  }
}

```

I tried this function twice with two different paths. First I gave path as '/css/mycustomcss.css' and second time I gave path as '/MYTHEMENAME/css/mycustom.css'.

UNFORTUNATELY NONE of these solutions worked for me. Am I missing something or is it something else?...please help.

# Answer
I was missing one line in code. here is what you have to do. in your .info file under optional css code write the following code.

```
css[yourcustomcss.css][name] = Your custom products styles
css[yourcustomcss.css][description] = This file holds all the product page CSS of your theme.
css[yourcustomcss.css][options][weight] = 12
settings[alpha_css][yourcustomcss.css] = 'yourcustomcss.css'

```

Now go and enable your 'yourcustomcss.css' in Appearance/yourthemename/settings/toggle-styles
> 0 votes

# Answer
To create a subtheme, follow all 10 steps mention in this article.

To add your own custom CSS files, add them in `./MYTHEMENAME/MYTHEMENAME.info` if you need minimal configuration.

Otherwise, add your own `MYTHEMENAME_preprocess_HOOK` functions to `./MYTHEMENAME/template.php` in your subtheme folder.

After you add your changes, add the following lines of code in `./MYTHEMENAME/template.php` at the very bottom :

```
drupal_flush_all_caches();
drupal_theme_rebuild();

```

This should flush the cash and add your changes. Then, comment out these two lines and refresh your browsers. Your changes should now be included.

The easiest way to test whether your `MYTHEMENAME_preprocess_HOOK` function is actually being used, is to add nothing but one of the following options to that function (and remove it when it generates output) :

```
echo 'MYTHEMENAME_preprocess_HOOK used'; // native PHP
var_dump('MYTHEMENAME_preprocess_HOOK used'); // native PHP
debug('MYTHEMENAME_preprocess_HOOK used'); // Drupal specific

```

If you don't want to clutter `./MYTHEMENAME/template.php`, you can also put your hooks in seperate files in the preprocess folder as described in the readme file.

```
TEMPLATE_preprocess_html() --> ./MYTHEMENAME/preprocess/preprocess-html.inc
TEMPLATE_preprocess_page() --> ./MYTHEMENAME/preprocess/preprocess-page.inc
TEMPLATE_preprocess_node() --> ./MYTHEMENAME/preprocess/preprocess-node.inc

```

Unfortunately, the documentation forgets to mention what would be suitable values for `TEMPLATE`. As you can see in the code in the process folder of inherited themes, `TEMPLATE` should be identical to `MYTHEMENAME_alpha`. It took me hours to figure that out.

For example, your page hook would be something like this if it was put in the file `./MYTHEMENAME/preprocess/preprocess-page.inc` :

```
function MYTHEMENAME_alpha_process_page(&$vars) {
  //debug($vars);
}

```
> 0 votes

---
Tags: theming, commerce
---


# Question
Title: How to display content type field values in tab panel format?
I have created custom content type. I want to display it's data (field values) in tab panel format. is there any way to change it through CSS?

# Answer
im using the Quick Tabs module for creating tabs. Here is a quote about it (from the module's project page):

> ... allows you to create blocks of tabbed content, specifically views, blocks, nodes\* and other quicktabs\*. You can create a block on your site containing multiple tabs with corresponding content. Clicking on the tabs makes the corresponding content display instantly, using jQuery. With the 6.x-2.x branch, this can be done in either ajax or non-ajax mode:
>
> * if you choose ajax mode for your Quick Tabs block (and this is chosen on an individual QT basis), only the content of the active tab will be loaded on page load and the content of the other tabs will be loaded via ajax on tab click (this is good for performance if you are loading, for example, several large views)
> * in non-ajax mode the tab content is just hidden / shown on tab-click. This latter method is an ideal way to do something like the Most Popular / Most Emailed stories tabs you see on many news websites, where it is used more as a space-saving device in your sidebar. If however, you want a QT block as the main content of your entire page, then the chances are that ajax mode will be more appropriate.
>
> Once created, the Quick Tabs blocks show up in your block listing, ready to be configured and enabled like other blocks. Multiple Quick Tabs blocks can be placed on a single page.
>
> For theming of the tabs, several styles have been provided for you to choose from (in the 7.x-3.x branch this functionality comes in a separate submodule, Quicktabs Tabstyles), along with the default option of no style, if you prefer to add your own theming instead.
> 1 votes

---
Tags: nodes
---


# Question
Title: Subtheme media query CSS in Omega Kickstart subtheme
I want to build a site based off of Omega Kickstart which is a subtheme of Omega. Of course I want to layer in my changes sparsely so I made a subtheme of Omega Kickstart.

All the guides out there for doing this assume that you only want one global CSS file in your new subtheme. That seems crazy to me -- I want to follow the same mobile-first pattern in my subtheme and individually override each targeted CSS file i.e. alpha-default.css, alpha-default-narrow.css, etc...

Is this possible? To have both omega-kickstart-alpha-default.css and MYTHEME-alpha-default.css?

Everything I try seems to want to override omega-kickstart\*.css with MYTHEME\*.css. And it seems to defeat the whole purpose of subtheming to copy omega-kickstart\*.css over to MYTHEME\*.css.

# Answer
> 1 votes
I had similar issues like this. I ended up simply overriding the CSS file in my template.php. I created a helper for me to do this. Simply run hook\_css\_alter and replace the file you are targeting with your own. In this case, the omega theme's grid file is here:

```
sites/all/themes/contrib/omega/alpha/css/grid/alpha_default/wide/alpha-default-wide-24.css

```

And I am replacing it with:

```
sites/mysite.com/themes/my_theme/css/grid/alpha_default/wide/alpha-default-wide-24.css

```

This is the code in my template.php

```
/**
 * Implements hook_css_alter().
 */
function my_theme_css_alter(&$css) {
  $themePath = drupal_get_path('theme', 'my_theme');
  $newCSS = array(
    'sites/all/themes/contrib/omega/alpha/css/grid/alpha_default/wide/alpha-default-wide-24.css' => $themePath.'/css/grid/alpha_default/wide/alpha-default-wide-24.css'
  }
  _my_theme_replace_file($css, $newCSS);
}
/**
 * Helper function to replace an existing file with a new path
 */
function _my_theme_replace_file(&$files, $newFile) {
  foreach($newFile as $oldpath => $newPath) {
    if(isset($files[$oldpath])) {
      $files[$newPath] = $files[$oldpath];
      $files[$newPath]['data'] = $newPath;
      unset($files[$oldpath]);
    }
  }
}

```

The helper function \_my\_theme\_replace\_file simply loops through the array, finds the old path and replaces it with the new one.

I hope this helps.

# Answer
> 1 votes
To create a subtheme, follow all 10 steps mention in this article. It includes instructions on how to add your own theme specific CSS files.

If you want them to load conditionally, add your own `MYTHEMENAME_preprocess_HOOK` functions to `./MYTHEMENAME/template.php` in your subtheme folder.

After you add your changes, add the following lines of code in `./MYTHEMENAME/template.php` at the very bottom :

```
drupal_flush_all_caches();
drupal_theme_rebuild();

```

This should flush the cash and add your changes. Then, comment out these two lines and refresh your browsers. Your changes should now be included.

The easiest way to test whether your `MYTHEMENAME_preprocess_HOOK` function is actually being used, is to add nothing but one of the following options to that function (and remove it when it generates output) :

```
echo 'MYTHEMENAME_preprocess_HOOK used'; // native PHP
var_dump('MYTHEMENAME_preprocess_HOOK used'); // native PHP
debug('MYTHEMENAME_preprocess_HOOK used'); // Drupal specific

```

If you don't want to clutter `./MYTHEMENAME/template.php`, you can also put your hooks in seperate files in the preprocess folder as described in the readme file.

```
TEMPLATE_preprocess_html() --> ./MYTHEMENAME/preprocess/preprocess-html.inc
TEMPLATE_preprocess_page() --> ./MYTHEMENAME/preprocess/preprocess-page.inc
TEMPLATE_preprocess_node() --> ./MYTHEMENAME/preprocess/preprocess-node.inc

```

Unfortunately, the documentation forgets to mention what would be suitable values for `TEMPLATE`. As you can see in the code in the process folder of inherited themes, `TEMPLATE` should be identical to `MYTHEMENAME_alpha`. It took me hours to figure that out.

For example, your page hook would be something like this if it was put in the file `./MYTHEMENAME/preprocess/preprocess-page.inc` :

```
function MYTHEMENAME_alpha_process_page(&$vars) {
  //debug($vars);
}

```

---
Tags: 7, theming, commerce
---


title: Views field filter handler

text:
# Question
Title: Views field filter handler
I have two tables: one that stores field with numeric values and another one that stores field with percentage value.

Is it possible to create view field that would store the multiplication result of these two fields? And is it possible to add such field to the filter criteria?

# Answer
> 1 votes
There are two ways to do this that come to mind:

1. **Use Computed Fields**: https://drupal.org/project/computed\_field. I haven't personally used this module but I've seen it recommended a number of times. You could create a hidden field on each piece of content which computes the value you desire. Then this can be used in the view as easily as any other field for both display and filtering.
2. **Use views\_php field**: https://drupal.org/project/views\_php. This will show up in the view options as 'Global: PHP' and will allow you to do pretty much anything with your data that you want to. The authors caution it's use because it's pretty easy to mess things up. I've found it to be a quick solution to problems. (As a side note, the most recent release of this functions differently in what variables it allows you to access, so be careful if doing updates. I would suggest using the most recent version.) Your code could be as simple as this in the output box:

```
<?php
$new_value = $row->value_1 * $row->value_2;
print $new_value;
?>

```

Then you could create a "Global: PHP" sort by with something like this:

```
$first = $row1->value_1 * $row1->value_2;
$second = $row2->value_1 * $row2->value_2;

if ($first > $second) {
  return 1;
}elseif ($first < $second){
  return -1;
}else{
  return 0;
}

```

---
Tags: views
---


title: How can I accomplish this using Views?

text:
# Question
Title: How can I accomplish this using Views?
I'm using Drupal 7.28 and Views 7.x-3.7.

I've created a vocabulary called Products and listed terms under this including Living, Dining, Storage, Office, Outdoor.

I've also created a content type called Products with an auto term reference for users adding content to select one of the terms.

What I want to do is create a view that will automatically create a page for each of the terms, so in the menu it will have for example Living, Dining, Storage, Office, Outdoor etc. I don't want to have to create a new view each time a term is added.

Then, if a term has been added but there is no content that has selected a term the page will just say 'No products' (which i know this bit can be done by setting a No Results behaviour.)

Thanks very much for reading.

# Answer
i am not sure whether this is exactly what you are looking for or not, but i would do it this way..

Override the taxonomy view (or clone it) from the views list. (this will override the view for all the taxonomy terms in your website.

After this install and enable the taxonomy Menu module. With this you can create a menu of the taxonomy terms for the specific content type.

For Showing the no items in the display add a "No results behavior" - under this select "Global: Unfiltered text "- click on Apply button- when the form appears put this " 'No products'" text in the text area and click on the apply button. You can also add markup for this text. save all the settings and check it. hope this helps
> 0 votes

# Answer
For anyone else looking for help with this in the future, here's how I did it:

I used the default pages that are generated for each term - I didnt realse that all terms generate a page that displays all of the content associated with them.

I then enabled and used the default Taxonomy view to edit the output of the term pages.

I also used the Taxonomy Menu module to create a menu of each taxonomy,
> 0 votes

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


title: Create a simple quiz for each video

text:
# Question
Title: Create a simple quiz for each video
I have a "video" content type, and I want from users watching my videos to answer some questions related to each single video.

Can you advice me, how can I create a quiz for each single video content ? Is there a module (I tried the quiz module but it's very complicated) to do that, or any other way will be apprecited.

thanks in advance.

# Answer
You can use the Webform module to create a quiz.

Here is a quote about it (from the module's project page):

> Webform is the module for making surveys in Drupal. After a submission, users may be sent an e-mail "receipt" as well as sending a notification to administrators. Results can be exported into Excel or other spreadsheet applications. Webform also provides some basic statistical review and has and extensive API for expanding its features.
>
> Some good examples could be contests, personalized contact forms, or petitions. Each of these could have a customized form for end-users to fill out. If you need to build a lot of customized, one-off forms, Webform is a more suitable solution than creating content types and using CCK or Field module.
> 2 votes

---
Tags: 7, forms, quiz
---


# Question
Title: Drupal 7: Protect entire site in a maintaince mode-esque fashion
Looking for a way to lock down the site like maintenance mode, but without having to use maintenance mode.

I don't want to use maintenance mode because I want to have that feature available for it's proper use.

However, I would like to able to have the site viewable as normal for logged in users, and anonymous users just get a screen telling them to login or register. Probably with a login/register box as well. So hopefully something with a template.

Any modules out there or maybe a simple custom module?

# Answer
> 1 votes
Remove the permission that allows users to view published content. They'll get an access denied message. Create a custom 403 page with the login info and poof! Robert's your mother's brother.

# Answer
> 0 votes
print screen a login and register page of drupal and enabled it in front page so that the user could see the login and register button.

---
Tags: 7, maintenance-mode
---


# Question
Title: Problem with commerce_checkout_page_info() function
I've been poking around in various forums trying to change the hard-coded values for the Checkout Page buttons and titles. For semantic reasons, I want to change the last submit button from 'Continue to next step' to 'Complete Submission'.

I have had success in changing the other buttons with combinations of hook\_form\_alter() and how hook\_menu\_alter()

```
function bartik_form_alter(&$form, &$form_state, $form_id){
dpm($form_id);
dpm($form);
if (commerce_form_callback($form_id, $form_state) == "commerce_cart_add_to_cart_form"){
    $form['submit']['#attributes']['title'] = $form['submit']['#attributes']['value']=t("Add to Inquiry List");
    }
if(strpos($form_id, 'views_form_commerce_cart_form_default')===0){
    $form['actions']['submit']['#value'] = t("Update List");
    $form['actions']['checkout']['#value'] = t("Submit List");

    }

```

However, I am having problems changing the final submit button in the commerce\_checkout\_form\_review form. I've tried the method suggested here http://mtt.desk.com/customer/portal/articles/1430204-how-to-customize-the-label-of-the-drupal-commerce-button-on-the-order-review-page, both as a module and as a function in the theme template, but neither method produces an error or gives me the desired text change.

```
function co_button_commerce_checkout_page_info_alter(&$checkout_pages) {
$checkout_pages['review']['submit_value'] = 'Submit Order';
}

```

So, I've been trying a couple of different variations, but I'm still not sure how to target the buttons on that form. I have also tried this little if statement, but it's still not effecting the change.

```
if(strpos($form_id, 'views_form_commerce_cart_form_default')===0){
$form['buttons']['continue']['#value'] = t('Complete submission');
}}

```

TIA, any advice would be greatly appreciated.

I think this is the relevant portion of the array

```
buttons (Array, 4 elements)
#type (String, 8 characters ) fieldset
#attributes (Array, 1 element)
continue (Array, 6 elements)
#type (String, 6 characters ) submit
#value (String, 21 characters ) Continue to next step
#attributes (Array, 1 element)
#suffix (String, 59 characters ) <span class="checkout-processing element-
#validate (Array, 1 element)
#submit (Array, 1 element)

```

# Answer
> 0 votes
I think you can handle it with `hook_form_later`, try something like below, change your condition according to your checkout base name , I hope this help you :

```
/**
 * Implements hook_form_alter().
 */
function yourmodule_form_alter(&$form, &$form_values, $form_id) {
  if($form['checkout_pane']['#value']['base'] == 'checkout_pane_review') {
    $form['submit']['#value']='yourvalue';
  }
}

```

# Answer
> 0 votes
Since all you're doing is trying to change the button text, you really should just be altering the checkout page info array for the relevant checkout page so its "submit\_value" reads as you want it to read. It looks like you got this right, and other folks can refer to the documentation in commerce\_checkout.api.php for more information.

If you add this alter function to a module or theme that's already installed on the site, remember you need to clear the cache for the hook to register and actually start altering the array.

---
Tags: commerce, hooks
---


# Question
Title: Security issues while using external javascript and php files to access mysql database in drupal nodes
I have created a search\_interface node which asks for filters and `onClick` event of the `submit button`, I have called an external `search.js` script. My search\_interface node is of a custom content type `Query`(this content type has no extra fields other than the default fields created by a new content type)

This script uses `getElementById()` to get user input and send it to an external php script using `POST` method. This script uses `mysqli_connect()` to connect to my database and then does query on the required table(only 1 table is being queried everytime). The result of `mysqli_query()` is passed back to the search.js script using `json_encode()` and in the `search.js` script, I have parsed this jsonData and created a `table string`. Then I have used `my_table.innerHTML = "table string"` to finally display the query on the drupal node.

* Is this method secure?
* Can some anonymous user access my .php script and get to know my mysql admin password? ( I use admin password during `mysqli_connect()` )
* Can my whole database be exposed easily even though I always query a single table of the database?
* Can the .php file be edited to update or delete parts of my database or the table in which I query every time?

Please help as I am new to drupal 6 and don't know much about security of php files and drupal nodes.

# Answer
> 1 votes
Doesn't look like any of the questions you have are directly related to Drupal. I highly suggest reading about PHP security concerns. This is a good resource to get started.

That said:

> Is this method secure?

Without looking at specific code, that is hard to say. Since you're running a database query based on user input, it's important you properly sanitize the input before running the query. I suggest using PDO instead of `mysqli_*` functions, since PDO is more widely used now and provides easy ways to use "prepared statements" to protect your database.

> Can some anonymous user access my .php script and get to know my mysql admin password? ( I use admin password during mysqli\_connect() )

Not unless the .php script prints the password to the screen. Sounds like it accepts POST data and will return JSON output with data from the database. Make sure your POST data in sanitized before running a query.

> Can my whole database be exposed easily even though I always query a single table of the database?

See above

> Can the .php file be edited to update or delete parts of my database or the table in which I query every time?

Not unless a malicious user has access to your web server

---
Tags: security
---


# Question
Title: Site in offline mode, any way to debug how this happened?
I came in this morning to find my companies site in offline mode. I personally checked with the only other site admin, and none of other users have the ability to turn off the site. I was using the Backup module prior to me leaving last night, but I've backed up hundreds of times and never encountered the module leaving the site in Offline mode.

Would there be any logs or any location in the database where this activity might be logged? We don't allow users to login to our Drupal site, just our own editors and a

I've tired Googling answers but I haven't got very far :(

running Drupal 6.x

# Answer
> 4 votes
Site offline is a matter of a global variable `site_offline` set to `1`. Any call of `variable_set('site_offline', '1')` can also result to put site into offline mode.

Invalid database configuration can also results as site offline but it adds some error message.

Unauthorized access to DB can be used to manually alter record in `variable` table for the values as variable.name='site\_offline', variable.value='s:1:"1"'

# Answer
> 1 votes
The script for Updating a module in administration menu can take the site offline as well.

# Answer
> 0 votes
A site restored from a backup produced with the backup\_migrate module is automatically placed in offline mode. This is presumably a protection to allow an administrator to adjust configuration settings before the site is made generally available. Is it possible the site was restored from backup?

---
Tags: 6, users, debugging, maintenance-mode
---


title: Offset problem in Drupal 7

text:
# Question
Title: Offset problem in Drupal 7
I want to use the Views module to display the top item from a listing.

I've utilized the "Use Pager" to display that one item. But sometimes I want to display the second item, or third item, or X item. I've found the offset option to skip the first item, but the result I get doesn't seem to match. What I get instead is some random item, and not, say, the second item.

Any suggestions?

# Answer
Did you accidentally enable random ordering as well? In a randomly ordered list, the second item will always be random as well.

If this is not the case, please provide more information about the configuration of your view. Two ways of doing this are to make a screen shot of the edit form, and to upload the exported view to http://pastebin.com.
> 0 votes

---
Tags: 7, views
---


title: Layout on Commerce checkout pages

text:
# Question
Title: Layout on Commerce checkout pages
Drupal Commerce.

On admin/commerce/config/checkout/form you can move around checkout panes between pages. This is cool!

It allows e.g. to move all panes on one page.

Now what I am trying to figure out is how to make a more interesting layout for this page. E.g. by "grouping" the panes into layout regions / columns, like I would for a node display.

Any ideas?

# Answer
> 1 votes
You can get at that with the commerce functions hook\_commerce\_checkout\_page\_info() and hook\_commerce\_checkout\_pane\_info(); with more documentation on that here: http://www.drupalcommerce.org/developer-guide/core-architecture/info-hooks/checkout-info-hooks#checkout-pane.

It's a little complicated because the panes, pages, and forms are hard-coded into DC's checkout logic. There are a couple of modules that let you override and specify your own pages or other cart functions https://drupal.org/project/dc\_co\_pages, and https://drupal.org/project/commerce\_cart\_view\_override

You'll probably need to do any serious changing by coding your own module calling the commerce functions/pages you need for your use case.

---
Tags: commerce
---


# Question
Title: Clean URLs on multisite; Clean URL test fails but unable to enable it
Clean URL test fails but unable to enable it. Here is my configuration files. I am able to access the page via `example.com/admin/config/search/clean-urls` as well as `example.com/?q=admin/config/search/clean-urls`

# Answer
> 0 votes
The mistake is in your `[QSA]` flag:

> To combine a new query string with an old one, use the \[QSA\] flag.

You don't want to do that. Drupal works fine with just:

```
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

```

If you will combine original query string with new one, then the test in `system_clean_url_settings()` have to fail, as it is:

```
if (strpos(request_uri(), '?q=') !== FALSE) {

```

If you are attaching original query string to new one, you are also adding that `?q=`, and this makes Drupal think you are still using non-clean method.

# Answer
> 0 votes
Check if you have .htaccess in your drupal root directory, it is hidden by default so to check if you have .htaccess in file simply ls -a in your drupal root directory.

# Answer
> 0 votes
You haven't specified it in your question, but is the subdomain located in the same directory /var/www? As far as I know rewrite rules are per directory. If this is the casa as it looks to me, you have to another rewrite rule.

This works as charm for me:

```
<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www/mydomain.com/
    ServerName www.mydomain.com
    ServerAlias *.mydomain.com mydomain.com
    UseCanonicalName On
    ErrorLog logs/mydomain.com.err
    CustomLog logs/mydomain.com common
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www/mydomain.com/
    ServerName www.mydomain.com
    ServerAlias *.mydomain.com mydomain.com
    UseCanonicalName On
    ErrorLog logs/mydomain.com.err
    CustomLog logs/mydomain.com common
</VirtualHost>

<Directory /var/www/mydomain.com/>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

```

If you have the subdomain located in another path then you mast add a second rewrite rule.

```
<VirtualHost *:80>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www/second_domain.mydomain.com/
    ServerName second_domain.mydomain.com
    ServerAlias *.second_domain.mydomain.com
    UseCanonicalName On
    ErrorLog logs/second_domain.mydomain.com.err
    CustomLog logs/second_domain.mydomain.com common
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www/second_domain.mydomain.com/
    ServerName second_domain.mydomain.com
    ServerAlias *.second_domain.mydomain.com
    UseCanonicalName On
    ErrorLog logs/second_domain.mydomain.com.err
    CustomLog logs/second_domain.mydomain.com common
</VirtualHost>

<Directory /var/www/second_domain.mydomain.com/>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

```

Also, remember to restart the httpd server: **service httpd restart**

Change the paths and the domain names accordingly. Are you using the root **/var/www**? For your site, it would be better if you used a subdirectory to store your sites as in this example. Furthermore, if you continue using the path **/var/www** check that there is not another rewrite rule included by default in your configuration file. In vi: when not editing, press slash and add te text: www, and press enter, // enter to search again; and check there is not any other rewrite rule for this path...

Another problem may be with the caches, check **Admin/Configuration/Performance** and click on **Clear all caches**.

I hope that this may be helpful...

# Answer
> 0 votes
The clean URLs test does a local HTTP request

```
$request = drupal_http_request($GLOBALS['base_url'] . '/admin/config/search/clean-urls/check');

```

I think in your case, the `drupal_http_request` is failing so Drupal marks the clean url test as failed.

More info: `system_clean_url_settings`

---
Tags: 7, .htaccess
---


# Question
Title: Save a new value with entity_metadata_wrapper to an entity field which is an array
I need to save a new value to a field on an entity and I was wondering if it was possible to use entity\_metadata\_wrapper or is it only possible to set an existing value?

# Answer
> 32 votes
When dealing with multi-value fields, the associated entity metadata wrapper object is an instance of EntityListWrapper (It may be a good idea to browse the API to look at the available methods. Also note this class implements the ArrayAccess interface)

So the simplest way to add new values to an EntityListWrapper is by using the "\[\]" operator:

```
$wrapper->field_example[] = $new_value;

```

This creates a new entry and assigns it the value. With this methods, the delta (the offset within the list of value) is created automatically. You can also set the offset yourself if you wish. Any of the three following methods are equivalent:

```
$wrapper->field_example[$delta] = $new_value;
$wrapper->field_example->offsetSet($delta, $new_value);
$wrapper->field_example->get($delta)->set($new_value);

```

In all three cases this will overwrite values if the delta already exists, and create a new entry if not.

You could also directly set an array of value on the field itself. Both of the methods are equivalent:

```
$value = array
  0 => array('property_example' => 'hello'),
  1 => array('property_example' => 'world')
);
$wrapper->field_example = $value;
$wrapper->field_example->set($value);

```

However this requires you to know the internal structure of the field you're assigning to as you're not using the field's metadata wrapper.

Finally you can empty a multi value field by setting it to an empty value. All three methods are equivalent :

```
$wrapper->field_example->set();
$wrapper->field_example = array();
$wrapper->field_example = NULL;

```

# Answer
> 3 votes
I found that

```
$wrapper->field_example[]->set($new_value);

```

was a fatal failure. But

```
$wrapper->field_example[NULL]->set($new_value);

```

was allowed.

---
Tags: entities
---


# Question
Title: Cannot figure out where the tmp folder is to add the .htaccess file per http://drupal.org/SA-CORE-2013-003
That doesn't make any sense to me. I do not have a tmp folder anywhere outside the root. I cannot find the `/tmp` folder supposedly outside the folder where my Drupal instance is located. Well, let me correct that. I found one, but placing the recommended `.htaccess` file in it didn't solve the error message. It didn't seem to be the correct tmp directory. Maybe I don't fully understand where outside the root dir is at? Isn't it the directory above where the installation is at? Is it in the html folder, the sites folder, or above the html folder?

Will the instructions in http://drupal.org/SA-CORE-2013-003 work if I create a tmp folder in the html folder? Where exactly do I create the tmp directory?

# Answer
> 1 votes
> Maybe I don't fully understand where outside the root dir is at? Isn't it the directory above where the installation is at? Is it in the html folder, the sites folder, or above the html folder?

The `tmp` folder is where your configuration says it is.

I looks like you've already navigated to *Administration » Configuration » Media » File system*, and found that the field "Temporary directory" says `/tmp` \- so that is where it is (this is also the default location).

Now, this is a *file system* path, not a Drupal path. The "/" in front tells you it is in the file system *root*.

To navigate to it, use the following command in the Gnu/Linux CLI:

```
 cd /tmp

```

> Will the instructions in http://drupal.org/SA-CORE-2013-003 work if I create a tmp folder in the html folder?

No.

> Where exactly do I create the tmp directory?

You *don't* create it. It should already exist on your system.

To fix the error message regarding the `.htaccess` in `/tmp` related to the security update you mention, do as follows:

First, in the GNU/Linux CLI, use the following two commands:

```
 cd /tmp
 rm .htaccess

```

Then in the Drupal GUI, as admin, navigate to *Administration » Configuration » Media » File system*. Do not change anything, but press "Save configuration". This will make Drupal create the correct `.htaccess` in the right place.

---
Tags: 7
---


title: add field with date field

text:
# Question
Title: add field with date field
I have created new field for my content type "Flag", its list type field

possible values of it is

```
-Draft
-Sent
-Approved
-Rejected

```

now for this field new table is created,now i want to store date here,what i exactly want is like:

```
-Draft on date DD/MM/YYYY (the date of the creation of the project)
-Sent on date DD/MM/YYYY
-Approved on date DD/MM/YYYY
-Rejected on date DD/MM/YYYY

```

now how to achieve it.

**am using drupal 7**

# Answer
Use Field Collections and add two fields to field collection and enable field collection field on your content type... Or Create two fields Flag and Flag date...

* Flag
* Flag Date

OR

You can use revisions to track these changes in Drupal. When ever you change above field make content as a new revision so that you can track dates too...

OR

Create a few more date fields, each for possible values to track the dates... use form api #states property to hide display fields based on selection of flag value..

* Flag
* Draft Date
* Sent Date
* Approved Date
* Rejected Date
> 2 votes

---
Tags: entities
---


# Question
Title: Display a block based on the term reference field of the current node
What I'm trying trying to do sounds fairly simple, but I can't get my head around it.

I'm having 2 taxonomy vocabularies: *machinery* and *batteries* (both created with NAT for all that matters), and 2 content types which are named the same.

Both the content types provide the ability to check related items (a regular term reference field). For the machinery node the user can check which batteries are suitable, and for the battery node the user can check which machines use this battery.

Basicly what I'm trying to is: if you're on a page about a specific machine, it should show the batteries that are related to it, be it as teasers (or fields) in a block. And vice versa: when you're on a page about a specific battery, it would show all the machines in which it fits.

I've been boggling around with relationships and contextual filters, but it just wouldn't work out so far (spent a couple of hours here). Does anyone have an idea how to sort this out please?

# Answer
There's possibly an easier way with the References module. In that case it wouldn't even require NAT, but just a View with contextual filter based on the Reference field.
> 0 votes

# Answer
I can't summarize those instructions, MPD, you have to follow the exact steps or it won't work. Full instructions:

Create 2 content types, both correctly configured with NAT:

```
Machinery
Battery

```

2 vocabularies, both will be filled along the way with terms generated by NAT:

```
Machines
Batteries

```

Remark the difference in names, just to keep things clear in this explanation (so you don't mix up).

Add a "Term reference" field in both the content types. In het "Machinery" content type this field will refer to the "Batteries" vocabulary, and vice versa: the "Battery" content type has a term reference field that's linked to the "Machines" vocabulary.

Create the necessary nodes with both the Machinery and the Battery content type - which will generate terms in both the Machines and Batteries vocabulary.

Once this is done, check the right terms in each node: what batteries are related to this machine (for the Machinery nodes), and vice versa: in what machines does this battery fit (in the Battery nodes).

Once this is done, create a View and create a block in it. The block in this example will display related machines, being displayed on the page of a battery.

Set the format to whatever you like (HTML-list, unformatted, grid, ...). I'm using fields in this example (not content, but it should work as well).

Add the fields you'd like to show (Title, Image, ...)

Add the following filter: Content: type (=Machinery)

Now add 2 relationships:

* NAT: Nid (Identifier: "NAT node")
* Content: Taxonomy terms on node
    + Relationship: "NAT node"
    + Vocabularies: "Machines"
    + Identifier: "term"

Add a contextual filter:

* File Usage: Entity ID
    + Relationship: "NAT node"
    + When the filter is not available: provide default value (Content ID from URL) Finally go to the Query settings of the View and check "Distinct" (to avoid duplicates).

Et voila, the first block is ready to go.

For the second block that will show associated batteries on a Machinery page, duplicate the block we've just created and modify the proper settings accordingly (content type filter, vocabulary in taxonomy terms on node).

You should be good to go - it works in both ways now.

I've add some screenshots in case they may be useful (with other names though than in this example, so don't get confused).

(Maybe the EVA module does something similar, both the method above works in both directions)
> -1 votes

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


# Question
Title: FullCalendar links open a new tab, don't want that
I have D7 with FullCalendar (7.x-2.0) installed. When viewing a month view and clicking on an event, the event opens in a whole new browser tab (no matter what browser I'm using).

I don't want that, I want to stay in the same tab. I read at http://arshaw.com/fullcalendar/docs/mouse/eventClick/ that I could change the "self" value from False to True. See below,I did that in fullcalendar.fullcalendar.js and now the link opens itself in the existing tab AND a new tab both.

How do I get this to work the way I want? Thank in advance for any help you can give me.

```
var options = {
  eventClick: function (calEvent, jsEvent, view) {
    if (settings.sameWindow) {
      window.open(calEvent.url, '_self');
    }
    else {
      window.open(calEvent.url);
    }
    return false;

```

# Answer
> 1 votes
In view edit, click on FullCalendar settings under Layout. There is an option to open events in new window.

---
Tags: javascript
---


# Question
Title: Recieving PDOExceptions and missing fields and table on Module installation
I'm new to Drupal and it's pretty much my first experience of adding Modules. I've mostly being using the Migrate module so far in.

On loading I'm getting PDO errors which are created by either missing tables not being added or missing fields in the database. This also happens when I set up my own migrate extension - in regards to the mapping.

*PDOException: SQLSTATE\[42S02\]: Base table or view not found: 1146 Table 'r*.migrate\_group' doesn't exist: SELECT mg.name AS name, mg.title AS title, mg.arguments AS arguments FROM {migrate\_group} mg; Array ( ) in migrate\_ui\_migrate\_dashboard() (line 29 of /*sites/all/modules/contrib/migrate/migrate\_ui/migrate\_ui.pages.inc).*

I can fix these errors - at least to the point of being able to have access to the Migrate UI . By looking in the migrate.install file

```
ALTER TABLE `migrate_status` ADD `group_name` VARCHAR( 255 ) NOT NULL COMMENT 'name of group' AFTER `machine_name`

```

This is not the only table I'm having to fix; but an example.

Also I think it's worthy of noting that the tables I'm fixing have commands such as 'serialize' On another test website I am now receiving a similar PDO error.

So my question is why this is happening and a permanent fix for when I reinstall this or any other modules

I have Drupal Commons 7x-3.12 core installed using Acquia .

Mysql version SELECT @@version;

Thank you for any advice that will push me in the right direction as to why I'm getting this issue.

# Answer
> 0 votes
I noticed that I was getting this error only on Modules that I've been installing directly into the modules/contrib/ folder. Using the 'Install new module' button in 'Modules' installation was not bringing up the PDO exception.

By the way if anyone else couldn't find that button thats becuase you need to activate the 'Update Manager' module first to be able to see it.

I hope this helps anyone else search for the same issue.

---
Tags: 7, database, migrations
---


# Question
Title: how to restore the calendar view created by the calendar module?
When you install the calendar module a calendar view is automatically created. For some reason it seems that I deleted this view. Now I need to use the calendar module and I need this view.

The version of the module is: **7.x-3.4**

I can't find a way to make that the calendar module recreate that view. This is what I did:

1) I disabled the calendar module

2) I uninstall the calendar module

3) I enabled the calendar module again

But the view is not created at all.

How can I have this view restored.

# Answer
it is very simple. Go to Home » Administration » Structure » Views and add new view from template. Yo could see in this section different calendar views. Regards
> 0 votes

---
Tags: views, datetime
---


# Question
Title: Translating strings to English from a second language
It seems that Drupal 7 doesn't provide a function to translate a non-English string to its English equivalent. I'd like to do this for a project I'm working on, but the absence of a reverse-translation function suggests that perhaps I shouldn't. Is there any reason for the absence of a function that translates strings back to English? And how should I achieve this functionality with my project?

# Answer
# `t()` function

By Drupal architecture English is a system built-in language which is used as a **source language** in code.
`t()` function allows to translate from system language to any other language. It is simple and expected behavior.

# UI

There are UI improvements in Drupal 8: http://hojtsy.hu/blog/2013-aug-20/drupal-8-multilingual-tidbits-12-english-can-now-be-translated

Comment about Drupal 7 "Custom English" and problems with default language:

> Using Drupal core alone, this was possible to achieve in Drupal 7 by configuring a "Custom English" language on the site with a language code different from "en", which then allowed you to replace text with your choosing. This quickly gets confusing though because then both the old "en" English language and your new "Custom English" will show up in language selectors, etc. If you disable the "en" English, then your old content saved with that langcode will not display properly. Its a whole can of worms. You may also use String overrides, but if you are using interface translation from core anyway, using one more module for the same task for a specific language is overkill.

# i18n features

More complex translation features (like Content translation from core or i18n package) less depend on system language but often depend on *default* language. Usually you can add content piece in any language and then translate it to English without any problems.

# Summary
> 2 votes

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


# Question
Title: Only one organic group id / name is shown in content listing
I want to create a block/page with a general content listing of all the content in the different organic groups.

Problem is the specific nodes only show **one group id / group name** even though it **belongs to multiple groups**.

To show the group name I used 'OG membership: Group Node from OG membership' relation.

Is there a way to do is with basic view functions. I suppose it can be done using a PHP field but I prefere the basic methods if they exist.

# Answer
Found a solution: Include 'Content: group audience'
> 0 votes

---
Tags: 7, views, organic-groups
---


# Question
Title: Workbench Moderation and Custom Field Issue
I have another "interesting" problem using Workbench Moderation. I'm using Workbench for workflow, along with Workbench Access, Workbench Moderation (7.x-1.3) and Workbench Moderation Notes on a new Drupal 7 site.

I have created a custom Approvers field on my content type that editors will use to select which approver should receive the notification email. This is a list field where the approver name is displayed for selection (the label) and the associated value (key) is the email address of the approver. The latter is to be used in a rule to send the email to the correct address. I have written some PHP to extract the value from the selected item in this Approvers list field:

```
<?php

$node_id = arg(1);
$node = node_load($node_id);
$fieldname='field_approvers';
 $items = field_get_items('node', $node, $fieldname);
if($items)
{
$key = $items[0]['value'];
echo "key = ". $key;
}
else
{
echo $node_id;
}
?>

```

Note that this is inserted in a block for testing purposes and I am not very experienced in PHP (or Drupal for that matter!).

While testing, I have discovered that before publishing the node, all works well and I can extract the correct email address. However, similar to my issue yesterday (Workbench Moderation - Issues with New Drafts of Published Nodes), once a node is published and set back to draft, things stop working properly. The published value of the list field is always returned, even when the list field itself shows the correct new approver. So, if I set back to draft and change the approver in the list field, the PHP code will always return the value from the published version of the node. I have debugged the node and checked the database and the web and I can't figure out how to get the Approvers list field value from the current revision.

# Answer
> 1 votes
Due to the underwhelming response, I had to figure it out for myself :-). To save any other newbie hours of angst, here is the solution:

As predicted, the answer was simple, but finding it was the problem! I eventually found how to load the latest revision by looking at the workbench moderation module source code. If you add the line under the $node variable assignation below, it will return the value on the current revision:

```
<?php

$node_id = arg(1);
$node = node_load($node_id);
$node = workbench_moderation_node_current_load($node); //NEW LINE!
$fieldname='field_approvers';
$items = field_get_items('node', $node, $fieldname);
if($items)
{
 $key = $items[0]['value'];
 echo "key = ". $key;
}
else
{
 echo $node_id;
}
?>

```

Hope this helps someone.

---
Tags: 7, workbench
---


# Question
Title: White screen appears when viewing huge number of nodes as view result
I have a View which display fields of nodes. I have to display all of the items. I cannot introduce a Pager.

There are approximately 4000 nodes as the result of the view. The View preview works perfectly fine, i.e all 4000 nodes are displayed, in the View preview result.

Placing the View on a panel page and loading the page gives the "White screen of death".

What could be the problem?

# Answer
Why not try use this module View Infinite Scroll to try stagger the amount of results returned by Views in one go? This would help the web server from running out of memory returning 4000 results in one go, but is better UX wise than implementing a pager.
> 0 votes

---
Tags: views, entities, nodes, panels, wsod
---


# Question
Title: Vagrant Drupal Development (VDD) Up Stalls
I'm trying to figure out why vagrant is stalling. I installed VirtualBox 4.3.12 and Vagrant 1.6.2, and then grabbed Vagrant Drupal Development (VDD) environment. When trying to bring the machine up it will immediately stall, stuck on: default: Verifying Hyper-V is enabled...

```
==> Default: Verifying Hyper-V is enabled...
INFO subprocess: Starting process: ["c:\\Windows\\System32\\WindowsPowerShell\\
v1.0\\/powershell.EXE", "-NoProfile", "-ExecutionPolicy", "Bypass", "&('c:\\Hash
iCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.6.2\\plugins\\providers\\hyperv\
\scripts\\check_hyperv.ps1')", "-ErrorAction", "Stop"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stderr: The term 'ConvertTo-Json' is not recognized as the nam
e of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.2\plugins\providers\hype
rv\scripts\check_hyperv.ps1:10 char:38
+ Write-Output-Message $(ConvertTo-Json <<<<  $result)
    + CategoryInfo          : ObjectNotFound: (ConvertTo-Json:String) [], Comm
   andNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

DEBUG subprocess: stdout: ===Begin-Output===

```

===End-Output===

# Answer
Hah! I simply added c:\Program Files\Oracle\VirtualBox to my PATH and all is well. I guess it was wanting to use vboxmanage command. I'm happy now.
> 1 votes

---
Tags: virtual-machine
---