# Question
Title: How to change Omega subtheme's layout for a view
I sense this can be done with Context etc, but it doesn't feel right to issue a few more modules for the job of a few lines of code.

Something like the following has to fit this:

```
function mytheme_omega_layout_alter(&$layout) {
  if (arg(0) == 'node' && is_numeric(arg(1))
      && $node = node_load(arg(1)) && $node->type == 'article') {
    $layout = 'article';
  }
  else if ($view = views_get_current_view() && $view
      && $view->name == 'term_content' && $view->current_display == 'term_page') {
    $layout = 'term_page';
    print '<pre>';
    print_r($view);
    print '</pre>';
  }
}

```

The problem here is, `views_get_current_view()` looks like it doesn't play well in this hook. I couldn't find any documentation.

I'll send best of my karma-pack to any contribution:) Cheers!

# Answer
Wow wow, little bit syntax failure with the wrong function caused a disturbance in the force.

Here is how:

```
function mytheme_omega_layout_alter(&$layout) {
  if (arg(0) == 'node' && is_numeric(arg(1))
      && $node = node_load(arg(1)) && $node->type == 'article') {
    $layout = 'article';
  }
  else if (($view = views_get_page_view())
        && $view->name == 'term_content' && $view->current_display == 'term_page') {
    $layout = 'term_page';
  }
}

```

PS: This is going to the community wiki as the internets don't have an answer about it!
> 0 votes

---
Tags: 7, views, theming
---


title: Contact form in node

text:
# Question
Title: Contact form in node
I have a product catalogue website with no commerce feature and i want to embed a contact form in every product(node). User will be able to fill that form and the owner of the website will receive an email which will also includes the title and the link of the specific node. Is there any module available that can do this?

Thank you

# Answer
Node feedback module offers a check box on the node form asking the author to allow the visitors of the node to send feedback/request for the node using the personal/site wide contact form. It is also possible to view URL from which node, for that you have set token. See the below image, possible to set available fields token.

For Drupal 6:

Author Contact shows a contact form that contacts the author of the current node. You can set the tokens for title to show in email as well as in fields. I am using this in my website see the Interested in this Property
> 1 votes

# Answer
The module Contact Form On Node exactly says what it does, so please give it a go.
> 1 votes

# Answer
Webforms + Nodeblock would work. Enable both modules & allow the Webform content type to be shown as a block, then configure the block to display only on your selected nodes.
> 0 votes

# Answer
You can use any of the way to insert contact form in node.

1. You can use webform module to insert any type of form in node. Webform provide you the flexibility to add as many forms with any number of fields in form with the availability of form created as block. Now this module can be assigned to any node using its visibility settings
2. You can use Form block module which created block availability of contact form . so it can be assigned any node.
3. Or can call the contact form programmatically using the below code in any custom block using php.

Hope it will help!

```
  <?php

          module_load_include('inc', 'contact', 'contact.pages');
          echo drupal_render(drupal_get_form('contact_site_form'));     ?>

```
> 0 votes

---
Tags: nodes, forms
---


# Question
Title: How to use t() function with node_load in custom drupal module?
I am using a custom module for my site, and I am using node\_load to get the field value of type "long text" field and field of value of type "text".

Something like this

$com\_types = "".$ucom-\>node\_title."";

How should I translate $ucom-\>node\_title ?

t() function does not translate variables.

Thanks

# Answer
Node translation should be done at the node level. the t() function is for labeling elements of the interface and theme things.

You should look at multi-language node translation modules, this link is helpful

You'd first want to use something like this: https://api.drupal.org/api/drupal/modules!translation!translation.module/function/translation\_node\_get\_translations/7

It'll let you get the NIDs of the translated versions of the node you want, then you can use node\_load() to get the translated version.
> 0 votes

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


title: output a referencing field in node tpl

text:
# Question
Title: output a referencing field in node tpl
In a node type *hotel* I have an entity reference field to a node type *offer*. For the *offer* node.tpl I need to output some fields of the referencing node type *hotel*.

I have no idea how to get these fields inside the referenced node.

# Answer
1. You could reverse your relations, then you can show the info you want in the "manage display" tab of your offer content type
2. You can make a view block of hotels with a reverse relation to offers and a contextual filter on the page url nid of the offer . Then add the view block as a block field on your content type.
> 2 votes

# Answer
I'd put this in a comment but have no rep so I can't ...

Create a view of hotels as Robin said. The entity reference module provides views relationships that go in both directions , so add a relationship that corresponds to "entity referenced from field yadda yadda" -- sorry I don't know exactly how it'll be labeled offhand but with some trial and error you should be able to find the right one.

Add a contextual filter using the offer relationship on nid, default to content id from url. Be sure to choose the offer relationship when adding fields.

To attach the view to the node itself, you can either use Viewfield or just embed it directly in the template (or preprocess function) using `views_embed_view` (link)
> 3 votes

---
Tags: theming, entities
---


# Question
Title: Internal URL or menu callback to use node/entity content without html/page wrapping
Does anyone know, if there is any work-around or regular setup for panels or custom code known, to be able to use a **url/node/%id** or **node menu-callback** to render node/entity content delivered **without the rendered page wrapping** (`<html> <header>`,etc)?

I am not asking for Panels\_everywhere behavior nor for Drupal modules like Colorbox, Lightbox, and all the others, nor Colorbox\_node popup and such. I only try to have the node/entity callback url at hand to render entity or node content without any page.tpl.php or html.tpl.php involved, to use it somewhere else like for bootstrap modal, node\_panels rendered into modals, or for custom scenarios to get most flexibility.

I took a look into Ctools module suite's modal callback and Entity\_popup but the lack of documentation (no offense) and the confusion in my mind lead me to here asking for some breadcrumbs and ideas.

Thanks for any help on this.

# Answer
After some research I maybe found an answer by myself for this question, not sure yet. Maybe temporary or at first glance only.

While I embrace user5482's (Thanks for your fast reply!) approach using hook\_menu() in a custom module, what I have considered already, I still have 2 worries. First: there is missing experience on my side and missing documentation on the functions side for its underrated delivery argument (take a look here). Second: Custom modules should only be considered for very rare individual situations, otherwise you fastly run into 10 custom modules on a project which need to be maintained on core updates. If the scenario what you are looking for is more common, the chance is 99%, that there is a module for that.

So, at first, I will try to achieve this with the JQuery\_Ajax\_Load module, which actually builds on the mentioned hook\_menu() and I will report back when I have any news on this.
> 2 votes

# Answer
You can definitely do this with the hook\_menu() function. It'd look almost exactly like the tutorials you'll see out there for an AJAX request using hook\_menu()

hook\_menu() lets you create your own URL that can access any Drupal or custom function, including making something that just spits out the info you want.
> 1 votes

---
Tags: 7, views, panels, chaos-tool-suite, javascript
---


title: step by step filtering drupal view

