# Question
Title: How can I get a views exposed filter to persist across multiple views?
I have 2 separate views that return a set of results for each of my content types. The fields are different, but the filters are exactly the same - Sort by Location / Distance. This Distance / Proximity filter is exposed, and it is set to 'remember' the last entry. I followed the tutorial here http://drupal.org/node/359463 to be able to filter results by distance. It works great.

In views, to remember the last entry, Views uses sessions. But, each view has its own individual $\_SESSION variable. That means what I set for one view does not carry over to the next, and even each view can have different values, which is not what I want. Here is a dump of the session after they have been set:

```
[views] => Array
    (
        [search_pages] => Array
            (
                [default] => Array
                    (
                    )

            )

        [baby_clothes_pages] => Array
            (
                [default] => Array
                    (
                        [distance] => Array
                            (
                                [postal_code] => 11211
                                [search_distance] => 100
                                [search_units] => mile
                            )

                    )

            )

        [baby_gear_pages] => Array
            (
                [default] => Array
                    (
                        [distance] => Array
                            (
                                [postal_code] => 22343
                                [search_distance] => 100
                                [search_units] => mile
                            )

                    )

            )

    )

```

What I would like to do is create a small module or snippet of code that will simply allow someone to type in their 5 digit zip code and then it update all the values across all my pages with this filter. If it is changed on any page, then it changes it for the rest of the pages as well. It also needs to work so that it affects the results on the next page load so that it correctly shows them filtered.

Here is a snippet of code I was experimenting with to try to set this value, but it's the wrong direction.

```
 $all_views = views_get_all_views();            // get an array of all views in use on the site

foreach ($all_views['category_pages']->display as $key => $value) {
 //check to see if the structure exists I am looking to modify
if(array_key_exists('postal_code', $all_views['category_pages']->display[$key]->display_options['filters']['distance']['value'])) {

//if so, set its value
$all_views['category_pages']->display[$key]->display_options['filters']['distance']['value']['postal_code'] = '28152';

//try setting the session instead
$_SESSION['views']['category_pages'][$key]['distance']['postal_code'] = '28152';
    }

```

What's the correct direction? How do I get this value changed? Could it be done in the template.php file with preprocess function? Should I do it in a module, and if so, what do I need to alter?

Very lost at this point. Thanks for the direction!

# Answer
The answer was much simpler than I was expecting. I almost had the code working above. By removing the views\_get\_view and set-\>display portions, it started working. Here is the finished code.

```
function zipcode_filter_views_pre_view  ( &$view, &$display_id, &$args) {

    $view->display['default']->handler->options['title'] = "this is the new title";
    $view->exposed_input['distance']['postal_code'] = $_SESSION['zipcode_filter']['zip'];
    $view->exposed_input['distance']['search_distance'] = $_SESSION['zipcode_filter']['distance'];

}

```

By simply altering the correct variable values in the views\_pre\_view hook, later parts of the Views execution do the rest of the work. Also, this code fires each time a views page is rendered, so it works for all views, regardless of how many there are. So, by storing the values in a session as Mandeep suggested, it affected all views that had the exposed filter field.
> 1 votes

# Answer
It sounds like you would need to save the value somewhere. Next when a page load event happens (on any page of your site) you need to load the value into the field. I think you might need to create a cookie to do this.
> 1 votes

# Answer
Take a look at Views Global Filters module. That will solve your problem.

The project page reads

> Use Views Global Filter on sites that feature multiple Views. You want the views to be driven by the same filter selection, for instance a country, a date range, a search term or even proximity to a post code.
> 0 votes

# Answer
$view-\>exposed\_input\['distance'\]\['postal\_code'\] = $\_SESSION\['zipcode\_filter'\]\['zip'\];

can explain better which are this variables \['distance'\] \['postal\_code'\] \['zipcode\_filter'\] \['zip'\]

I have two views, 2 display, page\_1 e page\_2 with path\_1 e path\_2; everyone have own exposed filter (same settings) on page\_1 if I use I have this url /path\_1?filter\_identifier\_1=18 (when is selected id term 18)

if I change display view url and select exposed I have this /path\_2?filter\_identifier\_2=18

I have only page variables and name filters and must remember every time that the page change, the previous filter value selected

so code must to be similar at this?

$view-\>exposed\_input\['page\_1'\]\['filter\_identifier\_1'\] = $\_SESSION\[previous\_page\]\[previous\_filter\_identifier\_value\];

$view-\>exposed\_input\['page\_2'\]\['filter\_identifier\_2'\] = $\_SESSION\[previous\_page\]\[previous\_filter\_identifier\_value\];

this if I leave both the exposed filter (first steps for understand how work)

previous\_page how can know this variable ? (in the example ther are only 2 display, but how when more?) previous\_filter\_identifier\_value how can know this variable ? is sufficient write only filter identifier name?

other:seen that I must have only one exposed, how can use $view-\>exposed\_input for to set the 2nd filter if isn't exposed and not have the filter\_identifier ?

........
> -1 votes

---
Tags: 7, views
---


# Question
Title: How to make persistent exposed filters in views
I'm aware of the "remember" option of views, but it is stored in session data (not persistent if you logout) and I want to keep the selections saved forever (so the users only have to do the selections once when they sign up).

I've done quite a lot of research regarding different options that maybe could do the trick, but haven't found out yet a viable solution to it. The options I've researched are:

1) With the module "views saved searches" (works but for usability reasons is not an option in this case)

2) Coding a way to remember the exposed filters selected via cookies or database (I haven't found anything about this and I don't know how to code a solution myself).

3) Making the selection in a node or profile page (with CCK, Nodereference/Entity Reference or Relation fields) and applying the selection of each user to "personalize" their view accordingly (maybe following one of the two options briefly mentioned in point 3 of this answer: https://stackoverflow.com/a/1409382 or using advanced features of relationships and/or arguments)

Any help would be appreciated.

Thanks!

# Answer
Take a look at Views Global Filters module. That will solve your problem.

The project page reads

> Use Views Global Filter on sites that feature multiple Views. You want the views to be driven by the same filter selection, for instance a country, a date range, a search term or even proximity to a post code.
> 0 votes

---
Tags: views
---


title: Drupal hook_theme() Template Issue

text:
# Question
Title: Drupal hook_theme() Template Issue
I am creating a block and I cannot get it to render correctly. I need to render a list of links but it is not working and it is showing nothing on the page.

I have the `hook_theme()` function like this:

```
function list_city_theme() {
  return array(
    'list_city_display' => array(
      'variables' => array(
        'title' => NULL,
        'locations' => NULL
      ),
      'template' => 'filter-by-city--display.tpl.php',
    ),
  );
}

```

And heres where i'm trying to set the theme inside the block view function:

```
$args = array(
  'title' => 'Filter by Town / City',
  'locations' => $locations
);
$block['content'] = theme('list_city_display', $args);

```

# Answer
> 0 votes
It is working for me. I have created a module called **testtheme** and mytemplate.tpl.php file is under testtheme/templates/.

Please try following sample code

```
/**
 * Implements hook_block_info().
 */
function testtheme_block_info() {
  $blocks['testtheme'] = array(
    'info' => t('Test Theme'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function testtheme_block_view($delta=0) {
  $black = array();
  if ($delta == 'testtheme') {
    $block['subject'] = t('Test Theme');
    $args = array(
      'title' => 'Filter by Town / City',
      'locations' => 'Bangalore',
    );
    $block['content'] = theme('list_city_display', $args);
  }
  return $block;
}

/**
 * Implements hook_theme().
 */
function testtheme_theme() {
  $path = drupal_get_path('module', 'testtheme');
  return array(
    'list_city_display' => array(
      'variables' => array(
        'title' => NULL,
        'locations' => NULL
      ),
      'template' => 'mytemplate',
      'path' => $path . '/templates',
      'type' =>'theme',
    ),
  );
}

```

# Answer
> 0 votes
To View the contents in a block must be implemented hook\_block\_view

```
/**
 * Implements hook_block_view().
 *@param $delta
 */
function list_city_block_view($delta='') {
  $block = array();
  switch($delta) {
    case 'block_name' :
      $block['content'] = theme('list_city_display', array('result' => array('title'=> NULL,'locations' => NULL)));
      break;
  }
  return $block;
}

```

---
Tags: blocks
---


# Question
Title: How to add multiple panel nodes to a panel page
What I need to achieve is essentially a panel page of panel nodes.

I have contact information for various divisions of a company. Then I used panel node to override the layout of these nodes. Now I need to maintain that layout and add them to a panel page or view.

Any help is much appreciated. Thank you in advance.

# Answer
> 0 votes
After a little playing around with views I solved it... the solution to my problem can be done in 2 ways.

The first way is to use views to simply create the list of nodes and then using some css, manipulate the containers and fields to position them the way you would like.

The second way is, if you have panels and views installed, you can select 'Panel fields' as the format to show the content on screen. This obviously has a whole lot of settings you can set to customize your layout.

After much frustration and lost time, the second way really solved my problem.

# Answer
> 1 votes
Panel nodes was once totally awesome.

They could only do so much though, largely because of limitations in the underlying nodes.

With D7, Panelizer can what panel nodes could, but on any entity. I would strongly recommend you switch to panelize. Not only will you be able to easily use any regular method to list, but panel nodes have effectively been abandoned for years now.

---
Tags: views, panels, nodes
---


title: Different link paths for view nodes

text:
# Question
Title: Different link paths for view nodes
I am using Drupal 7 and I have a block view in my home page. This block view selects nodes from two different content types. Only the titles from these nodes are appearing in the block view. By clicking on these titles I want to redirect in two different pages, based on the content type each view node belongs.

e.g For the view node with title : "Meeting on 3th September", I want to redirect on ".../drupal/meetings" page,but for the view node with title "Announcement of program" I want to redirect on ".../drupal/news" page

What is the way for redirection from view nodes to different links according the content type of the view nodes?

Thank you.

# Answer
I solved the previous problem as follows:

1.In my block view I added the field "Type", and i clicked the option "Exclude from Display"

2.In the field "Title" of the view, I disabled the option "Link this field to the original piece of content" and i rewrote the title with the rule: \[type\].

3.I added a redirection rule from each type to the corresponding link
> 1 votes

# Answer
What are the names of the Content Types that you have?

If your Content types are of **Meetings** & **News**.

You could possibly Rewrite the link on the `[node_title]` field using the Content type field. This would end up being `/drupal/[content_type]`
> 0 votes

---
Tags: views, redirection
---


title: How to use images in theme settings

text:
# Question
Title: How to use images in theme settings
In Drupal 7, I am trying to put an image field to allow an image to be uploaded to the theme settings.

I am using managed file from the form API to do this. Here is my code:

```
  $form['footer']['footer_logo'] = array(
  '#title' => t('Image'),
  '#type' => 'managed_file',
  '#description' => t('The uploaded image will be displayed on this page using the image style choosen below.'),
  '#default_value' => variable_get('footer_logo', ''),
  '#upload_location' => 'public://footer_logo/',
);

```

When I call the image using `theme_get_setting('footer_logo')`, I just get a set of numbers. How can I get the file path of the image instead? Also, is there away to pass the image through image cache settings.

# Answer
> 3 votes
It seems that this could provide an answer to your question :

```
$fid = theme_get_setting('footer_logo');
$image_url = file_create_url(file_load($fid)->uri);

```

(but I didn't test it).

# Answer
> 0 votes
Here's a bullet proof version to get you the image URL.

Basically, it does all the checks at each function call to be 100% sure you get a proper URL and also to not throw any errors in case the image isn't uploaded or the current theme doesn't have this setting available.

When done, `$file_url` is either an empty string or a valid URL in a string.

Good luck.

```
$file_url = '';
$file_fid = theme_get_setting('footer_logo');
if(!empty($file_fid)) {
    $file_loaded = file_load($file_fid);
    if($file_loaded !== false) {
        if(!empty($file_loaded->uri)) {
            $file_url_raw = file_create_url($file_loaded->uri);
            if($file_url_raw !== false) {
                $file_url = $file_url_raw;
            }
        }
    }
}

```

**In addition**, the way you're saving the image files they will be set to temporary only. Check my answer here for more info on how to solve this: https://drupal.stackexchange.com/a/136911/4861

---
Tags: forms, media
---


# Question
Title: hi I'M not getting the textfeild druing module development
```
$form['companydetails']['contact name']=array(
  '#type' => 'textfeild',
  '#title' => t('Contact name'),
);

```

this is my code but I'm not getting textfeild infront f contactname attribute....im getting blank page.....please help me out

# Answer
There could be more than one problem with this. Off the top of my head (with my knowledge of custom modules) it could be one of the following:

1. Incorrect spelling of 'textfield' in the #type parameter. (if the code is matched in your module file).
2. Is 'company details' a parent of 'contact\_name' e.g. a fieldset?
3. Are you returning $form at the end of the module\_hook function?

Maybe if you could provide the whole code surrounding the module\_hook() function I could help a bit better?
> 0 votes

---
Tags: forms
---


title: Different views for taxonomy terms

text:
# Question
Title: Different views for taxonomy terms
I am having vocabulary containing hierarchical taxonomy like this :

1. Category1
    1. subcategory1
        1. lastcategory1
        2. lastcategory2
    2. subcategory2
2. category2

I am using pathauto to taxonomies path .

Path are like this : www.example.com/category1

www.example.com/category1/subcategory1

www.example.com/category1/subcategory1/lastcategory1

At first path i want to show all subcategories taxonomy of category1 .

At second path i want to show taxonomy detail page of subcategory1 and below details i want to show subcategories of subcategory1 taxonomy .

At last path i want to show content connected to lastcategory1 taxonomy .

How can i accomplish this using views .

Note : I don't want to change the taxonomy paths . I am using drupal 7

# Answer
> 0 votes
See this tutorial. Looks like it does exactly what you ask.

The tutorial includes a video but here is the written explanation:

1) Create a Taxonomy Vocabulary here: admin/structure/taxonomy (And create a few terms)

2) Create a Taxonomy View here: admin/structure/views/add