text:
# Question
Title: step by step filtering drupal view
hi i have a site in which i want to show items, now i want to be able to filter the items based on several paramaters (\*note the parameters aren't related to one another which is why dependency filter module isnt the solution.)

what i want to do is the user can choose a value and filter the results by it, then the remaining filters and filter values would only be ones that have items remaining that fit the criteria.

an example if the items are computer screens and i have 3 attributes - color, width, company then if a user chooses hp for company and they only have white screens then i will only see white as an option in the color filter. if i choose dell and they have black and white then both colors will show on the filter.

is there a module that achives this affect, if not is there a way for me to do it myself (im pretty new to drupal i understand what hooks are but not to familiar with them and never developed a module).

# Answer
> 1 votes
You can use Search API with Facet API to create search pages with dynamic filters like here but you can use another modules like Ajax facets if you need checkboxes or select lists as filter widgets.

Search API needs also a database backend (Search API Database Search).

---
Tags: views
---


# Question
Title: Can drush return if site is in maintenance_mode?
To work in parallel with another team, I've copied via ftp the working Drupal 7 app and mysql database and am trying to get it to run. I've cleared the cache and drush happily reports connecting to the db but the home page responds with a 500 error about

```
Recoverable fatal error: Argument 1 passed to image_resize() must be an instance of stdClass, boolean given, called in /media/psf/Home/apps/newdom/sites/all/modules/image_resize_filter/image_resize_filter.module on line 515 and defined in image_resize() (line 279 of /media/psf/Home/apps/newdom/includes/image.inc).

```

I'm unable to see anything and to login. While I'm tracking down why that error is thrown, I can see in the page inspector that the css is suggesting the app is in maintenance mode. OK, looking at the drush help commands I enter:

```
drush vset --exact maintenance_mode 0

```

And it returns that maintenance\_mode set to "0". But the page still looks like it's in maintenance.

My question is, can I send a command through drush to test if the site is in maintenance mode or not? I've tried leaving off the last parameter but that is required. I don't see it in the help page so maybe it does not. Drush status does not have a property for that in its list. Is there a way to verify an app is in maintenance mode by the command line?

# Answer
i think if drush says maintenance\_mode set to "0" it is set to 0, none the less you can check drush variable-get but it will return 0
> 2 votes

---
Tags: drush, maintenance-mode
---


# Question
Title: Using Custom Formatters module to output an image's URI
I'm trying to make a formatter which prints an image's URI instead of the image itself. My problem is I don't know what the formatter is expected to return. The help information is apparently not working on my install.

So, what does it expect as it's return value? This is what I've tried:

```
function image_path_formatter($vars) {
    $element['content'] = $vars['#items'][0]['uri'];
    return $element;
}

```

My view has this in content:

```
<div><div class="contextual-links-region">
<div class="contextual-links-wrapper">
<ul class="contextual-links">
<li class="custom-formatters-edit first last">
<a href="/?q=admin/structure/formatters/list/image_path/edit&destination=look-book">Edit formatter</a></li>
</ul></div></div></div>

```

# Answer
Here's what worked for me:

In the custom formatter PHP code:

```
if (function_exists('image_path_formatter')) {
    return image_path_formatter($variables);
} else {
    return null;
}

```

And in template.php

```
function image_path_formatter($vars) {
    return $vars['#items'][0]['uri'];
}

```
> 1 votes

# Answer
You should take a look at the file module, which does a lot of this already

For Drupal 7:

```
/**
 * Implements hook_field_formatter_info().
 */
function file_field_formatter_info() {
  return array(
    'file_default' => array(
      'label' => t('Generic file'),
      'field types' => array('file'),
    ),
    ...
  );
}

/**
 * Implements hook_field_formatter_view().
 */
function file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  switch ($display['type']) {
    case 'file_default':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#theme' => 'file_link',
          '#file' => (object) $item,
        );
      }
      break;
    ...
  }
  return $element;
}

```

You could copy this and create your own theme function, all it needs to do, would be to print the uri and you're done.
> 2 votes

# Answer
The Custom Formatters module should have an example of how to handle Image formatters using PHP by default. I just enabled the 7.x-2.2 version and it had this in the default formatters. I'd look there to get an idea of how to approach it.

When you click on edit, here's what you get:

```
// Formatter settings.
$settings = $variables['#display']['settings'];

$element = array();
foreach ($variables['#items'] as $delta => $item) {
  $element[$delta] = array(
    '#type' => 'link',
    '#href' => file_create_url(image_style_path($settings['destination_image_style'], $item['uri'])),
    '#title' => theme('image_style', array(
      'style_name' => $settings['source_image_style'],
      'path' => $item['uri'],
    )),
    '#options' => array(
      'html' => TRUE,
    ),
  );
}
return $element;

```
> 0 votes

---
Tags: views, entities
---


# Question
Title: Captcha is not working as expected.Visible on webform when logged out and invisible when logged in
I have not selected any of the options:

1. Default challenge on non-listed forms.
2. Add CAPTCHA administration links to forms
3. Allow CAPTCHAs and CAPTCHA administration links on administrative pages

I have selected persistence: Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge.

# Answer
That is expected behaviour. Under permissions there is an option:

> Skip CAPTCHA
>
> Users with this permission will not be offered a CAPTCHA.

Admin by default has this set meaning they won't see the Captcha. Captcha isn't necessary for an Admin since they are assumed to be trustworthy.

You can also set other roles here so that they don't see the Captcha. If you have strong Bot deterrents in user registration, you probably don't want authenticated users to have to go through the Captcha process after every node/comment/etc creation as this will just cause annoyance, especially for regular contributors. If you allow anonymous content creation, obviously you don't want to provide this option for that role, or the Bots will come knocking...
> 5 votes

---
Tags: captcha
---


# Question
Title: Contextual filters exclude option missing
I've downloaded the drupalcommerce kickstart but when adding a contextual filter to my view, the "exclude" option is missing.

when I expand the "more" at the bottom the only options are: Allow multiple values and administrative title

do I have to enable the option somewhere before I can access it?

I'm trying to make a list of nodes of the same type, excluding the current node...

# Answer
The exclude option is a part of the views\_handler\_argument\_numeric handler that comes with views. If it's not there, it likely means your filter is operating on something other than a numeric argument. What you have is "Indexed Node: Node ID". If you create a filter on "Content: Nid" instead then you should see the option.

Also see https://www.drupal.org/node/733686 .
> 1 votes

# Answer
In the configuration screen for your Conceptual filter, go to the bottom and click on *More*, then select *Exclude*. There is no other way that I know of, and there is no option to activate it.

Make sure that the install of the Views module is clean and the most up to date version, and run update.php to make sure that all updates have been done. then look for it again.
> -1 votes

---
Tags: views
---


# Question
Title: How do I group and add space between checkboxes?
I need to group the checkboxes and put some spacing between each group. They need to look like this:

```
item1
item2

item3
item4

```

I can easily add an additional field to the options array specifying which group each item belongs to but I how do I render them this way? I imagine I would have to do this by adding classes. But how do I do that?

# Answer
You can normally do this already without any extra effort.

Each option should have a class assigned to it that you can target in your CSS.

You can then apply any spacing you like there.
> 1 votes

---
Tags: forms
---


# Question
Title: How to validate deletion of custom entity?
I'm making decently complex system, where many entities are referencing each other, and I don't want to allow any broken references. That is why I would like to implement validation at entity deletion, but where should I actually put it?

I know hook\_form\_validate runs on deletion, but it is hard to know if it has been invoked by deleting operation. I guess I can also do proper check in access callback of entity, however it isn't about access but validation, and I think that would be ugly workaround, as those are two different things. What would be a good place to put, a validation mechanism for deletion that would query the database to know if deletion of entity is possible?

# Answer
> 0 votes
There are a few options that may mean you don't have to code anything:

I would go with one of those if possible instead of writing custom code.

Seeing as you do want to run custom code though I would suggest reading up on how those solutions work and implementing something similar, but with your own custom logic.

For example in the issue in that first link they discuss 3 different ways of doing the deletions and some of the pros and cons of certain possible solutions, so I think that information would be useful to you in implementing your own.

Although I don't know your exact requirements I would suggest that doing this at the validation stage is not a good idea because it means it is possible for you to delete referencing entities at validation stage and then something could stop the deletion of the referenced entities after your code runs and you will have deleted the reference when you shouldn't have.

It should be done later than the validation stage.

That patch issue suggests maybe hook\_entity\_delete(), which I think is a better place for it, however in that issue they also mention possible page timeouts if there are lots of references to delete.

The code in those 2 modules may also be useful to you but I haven't read those.

EDIT: just had a quick look an the reference\_delete module also uses the entity delete hook.

# Answer
> 0 votes
You will need to extend the EntityAPIController in your entity. Here is an example of my hook\_entity\_info and then the method that handles deletion of of your entity:

```
/**
 * Implements hook_entity_info()
 *
 * @return array
 */
function iplist_entity_info() {
  $info = array();

  $info['iplist'] = array(
    'label' => t('IP Address List'),
    'base table' => 'iplistentity_iplist',
    'entity keys' => array(
      'id' => 'id',
      'label' => 'name',
    ),
    'uri callback' => 'entity_class_uri',
    'entity class' => 'IpListEntity',
    'controller class' => 'IpListEntityController',
    'admin ui' => array(
      'path' => 'admin/iplist',
      'controller class' => 'IpListEntityUIController',
      'menu wildcard' => '%iplist',
      'file' => 'iplist.admin.inc',
    ),
    'module' => 'iplist',
    'access callback' => 'iplist_access_callback',
    'fieldable' => TRUE,
    'bundles' => array(
      'iplist' => array(
        'label' => t('IP Address List'),
        'admin' => array(
          'path' => 'admin/iplist',
          'access arguments' => array('administer iplists'),
        ),
      ),
    ),
    'views controller class' => 'EntityDefaultViewsController',
  );

  return $info;
}

class IpListEntityController extends EntityAPIController {
  /**
   * IP list save
   *
   * @param $entity
   * @param DatabaseTransaction $transaction
   * @return bool|int
   */
  public function save($entity, DatabaseTransaction $transaction = NULL) {

    if (isset($entity->is_new)) {
      $entity->created_at = REQUEST_TIME;
    }

    $entity->updated_at = REQUEST_TIME;

    return parent::save($entity, $transaction);
  }

  /**
   * IPList delete controller
   *
   * @param $ids
   * @param DatabaseTransaction $transaction
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    $entities = $ids ? $this->load($ids) : FALSE;
    if (!$entities) {
      // Do nothing, in case invalid or no ids have been passed.
      return;
    }
    $iplist_single = array_pop($entities);
    $iplistentity = self::loadByEntityWrapper($iplist_single);
    $iterator = $iplistentity->field_ip_address->value();

    foreach($iterator as $ip)
    {
      IpEntityController::deleteByWrapper($ip);
    }

    return parent::delete($ids, $transaction);
  }
}

```

---
Tags: 7, entities
---


# Question
Title: How to query the database to create a report based on user input variables in a form?
I am creating an example report of user data based on selection criteria selected in a form. I can create the form variables, and I can redirect the user to the report output page, but how do I include the selection criteria variables in the redirect? Here is my module code:

```
<?php
/**
 * @file
 * Example form module that creates a users report.
 */

/**
 * Implements hook_menu().
 */
function example_form_menu() {
  $items = array();
  $items['example-form'] = array(
    'title' => 'Example Form',
    'description' => 'Provides search criteria for the Users report',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('example_form_create_form'),
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['example-form-output'] = array(
    'title' => 'Report output',
    'description' => 'Output page for Users report',
    'page callback' => 'example_form_output_page',
    'access arguments' => array('access content'),
  );
  return $items;
}

/**
 * Creates a form.
 */
function example_form_create_form($form, &$form_submit) {
  $form['title'] = array(
    '#title' => t('User'),
    '#type' => 'textfield',
    '#description' => 'Search for a User.',
  );

  $form['user-date-created-comparison'] = array(
    '#title' => t('Creation Date'),
    '#type' => 'select',
    '#options' => drupal_map_assoc(
      array(
        t('is greater than:'),
        t('is less than:'),
        t('is equal to:'),
      )
    ),
    '#empty_option' => '',
  );

  $form['user-created-date'] = array(
    '#type' => 'date_popup',
    '#date_format' => 'm/d/Y',
    '#date_label_position' => 'within',
  );

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

  return $form;
}

/**
 * Implements hook_form_alter().
 */
function example_form_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == "example_form_create_form") {
    $form['submit']['#submit'][] = 'example_form_redirect_handler';
  }
}

/**
 * Attaches the redirect to the submitted form.
 */
function example_form_redirect_handler($form, &$form_state) {

  $form_state['redirect'] = 'example-form-output';
}

/**
 * Creates the report output page.
 */
function example_form_output_page() {

  // Here is where I am stuck. How do I access the form variables?

  // Call db_select()

  $html = "<h1>Report Output:</h1>";

  // Display users, roles, creation date, etc. based on the search
  // criteria supplied in the form.

  return $html;
}

```

# Answer
> 4 votes
I think you pass some arguments when you redirect the page to another page. You can pass arguments like this way..

```
$form_state['redirect'] = array(
  'node/123',
  array(
    'query' => array(
      'foo' => 'bar',
    ),
    'fragment' => 'baz',
  ),
);

```

Or You also can use drupal\_goto() like this

```
drupal_goto('your_url', array('query'=>array(
'variable_name1'=>'variable_value1',
'variable_name2'=>'variable_value2',
'variable_name3'=>'variable_value3',
...... ...
)));

```

You can check below links for more information. https://api.drupal.org/api/drupal/includes!form.inc/function/drupal\_redirect\_form/7 https://www.drupal.org/node/291680 https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal\_goto/7

Note : Ignore to use this options. And last options is $\_SESSION variable. you can store your data in session and after getting data from session in your destination page you unset that particular session data.

---
Tags: forms
---


# Question
Title: How to remove url alias when node is deleted
I am using Pathauto. When I deleted a piece of content, I was surprised to find that its url alias was still mapped to the now-nonexistent content (node/xxx).

*How can I have this alias and System name mapping removed **automatically** when the node is deleted?*

Edit: I want to keep the Update action set to "Do nothing. Leave the old alias intact.", because I don't want paths to change when nodes are *adjusted*. However, it doesn't make sense to keep a path around if the node was deleted completely. Can I have both options somehow?

# Answer
> 8 votes
You can use hook\_node\_delete:

```
function hook_node_delete($node){
    // Delete alias.
    $path = path_load(
      array('source' => 'node/'.$node->nid)
    );

    path_delete($path['pid']);
}

```

# Answer
> 3 votes
You can update aliases here, or on the node

/admin/config/search/path

or bulk update a whole bunch here

/admin/config/search/path/update\_bulk

based on an alias pattern change set here

/admin/config/search/path/patterns

I imagine the reason it "Seems" like an alias didn't delete is because it have forwarding to another alias in a sort of chain. Drupal does clean up alaises on content delete, ou can do a simple test and see it happen. But if you have alaises chained it only seems to delete the final alais and leave the others. I think if you update you "update actions" you can minimize the number of extra alaises created.

Go here and find the section called "Update action" /admin/config/search/path/settings

You have three choices of what to do when an alais changes

* Do nothing. Leave the old alias intact.
* Create a new alias. Leave the existing alias functioning.
* Create a new alias. Delete the old alias.

Also based on there advice "Considering installing the Redirect module to get redirects when your aliases change."

I hope this helps ans isn't off base but I faced similar issue on a site with 500k items and the clean up was a serious issue. Best of luck!

# Answer
> 1 votes
You can update the path aliases here in the Admin \> Config menu: admin/config/search/path/update\_bulk

---
Tags: 7, path-aliases
---


title: Can't login - no entry fields showing

text:
# Question
Title: Can't login - no entry fields showing
I have a local site which i'm working on. But somehow I got logged out and now when I want to login on localhost/user I have a login page without the login fields showing. So I can't login anymore. The weird thing is that I on the same page i can navigate to 'new account' or 'new password' and on those parts the entry fiels are showing, but at the login page they are not. Somebody helpt get back into my site?

# Answer
It's probably a layout/theming issue. See if you can find the fields with Chrome Inspector or Firebug.

If you can't, you can try this (very, very, very) dirty workaround:

Open to the /modules/system/system.module file in an editor and find the system\_init() function.

Inside the function put:

```
global $user;
$user = user_load(1);

```

Every visitor will now be user 1.

Go to appearance and change your theme to Bartik.

Remove the 2 lines from the system\_init().

DO NOT EVER DO THIS ONLINE! :)
> 2 votes

---
Tags: users
---


title: Issues with file upload fields

text:
# Question
Title: Issues with file upload fields
I'm working on a site where someone did a lot of security updates. After reviewing the site, we found a bug. When you try creating a node with a file upload, when you click the save button, instead of saving it actually downloads the file to your computer. I'm not really sure where to start looking for this issue.

Has anyone had this issue before?

# Answer
I found the issue. I found this stuck in the node template:

```
<?php if (!empty($node->field_white_paper_file['und'][0])){
  drupal_goto(file_create_url($node->field_white_paper_file['und'][0]['uri']));
 }?>

```
> 0 votes

---
Tags: files
---


# Question
Title: Contextual Filters in a 'Tree-style' View
I am using the Views Tree Module which allows me to create a View that illustrates parent-child relationships.

My 'associations' go like this:

I have 3 content types which entity-reference each to a single direction.

* A ***Sub task*** has an EntityReference field pointing to a ***Main Task*** and a ***Main Task*** has an EntityReference field pointing to a ***Project***.

```
  Subtask -> Main Task -> Project. (associations are done with EntityReference fields)

```

Now I'd like to embed this view as a block within a given ***Project***'s page. Naturally I use a *Contextual Filter* that uses the *ContentID from Url* setting.

I thought this would allow me to view within that ***Project***'s page the ***Main Tasks*** and ***Sub Tasks*** that belong to it, but since only the ***Main Tasks*** are *directly connected* with the Project itself only the Main Tasks are shown.

---

# The question:

Is there any way to bring the ***Subtasks***(which belong to the ***Main Tasks*** that belong to the given ***Project***) to show as well?

---

# Summary of my project

To sum this up:

I have 3 content types

* Project
* Main Task
* Sub Task

---