You want to make sure that you choose "taxonomy" entities.

3) Add a contextual filter for "Taxonomy term: Parent term"

Make sure to select "Default Filter" and choose "Taxonomy term from url." Also, specify a "Default validation criteria" for "Taxonomy term" and choose "Convert taxonomy name to ID" and select "Transform dashes in url..."

4) Add a new page to this view, remove the contextual filter from this view and add a filter for "Taxonomy term: Parent term" and set it to "equal to" and leave the field there blank.

5) Save that view and create a new view here: admin/structure/views/add

Make sure this view is for a "Content" of type "Product Display" (or whatever entity bundle has the field for your taxonomy terms).

6) Add a contextual filter for your taxonomy term, mine was called "Product Categories"

Make sure this contextual filter displays "Contents of No Results." Also, specify a "Default validation criteria" for "Taxonomy term" and choose "Convert taxonomy name to ID" and select "Transform dashes in url..."

7) Add a "No results" item called a "View Area" and select "Page\_1" from your first view (this is the second page we created)

8) Save this view and go back to the first view.

9) Add a "No results" item called a "View Area" and select the second view that we just made.

10) Make sure your title field in the Taxonomy View doesn't link to the taxonomy term, but it outputs the field as a link to "catalog/\[name\]" that way your catalog names are clickable

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


# Question
Title: Managing large volume of content in tree hierarchy
Firstly I apologise if this has already been answered. I thought it would be a common problem and I'm surprised that I haven't found a general solution anywhere.

I have a large corporate website (about 8000 pages) which is currently organised in our existing CMS in a multi-level tree structure. The navigation menus, breadcrumbs and URLs are all automatically built based on the position of content nodes in the tree. This makes it particularly easy for content editors to create new content in the right place and have the menus, breadcrumbs and URLs always consistent.

We are probably going to move to Drupal 7. What is the standard approach to large, tree-structured sites like this? I don't want to have to create new tag names (taxonomy terms?) for every single section since there are hundreds of 'container' type pages that contain lists of other pages. It seems far easier to just slot the node into a tree.

I suspect there is something obvious I'm missing - I would think it is pretty normal to have a tree like structure of content. Any help much appreciated.

# Answer
Good strategy is to utilize Workbench and create sections from your menu.

So you would have your main menu, lets say 3-4 levels deep and mimic those in Taxonomy. Its easier to create taxonomy first as there is a module that will create menu from taxonomy.

So you create your taxonomy that has your structure going 3-4 levels deep. Then create a menu from it.

Install Workbench and Workbench Access and Moderation modules.

Configure Access to use Taxonomy for section assignment and then configure URL parameters to pull from Taxonomy as this will take care of your URL and breadcrumbs. Use Custom Breadcrumb module to generate breadcrumbs if you need them.

Then on each content type add a new filed for Sections which will pull from your taxonomy. So when adding content you select where in the tree it should live.

For example you are adding "Help" node which needs to live in About Us \> Services and About Us and Services are in the menu. Help does not need to be in menu but needs to follow the About Us \> Services \> Help path.

By using Workbench modules you can easily achieve that. In a sense your taxonomy acts as buckets into which content is placed. This drives URL, Breadcrumbs as well as left or right nav menu if you need one using Menu Block.

So to summarize the steps:

1. Create taxonomy of the items you want to be in menu.
2. Create menu from taxonomy using Taxonomy 2 Menu module.
3. Install Workbench suite of modules.
4. Configure workbench access to pull from Taxonomy.
5. Adjust content types to add a fields for Taxonomy selection, make it only 1 as you don't want multiple paths for nodes.
6. Configure URL Patterns to pull from taxonomy parents.
7. Install and configure Custom Breadcrumbs to also use URL path.
8. Install and configure Menu Block to use URL path.
9. Start adding content and assigning sections.

Additional benefits of this approach is that you can also restrict which roles or users can edit content in each section so you can have HR only have access to edit content in their part of the site.
> 1 votes

# Answer
Nothing stops you from using taxonomy, in fact you should be using taxonomy for categorization since a tree is a simplified and hierarchical form of taxonomy. So a tree is a subset of the features of taxonomy.

Since you can create taxonomies children and parents, you got essentially a tree. Drupal is all built around taxonomies so you really want to stick to using taxonomy if you go with Drupal.

> there are hundreds of 'container' type pages that contain lists of other pages. It seems far easier to just slot the node into a tree

You are describing a View here, and they can be programmatically created whenever someone requests the content of a section (a taxonomy term indeed). Think of it as an index that keeps itself updated automatically. The Views module is almost mandatory for every site.

You should really take your time thinking about the design and structure of your site before getting your hands dirty. The better the design, the lower execution time, this is so true with Drupal.

Hope it helps.
> 1 votes

# Answer
I posted this some while ago: "Order as text, manage huge trees with your favourite code editor" https://groups.drupal.org/node/254588.

Maybe not exactly what you could use, but just food for thought.

The idea of this module that I put together for myself is to grab the tree as text from UI, edit it in a code editor, paste it back, and save. Drupal crunches, creates the tree and you can view the hierarchy in a view that takes care of the tree formatting.

The cool thing is that code editor can handle hundreds or thousands of rows where browser can't.
> 0 votes

# Answer
I would say you don't need taxonomy or anything else, but ONLY a menu structure.

The menu system is enough to define what is the parent and what is the child, and the order of the children.

The Book module (shipped with core) uses the same strategy, but probably you don't even need that.

**Problem 1: How to edit large menus?**

* The menu configuration form will get very heavy if all menu items are loaded at once.
* There is no convenient bulk editing. Or is there?
* You may want a workflow that lets you build the hierarchy first, and add the nodes later.

Well, Menu editor does help you with the bulk editing. But it can only handle so many menu items at once. No hard limit, but it will slow down everything - but give it a try! There was a feature request that asked for paging, but this is naturally hard within a tree.

It also helps you to create dummy menu links that can be fleshed out (filled with nodes) later (via me\_node\_creation submodule).

So you could try this and help me improve this thing..

**Problem 2: Display sub-page teasers**

You said some of your pages are like containers for sub-pages. You probably want these to show a list of sub-pages.

One way I did this on a client side was to use Menupoly and create a custom MenuTheme that will render every link as a node teaser. Then a block via hook\_menupoly to display the submenu of the current page using this MenuTheme. I think I should upload that code in a sandbox!

I am sorry, this stuff is all "needs work", and I would love some help. But I think it can all become pretty cool.
> 0 votes

# Answer
To the OP about "How to manage huge menu trees" you can try https://drupal.org/project/bigmenu which is a drop-in replacement to the Drupal (6 & 7) menu admin UI that uses AJAX to load the subtrees as needed.

So you can expand and deal with just the sections of your thousand-item menu list without the all-in-one menu UI falling over.
> 0 votes

# Answer
I'm looking at Drupal for the first time and I found the lack of hierarchy support troubling and I think constantly updating taxonomies would be too much overhead for any large site, especially with a distributed authoring base (e.g. large corporation or government agency).

I think I have found a solution using module Node Hierarchy (primarily) and some other modules.

Essentially you specify which content types are allowed to be children and/or parents, and then when editing a node you have the option to 'create child'. Once child nodes are created, the parent node will have an option to view child nodes, and ordering can be controlled from this screen.

Use module Pathauto to automatically render URL alias based on parent-child-\[child\] relationships.

Finally use module Menu Block to add menus based on parent-child hierarchies.

A more detailed description/instruction is here:

https://www.youtube.com/watch?v=oz3xkF819c0

EDIT: Updated my answer to better conform to guidelines.
> -1 votes

---
Tags: taxonomy-terms, routes, breadcrumbs
---


# Question
Title: Site architecture - consistent paths, breadcrumb and menu
We've been trying to implement a site architecture that has a consistent menu, breadcrumb and path structure for all pages in the site.

This is easy for basic pages since the path can be set using the page's menu position (using pathauto), as can the breadcrumb.

eg: site.com/a-page/b-page

However, we also have 'articles' which appear in lists on certain pages, using certain tags.

The issue comes in preserving the consistent menu location (but no menu item), URL and breadcrumb for these articles whilst keeping the system easy to maintain.

eg: site.com/a-page/b-page/article-1 eg: site.com/a-page/b-page/article-2

(Most Drupal sites seem to just give up and use site.com/article-title ?)

Not all the articles are just 'news' so we don't want to just force the path to one format option using pathauto.

One solution we've identified for these articles is:

Add a field to the taxonomy for 'path to parent' which would contain the path to whatever page the articles are listed on (eg: a-page/b-page/) and then pathauto could then use this to build a relevant path to the content. Then create a Context for each term which sets the Breadcrumb and Menu trail to the correct location.

However, this does not seem very easy to maintain?

Does anyone know of a better solution?

# Answer
I think instead of using Article content type, you should use Book content type. so you could create a book page named a-page, then a page named b-page and provide it a-page as parent in options below. Now start adding article-1 and article-2 as child of b-page.

So when you view these pages article-1 or 2 the breadcrumb and will provide the url as site.com/a-page/b-page/article-1

Correct me if i misunderstood the question and do tick right if the answer is right.
> 0 votes

# Answer
I'm looking at Drupal for the first time and I found the lack of hierarchy support troubling and I think constantly updating taxonomies would be too much overhead for any large site, especially with a distributed authoring base (e.g. large corporation or government agency).

I think I have found a solution using module Node Hierarchy (primarily) and some other modules.

Essentially you specify which content types are allowed to be children and/or parents, and then when editing a node you have the option to 'create child'. Once child nodes are created, the parent node will have an option to view child nodes, and ordering can be controlled from this screen.

Use module Pathauto to automatically render URL alias based on parent-child-\[child\] relationships.

Finally use module Menu Block to add menus based on parent-child hierarchies.

A more detailed description/instruction is here:

https://www.youtube.com/watch?v=oz3xkF819c0

EDIT: Updated my answer to better conform to guidelines.
> -2 votes

---
Tags: routes, uri, breadcrumbs
---


# Question
Title: Change text format used for text field when displayed in a view?
I have a content type with a text field that may contain a token from the Media module (that WYSYWIG inserts). This token is typically transformed into HTML by enabling a specific filter for the text format used.

However, I want to create a view for nodes of this type that just **strips out the media token entirely**. This allows me to show the content w/o any images or captions.

Initially, I thought I could add my own field formatter using hook\_field\_formatter\_info and hook\_field\_formatter\_view, strip out the token right in the formatter, and then use that formatter when rendering the field in the view (views lets you select a formatter, like Default, Trimmed, etc).

The problem there is that by the time `hook_field_formatter_view` is called, the `safe_value` for the field is already computed and text has already been run through the input filter (so the token has been transformed).

I wonder if there's a way I can create a new text format that doesn't include the Media token filter and somehow tell views to render the field using that, but it doesn't appear like I can.

# Answer
I found an issue concerning something similar to you question on Drupal.org

https://www.drupal.org/node/1113088

There is some module code provided which may be useful to you.

The module looks like it uses a field formatter. Instead of taking out the media tags, it aims to strip out the resulting html tags.

```
$pattern = array('/<div class="media[^"]+">.+<\/div>/im', '/<p><\/p>/im', '/<p[^>]+><\/p>/im');
  $item['safe_value'] = preg_replace($pattern, '', $item['safe_value']);

```
> 0 votes

---
Tags: 7, views, media, input-formats
---


# Question
Title: Display user picture below content type article
How can i display user name and picture below node article. My theme is based on panels so i dont know where to write code for it. Or any admin option.

Thanks

# Answer
There is a module that comes with the Ctools module called Views Content Panes. Enable that. Also a good idea to enable the Context module, can be fetched here: https://www.drupal.org/project/context

Views Content Panes is used to output Views as panel panes.

Import code for a View that will be a good starting point for your solution is provided at the end of this answer. This view will display the Article's author username and picture.

You may need to edit the "Argument input" setting in the view.

I set it to use the "From context" option, and the required context of Author.

This has a good chance of working immediately, but we may need to go further into your panels configuration if it doesn't.

After enabling the Views Content Pane module, and importing and saving the view, you will be able to add the newly created pane to your panel.

Import this view code:

```
$view = new view();
$view->name = 'user_name_and_pic_for_articles';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'User Name and Pic for Articles';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Field: User: Picture */
$handler->display->display_options['fields']['picture']['id'] = 'picture';
$handler->display->display_options['fields']['picture']['table'] = 'users';
$handler->display->display_options['fields']['picture']['field'] = 'picture';
$handler->display->display_options['fields']['picture']['label'] = '';
$handler->display->display_options['fields']['picture']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['picture']['link_photo_to_profile'] = FALSE;
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';

/* Display: Username and Pic for Articles Content pane */
$handler = $view->new_display('panel_pane', 'Username and Pic for Articles Content pane', 'panel_pane_1');
$handler->display->display_options['argument_input'] = array(
  'uid' => array(
    'type' => 'context',
    'context' => 'entity:node.author',
    'context_optional' => 0,
    'panel' => '0',
    'fixed' => '',
    'label' => 'Author: Uid',
  ),
);

```
> 2 votes

---
Tags: 7, theming, panels
---


# Question
Title: How to display the 'Request New Password' page for Administrators.
What I'd like to do is have the exact same page as /user/password (when not logged in) that the 'Administrator' Role could use and send out emails to existing users.

However when logged in you get a 'Password reset instructions will be mailed to' message. I've had a hunt for a module or how to do it programmatically but can't find a solution.

Many Thanks

# Answer
Think you'd need to do it with Views Bulk Operations and Views.

Create a View (only accessible by the Admin role) which lists all the users, add VBO and I think reset password is included as one of the actions.
> 1 votes

# Answer
The full answer . Thanks to @colin\_shipton

is I used Login One Time, Views Bulk Operations and Views.

I had an issue getting Login One Time to work but the issue was actually with permissions not saving ( php.ini setting on local ) . So once you've checked your permissions for Login One Time & Views Bulk Operations everything should be fine.
> 0 votes

---
Tags: 7, users
---


title: Checkbox whether display Node title

text:
# Question
Title: Checkbox whether display Node title
How can I add a checkbox when I create a new page to decide wheter the user want to display the node title or not, as like the hook\_block\_configure() function ?

# Answer
To do this you need to follow the steps,

1. Edit the Page content type and add a new field "Show Content title" and add this one as checkbox, boolean.
2. In time of creating a new Page content check if you want to show the title or not.
3. Set the Page Content Type's "Show Content title" as hidden in Manage Display Settings page.
4. In your node.tpl.php you will see the following code

```
<h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>

```

Then add some check over there,

```

    <?php if($content['field_show_title'] == 1) : ?>
    <h2<?php print $title_attributes; ?>>
    <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
    </h2>
    <?php endif; ?>

```

This can solve the issue.
> 0 votes

# Answer
There is now also this module: https://www.drupal.org/project/exclude\_node\_title
> 1 votes

---
Tags: theming, nodes, 7
---


# Question
Title: How to unset _none option inside field collection?
Normally, in a node form you'ld unset the `_none` option like so:

```
function MYMODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
    unset($form['field_name'][LANGUAGE_NONE]['#options']['_none']);
}

```

Why doesn't this work in a field collection? I tried:

```
function MYMODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
    $field_collection = $form['field_field_collection'][LANGUAGE_NONE];
    $delta = 0;
    $max_delta = $field_collection['#max_delta'];
    while ($delta <= $max_delta) {
        unset($field_collection[$delta]['field_name'][LANGUAGE_NONE]['#options']['_none']);
        $delta++;
    }
}

```

In `dpm()` the option is unset and doesn't appear anymore. But on the screen it's still there... What to do?

# Answer
You're modifying a local variable. You need

```
$field_collection = &$form['field_field_collection'][LANGUAGE_NONE];

```

or

```
unset($form['field_field_collection'][LANGUAGE_NONE][$delta]['field_name'][LANGUAGE_NONE]['#options']['_none']);

```
> 2 votes

---
Tags: 7, entities
---


title: Add a custom field to a quiz

text:
# Question
Title: Add a custom field to a quiz
I've got a quiz. There is a content type to create a question. I've added a textfield to it (which will show a link to where the user can find the answer).