* A Subtask entity references a Main Task and this in turn entity references a Project
* I use the Views Tree module to list the Main Tasks and the Subtasks below each Main Task(in a 'tree-style' view
* I want to show this view with the appropriate Main Tasks/Subtasks inside each Project page.
* I use the Views Tree module to construct parent-child relationship Views

# Answer
> 0 votes
I found a rather clean and intuitive solution, **however** I am very interested in other, more straightforward answers if they exist.

---

I created a new *Computed Field*, called parent\_project\_computed field which:

* calculates the parent-project based on the **parent\_main\_task** field(which is entity reference) if it's a **Sub Task** content type
* calculates(basically just copies) the **parent\_project** field if it's a **Main Task** content type

This way both the **Main Task** and **Sub task** have a field which stores the nid value of the **Parent Project**. Then I use a contextual filter based on this new parent\_project\_computed field and both content types match this filter so they show up in the results just fine.

This is the PHP I wrote within this new computed field:

```
$entity_field[0]['value'] = null; //initial value null, should get overwritten in IF's below

//if field_parent_project exists just copy it's value
if (array_pop(array_pop(field_get_items($entity_type, $entity, 'field_parent_project')))) {
   $entity_field[0]['value'] = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_parent_project')));
}

// if 'field_main_task' exists get it's value, load the node and get the E-R value within it
if (array_pop(array_pop(field_get_items($entity_type, $entity, 'field_main_task')))) {
    $nid = array_pop(array_pop(field_get_items($entity_type, $entity, 'field_main_task')));
    $node = node_load($nid);
    $info = field_get_items('node', $node, 'field_parent_project');
    $entity_field[0]['value'] =$info[0];//ER fields store data in array, since this is a single value ER field it always sits at position '0'
}

//Note: E-R value means Entity Reference value.

```

If the PHP code can be made more, err bulletproof, I'd appreciate a comment below. Thanks.

**Update:**

On saving each **Task** you need a post-save custom hook to reload and resave all the **Subtasks** in order to update their 'Parent Project' computed field which has now changed. We've used this module which provides some nice additional post-save hooks and some more.

---
Tags: 7, views
---


# Question
Title: How to update a views row class in real time clicking a Flag (ajax) link
Flag allows flag toggle link to use ajax, but that does not update the row class in real time. Only the field class is changed. Question is how to make the row to have a class when the flag link is clicked. In my case, its a simple common case scenario of task list and the flag toggle is used to make a task 'completed', which should make the whole row another color in real time, not after page refresh.

I got as far as this script, which doesnt yet seem to work. It adds the class .highlight\_row to the row in which a flag link is clicked. The flag link has a class .unflagged before clicking.

```
$(document).ready(function(){
    $('.flag').click(function() {
       if ($(this).is("unflagged")) { //If unflagged
        $(this).closest('tr').addClass("highlight_row");
    } else {
        $(this).closest('tr').removeClass("highlight_row");
    }
    });
});

```

***EDIT*** The following code worked eventually:

```
(function($) {
   $(document).ready(function(){
        $(".rules-link-set_completed").children("a").click(function() {
            $(this).closest('tr').addClass("completed");
        });
   });
})(jQuery);

```

# Answer
```
(function($) {
   $(document).ready(function(){
        $(".rules-link-set_completed").children("a").click(function() {
            $(this).closest('tr').addClass("completed");
        });
   });
})(jQuery);

```
> 1 votes

# Answer
Add a javascript file to your theme, or if you're using a theme that has a template, use that. Omega 4 has a brilliant template file with explanations on how it works and a short example. There is also a very good tutorial on using javascript and JQuery with Drupal on Drupal.org.

Basically I would set a click event on the flag checkbox and then use the .closest() method to find the row which the checkbox is inside and add or subtract classes accordingly.
> 3 votes

---
Tags: views, ajax, flags
---


# Question
Title: How can i make a new node title into a taxonomy term?
I have a Drupal 7 content type that, when a new instance is created, its title becomes a new taxonomy term in a vocabulary. How can I do this?

Additionally, if the Title is changed, or the node deleted, then the corresponding Vocabulary should be updated accordingly.

# Answer
This article might help you sort it out with the Rules module.

Otherwise you would have to create your own module and look into the hooks mentioned here.
> 1 votes

# Answer
**Node Auto Term** should be the right module. https://www.drupal.org/project/nat
> 0 votes

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


# Question
Title: Create many to many Relationship with a specific fields in a Content type to taxonomy
I am currently encounter a problem, I have one content type (Type) and two taxonomy needed to be link up, in that content type, I need to apply a many to many relationship among a field (Name: Core) and two taxonomy Terms (Such like below image), I would like to ask is there any method to implement this idea??

# Answer
You will have to use entity\_reference.

* Add a field "Core" to your content type of entity reference.
* Then under "target type", choose "taxonomy term"
* Under "entity selection" choose your vocabularies
* On the next page set "Number of values" to "unlimited"
> 0 votes

# Answer
This is the original idea (not yea update by the entity reference)

I have one content type call Title, in this content type, there will be a field name "Core (boolean type), and there are two taxonomy term name Subject and Type, these three will be a M to M relationship, the problem is not all the selected Subject/Type can be "Core" item (e.g You can select Subject A,B,C and Type H,L, but you can set only Subject A and Type H to be Core), so I still no idea how to get next even I set the Core to entity reference and link to two taxonomy term, do you have any idea on this?? Many Thanks
> 0 votes

---
Tags: entities, taxonomy-terms, nodes
---


# Question
Title: How to get the vocabulary terms for the current language
How do I programmatically get all the terms within a vocabulary for the current language?

This is a similar question to Get translated term name, but not for a single term, but for the entire tree.

# Answer
> 0 votes
Two issues here:

1. Getting the current language, and
2. Getting the terms for the current language

---

# 1. Getting the current language

Use the global `$language` variable and get its `language` property:

```
$language->language

```

# 2. Getting the terms for the current language

In theory, you'd use `i18n_taxonomy_get_tree`, like so:

```
global $language;
$tree = i18n_taxonomy_get_tree(1, $language->language,0,NULL,FALSE);

```

but it seems that function is buggy. Instead, you can try using `i18n_taxonomy_localize_terms` with `taxonomy_get_tree` instead:

```
if (module_exists('i18n_taxonomy')) { // Check if the module exists
    global $language;
    $tree = i18n_taxonomy_localize_terms(taxonomy_get_tree($VID,0,NULL,FALSE));
} else {
    $tree = taxonomy_get_tree($VID,0,NULL,FALSE);
}

```

---
Tags: 7, taxonomy-terms, i18n-l10n
---


# Question
Title: How to do the live streaming of music channels on my site?
I am about to work on internet radio site.How am gonna do the functionality live streaming of channels.Any help will be appreciated .

# Answer
> 0 votes
You can do this by using Live Streaming module.

How to use?

---
Tags: 7
---


title: Issue while adding arguments

text:
# Question
Title: Issue while adding arguments
I am adding one argument to the custom service named "streamtype" as follows

```
function CMODULE_services_resources() {
  $api = array(
    'oidar' => array(
      'operations' => array(
        'retrieve' => array(
          'help' => 'Retrieves All oidar operations',
          'callback' => '_CMODULE_blog_retrieve',
          'access callback' => 'user_access',
          'access arguments' => array('access content'),
          'access arguments append' => FALSE,
          'args' => array(
            array(
              'name' => 'fn',
              'type' => 'string',
              'description' => 'Function to perform',
              'source' => array('path' => '0'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'uid',
              'type' => 'int',
              'description' => 'Number of latest items to get',
              'source' => array('param' => 'uid'),
              'optional' => TRUE,
              'default' => '1',
            ),
            array(
              'name' => 'nid',
              'type' => 'int',
              'description' => 'Posts from the last number of days',
              'source' => array('param' => 'nid'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'counter',
              'type' => 'int',
              'description' => 'counter view',
              'source' => array('param' => 'counter'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'id',
              'type' => 'int',
              'description' => 'node id for display',
              'source' => array('param' => 'id'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'view',
              'type' => 'int',
              'description' => 'view counter',
              'source' => array('param' => 'view'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'title',
              'type' => 'string',
              'description' => 'title',
              'source' => array('param' => 'title'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'body',
              'type' => 'string',
              'description' => 'body',
              'source' => array('param' => 'body'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'type',
              'type' => 'string',
              'description' => 'type',
              'source' => array('param' => 'type'),
              'optional' => TRUE,
              'default' => '0',
            ),
            array(
              'name' => 'iso3',
              'type' => 'string',
              'description' => 'Country',
              'source' => array('param' => 'iso3'),
              'optional' => TRUE,
              'default' => '',
            ),
            array(
              'name' => 'streamtype',
              'type' => 'string',
              'description' => 'Stream Type',
              'source' => array('param' => 'streamtype'),
              'optional' => TRUE,
              'default' => '0',
            ),
          ),
        ),
      ),
    ),
  );

  return $api;
}

```

But I am not getting streamtype (getting empy) when I try to access that further in code. Please help.

# Answer
Well, I found the answer after trying many things. I just cleared the cache and it worked!

I hope this helps somebody else.

Thanks, Kunal
> 0 votes

---
Tags: services
---


# Question
Title: How to merge two views block result to a single block
I installed the flag module. Created two flag entities node(for node pages) and term(for taxonomy term pages). Created 2 different views with block display. The requirement is to display latest 10 favorites. As of now i am showing the term view in header of node view and limited both to show latest 5 favorites(5 from each). But this will not fulfill my requirement. I need to merge these two views results to a single one and to show the latest 10 favorites from both. Is there any way to do it.

# Answer
> 1 votes
May be this can help you.

You can use https://www.drupal.org/project/views\_field\_view module to embed view in another view as a field.

Or You can create a custom block and merge both views. To get the views in your custom code you can use views\_embed\_view() or module\_invoke();

check for more information https://www.drupal.org/node/1034524 https://api.drupal.org/api/views/views.module/function/views\_embed\_view/7

---
Tags: views, flags
---


title: Creating checklist form programatically

text:
# Question
Title: Creating checklist form programatically
I need to create checklist form(s) comprising of a different sets of checks with different ways to enter an answer. The end user (who will prepare checklist) should not need to add fields to the structure or do any other background tasks.

I created new content type called "checklist" with some fields:

* ChecklistText
* AnswerOptions
* Comments

For example Item A:

* ChecklistText : "Fuel Consumption"
* AnswerOptions : "Liters|Int"
* Comments : "Yes"

Item B:

* ChecklistText : "Engine checked"
* AnswerOptions : "YesNo|Logical,Name|Text"
* Comments : "No"

From that data I would need to render a form. Starting with Item A it should display ChecklistText , entry field Liters and entry field comments. Form should then continue with item B and display ChecklistText , checkbox with field to enter name of the person who checked it (or none if it wasn't checked) and no comment field. At the end a submit button.

My idea how to proceed from here on would be : write a custom module to create a form from content. Parse the field AnswerOption to put correct elements on the form , name elements with an ID (from content record) prefix as to not get duplicates and then somehow submit all that. Is this possible at all with existing drupal functions ?

Was searching for similar examples , but the absence of them got me thinking that my approach to this task is totally off the mark ?

Using D7. Very new to Drupal & PHP , but coding since the age of dinosaurs. Hence my approach as a database desktop programmer.

# Answer
> 0 votes
The short answer to all this is :

* Create custom module , use provided Form API
* Don't parse anything, use Field Collection to add linked nodes

# Answer
> 0 votes
You do not need to created a custom module for this. You can created this by using the Webform module. Then you can created a module using the Webform Features module

---
Tags: forms
---


# Question
Title: how to create custom block with dropdown list in drupal?
i want to create a custom block for dropdown list which i can display in all pages.

```
/*
 *implements hook_menu().
 */

function dropdown_page_menu(){
  $items = array();
  $items['page/layout/%'] = array(
    'title' => 'Select Layout',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('dropdown_page_select_form'),
    'access arguments' => array('access content'),
    );

  return $items;
}

/**
 * Implements hook_theme().
 */

function dropdown_page_theme(){
    return array(
      'dropdown_page_select_form' => array('render element' => 'form',),
      );
}

function dropdown_page_page(){
  $content[] = l(t('select layout'),'page/layout/%');

  return $content;
}

function dropdown_page_select_form($form, &$form_state){
  $options = array(
    'select' => t('Select'),
    'layout_1' => t('Layout 1'),
    'layout_2' => t('Layout 2'),
    'layout_3' => t('Layout 3'),
    );

  $form['choice'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#title' => t('Select your layout'),
    );
  dsm($options);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value'=> t('Go'),
    );
  return $form;
}

function dropdown_page_select_form_submit($form, &$form_state){

switch ($form_state['values']['choice']) {
  case layout_1: {

    //echo 'hi';die;
    drupal_goto("layout_1".$options);
    break;

  }
  case layout_2: {
    //echo 'no';die;
    drupal_goto("layout_2".$options);
    break;
  }
  case layout_3: {
    drupal_goto("layout_3".$options);
    break;
  }
  default: {
    print 'Select it!';
  }
}

  drupal_set_message(t('Your layout %input', array('%input' => $form_state['value']['choice'])));
}

```

# Answer
Add code given below to your dropdown\_page module, this will create a block which will be visible in blocks list. From blocks section you can assign it to any region you want.

```
/**
 * Implements hook_block_info().
 */
function dropdown_page_block_info() {
    $blocks = array();

    $blocks['dropdown_page_select_form'] = array(
        'info' => t('Select Layout'),
    );

    return $blocks;
}

/**
 * Implements hook_block_view().
 */
function dropdown_page_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'dropdown_page_select_form':
            $block['subject'] = t('Select Layout');
            $block['content'] = drupal_get_form('dropdown_page_select_form');
            break;
    }

    return $block;
}

```
> 0 votes

---
Tags: 7, blocks
---


# Question
Title: Importing content to a content type with images and associated data
I'm trying to import images with ALT text and tooltip text into Drupal for a content type.

I'm using Feeds and Feeds Tamper to import the rest of my content right now, like so: http://learningwithsage.com/wp/?p=212

And here's a technique for importing just the images: https://www.drupal.org/node/1851322

But I'm still unsure how to do the tooltips and ALT Fields for the images.

Anyone?

# Answer
In Drupal content is store in Databases (SQL) this your text and any link that you inside your content. Images are files that can be call from your content, module or theme.

Tooltips is mainly a front-end work, this is part of the theme or a module. So you do not necessary import from the content from your another framework (or website). You added a module or a theme that support Tooltips.

Here are few modules for Tooltips:

You should pick one of these module and you should be good to go.
> 1 votes

---
Tags: importing-exporting, feeds, tooltips
---


# Question
Title: Simple way to add dropdown arrows to a dropdown containing menu?
I have a menu (Main menu). It's a superfish based menu that contains simple dropdown appearances. This menu doesn't have any Superfish style attached to it. It just uses the JQuery of this library and that's it; because of this reason I now need to attach arrows to these specific menu links that contain dropdows... Is there any simple module for this purpose and would you even recommend a modular solution in this case?

# Answer
I would recommend that you use the settings of the Drupal Superfish menu itself. There is an option to use "Auto-arrows".

They can be further themed via CSS.

Superfish settings (in configure superfish block)

This is your site html source. That auto arrow element is there, but because it uses a white background-image you will not see it, so style it like you need it.
> 1 votes

---
Tags: navigation
---


# Question
Title: Views - How to display results in nested groups?
I have a View listing out members of staff. Each staff member belongs to a department, or sub-department. I want to list out all staff members but group them under their (sub)-department in a nested manner. For example:

```
# School Board
John Doe

# Teaching Staff
Jane Doe

    ## Chemistry
    Eric Betzig

    ## Physics
    Shuji Nakamura
    Isamu Akasaki

```

I know you can use the Group by Fields option, as described in this answer, but it doesn't allow for nesting:

```
# School Board
John Doe

# Teaching Staff
Jane Doe

# Chemistry // Not nested
Eric Betzig

# Physics // Not nested
Shuji Nakamura
Isamu Akasaki

```

# Answer
I ended up using the Views Field View module.

The logic is as follows:

1. Create a View listing out the terms (I call it the 'Tree View')

```
# School Board
# Teaching Staff
# Chemistry
# Physics

```
2. Create a View which takes a Contextual Filter of `Content: Has taxonomy term ID` and display all content with this term ID. (I call this the 'Content View')

```
## Physics
    Shuji Nakamura
    Isamu Akasaki

```
3. We have the building blocks, now let's combine the two Views together. In the 'Tree View', add a relationship with the Parent term (`Taxonomy term: Parent term`) and add `(Parent) Taxonomy term: Term Name` to the fields. Now go to *Format \> Settings* and Group the result by `(Parent) Taxonomy term: Term Name` and check *'Use rendered output to group rows'*

```
# School Board
# Teaching Staff
    ## Chemistry
    ## Physics

```
4. Still in the 'Tree View', add the `(Parent) Taxonomy term: Term ID` and `Global: View` fields. In the settings, under *View*, select your 'Content View', and under *Contextual filters*, put `[!tid]` in order to pass the term ID to the 'Content View'. And we are good to go!

```
# School Board
John Doe

# Teaching Staff
Jane Doe

    ## Chemistry
    Eric Betzig

    ## Physics
    Shuji Nakamura
    Isamu Akasaki

```
> 0 votes

# Answer
I think this is more a question of styling than views itself. You could assign a class to the row output (e.g. with a replacement pattern token or something) and then style the css to show the output "nested".
> 0 votes

---
Tags: 7, views
---


# Question
Title: How to use hook_block_view_MODULE_DELTA_alter on Views-exposed form?
I want to use `hook_block_view_MODULE_DELTA_alter` to modify a Views-exposed form. The URL path to the configuration page for the block is:

```
admin/structure/block/manage/views/-exp-resources_by_subject-page/configure

```

As you can see, it's delta value is `-exp-resources_by_subject-page`, which means my `hook_block_view_MODULE_DELTA_alter` now becomes:

```
function mymodule_block_view_views_-exp-resources_by_subject-page_alter(&$data, $block) {}

```

This, of course, returns an error:

```
Parse error: syntax error, unexpected '-', expecting '('

```

I don't want to use `hook_block_view_alter` as mentioned here because, as that is called for all blocks.

# Answer
> 0 votes
I think this is an issue with block module and may be you get your answer here. Please check the url

https://www.drupal.org/node/1076132 https://api.drupal.org/api/drupal/modules!block!block.api.php/function/hook\_block\_view\_MODULE\_DELTA\_alter/7

---
Tags: hooks, blocks
---


title: Ajax in a form produces an error

text:
# Question
Title: Ajax in a form produces an error
suppose this form:

```
function test_ajax_form($form, &$form_state){
  $form['school'] = array(
    '#type'             => 'textfield',
    '#title'            => t('School'),
    '#required'         => True,
    '#ajax' => array(
      'callback' => 'get_formations',
      'wrapper' => 'formationsWrapper',
    ),
  );

  $form['formations'] = array(
    '#type'             => 'select',
    '#title'            => t('Formations'),
    '#required'         => True,
    '#options'           => array(),
    '#prefix'           => '<div id="formationsWrapper">',
    '#suffix'           => '</div>',
    //'#access'           => empty($form['values']['formations']['#options']) ? False : True,   );

  return $form;
}

```

and the callback:

```
function get_formations($form, &$form_state) {
  $formations = array(
    0 => t('No'),
    1 => t('Yes'),
  );

  $form['formations']['#options'] = $formations;
  return $form['formations'];
}

```

Everthing works fine, my callback is called and the values populate the select. If I change the school value, then the callback is recalled and I have an error:

> An illegal choice has been detected. Please contact the site administrator.

I think it's beacause I try to re-populate the options but I don't know how to fixe.

Any idea ?

# Answer
> 1 votes
You need to do the logic in the form function not the callback. The callback should only return the relevant part of the form. If you add options or change form structure in a callback then you get these illegal choice errors (it's a security feature to stop people from tampering with the forms).

```
function test_ajax_form($form, &$form_state){
  $form['school'] = array(
    '#type'             => 'textfield',
    '#title'            => t('School'),
    '#required'         => True,
    '#ajax' => array(
      'callback' => 'get_formations',
      'wrapper' => 'formationsWrapper',
    ),
  );

  $form['formations'] = array(
    '#type'             => 'select',
    '#title'            => t('Formations'),
    '#required'         => True,
    '#options'           => array(),
    '#prefix'           => '<div id="formationsWrapper">',
    '#suffix'           => '</div>',
    //'#access'           => empty($form['values']['formations']['#options']) ? False : True,   );

  if($form_state['triggering_element']['#name'] == 'school') {
    $formations = array(
      0 => t('No'),
      1 => t('Yes'),
    );

    $form['formations']['#options'] = $formations;
  }

  return $form;
}

```

And the callback:

```
function get_formations($form, &$form_state) {
  return $form['formations'];
}

```

---
Tags: forms, ajax
---


title: Views: link to an admin page

text:
# Question
Title: Views: link to an admin page
I want to print a link in place of a field in case of No Results Behaviour.

The link is to admin/commerce/products/add/, but drupal always add /content/ before my relative address.

I've try different attempts, but so far the only solution I've found is to write the absolute path.

# Answer
> 0 votes
If you want a proper relative path your url must start with a `/` at the beginin of your url like this : `/admin/commerce/products/add/`

# Answer
> 0 votes
You have to start link url with /

# Answer
> 0 votes
The problem was the Path value in the View Page Settings, it was set to `/content/page_name`.

The solution is to set it to `/page_name`

---
Tags: views, commerce, uri
---


# Question
Title: Is there a way to set two separate views with exposed filters in a panel page?
I have been attempting to create a panel page with two columns, one to display view1 and the other view2. The intent is to have the user choose a content type in each column using exposed filters and have the list of content displayed by the view in the panel page. This has turned out to be more complicated to execute than I first thought.

The problem is with the URL. I can have a URL to invoke the panel page, eg.`relate/relate`, and it will display the same list of all content in each column by default. However, when I change the content type in one of the columns, the URL is changed in response and only the changed view is displayed (the panel is not longer activated.

So I am trying to find a way to manage two views from the same page panel that either does not change the URL request or that the panel can manage correctly.

I have tried passing both content type names in the URL eg. `relate/%type1/%type2` and have each view read one of the URL positions using contextual filters. This has approach has several problems

1. I am not sure how to tell the view contextual filters how to react to only the relevant wildcard in a two wildcard URL `relate/%/%`.
2. How do I set up a contextual filter to read the value in the path segment and interpret it as a filter for a content type? The contextual filter can be set up to read the raw URL path segment (in the section re: what to do when the filter fails), but there does not appear to be a way to set up the validation to determine a content type.

Has anyone ever achieved this or can you suggest an approach that might work?

ADDITIONAL INFO

I found that I can prevent the URL from changing by setting a n option in the view content pane to use the Panel URL. This keeps the display as two columns (from the panel), but does not unlink the two similar view content panes. They still both change when I set the exposed filter for either. Apparently the exposed filter is only created once , but displayed twice and sends its setting to both panes. I found this to be true even if I create two distinct View definitions. If the settings for the filters are the same they appear to both run if either exposed filter is changed.

# Answer
> 0 votes
yes . you can show exposed filters in a block. See you view, on right hand side under **Exposed form** Caption. here you can put yes for ***Exposed form in block:No***. Now your filters are available in a separate block.

---
Tags: panels, views
---


# Question
Title: what permission is need to access to content page?
I have created a role and a user assigned to it. I want to give access to '?q=admin/content/node' to this role to see all the contents of the site. what permission should I set for this role? I am using Drupal 6.26.

# Answer
> 3 votes
According to the node module a user must have a role that is allowed for 'administer nodes'.

# Answer
> 0 votes
You need to set the 'Access the content overview page' permission ('Node' section on permissions page).

---
Tags: nodes, users
---


title: Seeking good IM/chat modules

text:
# Question
Title: Seeking good IM/chat modules
My users are asking for "chat", but I suspect they mean one on one IM rather than multi-uer chat rooms.

If there is no negative interaction, I could offer both.

There seem to be a few available, so I will just install them all and try them out one by one, unless someone can make a recommendation.

I need something stable for Drupal 7, easy to use for non-sophisticated users (although they all use IM & FB and the like).

We have Organic Groups so anything that can leverage that somehow might be a bonus.

---

Update: I am *not* asking what is "best". I am asking what is stable, well supported, easy to install and administer and easy for unsophisticated users. I ought to have made that clearer before. I just want to cut down my search list.

---

Review: Drupal Chat has a live demo, so try it out.

There is a small grey box labelled "Chat" permanently at the bottom of the screen, showing the number of on-line users. Clicking reveals a list of users, clicking one begins chat (whether the other user likes it or not).

Options are currently in progress (i.e. none).

User is not informed when partner disconnects and just keeps typing, getting no reply. "go idle/go online" has no effect.

User can chat, but that 's all. Still very much a work in progress as at Nov 2011.

# Answer
> 2 votes
Also check this out: http://www.cometchat.com/

Its not free but its cheap and looks good. Also it integrates with drupal.

# Answer
> 2 votes
There is a Drupal Chat module for chat. It uses node.js and hence highly scalable

> * Supports smileys (detects them automatically in chat messages)
> * Chat history is retained in between page loads
> * Provides option to use Normal AJAX, long polling and Node.js (only in 7.x) techniques to update chat messages
> * Provides optional integration with User Relationships module.

# Answer
> 2 votes
DrupalChat module has improved significantly now. It's cloud hosted commercial version is highly stable, extremely easy-to-use (as suggested in question) and offers both private (one-to-one) chat and multiple chat rooms. You may view live demo here.

# Answer
> 2 votes
You can try http://drupal.org/project/googlechat.

This module comes with following features

* multiple theme (base, blitzer, Cupertino, dark-hive and famous Google hangout).
* bottom right display of chat boxes.
* Auto-back-off polling policy
* Auto-scrolling of chat text and more

Detailed documentation is available at http://www.nextweblink.com/2015/02/18/google-style-jquery-chat-drupal/

# Answer
> 1 votes
You could try Chat Room module. It supports private chats.

# Answer
> 1 votes
You can try https://www.drupal.org/project/chatroom. Hopefully, it covers your requirements. Most ot the other modules I have search are very expensive.

---
Tags: 7
---


# Question
Title: Add the same field multiple times to a display suite node display
So I'm using display suite with a 2-column layout, and my node has an entity reference field (field\_journal). I'm already displaying field\_journal as a rendered entity in the LH column, but I'd also like to display a different grouping of fields from the linked entity in the RH column.

I was thinking the best way to do that would be to add field\_journal *again* to the RH column, but I can't figure out how to duplicate fields in display suite.

Is there some way to add the same field to a node display in 2 different places in the layout? Or can anyone help me with a workaround?

# Answer
Since you're using display suite you can use hook\_ds\_fields\_info for defining a new display suite field that you can use to clone your existing field.

```
/**
 * Implements hook_ds_fields_info().
 */
function MODULE_ds_fields_info($entity_type) {
  $fields = array();

  $fields['node']['journal_clone'] = array(
    'title' => t('Journal clone'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'MODULE_journal_clone',
  );

  if (isset($fields[$entity_type])) {
    return array($entity_type => $fields[$entity_type]);
  }
  return;
}

/**
 * Render a clone of journal.
 */
function MODULE_journal_clone($field) {
  $build = '';
  if (isset($field['build']['field_journal'])) {
    $build = $field['build']['field_journal'];
  }
  return render($build);
}

```
> 0 votes

---
Tags: display-suite
---


# Question
Title: URLs aren't working after site migration
My problem is two fold:

1. After migrating my site, many of the URLs aren't working, and producing 404 errors. But the main landing page is working, and so are most/all of the features on the main page.
2. My configuration for custom 404 error pages are being ignored, and were working before copying the root of the web server files over. This I'm not so worried about.

These are the steps I used to migrate the site:

1. mysqldump the database from the originating server.
2. Import the database to the new server, using the same mysql credentials.
3. Copy the root of the web server files over to the new location.

This is my setup: CentOS6 nginx MySQL php, php-fpm Drupal 7

The only real difference between the originating server and the target server is that the originating server is centos5.

I am not a drupal expert, but I did some searching and I keep coming across "clean urls". I'm not exactly sure what that is.

Is there a better way to migrate a drupal site, or is there something I did wrong?

# Answer
> 1 votes
This indeed sounds like a clean URL problem.

Standard Drupal URLs use query strings like: www.example.com/?q=string/string/site Clean URLs rewrite this to www.example.com/string/string/site which is better for SEO.

Check the browser's adress bar to see if clean URLs are working. If not and if you used them on the previous install, you need to either deactivate them in drupal or get them working again. You need to activate it in settings and use correct .htaccess with Clean URLs rewrite rule.

The reason why the home page is working is that there is no query string in www.example.com/

# Answer
> 0 votes
I'm sure there are different ways to do this, but I've been successful using the Backup and Migrate project. Follow the directions in this great article: http://www.seascapewebdesign.com/blog/how-transfer-your-website-one-server-another

---
Tags: 7, uri
---


title: different options per user

text:
# Question
Title: different options per user
I have the following situation. A content type called cities holds all the cities in my country. A second content type holds all sales per city.

When a user logs in, I need him to see just some cities to which load sales. this means that a second user will see other cities.

How is this doable?

Regards, Martin

# Answer
> 1 votes
after adding the custom field to the user profile, i added a hook\_form\_alter() in seven theme template. (it should be added in administrative theme).

in this hook i read the user custom field using $user\_full = user\_load($user-\>uid)

setting global $user; is required to use $user in template.php

now i can modify other forms according to user custom field content

that's all

# Answer
> 0 votes
ok, by going to Config \> People \> Account Settings \> Manage Fields it is possible to add a field to the user profile.

Just make sure you check this option Display on user registration form.

the field type is set as Entity reference to the cities content type.

This allows the user profile to carry the country in the profile structure. Now i need to find a way to use this information elsewhere to filter them based on country.

---
Tags: users
---


# Question
Title: Multi step registration - save on last step
I'm using the module Multi-Step Registration module. The problem is that the user is saved after clicking the continue button on the first step. So when a user quits after 3 steps the user is saved already ... (but the registration process isn't completed).

Does anyone have an idea how I could the save the user on the last step or a workaround to fix this?

# Answer
You could consider one of two modules that force users to complete their profile if they've dropped off halfway thorough, but still created the account:

Complete Profile or Profile Fields Force Filling

Or, roll your own form using ctools.
> 0 votes

---
Tags: 7, users, forms
---


# Question
Title: In a Quick Tabs module what does this display do in a TAB TYPE view?
There are two options in my Quick Tabs settings:

1. display:Master
2. block:sid(depends on the view you have selected)

I want to know their individual effects on output.

# Answer
> 1 votes
I would recommend reading this post regarding purpose of Master Display in Views. It contains the standard settings for a view that take a effect when you create a new display in the view. If you don't have specific settings differing from master display in your other displays you could (and maybe should) use it in the Quicktab.

---
Tags: views, blocks
---


title: Status Report vs Available Updates

text:
# Question
Title: Status Report vs Available Updates
My Status report shows that my Drupal version is 7.32 but my Available Updates page says 7.30. Can you tell me why they would be different? No recent updates have been made.

# Answer
> 0 votes
This could indicate that your site was hacked due to drupalgeddon bug. If you have not updated from 7.30 it is likely that an attacker changed the version numbers. Check here: https://www.drupal.org/node/2357241

---
Tags: status-messages
---


title: Ajax progress bar using example module

text:
# Question
Title: Ajax progress bar using example module
I am new to drupal, currently learning about example module and its sub module, I already created the form using custom modules, in that form I wish to add progress bar for submit button, i referred many sites but, i can't get any clear idea, what i did for submit button is,

```
function custom_form_menu() {
$items = array();
$items['think/form'] = array(
'title' => t('Entry Free'),
'page callback' => 'custom_form_form',
'page arguments' => array('ajax_example_progressbar_form'),
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
'file' => 'ajax_example_progressbar.inc',
);
return $items;
}

```

and for submit button,

```
custom_form_my_form($form , &$form_state) {
$form['first'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#description' => "Please enter your first name.",
'#maxlength' => 6,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}

```

So, now how can I add progress bar in this submit button, when the form is submitted.

# Answer
Progress bar example:

```
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
    '#ajax' => array(
        'callback' => 'import_submit_callback',
        'wrapper' => 'import-form',
        'progress' => array(
            'type' => 'bar',
            'message' => t('Importing..'),
            'url' => 'import/progress', //url to fetch current progress percentage
            'interval' => '1000' //progress bar will refresh in 1 second
        )
    ),
);

```

Then create menu like this for url 'import/progress' :

```
$items['import/progress'] = array(
    'title' => t('Import progress'),
    'page callback' => 'import_progress',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
);

```

Then output json data indicating current status like this in that page callback function:

```
function import_progress() {
    $progress = array(
        'message' => t('Starting import...'),
        'percentage' => -1,
    );

    $completed_percentage = variable_get('import_status'); // calculate progress percentage here

    if($completed_percentage){
        $progress['message'] = t('Importing...');
        $progress['percentage'] = $completed_percentage ;
    }

    drupal_json_output($progress);
}

```

Further reading: https://www.drupal.org/node/1401966
> 1 votes

---
Tags: ajax
---


# Question
Title: How to create a sequence of nodes to work as a "tour" through a site?
I can think of different ways, like creating a View with all nodes available and sort them with DraggableViews so I have a tree, and then adding a Next/Prev buttons if the user wants to see the site not as individual nodes, but as a Tour, being taken from the first node to the last one in a specific order.

Anyone has any better, less of a hassle, ideas?

# Answer
> 0 votes
Custom Pagers

> Custom Pagers allows administrators to define context-sensitive previous/next pagers for any node type. The list of nodes to be cycled through is generated by a user-selectable view, and each pager can be displayed above or below the node body or in a sidebar block. This makes it possible to duplicate the paging functions of forum.module and book.module, as well as more complex stuff like comic strip navigation. Requires token.module and views.module.

and Nodequeue

> The Nodequeue module allows users to collect nodes in an arbitrarily ordered list.

---
Tags: nodes
---


# Question
Title: I lost custom fees when apply pricing rules
I'm using commerce fees modules to add fees when I create orders manually from the backoffice, but click when I click apply pricing rules I lost the added fees. If I add fees (custom fees line item) after applying pricing rules, the VAT taxe be applyed to the unit price only.
Any help please.

# Answer
Are you using Rules 7.x-2.8? There's a known issue with that release that breaks the application of pricing rules: https://www.drupal.org/node/2403851

The latest development build of Rules may fix the issue: https://www.drupal.org/node/2324587
> 0 votes

---
Tags: commerce
---


# Question
Title: Allow user to request resend of activation email
I would like to code a way for a user to request the activation email be resent. Is there a function I can call from within a form-submit hook that will accomplish this?

(using Drupal 7)

# Answer
> 3 votes
First you need to create a custom form page using `hook_menu()` to allow users to enter their emails.

```
 /**
 * Implements hook_menu().
 */
function custom_user_menu() {
  $items = array();

  $items['user/trouble'] = array(
    'title' => 'trouble logging in',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_user_trouble_logging_in_form'),
    'access callback' => TRUE,
  );

  return $items;
}

```

Second, you need to create form structure

```
function custom_user_trouble_logging_in_form($form, &$form_state) {
  $form['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-Mail address'),
    '#size' => 60,
    '#required' => TRUE,
  );

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Resend activation email'),
  );

  return $form;
}

```

Third, validation step (check if user email already registered)

```
/*
 * Validation function
 */
function custom_user_trouble_logging_in_form_validate($form, &$form_state) {
  $account = user_load_by_mail($form_state['values']['mail']);

  if(!$account) {
     form_error($form['mail'], t('Invalid user email'));
  }
}

```

Fourth, resend user activation email on form submission.

```
/*
 * Submit function for the 'Re-send welcome message'.
 */
function custom_user_trouble_logging_in_form_submit($form, &$form_state) {
  global $language;

  $destination = array();

  if (isset($_GET['destination'])) {
    $destination = drupal_get_destination();
    unset($_GET['destination']);
  }

  $account = user_load_by_mail($form_state['values']['mail']);
  $user_register = variable_get('user_register', 2);

  switch ($user_register) {
    case 0:
      $op = 'register_admin_created';
      break;
    case 1:
      $op = 'register_no_approval_required';
      break;
    case 2:
      $op = 'register_pending_approval';
      break;
  }

  $mail = _user_mail_notify($op, $account, $language);
  if (!empty($mail)) {
    watchdog('user', 'Welcome message has been re-sent to %name at %email.', array('%name' => isset($account->realname)? $account->realname : $account->name, '%email' => $account->mail));
    drupal_set_message(t('Welcome message has been re-sent to %name at %email', array('%name' => isset($account->realname)? $account->realname : $account->name, '%email' => $account->mail)));
  } else {
    watchdog('user', 'There was an error re-sending welcome message to %name at %email', array('%name' => isset($account->realname)? $account->realname : $account->name, '%email' => $account->mail));
    drupal_set_message(t('There was an error re-sending welcome message to %name at %email', array('%name' => isset($account->realname)? $account->realname : $account->name, '%email' => $account->mail)), 'error');
  }
  $form_state['redirect'] = $destination;
}

```

**Note:** `custom_user` is the name of the module that I used. You can change to whatever you like.

# Answer
> 0 votes
The previous answer will not work. \_user\_mail\_notify states that "By default, we always notify **except for canceled and blocked**.

Here is an implementation that notifies the user when they try to log in and sends them another email at that time using a custom user\_mail\_notify. "cgps\_my\_misc" is the name of a custom module.

```
<?php

function cgps_my_misc_form_alter(&$form, $form_state, $form_id)  {

  switch ($form_id)  {
    case 'user_login_block':
          $form['#validate'][] = 'cgps_my_misc_user_login_name_validate';
          break;
  }
}

function cgps_my_misc_user_login_name_validate($form, &$form_state) {
  if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {

    drupal_get_messages('error'); //Purges drupal core error message so we can set out own
    form_set_error('cgps_my_name', t('The account %name has not been activated.', array('%name' => $form_state['values']['name'])));

    $user = user_load_by_name($form_state['values']['name']);

    $mail = cgps_my_misc_user_mail_notify('register_no_approval_required', $user);

    if (!empty($mail)) {
      watchdog('user', 'Welcome message has been re-sent to %name at %email.', array('%name' => isset($user->realname)? $user->realname : $user->name, '%email' => $user->mail));
      drupal_set_message(t('Welcome message has been re-sent to %name at %email', array('%name' => isset($user->realname)? $user->realname : $user->name, '%email' => $user->mail)));
    } else {
      watchdog('user', 'There was an error re-sending welcome message to %name at %email', array('%name' => isset($user->realname)? $user->realname : $user->name, '%email' => $user->mail));
      drupal_set_message(t('There was an error re-sending welcome message to %name at %email', array('%name' => isset($user->realname)? $user->realname : $user->name, '%email' => $user->mail)), 'error');
    }
  }
}

function cgps_my_misc_user_mail_notify($op, $account, $language = NULL) {
    $params['account'] = $account;
    $language = $language ? $language : user_preferred_language($account);
    $mail = drupal_mail('user', $op, $account->mail, $language, $params);
  return empty($mail) ? NULL : $mail['result'];
}

```

---
Tags: users, emails
---


# Question
Title: How disable view page functionality and revert to pure view with master display?
> On view setting page

I have view with menu link and path. I want to turn it off, revert to basic view `master`. I've try to remove menu, but didn't change anything. Then I try to remove path but is mandatory. Clone view make same view with page path.

Only solution I can see is create new view and repeat settings (I don't want to do that!), another is to just change path to some useless one so it dons't conflict with my menu links (paths). Any ideas?

# Answer
While creating a view uncheck Create a page checkbox and check create a block checkbox;

If you already have created a View, you can add new display as shown in figure below:
> 0 votes

# Answer
I just realize that all you need is to remove current display type, like show on attached screenshot. So when you have only e.g. `page` display type after removal it'll become `master` again.
> 0 votes

---
Tags: views, routes
---


# Question
Title: How can I change page elements (menu, blocks, etc) based on a chosen 'audience' link?
There are many sites which allow users to select their "customer type" or "audience", which then displays different information on the front page and provides them with navigation and content appropriate for their needs. Banks, higher-education institutions, and medical providers do this often (http://chase.com, http://aetna.com).

I'm looking for the best way to implement this on a site I'll be developing over the next few weeks. I need the main navigation to change per audience and I'd like to show specific content on the home page and sidebars based on that context. I don't think I want to use subdomains or multi-site; it seems that there should be a better way.

I'd like the URL structure to look like "mysite.com/audience1", "mysite.com/audience2", "mysite.com/audience3", and so on for the front page. Deeper pages would follow that url prefix ("mysite.com/audience1/products/tools")

There are also 'global' resources which any audience would find useful and I've been wondering about how I'd handle that use-case as well.

Should I look into panels, context, display suite, other modules? Any guidance is appreciated. Thanks!

# Answer
Explaining the whole process would be bit complicated

i ll provide you some steps try to follow that.

In our project the same structure you have mentioned is used we have global pages like **mysite.com/products** and some further branch level pages like **mysite.com/chennai/products**

**Step one:** create a view page in views.

**Step two:** create a taxonomy term reference for the audience.

**step three:** create a block and in contextual filter add taxonomy term as contextual filter and in provide default value give get taxonomy term by url.

**step four:** for every content you create it should have the term reference field.

**step five:** when you pass the audience name in the url it should display the content related to the taxonomy term.

**step six:** like wise you have to configure the block in all the pages

**step seven:** in block settings give display only in that particular page

now what this will do is for every block it will be displayed their content based on the url if you change the url to audience two it will show the content having the taxonomy term as audience two as their value.

hope this will give you a start up for the task :p
> 0 votes

---
Tags: views, panels, 7
---


# Question
Title: More than one modules implementing the hook_module_implements_alter
How can I know what module will implement earlier?

I have a module (custom) which implements *hook\_module\_implements\_alter* and an other module (contrib) which is also implements it. In this case the contrib module is being executed later, overriding my implementation.

So, how can I ensure that my module will be executed later?

# Answer
You need to change the weight of the modules in system table to modify their execution order.

One module that can help you in that is the Modules Weight, which provides an admin interface and avoids changing the SQL record directly.
> 2 votes

---
Tags: hooks
---


# Question
Title: Drupal 7 globalredirect not working for /node/ redirection
I want to redirect my site from URLs like

`/node/530`

to

`/Services/TrainTickets.html`

I installed GlobalRedirect module as I've read it would address this problem, but the same page is still accessible at `/node/530` path.

Anybody knows what the problem could be and how I could resolve it?

I also want to make it impossible to access the site via

`http://www.waytorussia.net/node?page=31` and so on...

Thanks!

UPDATE I use Drupal for Facebook module and I've seen there were issues with that as it uses custom url rewrite but did not find any resolution.

# Answer
For your first problem why are you not simply using Clean URLs, which is built into Drupal? I'm assuming you're using version 7.x.

I'm not absolutely certain about adding the *.html* added to your url aliases and whether that will break something, but I'd imagine you could easily fix that by using some mod\_rewrite and just appending *.html* to all your clean URLs.

What I mean then is in your Drupal system your URL aliases will be */Services/TrainTickets*. Essentially you'll still be using default/core clean URLs for all your paths. In **.htaccess** file though you can use *mod\_rewrite* to append *.html* to all your paths.

For your last problem re: blocking access to all */node/x* paths, the first thing I thought of was again to use *mod\_rewrite* to redirect to a custom built 404 Page Not Found page, instead of having to use a Drupal module. However, I've never tried this and am not certain this approach would work. I took a quick look though and it appears someone else thought of this too:

https://www.drupal.org/node/164526#comment-7919767

One issue I see right away is that you'd want to ensure that the path is a node view page (i.e. node/x) and nothing more (e.g node/x/edit - which would mean you're logged in), otherwise you'll run into some issues when logged in and trying to edit content.

Maybe try it out? Worth a shot.
> 0 votes

---
Tags: 7, nodes, redirection
---


# Question
Title: How to get a list of all the selected values for a field programmatically?
How can I get a list of all the selected values for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values in the "countries" field, in the "regions" field, by doing this:

```
$node->field_regions = $node->field_countries;

```

Here is the result when I select France in the countries field :

```
Country: France

Regions: France

```

**Edit**: I tried with the function:field\_get\_items(), but all I get is an array:

```
$items = field_get_items('node', $node, 'field_countries', $node->language);

```

Something is wrong? I also tried with this but I get the same result...

```
$items = $node->field_countries[$node->language][0]

```

# Answer
Because fields can have multiple values both of the methods you describe will return an array. Each of those array items will itself be an array, of all the possible columns for the field. In the case of text fields the only column you really need to worry about is the `value` column.

Assuming your particular field does not accept multiple values, or it does and you only want the first value, the following should work:

```
$items = field_get_items('node', $node, 'field_countries', $node->language);
$item = array_shift($items);
$value = $item['value'];

```

or

```
$value = $node->field_countries[$node->language][0]['value'];

```
> 7 votes

# Answer
`field_get_items()` is the solution that is typically recommended. However, there are some caveats.

It is important to check if the field is empty. In this case field\_get\_items() returns false (which sucks).

```
$items = field_get_items('node', $node, 'field_countries', $node->language);
if (!empty($items)) {
  $item = reset($items);
  return $item['value'];
}
else {
  return NULL;
}

```

I think you can generally be sure that if an item exists, it will be in the zero \[0\] index. And isset() is a very robust thing. So the following works as well:

```
$items = field_get_items('node', $node, 'field_countries', $node->language);
return isset($items[0]['value']) ? $items[0]['value'] : NULL;

```

For some field types, the value is not in $item\['value'\] but in $item\['tid'\] or something else.
In the usual case (I can't think of an exception atm), the value will be the first thing in the $item array. So the following will also work, but this is more by coincidence than by design. So personally I would not count on it.
(If $items is a (non-empty) array, then we can safely (\*) assume that every $item will be an array too, and not something else.)

```
$items = field_get_items('node', $node, 'field_countries', $node->language);
return isset($items[0]) ? reset($items[0]) : NULL;

```

The return value of field\_get\_items() is by-value, so it is generally ok to modify the $items array. This means you can use array\_shift().

```
$items = field_get_items('node', $node, 'field_countries', $node->language);
return !empty($items) ? array_shift(array_shift($items)) : NULL;

```

(\*) Most of the assumptions we make here are not based on language-level guarantees, but just on how Drupal generally works.

Btw the following trick can be helpful sometimes, but it is not a complete solution of the original question:

```
$items = field_get_items(..) ?: array();

```

This guarantees that $items is always an array. But for snippets above this does not really help us.
> 6 votes

---
Tags: 7, entities
---


# Question
Title: Add content type to a taxonomy - Drupal 7
Hello everyone I have content type named contact where I have many fields like name, email, phone, country... and a taxonomy named organization with fields name, acronym and contact. What I try to do is when I create a new term of this taxonomy I have the possibility to add contact. Many thanks in advance

# Answer
> 1 votes
if I understand it right, you're trying to reference a "contact"-node...

You can use the module "entity reference" (https://www.drupal.org/project/entityreference) for that.

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


title: Expand region to fill screen size

text:
# Question
Title: Expand region to fill screen size
I have a splash page where the user will choose a language before entering the site. This page only needs the header region and a background image (for the #main-wrapper div) that should occupy the rest of the screen size.

I'm using

```
#main-wrapper {
    background: url('img.jpg') center no-repeat;
    height: 100%;
    width: 100%;
    background-size: cover;
}

```

But it doesn't fill the available space, only the #main-wrapper div, so I end up with a grey area below the background image, where the footer should be.

* Is there a way to make this region expand all the way to the bottom (I don't need the footer in this particular page) without declaring it's height in px?
* I want to avoid scrollbars when not necessary, and have the image fill the space when resizing the window or viewed on mobile.

Is it possible to do this with Bartik theme?

EDIT:

I've already hidden the footer, but that doesn't make the #main-wrapper div reach all the way to the bottom. I still get a blank space below it.

# Answer
You could style that special page with css to not display the footer (display:none). Drupal delivers a css class in the body tag that identifies the current node, like so .page-node-x, where x is the node id of the page. So you could go like page-node-x .footer.

You could also use a page.tpl override for the specific page where you remove the footer region. Create a copy of page.tpl.php in your themes template folder and name it page--node--x.tpl.php. Remove footer in this file completely.

And as for fullsize background image, maybe this module could be interesting: https://www.drupal.org/project/supersized
> 1 votes

# Answer
If footer is just transparent, you could also go by applying your rules to body instead of #main-wrapper.

Also, Drupal should hide empty regions AFAIK. Thus, you can try to hide everything in footer region using visibility rules. If that does not work, check page.tpl.php.

Hiding it via page-node-x class with display: none; visibility: hidden; is the easiest way though!
> 1 votes

# Answer
As many others have mentioned, why not just add the background-image to body?

```
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background-image: url('img.jpg');
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

```
> 0 votes

---
Tags: 7
---


# Question
Title: Does anybody else encounter issues with the new Flexslider 2.3.0 library and Drupal?
After installing the most recent version of the flexslider library (`2.3.0`) the Drupal Flexslider module (`7.x-2.0-alpha3`) is not able to find the flexslider library anymore.

I get the following error on `admin/reports/status`:

**FlexSlider version could not be determined. Please consult the README.txt for installation instructions.**

# Answer
> 0 votes
I realized that the most recent version does not work with the Drupal flexslider module. I **downgraded** the flexslider JS library to version `2.2.2` and the flexslider Drupal module got recognized.

I used the following JS library version of flexslider ... here you can find all releases

---
Tags: 7, javascript
---


# Question
Title: Views: alter data of a View of another module
I wanted to add a relationship to data in a View of an existing module, so I've hacked the code (the function `modulename_views_data`) and it works.

Now I want to create a new module to do this extension, leaving clean the original one. I guess I should use the `function views_data_alter(&$data)` but I don't understand how to bind it to the other module.

# Answer
> 1 votes
You would create a module. It only needs a simple modulename.info file and modulename.module file.

If you called your module 'mymodule', then in mymodule.module add the function:

```
mymodule_views_data_alter(&$data) {
  \\custom code
}

```

Clear the caches and you should be good to go.

The hook system allows modules to interact with other modules code. By naming your function `MODULENAME_views_data_alter` you are telling Drupal that you want to take advantage of the hook `HOOK_views_data_alter`.

---
Tags: views
---


# Question
Title: How can I use Typekit fonts, preferably without contributed modules?
I need to use some fonts from Typekit on the site I'm working on. Without the help of an extra module would be the best solution.

I have two lines to go in the `<head>` of page.tpl.php that call scripts.

Should I put them in /themes/mytheme/template.php? If so how, can you give me an example of what the code should look like?

Can I just put the call for the scripts right in the page.tpl.php file, with `drupal_add_js()`?

Anything else I should know?

Helpful links would be cool too. I got a bunch from #drupal on IRC today but none pinpointed it enough for me.

# Answer
If you want the typekit code on every page of your site and you don't want a complicated solution just put the code in the page.tpl.php file. They are external scripts I assume so drupal\_add\_js won't help you in D6.

You can add things to the scripts variable in template\_preprocess\_page(), but if you are going to do that on every page then you may as well just put it next to where the scripts are printed in page.tpl.php
> 1 votes

# Answer
I personally like the preprocess function, but you can also hardcore the script in the page.tpl.php or html.tpl.php (inside the tags)

Here is some sample code for the preprocess function. This would go inside template.php:

```
/**
* Implements template_preprocess_html().
*/

function MYTHEME_preprocess_html(&$variables) {
 //Adds typekit js to theme
 drupal_add_js('//use.typekit.net/wje3ojf.js', 'external');
 drupal_add_js('try{Typekit.load();}catch(e){}', 'inline', 'page_bottom');
}

```

I wrote an article on how to do this if you want to read the whole thing:

http://cheekymonkeymedia.ca/blog/drupal-planet/how-add-typekit-fonts-your-drupal-website
> 0 votes

---
Tags: theming, javascript, 6
---


title: Drupal set message class

text:
# Question
Title: Drupal set message class
I've been trying to add a class to a drupal\_set\_message() function. i found one article that said it worked, but i could not get it to work on mine. am i missing something?

I have `drupal_set_message(t('an error has occured'),'custom-error');`

these are the only output i get from the html

```
<div class="alert alert-block">
<a class="close" data-dismiss="alert" href="#">×</a>
an error has occured</div>

```

any help would be appreciated.

# Answer
For drupal set message below is a syntax.

```
drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE);

```

**Parameters**

**string $message:** (optional) The translated message to be displayed to the user. For consistency with other messages, it should begin with a capital letter and end with a period.

**string $type:** (optional) The message's type. Defaults to 'status'. These values are supported:

'**status**'

'**warning**'

'**error**'

You should pass any one of the status message with your custom class separated with space as shown below

```
drupal_set_message(t('an error has occured'),' status custom-error');

```
> 2 votes

# Answer
To solve this issue, i created a theme\_status\_message on my template.php, inside it contains the default theme\_status\_message with some minor changes. Cleared the cache and the classes are adding. It's weird how it's not working when I didn't create one even though it was in the theme.inc file.

Also, it seems like the default has become 'status' instead of 'success' before the changes. Anyone know how to chnage the default without changing the bootstrap.inc file?
> 0 votes

---
Tags: 7
---