When I look at the question itself the textfield has been added and is being displayed on the screen. But when the question is part of the quiz, the textfield isn't there anymore (not on the screen, nor in the code).

Who can help me?

Maybe I need to add some kind of hook to the Quiz module but I don't know how hooks/custom modules work.

Thanks in advance.

# Answer
> 1 votes
There are probably many ways doing this. I'm still new as well, so go easy on me.

I would suggest you to create a taxonomy `quiz`. Each list item of `quiz` would be your question. Then for the content type `answer`, have a field named `question` and select `term reference`, choose select list as the widget type. That way, when a user create a new content `answer` and refer to one of the question from taxonomy `quiz`, you can just click on the `question` and it will give you a list of `answer`.

Other ways would be using Node Reference, but I couldn't get my mind around how to refer back to the question itself, maybe Relation would do the trick.

But try my first suggestion first.

# Answer
> 0 votes
I think your custom field is not appeared in the question form of the Quiz. The path is, for example, **node/8/take**. It is a custom form/page created by the Quiz module.

You would need to alter the form using hook\_form\_alter() from your custom module. Then you would need to load the node (question) to get the field value using node\_load() and add it to the form using `#markup` attribute.

```
function MYMODULE_form_alter(&$form, &$form_state, &$form_id){
    if($form_id == 'quiz_question_answering_form'){
        $qnode = node_load($form['question_nid']['#value']);
        $form['link2answer'] = array(
            '#markup' => l('See answer', $qnode->field_link2answer['und'][0]['safe_value']),
        );
    }
}

```

If you don't know how to create a custom module, check the documentation.

# Answer
> 0 votes
With quiz 7.x-5.0-alpha4+72-dev the array structure has changed somewhat. You will want to use this code:

```
/**
 * Implements hook_form_FORM_ID_alter()
 */
function my_module_form_quiz_question_answering_form_alter(&$form, &$form_state, $form_id) {
  // Print custom fields on the question page during the quiz.
  foreach ($form['questions'] as $node_key => $node_value) {
    $qnode = node_load($form['questions'][$node_key]['header']['body']['#object']->nid);
  }

  $field_source_url = !empty($qnode->field_source[LANGUAGE_NONE][0]['url']) ? $qnode->field_source[LANGUAGE_NONE][0]['url'] : '';
  $field_source_title = !empty($qnode->field_source[LANGUAGE_NONE][0]['title']) ? $qnode->field_source[LANGUAGE_NONE][0]['title'] : $field_source_url;
  $field_source = l($field_source_title, $field_source_url);

  $form['navigation']['#prefix'] = theme('question_link', array(
    'field_source' => $field_source,
  ));
}

/**
 * Implements hook_theme()
 *
 * @return array
 */
function my_module_theme() {
  $items = array();
  $theme_path = drupal_get_path('theme', 'my_theme') . '/templates';

  $items['question_link'] = array(
    'path' => $theme_path,
    'template' => 'question-link',
    'variables' => array(
      'field_source' => NULL,
    ),
  );

  return $items;
}

```

Then in sites/all/themes/my\_theme/templates/question-link.tpl.php

```
<?php if($field_source): ?>
  <strong>Source field</strong>
  <div class="question-field-source"><?php print $field_source; ?></div>
<?php endif; ?>

```

Clear the cache to alert Drupal of the new template file.

---
Tags: quiz, 7
---


# Question
Title: Trying to get property of non-obJect Custom Module
Notice: Trying to get property of non-object in speakerdetailblock\_preprocess\_block() (line 42

# Answer
This error occurs when you are getting language from a non object. To fix this check that whether the node is a object and check that 'language' exists in the $node or not.

```
if(is_object($node) && isset($node->language))

```

Then check the stuff that you are going to do.
> 2 votes

---
Tags: 7, theming, comments
---


# Question
Title: Populate multiselect options onchange of dropdown using AJAX
I have created a content type (Geological Locations) with 2 fields, Country and States.

The Country field is a select box, and States field is a multiselect. So if i select a Country, the States multiselect should be populated based on the selected Country using AJAX.

In my custom module, i used **node\_form\_alter()** to customize the node creation form.

I have tried the below code, but it is not working as expected.

```
function demo_form_geological_locations_node_form_alter(&$form, &$form_state, $form_id) {
    $form['additional_settings']['#access'] = false;
    $form['field_country']['und']['#options'] = array(''=>'Select', 'india'=>'India', 'usa'=>'USA');
    $selected = isset($form_state['values']['field_country']) ? $form_state['values']['field_country'] : '';

    $form['field_country']['und']['#ajax'] = array(
          'callback' => 'ajax_states_callback',
          'wrapper' => 'states-wrapper',
    );

    $form['field_states']['#prefix'] = '<div id="states-wrapper">';
    $form['field_states']['#suffix'] = '</div>';
    $form['field_states']['und']['#options'] = ajax_get_state_options($selected);

    return $form;
}

function ajax_states_callback($form, $form_state) {
    return $form['field_states'];
}

function ajax_get_state_options($key = '') {
    $options = array(
        t('usa') => drupal_map_assoc(
          array(
            t('Florida'),
            t('Georgia'),
            t('Atlanta')
          )
        ),
        t('india') => drupal_map_assoc(
          array(
            t('Maharashtra'),
            t('Gujarat'),
            t('Karnataka')
          )
        )
    );

    if (isset($options[$key])) {
        return $options[$key];
    }
    else {
        return array();
    }
}

```

Can anyone tell me where i am going wrong? I am expecting the output like below screenshot, when i select the Country "India":

# Answer
Awesome question with full detail.After checking I tested it on my local dev box for its fix. Use the below code for its fix. I have written the problem & its fix below.

```
    <?php

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

  $form['additional_settings']['#access'] = false;
  $form['field_country']['und']['#options'] = array(''=>'Select', 'india'=>'India', 'usa'=>'USA');
  $selected = isset($form_state['values']['field_country']) ? $form_state['values']['field_country']['und'][0]['value'] : '';
  $form['field_country']['und']['#ajax'] = array(
    'callback' => 'ajax_states_callback',
    'wrapper' => 'states-wrapper',
  );
  $form['field_states']['#prefix'] = '<div id="states-wrapper">';
  $form['field_states']['#suffix'] = '</div>';
  $form['field_states']['und']['#options'] = ajax_get_state_options($selected);
  return $form;
}

function ajax_states_callback($form, $form_state) {
  return $form['field_states'];
}

function ajax_get_state_options($key = '') {
    $options = array(
        t('usa') => drupal_map_assoc(
          array(
            t('Florida'),
            t('Georgia'),
            t('Atlanta')
          )
        ),
        t('india') => drupal_map_assoc(
          array(
            t('Maharashtra'),
            t('Gujarat'),
            t('Karnataka')
          )
        )
    );

    if (isset($options[$key])) {
        return $options[$key];
    }
    else {
        return array();
    }
}

?>

```

Problem was at line

```
$selected = isset($form_state['values']['field_country']) ? $form_state['values']['field_country'] : '';

```

you were passing the array to the selected value .i.e. countries array but the function ajax\_get\_state\_options needs the key of selected country to return the array of states based on selected country.

I have tested this on php 5.3.27 Other suggestions :

1. you can also use the existing field api wrapper generated by field api.

P.S. : Double slap myself to track this small mistake in 1h 30 minutes.
> 1 votes

# Answer
Have you tried one of the following modules?

Multiselect (this one suits the most)

Hierarchical Select (relatively easy to configure)

Conditional Fields (requires separate dropdown lists)

A combination of Multiselect and Hierarchical Select will mostly help you achieve what you have shown.

Regards,

Supriya Rajgopal
> 1 votes

# Answer
You return `$form['field_states']` wrapped in `<div id="states-wrapper">` to replace content of `<div id="states-wrapper">`. Try removing wrapper when returning form element via AJAX like:

```
function ajax_states_callback($form, $form_state) {
    unset($form['field_states']['#prefix']);
    unset($form['field_states']['#suffix']);
    return $form['field_states'];
}

```

You should consider moving `$form['field_states']` to a container.
> 0 votes

# Answer
Try Reference Field Option Limit
Find the Documentation related to this module here Documentation
> 0 votes

---
Tags: 7, forms, ajax
---


title: How do I override a field template?

text:
# Question
Title: How do I override a field template?
I am trying to override a field template with my own one. The field is called field\_test, so I created a field--field-test--mynodetype.html.twig template file \` in root-theme-directory/templates/, but Drupal doesn't recognize it.

I cleared the cache from the UI, enabled debug mode in settings.yaml, installed the Devel module, and re-generate the theme registry on each request, but nothing seems to help. The field gets always rendered with the default field.html.twig template.

How do I override the field template Drupal uses?

# Answer
> 15 votes
You need to specify the entity type (node, taxonomy\_term, ...) in the template name suggestion as you specified, i.e. field--node--field-test.html.twig.

*node* is the entity type, and *field-test* is the field name.

If you want to know which template is generating a particular markup element, you can use Twig's debug option. You enable Twig debugging in sites/default/services.yml; set the value of `debug` in `twig.config` to `true`.

I have added the *field\_test* field to the *Article* nodes, and I got the template suggestions in the HTML source.

```
<!-- FILE NAME SUGGESTIONS:
   * field--node--field-test--article.html.twig
   * field--node--field-test.html.twig
   * field--node--article.html.twig
   * field--field-test.html.twig
   * field--string.html.twig
   x field.html.twig
-->

```

After getting the suggestion, I created a template file and kept this in the templates directory of the theme.

Remember to clear the cache.

See Working With Twig Templates for more information.

# Answer
> 3 votes
Templates *must* be placed in a 'templates' directory in your theme. They won't be picked up in the root of your theme. See https://www.drupal.org/node/2349803#templates (which I just updated to note the difference from the Drupal 7 behaviour).

---
Tags: 8, theming
---


# Question
Title: How to upload multiple files and predefine filetypes?
Does someone know how it is possible to upload multiple files with the dropbox client module for drupal 7?

It would be nice if it could be integrated with plupload.

Also i would like to know how i can predefine the filetypes users can upload?

I'm a n00b in php, can someone give me some tips or solutions?

Here is the part of the upload funktion in the dropbox client module.

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

  $form[ 'upload' ] = array(
    '#title' => t('Upload file'),
    '#type' => 'file',
    '#size' => 20,
    );
  $form[ 'submit' ] = array(
    '#type' => 'submit',
    '#value' => t( 'Upload' ),
    );
  return $form;
}

function dropbox_client_upload_form_submit( $form, &$form_state ) {

  global $user;

  $dropbox = dropbox_client_get_client();

  //Process files
  $uploads_dir = dirname( $_FILES[ 'files' ][ "tmp_name" ][ 'upload' ] );

  $tmp_name = $_FILES[ 'files' ][ "tmp_name" ][ 'upload' ];
  $name = $_FILES[ 'files' ][ "name" ][ 'upload' ];
  $filename = "$uploads_dir/$name";
  move_uploaded_file( $tmp_name, $filename );

  $dpath = (isset( $_GET[ 'dpath' ] )) ? $_GET[ 'dpath' ] : '/';
  $result = $dropbox->add( $dpath, $filename );

  if ( property_exists( $result, 'error' ) ) {
    drupal_set_message( $result->error );
  }
  else {
    drupal_goto( $_GET['q'], array( 'query' => array( 'dpath' => $dpath ) ) );
  }
}

```

Thank you!

Best regards, meckl

# Answer
> 0 votes
> Also i would like to know how i can predefine the filetypes users can upload?

Specify the file types restriction on the file field with 'file\_validate\_extensions' in the #upload\_validators array in the file field. See the form api for reference. See the file\_managed field.

---
Tags: 7, forms, files
---


# Question
Title: Resending webform submission doesn't use custom mail template
I created a custom webform email template named webform-mail-1.tpl.php that is used when a user submits a webform. The problem is, if someone modifies that submission and wants to resend that submission by email, the email uses the default template instead of the custom one ...

Does anybody have an idea as to why this happens ? I didn't read anything about needing a separate template for emails that are sent again ...

Thanks !

# Answer
> 0 votes
Site was using two different themes and webform was submitted from the front end theme(first theme) and back end theme(second theme) The problem was that the webform template was present in the front end theme and not in the back end theme. So that's why when the user submitted the webform once the email uses the custom template.and when the user edit the webform under the back end theme the webform custom template is not present in this theme so the webform was using the default template. Fix : Keep the similar custom template in both themes.

---
Tags: webforms, emails
---


title: how to remove quicktabs extra url

text:
# Question
Title: how to remove quicktabs extra url
I have a quicktabs on my homepage. When the tabs are clicked the url of homepage changed to like this:

http://www.example.com/home?qt-homepage\_tab\_menu=0#qt-homepage\_tab\_menu . . . What should I do if I only want to have http://www.example.com when any tab is clicked?

Thank you!

# Answer
> 0 votes
I believe that could happen if you have a Javascript error on your page, or that you have Javascript disabled in your browser. For the former, open the error console (`Ctrl`+`Shift`+`J` in Firefox and Chrome) and try to figure out what might be causing it.

# Answer
> 0 votes
Thank you enzipher for the tip. There were few javascript/jQuery errors but the main problem was the file google\_analytics\_et.js. I searched and found a patch from here: https://www.drupal.org/files/google\_analytics\_et-single\_event-1870694-0.patch

Problem solved. Hope this will help other people. I have spent too much of time on this.

---
Tags: uri
---


# Question
Title: Changing group visibility needs group content to be resaved when group content visibility field is set to "Use group defaults"
Drupal Commons 7.x-3.2
Organic Groups 7.x-2.1

Content type: **Mygroup**
Field: **Group visibility** \- value: *Public*

Content type: **Mypost**
Field: **Group** \- default value: *Mygroup*
Field: **Group content visibility** \- default value: *Use group defaults*

Now when I create a group and a post based off on these content types everything is fine. As in everything is visible for all users.

Now when I change the **Group visibility** to *Private* I would except the post to not be visible anymore (because of the *Use group defaults* setting.

Unfortuanetely that's not working until I resave the post content. Then it will respect it's parent's settings.

This bug is mentioned in this video (around 6 min)

Does anyone know how to solve this problem?

# Answer
> 0 votes
**Reason.** I assume you see this behavior because all the node permissions are cached in Drupal, and only updated when (re-)saving a node or rebuilding the permissions.

**Workaround.** So instead of re-saving all nodes of your group individually, a faster workaround would be to go to `admin/reports/status/rebuild` and rebuild all permissions at once. This would probably also be the place to hook into for a real bugfix: rebuilding of the group nodes permissions, triggered when saving the group node with a different value in the "Group visibility" field.

(This answer is an educated guess, I didn't test myself so far.)

**Redesign discussion.** A still better solution would however be a larger rework of the OG permissions system, as discussed in Drupal issue #1122388. See esp. comment #10 there, discussing that the "Group content visibility: use group defaults" value is not that meaningful as it prohibits a use case where one wants the group itself publicly visible, but have its content default to private, and setting that via a fallback to the group setting so that later changes are simple. This scenario (publicly visible group node with private group content nodes) is supported by newer versions of Drupal Commons 7.x-3.x (using OG 7.x-2.7 here), but changing the setting only affects group content nodes added afterwards. So it's not the "fallback to group provided default" we want here, even though the "Group content visibility" field has "use group defaults" as its default value (which is not used though). That could be reported as a bug / improvement request to Drupal Commons.

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


# Question
Title: How to make an existing private OG group and its nodes public?
I use Drupal Commons 7.x-3.12 (uses OG 7.x-2.7). There, I have a private group with private posts. (Means, the group node uses privacy settings "Joining requires admin approval" and "Hide contributed content from non-members").

I want to make this private OG group public, and all content nodes in it.

So I tried and set "Privacy settings: Any site member can contribute" when editing the group node, and rebuilt the permissions. This made the group node publicly visible, but none of its content nodes – neither those created before nor after this change.

# Answer
How to make your private OG group public, and existing posts in it:

1. **Make the group node public.** Edit the group node and set "Privacy settings: Any site member can contribute". You did that already. It should be all there is to do, but due to bugs we have some more steps:
2. **Make existing content nodes public.** Set the `group_content_access` field of existing posts to "Public - accessible to all site users". For that, run the following command, replacing `3183` with the node ID(s) of your own affected *group* node(s). We use `drush` here, but you could also run it in the database directly.

```
drush sql-query "UPDATE field_data_group_content_access
  SET group_content_access_value = 1
  WHERE entity_type = 'node' AND entity_id IN (
    SELECT etid
    FROM og_membership
    WHERE entity_type = 'node' AND group_type = 'node' AND gid IN (3183)
  )"

```

(Note to self: Don't copy&paste such commands to a Freemind rich text node for adapting before executing. Saving, re-editing and then copying the node content will convert spaces to non-breaking spaces, making the SQL commands fail with confusing error messages.)
3. **Check results.** Check that the `group_content_access` field is now `1` for all nodes in your group. To do that, execute this, again replacing `3183` with your group node ID(s):

```
drush sql-query "SELECT entity_id, group_content_access_value
  FROM field_data_group_content_access
  WHERE entity_type = 'node' AND entity_id IN (
    SELECT etid
    FROM og_membership
    WHERE entity_type = 'node' AND group_type = 'node' AND gid IN (3183)
  )"

```
4. **Make future content nodes public.** Due to a bug, the Drupal Commons setting "Any site member can contribute" that we changed above does not properly change the relevant OG setting. This causes new posts to be still "Private - accessible only to group members" (value `1`, in this case). So we have to change the OG setting ourselves. To do that, execute this, again replacing `3183` with your group node ID(s):

```
drush sql-query "UPDATE field_data_field_og_access_default_value
  SET field_og_access_default_value_value = 0
  WHERE entity_type = 'node' AND entity_id IN (3183)"

```
5. **Rebuild permissions.** Either do click the button in `admin/reports/status/rebuild`, or run:

```
drush php-eval "node_access_rebuild();"

```

**Background knowledge and details**

* Setting the group node to "Privacy settings: Any site member can contribute" as you did does not affect already existing group content nodes because they have a separate field `group_content_access` that has been set at node creation to value `2`, according to the then-active group settings (`2` means "Private - accessible only to group members", as can be seen when editing a content type's `group_content_access` field via the Drupal CCK interface). So you have to set this field somehow manually to `1`, which means "Public - accessible to all site users".
* In order to change the `group_content_access` field, when using vanilla OG modules you can just change that in the node create / edit form as the field shows there. In your version of Drupal Commons however, it does not show there. This is a tweak via a hook, since Commons wants to simplify the group visibility logic by introducing the group-wide "Privacy setting" field. It means we had to resort to direct database manipulation above.
* The "Group content visibility" (`group_content_access`) field has a third value `0`, meaning "Use group defaults". Using it leads to a fallback to the value of the "Group visibility" (`group_access`) field of the containing group, as confirmed here. It does *not* mean a fallback to `group_content_access` field of the containing group, as confirmed here (that field only exists if the group is *simultaneously* group content). Anyway, this fallback behavior is confusing and inflexible, as the fallback value does not allow to have a publicly visible group node with private content nodes. A rework is under discussion.
* Drupal Commons 3.x-3.12 and newer has a workaround for this that enables having a publicly visible group node with private group content nodes. It's done with the combination of the group's privacy settings you used ("Joining requires admin approval" plus "Hide contributed content from non-members"). This is only a workaround however, since it means that all group content nodes have to set their "Group content visibility" field to an explicit value (`1` or `2`) rather than the fallback (`0`). It leads to the manual effort when wanting to change a group from private to public later, as you tried. This should be considered a bug that is still awaiting its real fix. I want to report this to Drupal Commons, but have to re-test with the newest release 7.x-3.19 first.
> 1 votes

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


# Question
Title: How can I protect a disabled form from being submitted?
I need to protect **URL alias** from being submitted.

I've tried setting #disabled, #access, unset(), and what not. It hides the form, but the user is still able to modify the form on the client-side and submit it.

How do I prevent this form from being submitted on the client-side?

My current module code

```
<?php
function mymodule_form_alter(&$form, &$form_state){
  if (empty($form['type']['#value'])) return;
  $form['#after_build'][] = 'mymodule_after_built';
}

function mymodule_after_built($form, &$form_state) {
  $form['path']['#access'] = FALSE;
  $form['path']['alias']['#access'] = FALSE;
  $form['path']['alias']['#value'] = $form['path']['alias']['#default_value'];

  return ($form);
}

```

**UPDATE:**

To clear the question, I am not asking how to hide the form, but how to prevent the end-user from manually altering the code and submitting the form I just hid.

End-user can just edit source code and add `<input type="text" id="edit-path-alias" name="path[alias]" value="" size="60" maxlength="255" class="form-text">` and still enter the alias.

# Answer
> 1 votes
Found the issue! It seems to be a Drupal bug.

`#access` set in `#after_build` does not completely override the `#access` settings, set in `hook_form_alter`.

In theory, a form is altered by `hook_form_alter` and `hook_form_alter` is altered by `#after-build`. When I try setting `#access` in `hook_form_alter`, to alter the form, everything works. However, when I try setting `#access` permissions in `#after_build`, to alter `hook_form_alter`, it only hides the form, still allowing anyone to submit it, by altering the code on the client side.

As a temporary solution, I disabled URL alias permissions, by unchecking "Administer URL aliases" and "Create and edit URL aliases".

# Answer
> 0 votes
If you set #access to FALSE in #after\_build callback, the value will not be submitted even if it's sent to server.

---
Tags: forms
---


# Question
Title: How to print external html output in form_submit
I have written a form that accepts user's input and based upon the input queries an external site and extracts the html of the result page from the external site. Is there a way to print html inside the form submit so that the results would appear on my drupal site. Following is my form\_submit. (Drupal 7 is the version that I am working with)

```
   function tripal_search_form_submit($form, &$form_state) {
    //debug($form_state);
    switch ($form_state['triggering_element']['#name']) {
     case 'submit':
     $string=$form_state['input']['string'];
     $organism=$form_state['input']['dropdown'];
     $some_var = file_get_contents("http://legumeinfo.org/gb2/gbrowse/$organism/?q=$string");
     print $some_var //This is were I need help
     break;
     case 'reset':
     $form['items']['name'] = array(
     '#type' => 'markup',
     '#value' => '<input class="form-button" value="Reset" type="reset">',
     '#weight' => 2000,
    );
   break;
  }
}

```

# Answer
> 2 votes
You might try using the drupal api function drupal\_set\_message()

https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal\_set\_message/7

so in your case:

```
drupal_set_message($some_var); // will display the rendered html as a status message

```

# Answer
> 0 votes
I am not sure if I understood the question correctly, but if you don't mind to look at other solutions already there for that part about grabbing from external sources, I can only suggest to look at modules like: Prepopulate , Entityreference prepopulate, Quickpost bookmarklet, Simple bookmarklet, Bookmarklet and how they have achieved it. For sure, depending on your needs, it mayd not be exactly what you look for. But maybe a starting point or side by side inspiration ...

There are also maybe other useful questions around near to yours: Which hook do I need to use to pull external content in pages?

I also would recommend to give more details about your Drupal version etc. (tags) to gain more answers here. Hope it helps. Best regards.

# Answer
> 0 votes
The `drupal_get_form` functionpProcesses a form array and produces the HTML output of a form. If there is input in the `$_POST['edit']` variable, this function will attempt to validate it, using `drupal_validate_form`, and then submit the form using `drupal_submit_form`.

When you are building your form you want to set re-direct to false:

```
$form['#redirect'] = FALSE;

```

Please take a deep look at redirect here: http://api.drupal.org/api/drupal/developer--topics--forms\_api\_reference.html/6#redirect

Drupal helps you create and process forms right inside your module. The APIs Drupal offers make it very simple to make an addition or modification of your form as the forms are arrays and even the validation and submission happens in a different function. This modular approach keeps the form code in your module clean and easy to maintain. You also do not need to bother with the HTML details of the form if you use the Drupal form API – all the HTML is auto-generated. Have fun creating your next form in your Drupal module!

Take a look at this group post: **\[Modifying individual form elements html markup with form api\]**. I hope it can help you somehow.

Thank you.

---
Tags: forms
---


title: Menu doesn't expand

text:
# Question
Title: Menu doesn't expand
I have a primary link created and set of links whose parent is the primary link.

I have enabled "Show as expanded" to all of them (tried with first primary also) but yet the sub-menus don't appear in the screen.

How do I resolve it?

I have went through Structure -\> Menus -\> Main Menu and list links.
Then, I have clicked edit on the About Me link.

# Answer
If you want to stick with bartik theme then there is one tutorial at Add drop down menu support to Bartik. However I have not tested it, but comments suggests that it works. It is as easy as adding some custom CSS to main menu in bartik theme.

My suggestion would be to use some other theme such as skeletontheme, which is responsive and have good support to your requirement. I have used this theme a lot for many projects.
> 0 votes

---
Tags: 7, navigation
---


title: Adding Gmap to webforms

text:
# Question
Title: Adding Gmap to webforms
I allready download gmap, location and some other modules that in this catagory and still I dont succeed to add a field in gmap type to my webform page so users could put it their location (not in the register of the users, in the form that I build!

How do I do it? I saw this: https://drupal.org/project/webform\_gmap but it's for Drupal 6 and I'm using 7.

# Answer
Drupal 7: Webform Gmap Location

https://www.drupal.org/sandbox/drecksau/2096563

> This module adds «Gmap» component to Webform.
> This component allows you to mark the location using the Google map.
> Also below the map can be displayed autocomplete address field.
> 0 votes

---
Tags: 7, webforms, google-maps
---


# Question
Title: How do you remove or hide the 'Permalink' in comments?
Does anyone know how to remove or hide the 'permalink' in the comments section (i.e on posted comments).Here is a copy of one of my comments -

" Permalink Submitted by Jade K on Fri, 11/11/2011 - 14:28"

Additionally, does anyone know how to rename or remove 'submitted by' from comments?

# Answer
> 6 votes
Copy the default comment comment.tpl.php into your theme directory:

```
cp /your_drupal_path/modules/comment/comment.tpl.php /your_drupal_path/sites/all/themes/mytheme/comment.tpl.php

```

Search and change the following lines into your theme's path comment.tpl.php:

From:

```
<div class="submitted">
<?php print $permalink; ?>
<?php print $submitted; ?>
</div>

```

To:

```
<div class="submitted">
<!-- Do not show Permalink on comments -- it will still have a link on the comment title
<?php print $permalink; ?> -->
<?php print $submitted; ?>
</div>

```

This will do the magic!

# Answer
> 4 votes
This really depends on what theme you are using. Oddly enough, I can't find a theme on my machine that includes the permalink link like that, but you should take a look at the **comment.tpl.php** for the theme you are using.

The default one for Zen for Drupal 6 has this in it:

```
<div class="submitted">
  <?php
    print t('Submitted by !username on !datetime.',
      array('!username' => $author, '!datetime' => $created));
  ?>
</div>

```

If you are using Drupal 7, then there is a decent chance that the text is coming from template\_preprocess\_comment.

I both cases, note where the text is coming from: the t() function.

You could just edit the text, but that is not the proper way to handle it. t() handles translation, but it also can handle custom localization. These are done with string overrides, which can be handled several different wants. The String Overrides module is the easiest way. You can also do them in your **settings.php**. I don't have the link handy for that syntax, though.

If you want to hide either of these in Drupal 7, then you need to implement your own template\_preprocess\_comment() and unset() `$permalink` and/or `$submitted`. For Drupal 6, just remove that code blip from the template file.

# Answer
> 1 votes
better add this in your css: .permalink {display: none;}

# Answer
> 0 votes
add this in your css .permalink {font-size:0px;}

---
Tags: 7, comments, theming
---


# Question
Title: Attaching Conditional widget on Drupal Field
I have extended drupal user registration form by attaching fields to user entity.

One of the field is to let user select duration. I have set it up as radio button.

```
Form: When you started:

(radio button) Not yet started (need help)

(radio button) Just starting (1-2 years)

(radio button) Traction: (2-3 years)

(radio button) Experienced: (4+ years)

(radio button) We started our CI program in: (field for year)

```

Now the requirement is if the user select any of the top 4 options it shoudl go as it is. But if none of the above suites users choice than he will select the last radio button and on this radio button he should be able to type his year manually. So basically a text field should appear. I've no clue how to achieve this and didn't find it on google too.

# Answer
> 0 votes
You should create another field for the year and use e.g. Conditional fields module so that year field appears only when a specific option is selected.

Generally speaking, you should use form API states processing, and the Conditional fields provides UI for that.

---
Tags: 7, users, entities
---


# Question
Title: How to add number format function in decimal results in views 3
I am displaying some float value in my view. How can I make them till two decimal places?

Is there a way to add number\_format function in view results?

# Answer
> 1 votes
You could rewrite the field output and use PHP to adjust it to your needs.

EDIT: To be able to actually use PHP in your rewrite rules you need an additional module called Views Custom Field.

# Answer
> 0 votes
At least in my version of Views (7.x-3.8), there is a built in option for rounding. It appears on the field views settings for any float. \- click on "Content: XXX" in the fields section \- check the box "Round", description "If checked, the number will be rounded." \- enter the number of decimal places in the "Precision" box.

In the views export it comes up as "set\_precision".

---
Tags: views
---


# Question
Title: Display a view inside a field collection with eva
I'm trying to display a view inside a field collection via EVA. I've created the view which accepts the nid of the containing content type as the context argument and all is good in that the view shows correctly when the nid is passed in, however I think the problem is that a field collection is stored as a separate piece of content, so the nid that is supplied when viewing is not that of the containing content type.

The view returns nothing when inserted into the field collection.

Is there a specific way to get the containing content-type nid into the view via the field collection? I've looked in the tokens section for the argument input in the eva view, but nothing specifically for the containing nid, only the specific field collection nid.

# Answer
> 1 votes
After thinking outside the box a bit, the answer lies in setting the contextual filter to accept the "field collection item" id using the appropriate relationship (not the field collection item entity).

---
Tags: 7, views, entities
---


# Question
Title: How to Map files if I have fid in Drupal 6 table and field in Drupal 7 content type?
I have a drupal 6 database in which custom table is used to store the details. In the custom table a column `fid` contains the `fid` of file.

I have migrated the files and it migrated successfully. I mapped the node fields to that fid. I have added the following code :

```
$this->addFieldMapping('field_image', 'fid')->sourceMigration('ExFiles');

```

It showing me following message :

```
The specified file 3424 could not be copied to public://3424.

```

I want to know how to map files from custom table field?

# Answer
I think you also need to specify the file\_class:

```
$this->addFieldMapping('field_image', 'fid')
  ->sourceMigration('ExFiles');

$this->addFieldMapping('field_image:file_class')
  ->defaultValue('MigrateFileFid');

```

This is explained in the file migration docs; without the class, the source is assumed to be a URI and not a fid.
> 1 votes

---
Tags: 7, migrations
---


# Question
Title: Wierd admin_path behaviour, does it should be like this?
I have even two questions - both are connected to hook\_admin\_path().

1. Does menu path `'user/*/edit'` and `'user/*/account/edit'` are the same, from admin\_path perspective and was D7 designed with such functionality? I want menu item `'user/*/account/edit'` to be shown on default theme.

When I try to show a menu item with path:

```
'user/*/account/edit'  - showed on admin theme
'user/*/account/edit1' - showed on default theme

result of path_get_admin_paths():
Array ([admin] =>
admin
admin/*
user/*/cancel
user/*/edit
user/*/edit/*
...
)

```

checked with:

```
path_is_admin('user/%user/account/edit'); // TRUE
drupal_match_path('user/%user/account/edit', 'user/*/edit'); // TRUE

```

2 . I tryed to change it with

```
function MY_MODULE_admin_paths_alter() {
  $paths = array(
    'user/*/edit' => FALSE,
    'user/*/edit/*' => FALSE,
  );
}

```

But result of path\_get\_admin\_paths() is the same? No other functions call hook\_admin\_paths\_alter(). As I understand, this function shall be the last and should change admin\_path.

Any ideas about that?

# Answer
> 1 votes
Thank you Clive, I mistakenly used pattern from hook\_admin\_paths() and not hook\_admin\_paths\_alter() function.

The correct way was:

```
function MY_MODULE_admin_paths_alter(&$paths) {
  $paths['user/*/edit'] = FALSE;
  $paths['user/*/edit/*'] = FALSE;
}

```

---
Tags: hooks
---


title: Custom content type show taxonomy image

text:
# Question
Title: Custom content type show taxonomy image
What i want is to have a field called Manufacturer so the user can select the product manufacturer. The way to show the field is an image linking to the Manufacturer page.

example: Product "door handles 0001" has a Manufacturer Audi.

I'm thinking using taxonomy terms with one more field in them (image) but when i import the field just show the name linking to the taxonomy term not the image.

I have see that stackexchange but i can't manage to do it, the patch is a little outdated..

# Answer
The easiest answer to your problem might be the taxonomy image module:

> "The taxonomy\_image module allows site administrators to associate images with taxonomy terms. With the association created, an admin can then make a call to 'taxonomy\_image\_display()' from their theme or other PHP code to display the appropriate image."

but since you already have a field associated with your taxonomy term, you just want to suppress the output of the tags in your node template and replace it with code that loads the term field and then renders it, ex. roughly:

```
/* load your term object */
$term= taxonomy_term_load($node->field_tags['und'][0]['tid']);

/* load the entity object (your field names will vary)
$result=field_view_field('taxonomy_term',$term,'field_image','image');

/* display the rendered result, this can be set in manage display for your field to use image styles, etc. */
print render($result);

```
> 1 votes

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


# Question
Title: Removing divs added by render and node.tpl.php
I'm trying to build an HTML5 template for Drupal 7, and I'm quite particular about clean code. I want full control over the HTML and CSS which for the most part I get using my own custom theme. In other words I have an HTML5 and CSS set I want to use exactly as is in Drupal. I'm not too clued up on how the whole pre-process function thing works.

When I use 'print render($page\['content'\])' in my page.tpl.php file it adds

```
<div class="region region-content">
    <div id="block-system-main" class="block block-system">
        <div class="content">

```

And then when I add 'print render($content)' in the node--custom.tpl.php it adds

```
<div class="field field-name-body field-type-text-with-summary field-label-hidden">
    <div class="field-items">
        <div class="field-item even" property="content:encoded">

```

I don't want any of these divs. How do I get rid of them?

# Answer
> 17 votes
The div ids and classes you see inside $page\['content'\] comes from region.tpl.php \> block.tpl.php \> node.tpl.php Drupal content passes through these template files, each step adds some divs.

* **Step One**

region.tpl.php file contains the code as follows

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

```

now if you make changes in this file it will effect all the regions of your page. If you want to control only the content area, create a new file name it region--content.tpl.php in that file paste only

```
<?php if ($content): ?>

    <?php print $content; ?>

<?php endif; ?>

```

This will get rid of div created for only content region.

* **Step Two**

Make a copy (if we make changes in block.tpl.php all the blocks will be effected) of block.tpl.php and name it block--content.tpl.php and remove or change the divs. Without the divs the file will contain the following code to output content.

```
<?php print render($title_prefix); ?>
    <?php if ($block->subject): ?>
      <h2 class="block-title"<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
    <?php endif;?>
      <?php print render($title_suffix); ?>
      <?php print $content; ?>

```

This will get rid of div created by bock.tpl.php

* **Step Three**

Now edit the node.tpl.php file to remove or change the divs. Without the divs the file will contain the following code to output content. \>"\>

```
    <?php print $user_picture; ?>

    <?php if ($display_submitted): ?>
      <span class="submitted"><?php print $date; ?> — <?php print $name; ?></span>
    <?php endif; ?>

        <?php
          // We hide the comments and links now so that we can render them later.
        hide($content['comments']);
        hide($content['links']);
        print render($content);
       ?>

    <?php if (!empty($content['links']['terms'])): ?>
      <?php print render($content['links']['terms']); ?>
    <?php endif;?>

    <?php if (!empty($content['links'])): ?>
        <?php print render($content['links']); ?>
      <?php endif; ?>

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

```

This will get rid of all div and classes. Now you can wrap the content with your own divs. Please let me know if it works for you.

# Answer
> -2 votes
What works perfectly for me is: `strip_tags(render($var));`

---
Tags: 7, theming
---


# Question
Title: Get the default image for a profile2 image field with code
I need to get the fid of the image specified as the default for an image field in a profile2 profile.

There is a field\_get\_default\_value function, but it is not clear to me how to use it.

I'm using Drupal 7.

# Answer
You don't need to bother with the field\_get\_default\_value function, you can use the field\_info\_field function. For image fields, it will provide the fid for the default image in \['settings'\]\['default\_image'\].

Suppose your field is "field\_picture", then this will get you the fid and file:

```
$info = field_info_field('field_picture');
if (!empty($info) && $info['settings']['default_image'] > 0) {
    $default_img_fid  = $info['settings']['default_image'];
    $default_img_file = file_load($default_img_fid);
}

```
> 4 votes

# Answer
I'd like to add a precision:

Sometimes the default image of an image field is set **specifically** for a particular **content type**, and in this case `field_info_field()` will not give you the right information.

If you're looking for the default image's `fid`, in this case you must use `field_info_instance()`

```
// the entity type is: node, and field name: field_image
// but it could be something else.
$info = field_info_instance('node', 'field_image', 'machine_name_content_type');
//then it's the same has Whiskey said
if ( !empty( $info ) && $info['settings']['default_image'] > 0 ) {
   $default_fid = $info['settings']['default_image'];
   $default_img_object = file_load( $default_fid );
}

```
> 3 votes

---
Tags: 7, entities, users
---


title: Cannot login to my Drupal site

text:
# Question
Title: Cannot login to my Drupal site
A while back I made a site for our Operettic society in Holland, after a while I transferred the maintenance to another person who came just recently back at me with a problem.

The site is stuck in maintenance mode, and also the `/user/login` doesn't work, I also tried the `?q=user` possibility, but this also didn't work.

Also made the following query to the database:

```
UPDATE variable SET value = 's:1:"0";' WHERE name= 'site_offline';
DELETE FROM cache WHERE cid = 'variables';

```

Anyone some thoughts on this?

Thanks in advance!

# Answer
If you can login with ssh on the server you could use drush to unset the maintenance mode±

drush vset maintenance\_mode 0
> 0 votes

# Answer
I got one solution here. I faced this problem once and it worked for me. I logged in to the application by admin programmatically using below code

```
 global $user;
    $user = user_load(1);
    drupal_session_regenerate();
    drupal_goto('user');

```

Make sure to delete the above code once the site is set back from maintenance mode. Otherwise this will give administration access to any user visiting the website.
> 0 votes

---
Tags: users, maintenance-mode
---


# Question
Title: Modules to create submenu with custom markup
I have a question about how to create menu with full custom markup. Custom markup is applied not to menu items, but to entire submenu.

An example of such menu is provided below:

As you can see, submenu items have different visual attributes. And they are arranged like in a grid layout.

I think, it's possible to catch mouse over events and show html element with the submenu content, when user points cursor at submenu.

But, if you know any Drupal modules, that allow to implement such a feature, or simplify this task, it will be great.

Thanks in advance.

# Answer
Check Out these two modules..: TB Mega Menu and Nice Menus

Here is a post which lists some of them Mega Menu modules for Drupal
> 1 votes

# Answer
Well I did this using Menu attributes module. Simply add any Class or Id to any menu item you want to style.
> 0 votes

---
Tags: routes
---


# Question
Title: How to wrap field out put in custom markup?
**Situation** I have a custom module that is using hook\_field\_formatter\_info() to add an "fancy" option to the image field in the manage display of a content type. When this option is chosen I want to be able to surround the ENTIRE field in custom divs and markup. I want the solution to be a hook in my custom module and not a template override.

**Process** A user wants the display of an image field to be the "fancy" option. They check it in the drop down and click save from the content types Manage Display admin page. Now on that content type node there should be custom markup surrounding the entire field even if there are multiple images, the new markup should surround ALL the images and not each individual image.

**hook\_field\_formatter\_view** hook\_field\_formatter\_view seems to demand it's output be an array and I can't seem to be able to wrap the output in a div.

**Template overrides** I can't just make a field.tpl.php for the specific field because like I initially mentioned I need to be able to switch themes and the module still work like normal. Unless there is a way to get my module to override any field where said field has hook\_field\_formatter\_info() set specifically.

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

  foreach ($items as $delta => $item) {
    if ($index === NULL || $index === $delta) {
      $element[$delta] = array(
        '#theme' => 'bootstrap_modal_image_formatter',
        '#item' => $item,
        '#entity_type' => $entity_type,
        '#entity' => $entity,
        '#node' => $entity, // Left for legacy support.
        '#field' => $field,
        '#display_settings' => $display['settings'],
        '#delta' => $delta,
      );
    }
  }

  // $element = '<div id="CUSTOMDIVSTUFF">' . $element . '</div>';

  return $element;
}

```

And here is the #theme function:

```
function theme_bootstrap_modal_image_formatter($variables) {

  $item = $variables['item'];
  $entity_type = $variables['entity_type'];
  $entity = $variables['entity'];
  $field = $variables['field'];
  $settings = $variables['display_settings'];

  $image = array(
    'path' => $item['uri'],
    'alt' => isset($item['alt']) ? $item['alt'] : '',
    'title' => isset($item['title']) ? $item['title'] : '',
    'style_name' => $settings['bootstrap_modal_node_style'],
  );

  if (isset($item['width']) && isset($item['height'])) {
    $image['width'] = $item['width'];
    $image['height'] = $item['height'];
  }

  if (isset($item['attributes'])) {
    $image['attributes'] = $item['attributes'];
  }

  // Allow image attributes to be overridden.
  if (isset($variables['item']['override']['attributes'])) {
    foreach (array('width', 'height', 'alt', 'title') as $key) {
      if (isset($variables['item']['override']['attributes'][$key])) {
        $image[$key] = $variables['item']['override']['attributes'][$key];
        unset($variables['item']['override']['attributes'][$key]);
      }
    }
    if (isset($image['attributes'])) {
      $image['attributes'] = $variables['item']['override']['attributes'] + $image['attributes'];
    }
    else {
      $image['attributes'] = $variables['item']['override']['attributes'];
    }
  }

  $entity_title = entity_label($entity_type, $entity);

  if ($style_name = $settings['bootstrap_modal_image_style']) {
    $path = image_style_url($style_name, $image['path']);
  }
  else {
    $path = file_create_url($image['path']);
  }

  $caption = 'some value';
  $gallery_id = 'some value';

  return theme('bootstrap_modal_imagefield', array('image' => $image, 'path' => $path, 'title' => $caption, 'gid' => $gallery_id));
}

```

Been working on this for days, I'm drowning here.

# Answer
> 2 votes
Might be misunderstanding but it sounds like you just want a `#prefix` and `#suffix` on the base render element:

```
function bootstrap_modal_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array(
    '#prefix' => '<div class="wrapper">',
    '#suffix' => '</div>',
  );

  ...

```

# Answer
> 1 votes
I think form alter would be a better choice:

```
function MODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'FORM_ID':
      $form['fieldA'] = array(
            '#prefix' => '<div class="wrapper">',
            '#suffix' => '</div>',
      );
      break;
  }
}

```

---
Tags: 7, hooks
---


# Question
Title: How to get new migrations to show up in the Migrate UI
My question is a general one: how do you get new migrations, which you've created via a custom module using Migrate, to show up in the Migrate UI at /admin/content/migrate ? What lines of code are necessary in your custom module for this?

Specifically, I'd like to know what's missing from a particular custom module (called ea\_hub\_migrations.module) that I've created. I created this by cutting down the migrate\_example module, but after enabling ea\_hub\_migrations.module the migration group it defines isn't showing at /admin/content/migrate . By contrast, the migration I created with the module at https://drupal.org/node/1285276 does show up there. Here is the code for my custom module - I'd be very grateful if someone could take a look and tell me what's missing:

ea\_hub\_migrations.migrate.inc (included via ea\_hub\_migrations.info) - http://pastebin.com/KWMHd3gx

# Answer
First, the function `*_migrate_api()` in `*.migrate.inc` should include the `$api` with the key `api` of 2, and the key `migrations` of the array for your migration.

If you have newly added your migration, drastically changing the code etc, you perhaps need to make Drupal recognise the hook you have just created in your migration module; a guaranteed way for that is to disable once and (re)enable your migration module.

Then you need register your migration. If you use Drush,

```
drush migrate-register --group=YourMigrationGroupName

```

would do a job. After Flusing all caches (`drush cc all` etc), you will see the migration in your migration UI (hopefully!).

I am not an expert, but the above is based on my recent experiences.
> 3 votes

---
Tags: migrations
---


title: Drush not connecting: bootstrap error?

text:
# Question
Title: Drush not connecting: bootstrap error?
I've installed Drupal 7, Drush 7.0 and the Omega 4 theme. I'm using MAMP. I'm attempting to create an Omega subtheme with the command line:

drush omega-wizard

I then receive the following error.

>

When I run `drush --debug`, this is the result. Can anyone decipher this?

>

# Answer
> 1 votes
Is your settings.php file in a folder called 'default'? If not, you might need to tell Drush where to find it by using `--uri=mysite.com` or `-l mysite.com`.

See: Drush Bootstrap Error on Multi-Site Install

# Answer
> 0 votes
You need to make sure drush uses the exact same php as MAMP is configured for. Start with

```
which php

```

and make sure it is the one configured within MAMP. Edit the PATH variable in .bashrc or whichever other shell config file you have active on your Mac account. Your screenshot seems to imply you've got this covered, but double check nonetheless.

Next run

```
drush status

```

and check whether drush fully bootstraps Drupal, indicated by successful connection to the database. (BTW: You should not connect to the database as root, not even on your laptop.) Run this inside sites/default to really be sure you are picking up every bit of configuration detail while you figure out issues.

As a last resort follow up on the links your error message spewed out.

# Answer
> 0 votes
I had this same issue. The debug output showed that drush couldn't find a path to MySQL, so I created a symbolic link to mysql in /usr/bin to resolve the issue as such:

> sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql

---
Tags: drush
---


# Question
Title: How to sort nodes per domain with the Views module?
I have to display nodes in different order(weight) inside a view per domain on a multi-domain site.

**example:**

```
on domain1: view-beverages => 1-Coca Cola, 2-Perrier, 3-Redbull, 4-IceTea ...
on domain2: view-beverages => 1-Perrier, 2-IceTea, 3-Redbull, 4-Coca Cola ...
...

```

I thought to use the module Flag Weights, but Flag is per user and not per domain.

Do you think I can do this by using "Draggableviews"?

Can I create a table view for each domain with Draggableviews to manage the order of the node by domain, and make the final display view chose automaticaly the "sort criteria" (Draggableviews : Weight) of the courant domain. I hope I am clear enough.

How can I do this, or there is an alternative?

# Answer
> 0 votes
You are right: Best ot achieve ordering in views-lists is indeed draggableviews. But beware that this doesn't work with all styles. I am not sure, since it is half a year ago I have needed it for a project, but I think draggableviews is made for tables in mind. But as far as I remember there was an additional module making it possible also for other listing styles.

But the rather real problem is not how to order the views list items. The problem is that you need 2 almost same but a little bit different views (page-views? or block-views?), and how to let the 2 views show up on 2 different domains. I assume you would like to have the kind of same page on the same path but on two different domains in two different orders. The problem here is, if you try to achieve this with overriding paths by 2 different views and different domain conditions, the filtering or conditioning of the view depending the domain will make some trouble... It will always try to load both views and will always take the first arriving and if the condition doesn't fit, it will not change to the other. This is not a bug. It is because of how overriding paths works.

Let me know if you have any idea how to achieve this last part. Maybe I can help then on some further steps on it. But in the moment I see the end of the road here.

---
Tags: views, domain-access
---


# Question
Title: Domain Access: Edit admin/domain/content/ display settings, filters etc
I am using Drupal Commerce and Domain Access module and I wonder where I could be able to edit how page admin/domain/content is displayed. I would expect to find a View page which is utilised by this module to show content and to allow to add filters and fields.

I have got a multi-domain site with thousands of products and I need to filter content by manufacturer or other field and to assign all products with desirable keywoord to selected domains.

Am I missing anything? I have not found any corresponding View. Thank you for an answer

# Answer
> 0 votes
Domain Access does not provide a view like you want.
You could try the Admin Views module which overrides the standard content admin page with a view.
Also, Domain Views module which integrates domain access with views.

# Answer
> 0 votes
The Domain Access module for Drupal is for sorting and displaying content and themes/styles depending on the added system aware domains, which have to be covered, and only works with proper virtual host settings on server for incoming calls. It can achieve to give the visitor the feeling to be on two different places or at near but slidely different places. It is made for the cases where you definitely need a shared backend and content or design pool for two different domains but should not be considered for any case. It isn't as easy as it reads on the module project page. It needs further understanding how paths work in Drupal universe and can get broken on bigger updates. And you will have a hard time to teach a views view to be filtered different depending on incoming domain, even with Domain Views Module at hand.

I sadly can not confirm to use the other recommendation Admin Views modules because it is too limited in its approach and its not true that views doesn't support overriding admin pages. It works very well and is mostly one of my first steps in a new Drupal installation. It even works great with the different tabs on the admin pages (like admin/content with the **files** or *comments* tab) and there are enough tutorials around explaining the path settings to setup and how it works. I hope I make noone upset here, but I think it is not true to say, that you need Admin View module for overriding admin pages like admin/content etc. Maybe there was a time when it was hard to achieve this with views allone, but in the meantime views has a lot of options to make it work and even with more options than Admin Views module provides out of the box and stucks there on its limits.

---
Tags: views, domain-access, nodes
---