title: Missing sections, and undefined indices

text:
# Question
Title: Missing sections, and undefined indices
I'm migrating a drupal 7 site from one hosting provider to another. I've hit some snags along the way. The main one comes from page.tpl.php.

On the screen I see various messages such as:

```
Notice: Undefined index: highlighted in include() (line 126 of /public_html/cconn/modules/system/page.tpl.php).

Notice: Undefined index: sidebar_first in include() (line 138 of /public_html/cconn/modules/system/page.tpl.php).

Notice: Undefined index: sidebar_second in include() (line 144 of /public_html/cconn/modules/system/page.tpl.php).

```

In page.tpl.php the missing sections are defined as such:

```
<div id="content" class="column"><div class="section">
    <?php if ($page['highlighted']): ?><div id="highlighted"><?php print render($page['highlighted']); ?></div><?php endif; ?>
    <a id="main-content"></a>

```

Does anyone have any thoughts on what's going on and how to remedy it? The site itself *does* come up, but as mentioned with these large chunks missing.

# Answer
> 0 votes
It seems some of the variables are not defined properly. It is recommended to define variables properly to avoid some security vulnerabilities or bugs. Although PHP doesn't create any execution error.

To Solve this, you may choose any of below choices.

1.) Properly declare variables - Recommended

```
$value = isset($_POST['value']) ? $_POST['value'] : '';

```

2.) Set custom error handler function

```
set_error_handler('myHandlerForMinorErrors', E_NOTICE | E_STRICT)

http://php.net/manual/en/function.set-error-handler.php

```

3.) Disable E\_NOTICE from reporting - Fix

```
error_reporting( error_reporting() & ~E_NOTICE ).

```

---
Tags: installation
---


# Question
Title: Contextual filter on entity reference field in indexed view
I have two pages: jobs and offices.

My jobs page is an indexed view (with Search API) which displays jobs that have an entity reference field to the office it belongs to.

I want to put a link on my office page that links to the job page which only shows the jobs belonging to that particular office.

I've followed a few examples but none of them seem to work with my indexed view. Has somebody done something similar?

This is what I did: https://www.drupal.org/node/1841004 but it doesn't seem to work.

Thanks!

# Answer
If you want to show the jobs for that particular office on your job page, you might want to use a parameter. you need to pass the nid of that office to the url.

Create a link similar to this:

```
  $nid = arg(1);
<?php
    $l = l( t('More Jobs'), 'list-of-jobs',   array('query' => array('field_office' => $nid)  ));
    echo $l;
        ?>

```

your entity reference field is "office" right? use that field for your contextual filter. then use Views Contextual Filter Query module to get the parameter from the URL. In my example, it's field\_office.

Hope this helps!
> 0 votes

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


# Question
Title: Update theme table using callback function in Ajax
I have two elements in my form: a select and a table element. Everytime onchange event is triggered on select element, I want to update the values in my table. I want to do query and change the values of '#rows' in the table.

```
function myid_print_user_page_form($form, &$form_state)
{
    $form = array();
    $form['myid_print']['option'] = array(
        '#type' => 'select',
        '#options' => array(
            0 => t('All'),
            1 => t("Printed ID's"),
            2 => t("Unprinted ID's"),
        ),
        '#default_value' => 0,
        '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_table_wrapper',
        ),
    );

    // Build the sortable table header.
    $header = array(
        'id_number' => array('data' => t('ID Number'), 'field' => 'id_number','sort' => 'asc'),
        'student' => array('data' => t('Student'), 'field' => 'student', 'sort' => 'asc')
    );

    //Get the node data.

    $query = db_select('student', 't1',array('target' => 'import'));
    $result = $query
        ->fields('t1', array('studid','lastname', 'firstname', 'middlename', 'extname'))
        ->condition('t1.id_status',1,'=')
        ->distinct()
        ->execute();

    //Build the rows.
    $rows = array();
    foreach($result as $record){
        $rows[$record->studid] = array(
            'id_number' => $record->studid,
            'student' => $record->firstname . ' ' . $record->middlename . ' ' . $record->lastname . ' ' . $record->extname,
        );
    }

    //Build the table
    $form['table'] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#prefix' => '<div id="myid_table_wrapper">',
        '#suffix' => '</div>',
    );
    return $form;
}

```

I'm stuck here, I don't know what to put in my callback function.

```
function myid_print_all_submitted_id_callback($form, $form_state)
{
    //Do query here and put the query results in the table.
}

```

Any help would be very much appreciated.

# Answer
> 0 votes
You can access the values of the form elements using the $form\_state parameter. So when you have the value of the select element, you can perform the query as required, build the table using theme\_table and return the result. The returned result can be replaced or appended to the ajax wrapper defined in your form.

---
Tags: forms, theming, ajax
---


# Question
Title: Add commas between allowed file extensions
I need to restrict the user to upload only the file extensions that i mentioned in the Allowed file extensions filed. It works properly. But in front-end, i need to add a comma separator for this format.

Actual - Allowed file types: ai aif avi bmp csv doc docx eps fla flv gif img.

Expected - Allowed file types: ai, aif, avi, bmp, csv, doc, docx, eps, fla, flv, gif, img

# Answer
You are definitely allowed to separate file types by comma in the admin are

For user area, find the ID of the form (you can find this in the firebug) then

```
function YourTheme_form_alter(&$form, &$form_state, $form_id){
      if($form_id == "TheFormID"){
            kpr($form);
      }
}

```

In this way you can find the form elements. get the Key of image field in the form array, if it is `image` then write

```
function YourTheme_form_alter(&$form, &$form_state, $form_id){
      if($form_id == "TheFormID"){
            $form['image']['#description'] = t('File types are comma separated')
      }
}

```

This is the general idea but a few modification might be needed
> 1 votes

# Answer
I used theme\_file\_upload\_help hook.

```
 function bartik_file_upload_help($variables) {

 $description = $variables ['description'];

 $upload_validators = $variables ['upload_validators'];

 $descriptions = array();

  if (strlen($description)) {

     $descriptions [] = $description;
    }

  if (isset($upload_validators ['file_validate_size'])) {

     $descriptions [] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators ['file_validate_size'][0]) . '</strong>'));

 }

 $a = explode(" ", $upload_validators ['file_validate_extensions'][0] );
  if (isset($upload_validators ['file_validate_extensions'])) {

$descriptions [] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain(implode(", ", $a)) . '</strong>'));

 }

return implode('<br />', $descriptions);

}

```
> 1 votes

---
Tags: files
---


title: SHS module in drupal 7 views

text:
# Question
Title: SHS module in drupal 7 views
I am using Simple hierarchical select module and I am having terms lists like below;

1. India

a) Karnataka

* Bangalore

So, I want this filed as exposed filter in my views. Let me give example, assume if 3 nodes are selected "Bangalore".

So, whenever I select the "India" or "Karnataka" means it should shows the content which is selected as "Bangalore" in views.

How should I achieve this process?

Any configuration has to be done?

Can anyone please help me out in this case?

Thanks in advance

# Answer
> 1 votes
1) Add filter "Content: Has taxonomy terms (with depth; Simple hierarchical select)"

2) choose your vocabulary

3) in the selection type choose "Simple hierarchical select"

4) select Depth 2 and click on save.

5) Tick in the "Expose this filter to visitors,"

Here the trick is in the Depth selection

# Answer
> 0 votes
I presume you already set your Taxonomy and your node has add field (example: you name this field as "Place")for select either Bangalorem, India or Karnataka.

In the views, add FILTER CRITERIA. Select Content: Place. Selection type: You can choose dropbox. Save the view. Last, click on the same CRITERIA again (example: Content: Place (= )) and choose Bangalorem

---
Tags: theming, views
---


# Question
Title: how to create manual reports and graphical represntation as content type
Hello guys any Module which can provide tools so that we can manually input data and output them as graphical representation. I have tried Data visualization module but its complex to add JSON data.

# Answer
Try to use any of these modules :

1. Google Analytics Report

> Google Analytics Reports provides graphical reporting of your site's tracking data. Graphical reports include a dashboard widget for admins, a small path-based report in blocks, and a full path-based report.

2. Forena Reports

> Forena is database report writing software built on the Drupal platform. Forena is built of the idea that if you can write the SQL necessary to get the data out of a database, it should take very little work to get that data out on the web. It is designed to leverage knowledge of HTML, CSS, SQL and Java Script to help you create rich interactive web reports.

3. Charts & Graphs

> Charts and Graphs is an API for developers. It can easily be extended by third-party modules that want to add their own charting implementations. It does nothing by itself.
> 1 votes

---
Tags: database
---


title: old website to new website

text:
# Question
Title: old website to new website
Old website is running on live. The version of the old website is drupal 6. Last two months ago, I receive a task to create new website by using drupal 7 to replace old one. That time i have 0 knowledge of drupal. Now ready to replace old one and face problem. Old website is drupal 6. New one is drupal 7. Sure have problems.That why i decide to duplicate old website and database to sub domain. Purpose is to upgrade old website from drupal 6 to 7. Old website in sub domain display succesfully, but the link all point to site listing of the sub domain

FYI, I had managed to replace new website D7 to old website D6 successfully. However, the solution is not base on migrate D6 To D7. This question will be remain unanswered...

# Answer
> 1 votes
First thing you should do is contact your web hosting provider and see if you can go back to working copy of your website. After you have a working copy of your website download that into a local environment. I would recommend to this either a Mac or Linux machine (ubuntu os what I user).

Once you have your local environment you can start trying migrating from D6 to D7. You should never try an migration a production site.

From here you can use `drush sup` to upgrade your website. After your website is been successful upgrade from D6 to D7. You should consider uploading that to your web hosting provider.

# Answer
> 1 votes
I'll use this answer to try to help/guide @peifa. I'll do so by enhancing my answer in multiple steps (iterations), depending on which parts need more details etc as per peifa's knowledge. To Peifa: please add comments to this answers to confirm, ask extra questions, etc where appropriate, OK? And try to EDIT your question instead of adding comments to it (that is not really helpful, since too time consuming to digest I feel). Like the comment about "local host", put that in the question, and then delete that comment again. To anybody else: feel free to edit my answer to refine, correct, etc.

Assumptions: current live (production) site is D6, ultimate deliverable is to REPLACE it entirely with a D7 equivalent, in production status also.

Approach: clone the D6 version from production environment to some TEST environment, which is what in the original post (OP) seems to be called "subdomain". I'm assuming you're using apache as the webserver (if not: what else)? And since I do not see "localhost" or "virtualbox" or anything similar, I assume anything related to the upgrade is happening somewhere online. If not please enhance the OP to claify.

**Step 1**: update your a apache configuration, to add the config about the root folder for the D7 site and the subdomain name (as it will be used in the URL to surf to it)..

**Step 2**: make sure you're aware of the upgrade instructions.

**Step 3**: Upgrade Drupal core (and the database) from D6 version to D7 version. Need I provide more details on that?

**Step 4**: Upgrade relevant contrib modules from D6 to D7. Need I provide more details on that?

---
Tags: 7, migrations, upgrading
---


# Question
Title: How to change Drupal module load sorting(weight) order
I need to understand how can we change module weight.

* Do we really change that value for custom module.
* What are the default values?
* If we change weight value what will be effect on Drupal bootstrap process?

# Answer
> 1 votes
You can do this by using Modules Weight module.

> This module provide admin interface for users/people has the access to modules page to reorder the module weights as they want.

---
Tags: 7
---


title: Can't find View's Filters variables

text:
# Question
Title: Can't find View's Filters variables
I'm trying to create a button that create a new content type based on the one selected in the view filter. I have had some problems finding the correct variables to use them in that case. I'm actually new in the drupal community (so don't be mean if my question is irrelevant for you).

Edit: The code is the one provided as an example for the view with seven as a theme. The part i want to edit is this one :

```
  **<?php if ($exposed): ?>
    <div class="view-filters">
      <?php print $exposed; ?>
      <?php
      /**
       * Création d'un bouton de rajout de proposition (yes, this is french ^^)
       */?>
     <?php
         $chemin = "../node/add"; // i want this URL to be dynamic and to change each time
         //someone clic on a new option in the exposed filter. E.G. if he clics on volvo,     the
         //button should show "add a new volvo car" with the proper link
    print"<a href=\"".$chemin."\">
    <input type=\"submit\" class=\"button\" name=\"Ajout Type de Contenu\" value=\"Ajouter     une XXX\" />
    </a>" ;
      ?>
    </div>
  <?php endif; ?>**

```

Thanks !

# Answer
If I understand correctly your current problem is getting the current values of the exposed filters.

Wherever you are putting your code, as long as you have access to the view object you can get these values using view::get\_exposed\_input() like this:

```
$filters = $view->get_exposed_input();
// You can then access the value of a specific filter like this.
$value = $filters['FILTER_NAME'];

```

You can then use those values to implement whatever logic you require.
> 0 votes

---
Tags: views, configuration
---


title: facets do not display on my search page

text:
# Question
Title: facets do not display on my search page
I've setup apache solr and the facet api for my drupal 6 site, however I can't seem to get my facets to show up on my search page. The only time they show up is when I enable 'show enabled facet blocks under the search box' when there are empty results.

I tried to add my facet block to a region, but it remains blank.

I would think the facets should display on the search page automatically?

# Answer
> 0 votes
You should put your facet blocks into a regions and also you should be sure that they are rendered after the search is executed.

---
Tags: 6, search
---


# Question
Title: How to adapt #prefix/#suffix for each option in radio form using hook_form_alter()?
I need to modify the html code of radio buttons generated by Ubercart Attributes. So I want to do it using hook\_form\_alter().

If I dsm() the $form I need to change using hook\_form\_alter() I get this

```
attributes (Array, 7 elements)
#theme (String, 24 characters ) uc_attribute_add_to_cart
#id (String, 42 characters ) uc_product_add_to_cart_form-472-attributes
    #type (String, 6 characters ) radios
    #default_value (NULL)
    #options (Array, 4 elements)
        0 (String, 7 characters ) Color 1
        1 (String, 7 characters ) Color 2
        2 (String, 7 characters ) Color 3
        3 (String, 8 characters ) Color 17
    #ajax (Array, 2 elements)
    #title (String, 4 characters ) yeah
    #description (String, 0 characters )
    #required (String, 1 characters ) 1

```

I can apply a #prefix/#suffix to div wrapping all radio buttons:

```
<div class="test">
  <div class="form-item form-type-radios form-item-attributes-8">
     <div class="form-label">
        <div class="element-inner">
           <div class="el">
               <div id="edit-attributes-8" class="form-radios my-custom-class">
               <div class="form-item form-type-radio form-item-attributes-8">
               <div class="form-item form-type-radio form-item-attributes-8">
               <div class="form-item form-type-radio form-item-attributes-8">
              <div class="form-item form-type-radio form-item-attributes-8">
           </div>
        </div>
        <div class="description"></div>
      </div>
    </div>
 </div>

```

I proceed like that for this result:

```
$form['attributes']['8']['#prefix'] = '<div class="test">';
$form['attributes']['8']['#suffix']= '</div>';

```

The problem is that I want to apply this #prefix/#suffix to all options instead, I tried something like that but it doesn't work:

```
$form['attributes']['8']['#options'][0]['#prefix'] = '<div class="test">';
$form['attributes']['8']['#options'][0]['#suffix']= '</div>';

```

So is it possible to do it this way? Any suggestion?

# Answer
In your form\_alter you can tell drupal to use your custom theme\_radio like this:

```
$form['attributes']['#theme'] = 'MYCUSTOM_radio_theme';

```

Then in 'MYCUSTOM\_radio\_theme:

```
$element = $variables['element'];

$element['#attributes']['type'] = 'radio';

element_set_attributes($element, array('id', 'name','#return_value' => 'value'));

if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_value']) {
    $element['#attributes']['checked'] = 'checked';

}
  _form_set_class($element, array('form-radio'));

  return '<div class="test"><input' . drupal_attributes($element['#attributes']) . ' /></div>';

```
> 3 votes

# Answer
There is an easy answer to this, but I was very nearly driven insane trying to find it because it doesn't appear to be documented anywhere.

```
$form['input']['option_key'] = array(
  '#prefix' => '',
  '#suffix' => '',
);

```

This is counter-intuitive because it creates an entirely new array for #prefix and #suffix, but I swear it works. In OP's case you would use $form\['attributes'\]\[0\] to get the first option ('attributes' appears to be the name of the radio button collection, not the form's #attributes array). If it were using strings as array keys you'd use $form\['attributes'\]\['option\_name'\].

I imagine you can do some other interesting things too.
> 2 votes

# Answer
Maybe you could override the theme\_radio function instead of using form\_alter.
> 1 votes

# Answer
Since I can't comment, what @taburk has said is by far the best option. A note of point though, this method can ONLY be done with a hook\_form\_alter (or hook\_form\_FORM\_ID\_alter) as the form array must already exist.

Also, in your form alter remember that as the array already exists you need to append the prefix/suffix keys to it, not overwrite the existing array.

```
<?php
if($form_id == 'my_form_id'){
        foreach($form['my_radio_field']['#options'] as $macname => $thememarkup) {
            $form['my_radio_field'][$macname]['#prefix'] = '<div class="col-md-6">';
            $form['my_radio_field'][$macname]['#suffix'] = '</div>';
        }
    }
?>

```
> 1 votes

---
Tags: forms
---


# Question
Title: Passing path arguments to a form builder
I'm trying to understand how to port the following D7 code to Drupal 8.

```
function x_menu() {
    $menu['x/form/test/%/%'] = [
        'page callback' => 'drupal_get_form',
        'page arguments' => ['x_form_test', 3, 4],
        'type' => MENU_CALLBACK,
        'title' => 'Test Form',
    ];
    return $menu;
}

function x_form_test(&$form, $form_state, $arg1, $arg2) {
    return $form;
}

```

From what I can glean from the documentation of the Routing and Form API, the new way to connect a path to a form is to put this in `x.routing.yml`:

```
x.form_test:
    path: 'x/form/{arg1}/{arg2}',
    defaults:
        _form: '\Drupal\x\XFormTest'
        _title: 'Test Form'

```

and then create a form class `XFormTest` that ultimately descends from `FormBase`.

However, it's clearly impossible\* to add extra arguments to an inherited function signature like `public FormInterface::buildForm(array $form, FormStateInterface $form_state)`

How can I read `$arg1` and `$arg2` in `XFormTest::buildForm()`, preferably while still pointing the route at the form rather than putting a Controller around it?

(Routing API: https://www.drupal.org/node/2092643)

\*Update: Maybe it's not so much impossible as that I'm not doing it correctly.

My function declaration

```
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class XBBCodeHandlerForm extends FormBase {
  public function buildForm(array $form, FormStateInterface &$form_state, $format = XBBCODE_GLOBAL) {
  }
}

```

generates the following fatal error:

```
PHP Fatal error:  Declaration of Drupal\xbbcode\Form\XBBCodeHandlerForm::buildForm()
must be compatible with
Drupal\Core\Form\FormInterface::buildForm(array $form,
Drupal\Core\Form\FormStateInterface $form_state)
 in /home/arancaytar/software/web/drupal/modules/xbbcode/src/Form/XBBCodeHandlerForm.php
on line 161

```

Edit: I misunderstood the fatal error; it wasn't caused by the extra argument but by changing the value argument $form\_state to a reference argument. PHP does allow adding optional arguments to overriding functions, apparently.

# Answer
> it's clearly impossible to add extra arguments to an inherited function signature

Not true - adding extra arguments to a function signature is one of the fundamental reasons that inheritance exists in OO.

You literally just need to add your arguments to the function signature to make this work:

```
public function buildForm(array $form, FormStateInterface $form_state, $arg1, $arg2) {
    // You have $arg1 and $arg2 available
}

```

You could do something more fancy and get typed data by using parameter upcasting, otherwise you'll get the args as strings.

Examples here.
> 1 votes

---
Tags: forms, 8, routes
---


title: Disable 1 step for one time login

text:
# Question
Title: Disable 1 step for one time login
Is it possible to disable the page of one time login which can be accessed from the reset user password URL sent to the mail:

> www.example.com/user/reset/1234/1429007410/5H-zpRSsUsNNdiiFMZeaIZVthjO4uJjjrsVJ8Jg75Ys

and send the user directly to logged in edit profile page:

> example.com/user/1234/edit?pass-reset-token=fNWPgVXjnHocvcT3mWxp38vOCuLpz1e5lErOCCDGTe0

so we can make it 1 step instead of 2 steps and consider the user clicked the login button from the page 1 which can be dispensable !?

# Answer
> 0 votes
I found simple solution with this module Simple Password Reset

---
Tags: users
---


# Question
Title: Get id of selected option in Drupal Forms API
I have a select element in my form.

```
function myid_print_user_page_form($form, &$form_state)
{
    $form = array();
    $form['options'] = array(
        '#type' => 'select',
        '#options' => array(
            0 => t('All'),
            1 => t("Printed ID's"),
            2 => t("Unprinted ID's"),
        ),
        '#default_value' => 0,
        '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_print_search_idnumber_wrapper',
        ),
    );

    $form['myid_print_search_idnumber_wrapper'] = array(
       '#type' => 'item',
       '#markup' => '<div id= "myid_print_search_idnumber_wrapper"></div>'
    );
    return $form;
}

```

I'm stuck in the callback function. It always return 1, even though I selected other options.

```
function myid_print_all_submitted_id_callback($form, $form_state)
{
    return $form_state['values']['options'];
}

```

Where am I missing?

# Answer
> 1 votes
You can use this code

```
function myid_print_user_page_form($form, &$form_state)
{
    $form = array();
    $form['options'] = array(
        '#type' => 'select',
        '#options' => array(
            0 => t('All'),
            1 => t("Printed ID's"),
            2 => t("Unprinted ID's"),
        ),
        '#default_value' => 0,
        '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_print_search_idnumber_wrapper',
        ),
    );

    $form['myid_print_search_idnumber_wrapper'] = array(
       '#type' => 'item',
    // When the form is rebuilt during ajax processing, the $selected variable
    // will now have the new value and so the options will change.
       '#markup' => isset($form_state['values']['options']) ? $form_state['values']['options'] : '',
       '#prefix' => '<div id="myid_print_search_idnumber_wrapper">',
       '#suffix' => '</div>',
    );
    return $form;
}
function myid_print_all_submitted_id_callback($form, $form_state){
// rebuild the form
    return $form['myid_print_search_idnumber_wrapper'];
}

```

---
Tags: forms, ajax
---


# Question
Title: When I click a radio button its value should display in textfield
Above is the sample screenshot of my form where I would like to do is:

When I click/check on radio button "One" then its value should display in textfield of "Display".

Code:

```
function test_radio_menu() {
  $items['test_radio'] = array(
    'title' => 'test_radio',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('test_radio_form'),
    'access arguments' => array('access content'),
    'access callback' => TRUE,
    );
  return $items;
}

/**
* Implements hook_form().
*/

function test_radio_form($form, &$form_submit){

/* the options to display in our form radio buttons */
$options = array(
  'one' => t('One'),
   'two' => t('Two'),
);

$form['count'] = array(
  '#title' => t('Count'),
  '#type' => 'radios',
  '#options' => $options,

);

$form['display'] = array(
'#title' => t('Display'),
'#type' => 'textfield',
'#value' => ,
  );

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

return $form;
}

```

# Answer
> 1 votes
You should use drupal ajax form try this code

```
function test_radio_form($form, &$form_submit){

/* the options to display in our form radio buttons */
$options = array(
  'one' => t('One'),
   'two' => t('Two'),
);

$form['count'] = array(
  '#title' => t('Count'),
  '#type' => 'radios',
  '#options' => $options,
  '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_print_search_idnumber_wrapper',
  ),

);

$form['display'] = array(
'#title' => t('Display'),
'#type' => 'textfield',
'#value' => isset($form_state['values']['count']) ? $form_state['values']['count'] : '',
'#prefix' => '<div id="myid_print_search_idnumber_wrapper">',
'#suffix' => '</div>',
  );

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

return $form;
}
function myid_print_all_submitted_id_callback($form, $form_state)
{
      return $form['display'];
}

```

# Answer
> 0 votes
it should work like this

html :

```
  <input type="radio" name="mode" id="radio"   class="test1" value="text" onclick="BT('#message')" />

```

js

```
function BT (id) {

    $('.Bt')..attr('id', 'your-id-value');

}

```

---
Tags: forms, javascript
---


title: Display Comment Form in Sidebar

text:
# Question
Title: Display Comment Form in Sidebar
I'm relatively new to Drupal and I'm working on a page that needs comment functionality for non-authenticated users. I tried some various forms (Webform, EntityForm) but they just seemed like way too much. The comments module has exactly what I need as far as submission and moderation goes.

I tried adding the form to the sidebar of a page but it showed up with a massive rich text editor and kind of broke the layout.

Is it possible to insert a very basic comment form with a simple long-text field and a submit button? If so...how?

Screenshot:

# Answer
> 1 votes
You may use Panels module.

Using that you can place comment form any where as your specification.

For more info go through project documentation .

# Answer
> 0 votes
Maybe provide a Screenshot of that broken Layout, and how did you get the form to show up on in the sidebar? (there are various ways)

Comments are tight to nodes, you can modifiy the fields of a comment if you edit the specific content type that is commented on, e.g. remove title, and only have a long text field.

Furthermore for the editor itself: Drupal comes with a few basic text formats: plaintext, filtered html and full html. You can modify the display and features of each, e.g. create a comment text filter and limit it to plaintext or reuse the already existing plaintext filter, afterwards you should limit anonymous users to only be allowed to use this specific filter (that removes the whole stuff about switching text formats as well).

For more answers you should ask more specific questions.

# Answer
> 0 votes
Use this code to load the form

```
$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);

```

and then display the `$form` in the sidebar

# Answer
> 0 votes
I had a similar problem in that I was programmatically creating an 'answer' node per question. Also needed to have ability to comment on that answer. Drupalist's answer to programmatically creating a comment helped a lot:

```
$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);

```

More details on programmatically creating comments at https://www.drupal.org/node/1030676#comment-6305154

I also had to make sure that each instantiated answer (node) had:

'comment' =\> 2,

which allows the programmatically created node to be open for comments (2 = read/write, 1 = read only, 0 = closed)

# Answer
> 0 votes
You can use hook\_form\_alter() to modify the form fields.

---
Tags: comments
---


# Question
Title: Is there a built-in way to get a language+country locale pair?
`global $language` only holds the language code. I wonder if there's any possibility to get a country code as well, at least of that country I set as default country at `/admin/config/regional/settings`.

Some external services need that locale (`en_US`, `cs_CZ`, `de_AT`) to be loaded in a matching language. Especially in multisites a language+country locale pair would be very handy for loading such services from within one module.

Possible workaround would be to set a new global variable holding a proper locale right?

# Answer
> 2 votes
you can get default country value using

```
<?php
print variable_get('site_default_country', '');
?>

```

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


title: Customise Webform Email Submission Data

text:
# Question
Title: Customise Webform Email Submission Data
In the webform-mail.tpl.php template, it outputs the main form data using:

```
[submission:values]

```

I am using the html format (using mime-mail) and this outputs to the email html in the form:

```
<div><label>Name</label>Name value</div>

```

Is there a way I can customise the output so that it doesn't use the label field and uses a `<p>` tag instead?

The problem with the `<label>` tag is that I cannot style it in Microsoft Outlook as it ignores all styling for this tag, and the email is quite difficult to read/understand.

# Answer
> 0 votes
I managed to find the answer from an identical question at How to use \[submission:values\] in Email template in Webforms.

Using the webform-submissions.tpl.php template I changed the output structure from:

```
<div><label>Name</label>Name value</div>

```

to:

```
<div><p class="label">Name</p><p class="value">Name Value</p></div>

```

Using the code below:

```
<?php
if ($format == 'html') {
    $output = drupal_render_children($renderable);
    $output = preg_replace('/<label.*?>/', '<p class="label">', $output);
    $output = str_replace(' </label>', ':</p><p class="value">', $output);
    $output = str_replace('</div>', '</p></div>', $output);
    print $output;
}
?>

```

Now the styling in my Outlook emails look much better :)

---
Tags: webforms, emails, theming
---


# Question
Title: Combining fields and avoiding duplicate display
I use below code for printing out images in search results. I get double print outs on the ALT tags. If I disable ALT tags all displays just fine.

```
<a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>
  <a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_product_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>

```

If I add fields like below, I get only the print out of one of the fields and not both.

```
<a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_product_image['und'][0]['uri'],
        'path' => $result['node']->field_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>

```

What am I missing? Thanks much for your input.

# Answer
I don't think this will necessarily fix your problem, but you're calling the theme\_image\_style incorrectly, it should be:

```
theme('image_style', array(
  'style_name' => 'thumbnail',
  'path' => $result['node']->field_image['und'][0]['uri'],
  'alt' => $title,
  'title' => $title,
  'attributes' => array('class' => 'search-result-img'),
));

```

Your second example is wrong, you can't call `path` twice.
> 1 votes

---
Tags: entities
---


title: Is there a Ping Module?

text:
# Question
Title: Is there a Ping Module?
I'm creating a support site for a hosting company in D7 and one of the features that they have asked for is for drupal to ping each of the servers, (I have a content type called Server which has ipaddresses attached to it) and report back the status. I want to set it up as cron job. Is there a module for Drupal that I can add that gives me this feature? if not can you give me any pointers how to get started on building one?

Thanks

Kieran Briggs

# Answer
> 2 votes
The multiping module will provide this feature in Drupal 7, since the ping module is not part of core anymore. The D7 branch hasn't been started, but there is a patch that you can test that ports the module to Drupal 7. If you test it and it works for you, please comment on that issue, the more people that review that patch the closer the module will get to a full D7 release.

# Answer
> 0 votes
The Ping module seems like a good and supported solution for Drupal 7.

---
Tags: 7
---


title: Add permissions for a new content type

text:
# Question
Title: Add permissions for a new content type
Context: I created a new content type (press room nodetype) locally and made a feature with it so it is easier to deploy on my dev-stage-prod environments. This works perfectly well. The thing is, is I need to add permissions to some user roles right away in the same deployment process. I can't find the proper way to run some code after the feature-revert-all;

At the moment I put my code in a new module press\_room.install.

```
function press_room_update_7001() {
    module_enable(['press_room_nodetype']); // installs the feature that will add the new content type

    $permission = [
        'edit any press_room content' => true,
    ];
    _add_permission_to_role('myrole',$permission); // too soon, content type not yet created
}

```

This module is enabled by another .install (homepage).

```
function homepage_update_7003() {
    module_enable(['press_room']);
}

```

With this code the new content type is created and the module to preprocess its output is enabled but the permissions are not given. It seems the content type is not (fully) created when the permissions needs to be added, so Drupal skips those lines and do nothing. If I run my code a second time, it works since the content type already exists.

Has anyone a solution to process code after a new content type has been created. What is the proper way to do this? Thank you.

# Answer
> 1 votes
This may not be what you're looking for but here is what we do to deploy on several production sites.

1. Store as much in Features as possible
2. Write update scripts when needed (as you've done). However, we enable modules via drush, never in code.
3. then run: `drush en feature_module_name -y && drush updb`
    * If multiple modules need to be enabled, we normal setup a chain of dependencies in the \*.info files.

---
Tags: 7, nodes, features, deployment
---


# Question
Title: What's wrong with my GET request? (Commerce Services, REST)
I'm developing a mobile app to connect with my Drupal Commerce (Kickstart) store, using a REST server.

When I do GET: `endpoint/rest/product` it retrieves the products list

```
<result is_array="true">
    <item>
        <revision_id>1</revision_id>
        <sku>TOT1-GRN-OS</sku>
        <title>Tote Bag 1</title>
        <revision_uid>1</revision_uid>
        <status>1</status>
        <log />
        <revision_timestamp>1423972403</revision_timestamp>
        <data />
        <product_id>1</product_id>
        <type>bags_cases</type>
        <language>und</language>
        <uid>1</uid>
        <created>1423972403</created>
        <changed>1423972403</changed>
        <title_field>Tote Bag 1</title_field>
        <commerce_price>
            <amount>1600</amount>
            <currency_code>EUR</currency_code>
            <data>                <components />
                </data>
        </commerce_price>
        ...
    </item>
    <item>
     ...
    </item>

```

Everything looks fine. I can even GET `endpoint/rest/product?status=1` and it does filter well.

I'm trying to filter by commerce\_price.amount:

GET `endpoint/rest/product?commerce_price.amount=1600`

but it's not working. I have no problems filtering by a first level key, but can't access second level ones and so on. What am I doing wrong?

# Answer
> 1 votes
From what I understand, querying only works on entity properties. That is why `status` works, commerce\_price is a field and won't work. Checkout Services Entity API, it may do what you're looking for.

You may still be out of luck though. You alternatives will be to use `services_views` or write your own Services Resource.

---
Tags: commerce, services, 8
---


# Question
Title: How do I grab multiple commits from a different release branch?
I am currently a maintain a module on Drupal.org. I had high hopes of working on a 8.x release, however I ran out of time and made extra commits in the 7.x-2.x branch. Now my git repository looks like something below:

```
  7.x-2.x     x - x - x - x - x - x - x
                       \
  8.x-1.x               x

```

How do bring 8.x-1.x up to speed with the 7.x-2.x. What commands do I need to run. I thought I would ask the question here as Drupal.org is a little bit unique in how it organizes its repositories.

# Answer
A normal merge should work fine. It shouldn't remove the merged branch. If it does, you can always recreate the branch.

If you want to take just some of the commits, use "git cherry-pick".
> 2 votes

---
Tags: version-control
---


# Question
Title: Drupal 7 Views Table Blocks Common Fields Sorting not working in single page
My site having dashboard page where I am displaying multiple Views blocks (2-3) with Table format. Each block have few common fields to display with different filters. These blocks have exposed form as well. The issue I am facing with SORTING on common fields. The fields which are not common, sorting on those are working as expected. Filter and Paging are also working fine on each block as I have set different page id for those.

Do you have any idea how to make those sorting possible ? Note: Ajax is ON in each block and machine id is also set different.

# Answer
> 0 votes
You need to change the Filter identifier under the More fieldset at the bottom of the exposed filters in the View

---
Tags: views
---


# Question
Title: I need help with an existing variable of drupal
How I can use in my code the value where exists on configuration-\>Logging and errors-\>Database log messages to keep?? Could anyone help me to find out how I can use this number that the user will select? What is the name of these variable??

# Answer
> 2 votes
The "Database log messages to keep" tells the site how many entries to store in "Recent Log Messages" (/admin/reports/dblog). It stores a record of watchdog events and php warning/errors, etc.

The limit is stored in the variable table, under the variable name of dblog\_row\_limit.

---
Tags: 7
---


title: format_date() not working

text:
# Question
Title: format_date() not working
I've got a field in a content type called "field\_program\_date" of type "Date". I'm using Drupal's `format_date()` function to format the date in the content template like this:

```
$program_date = format_date($node->field_program_date[$node->language][0]['value'], 'custom', 'F j, Y');
print $program_date;

```

Something is wrong because nothing gets printed out at all.

# Answer
Since the date is not coming out as a timestamp, you can to use strtotime. Something like:

```
$date = strtotime($node->field_program_date[$node->language][0]['value']);
$program_date = format_date($date, 'custom', 'F j, Y');
print $program_date;

```
> 2 votes

# Answer
Have you tried printing out the value of $node-\>field\_program\_date\[$node-\>language\]\[0\]\['value'\]? format\_date takes a unix timestamp as it's first param. So if the variable isn't in a format like "1429026611," then you'll need to convert it to a timestamp first.
> 1 votes

---
Tags: datetime
---


# Question
Title: Include full term name including "in" "and" etc when used for URL alias
Im using taxonomy terms to create my URL aliases. At the moment the word "in" is stripped out.

So if the term was "Fun in London"

The URL created would be "fun-london".

How can I include the full path? So I would have "fun-in-london".

# Answer
You can choose "strings to remove" on the settings page:

/admin/config/search/path/settings
> 0 votes

---
Tags: path-aliases
---


# Question
Title: Allowing HTML in block title - where is $block->subject created?
I want to get a `<br>` tag into a block-title but by default the brackets are turned into html characters. My theme's block.tpl is

```
<h2<?php print $title_attributes; ?>><?php print $block->subject; ?></h2>

```

so it looks like the rendering isn't happening there. I can't find where `$block->subject` is getting processed. It's not in my theme's template.php. So where in core is `$block->subject` assembled?

# Answer
> 3 votes
You may be interested in Block Class Styles, which has an additional feature:

> Allows the ability to set a global text format for custom block titles; this allows you to now have HTML in your custom block titles. Yes, you can now have block titles that contain HTML markup!

# Answer
> 0 votes
Found the line in `block.module`:

`$block->subject = $block->title == '<none>' ? '' : check_plain($block->title);`

Decided to skip any fanciness and just replace `$block->subject` with `$block->title` in my `block.tpl.php`. Easy.

# Answer
> 0 votes
i went this route without having to hack core or install another module. this solution is good if you just need to insert a limited amount of html. in my case i just wanted to surround the text with an em\> tag for styling purposes.

i made a new tpl file to override block.tpl.php in my templates folder and I added in the following:

```
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

  <?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2<?php print $title_attributes; ?>>

  <?php

  $xtitle = preg_replace('/\*\*/', '<em>', $block->subject, 1);
  $xtitle = preg_replace('/\*\*/', '</em>', $xtitle, 1);

  print $xtitle;

  ?>

  </h2>
<?php endif;?>
  <?php print render($title_suffix); ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php print $content ?>
  </div>
</div>

```

All I'm doing is just doing a string replacement for * * . Now i can just surround my titles with \** if i want to add the em\> tag.

# Answer
> 0 votes
You can add an if or switch statement at the top of block.tpl.php to match the unique block delta and then you can change the value of `$block->subject`:

`if($block->delta == 'BLOCK_DELTA'){
 $block->subject = t('A title with some HTML');
}`

Install devel and the use `kpr($block->delta);` to find out what the delta is.

Don't forget to pass the title through the t function.

---
Tags: 7, blocks
---


# Question
Title: Printing raw field value to use in path to files
I have field called "field\_cat\_id" which has a numerical value (10201; 10202 etc). The field represents a category id and it is also used to arrange PDF files,

I would like to print this (raw) value and use it in the path as shown below in the snippet of my node.tpl.php:

```
    <?php
     $catid = print $content['field_cat_id'][0]['#markup'];
       $path = "/home/site/library/files/" . $catid . "/";// to switch to this once all is working
    $files = scandir($path); ?>

    <ul id="booklist">
      <?php foreach ($files as &$value) {
        echo "<li> <a href='http://localhost/library/files/".$catid."/".$value."' >".$value."</a></li>";
    }?>
    </ul>

```

The output for $path comes out like this:

```
/home/site/library/files/1/

```

Where am i going wrong? When I run

```
   <?php print $content['field_cat_id'][0]['#markup']; ?>

```

The output is for example "10201"

# Answer
```
$catid = print $content['field_cat_id'][0]['#markup'];

```

Try removing the print.
> 1 votes

---
Tags: nodes, theming, entities
---


# Question
Title: Migrating user profile picture from D6 to D7
I'm migrating a site from D6 to D7 and I want to do the User migration in code. The basic profile works fine except for the user picture. I read that it's best to write a separate class for this file so I did. Unfortunately I'm getting nowhere with it. Can you see anything wrong with this code? I plan to use this class as a dependency in the user profile migration class where I should be able to attach the image based on file id generated in this class.

```
class MigrateDAFiles extends Migration {
    public function __construct(array $arguments) {
        $this->arguments = $arguments;
        parent::__construct($this->arguments);
        $this->description = t('Profile images');
        $this->map = new MigrateSQLMap($this->machineName,
            array(
                'picture' => array(
                    'type' => 'varchar',
                    'length' => 255,
                    'not null' => TRUE,
                ),
            ),
            MigrateDestinationFile::getKeySchema()
        );
        $this->destination = new MigrateDestinationFile();
        $query = db_select('users', 'u')
            ->fields('u', array('picture'))
            ->isNotNull('picture');
        $query->distinct();
        $this->source = new MigrateSourceSQL($query);

        $this->addFieldMapping('value', 'picture');
        $this->addFieldMapping('source_dir')->defaultValue('http://www.example.com/sites/default/files/artist-pictures/');
        $this->addFieldMapping('file_replace')->defaultValue(FILE_EXISTS_REPLACE);
        $this->addFieldMapping('status')->defaultValue(1);

        $this->removeFieldMapping('path');
}

```

# Answer
I believe you need to do picture migration separately per the docs (assuming you are using Migrate D2D, which you probably should). This is all I had for picture migration from one I did last year:

```
$picture_arguments = $common_arguments + array(
  'machine_name' => 'pictures',
  'description' => t('Migration of user pictures from Drupal 6'),
  'default_uid' => 1,
  'source_dir' => '/some/path/to/sites/default/files/',
  'destination_dir' => 'public://pictures',
);

Migration::registerMigration('DrupalPicture6Migration', $picture_arguments['machine_name'], $picture_arguments);

```
> 0 votes

---
Tags: users, migrations
---


title: connect drupalgap app to drupal site

text:
# Question
Title: connect drupalgap app to drupal site
i have a problem and the documentation of drupalgap is not too specific. I have a site for example "www.mysite.com" and i have in a localhost a site built in drupalgap that i want to connect with "www.mysite.com" and the drupalgap app shows the content of the database stored in mysite. It's possible to achieve that? I installed the services module and configured it but i don't know how to proceed. Any help will be appreciated. Thank you.

# Answer
1. Install the DrupalGap SDK on localhost, e.g. /var/www/drupalgap
2. Open its app/settings.js file, and point its site\_path to www.mysite.com
3. Launch Google Chrome w/ security disabled and open http://localhost/drupalgap/index.html (if you're in web app mode, or use Ripple if you're in phonegap mode).

More information available here: http://drupalgap.org/node/223
> 1 votes

---
Tags: database, javascript
---


# Question
Title: Views page list of all content grouped by taxonomy term
I have created a view in Drupal 7 that displays all nodes that contain a particular taxonomy vocabulary. The view contains a page in an unformatted list format set to show content | teaser. All I am trying to do is to group the list by the specific taxonomy term. Here is an example of what I'm talking about:

**TERM A**
Title
Teaser

Title
Teaser

**TERM B**
Title
Teaser

I've scoured the web and have only found solutions for displaying EITHER taxonomy terms OR content, but not both. Am I missing something? Is this not possible with Views?

Thank you so much to whomever can help, I've been agonizing over this for days.

-Dave

# Answer
1. Create a view: Show `Content`
2. Add a **Relationship**:
    * *Content: Taxonomy terms on node* (don't check vocabularies) \[Identifier: `term`\]
3. Add a **Contextual filter**:
    * *Taxonomy vocabulary: Vocabulary ID*:
        + Provide value from URL -\> Path component: `2`
4. Add **Fields**, e.g.:
    * *Taxonomy term: Name* which uses the *Relationship* `term`
        + Check: *Exclude form display* and *Link this field to its taxonomy term page* if you like
    * *Content: Rendered Content*:
        + Display -\> Show complete entity
        + View mode -\> Teaser
5. Define **Format**:
    * e.g. Unformatted list, go to Settings and set for *Grouping field Nr. 1* -\> *(term) Taxonomy term: Name*

If you don't like/want to use *fields* as view display rows you can choose Content or Rendered Entity and check 'Force using fields' on Format options do group nodes by taxonomy term.

Now, you can create a page where the path is `vocabulary/%` (or something like that), so the contextual argument we have set in step 3 (path component = `2`) will be now passed to the view as a Vocabulary ID (`vid`). You can also define an alias for path `vocabulary/$vid` (vocabulary/2 =\> cars).

---

This is the exported view:

```
$view = new view();
$view->name = 'nodes_terms_vocabulary';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Nodes and Terms by Vocabulary';
$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'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['grouping'] = array(
  0 => array(
    'field' => 'name',
    'rendered' => 1,
    'rendered_strip' => 0,
  ),
);
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['style_options']['uses_fields'] = TRUE;
$handler->display->display_options['row_plugin'] = 'node';
/* Relationship: Content: Taxonomy terms on node */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
  'section_ytic' => 0,
  'section_apti' => 0,
  'language' => 0,
  'newsletter' => 0,
  'tags' => 0,
  'subjects' => 0,
  'translation_mode_type' => 0,
  'internal' => 0,
  'resources' => 0,
);
/* Field: Excluded: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'term_node_tid';
$handler->display->display_options['fields']['name']['ui_name'] = 'Excluded: Taxonomy term: Name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'node';
$handler->display->display_options['sorts']['title']['field'] = 'title';
/* Contextual filter: Taxonomy vocabulary: Vocabulary ID */
$handler->display->display_options['arguments']['vid']['id'] = 'vid';
$handler->display->display_options['arguments']['vid']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['arguments']['vid']['field'] = 'vid';
$handler->display->display_options['arguments']['vid']['relationship'] = 'term_node_tid';
$handler->display->display_options['arguments']['vid']['default_action'] = 'default';
$handler->display->display_options['arguments']['vid']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['vid']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['vid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['vid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['vid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'nodes_terms_vocabulary_page');
$handler->display->display_options['path'] = 'vocabulary/%';

```
> 3 votes

# Answer
Here's how you would go about doing this:

1. Include the tag you want to group by in your fields (see map)
2. Click on your format settings. (see map)
3. Set grouping field to the tag.
4. Set exclude from display to true in your tag field.

That should get you to where you want to be.

Here's a map of where 1 and 2 would be located.
> 3 votes

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


# Question
Title: Progress Bar to prevent repeated WebForm Submissions?
I'm getting duplicate webform submissions from what I call "Happy Clickers". I would like to implement a progress bar when someone submits a webform to prevent them from clicking multiple times. I tried the pgbar module, but it's not the solution that I am looking for.

Can anyone recommend a Drupal module to accomplish this? I'm using Drupal 7.

Thanks-in-Advance,

John

# Answer
> 0 votes
If you just want to limit Happy Clickers, in the webform go to Form settings and there are options for Total submissions limit & Per user submission limit. I would suggest changing the Per user submission limit to once every minute.

# Answer
> 0 votes
Used the Hide\_Submit module to hide the submit button while the webform is being processed.

Problem solved!

---
Tags: webforms
---


# Question
Title: Render a field contained inside of another field
I am using Drupal Paragraphs module that lets you create "bundles" of fields inside other fields. (It does this using entities). Each bundle has it's own tpl.php file.

In addition, you can nest "sub-bundles" inside the "main-bundles" for complex layouts.

I have created a "main-bundle" called `field_panels_content`.

Inside this is another "subbundle" which holds a `field_body_text`. The "main-bundle" can hold an unlimited number of "sub-bundles".

In my theme, I need to access the all `field_body_text` fields from the multiple "subbundle" from the tpl.php file that is for the "main-bundle".

I have used devel\_themer and found I can get to the `field_body_text` fields like this:

```
<?php print render($content['field_panels_content'][0]['entity']['paragraphs_item'][9]['field_body_text']); ?>
<?php print render($content['field_panels_content'][2]['entity']['paragraphs_item'][10]['field_body_text']); ?>
<?php print render($content['field_panels_content'][2]['entity']['paragraphs_item'][12]['field_body_text']); ?>

```

As you can see this does not make for efficient theming as I would need to know the second array value in order to print it out (e.g. \[9\]\[10\]\[12\]).

Is there away I can use a loop or some other PHP function to get to the second array value automatically without knowing it?

This second array value changes with each new piece of content (e.g. If I add a new subbundle it will have a value of \[13\]. The reason the numbers jump from \[10\] to \[12\] is because I deleted the subbundle that was \[11\].

---

---

## Update

Here are some more steps I have tried (from this page):

Here is an example loop:

```
<?php
foreach ( $content['field_panels_content'] as $wrapper) {
  foreach ( $wrapper['entity']['paragraphs_item'] as $item ) {
    if ( !empty($item['field_body_text']) ) {
      print render($item['field_body_text']);
    }
  }
}
?>

```

It produces the following results: Cannot use object of type ParagraphsItemEntity as array in foreach ( $wrapper\['entity'\]\['paragraphs\_item'\] as $item ) {

Here is a reworked version:

```
<?php
foreach ( $content['field_panels_content'] as $wrapper) {
  foreach ( $wrapper['entity'].paragraphs_item as $item ) {
    if ( !empty($item.field_body_text) ) {
      print render($item.field_body_text);
    }
  }
}
?>

```

Error message: `Fatal error: Cannot use object of type ParagraphsItemEntity as array in line "foreach ( $wrapper['entity'].paragraphs_item as $item ) {"`

Editing the code so only field\_body\_text is in square brackets (e.g. `$item['field_body_text']`), produces this error message: `Fatal error: Cannot use object of type ParagraphsItemEntity as array`

Editing the code so only paragraphs\_item is in square brackets (e.g. `$wrapper['entity']['paragraphs_item']`), produces this error message: `Fatal error: Only variables can be passed by reference in line print render($item.field_body_text);`

If I use print instead of render, I get this error message: `Fatal error: Cannot use object of type ParagraphsItemEntity as array`

---

---

## Other Notes

The following code works perfectly:

```
<?php print render($content['field_panels_content'][0]['entity']['paragraphs_item'][9]['field_body_text']); ?>
<?php print render($content['field_panels_content'][1]['entity']['paragraphs_item'][10]['field_body_text']); ?>

```

So surely it should be a simple case to refactor the code into a loop to get the desired result.

---

## Please note

I don't want to use other modules.

I will be printing out all the field\_body\_text separately at the top of the tpl file. I'll then display the whole paragraph (with the `field_body_text` still in it) in the normal way.

# Answer
> 4 votes
I think the issue here is that each of those paragraph groupings contain various elements that are array keys. For example, if you dpm up to $content\['field\_paragraph'\], you may see values that look like this:

I think the issue is, due to your loops, your trying to render/loop through things that aren't objects. To get around this, you might want to try checkin if the key is numeric before proceeding on.

Something along the lines like this:

```
<?php
    foreach($content['field_paragraph'] as $key=>$array){
  if (is_int($key)) {
    foreach ( $array['entity']['paragraphs_item'] as $key2=>$item ) {
    if ( is_int($key2) ) {
      print render($item['field_body']);
    }
  }
  }
}

?>

```

Note the is\_int($key), that's what you need to get the errors to go away. Note my code has my own field names in it, so you'll just need to switch yours in.

# Answer
> 2 votes
Instead of overriding and creating templates, manage all of the display of the entity through the UI and create field formatters for field types when core doesn't cover your display requirements.

This is a much cleaner way of defining displays, templates get messy fast especially when diving into references.

---
Tags: entities, theming
---


# Question
Title: Custom external read-only databases with Drupal, how to use views to communicate with the external database?
I have a pretty detailed relational database that I would like Drupal to communicate with (Read Only). Now, I know that I can create custom modules to output the data but I am not sure I will be leveraging Drupal's benefits using in that fashion (it seems like a hack). I do not plan on moving the data to Drupal either (too large in size and also more than 80 tables).

Is there a way that I could use views to get the data out from my external database without interfering with the Drupal core? I am sure that Drupal developers run into this issue many times, I would like to have a pointer as far as where to look. Is that possible? has anyone ever done this?

I have already used Google in an attempt to find a solution. I even tried the entity module, entity api, data module a few other API and modules without success.

Just need a workflow/pointer or simply a successful website that is using Drupal in that fashion.

I am using Drupal 7 and I will be willing to go to Drupal 8.

# Answer
Yes there is a way to use views to get data out of an external database. You will need the hooks\_view\_data()

There is however the limitation the view can not cross databases I believe.

To solve this, you can write a custom module

```
<?php

function yourmoduleame_views_views_api() {
   return array(
      'api' => 3,
   );
}

function  yourmodulename_views_views_data() {
   $data['arTable']['table']['group'] = t('yourtable Data');
   $data['arTable']['table']['base'] = array(
      'field' => 'id',
      'title' => t('your title'),
      'help' => t('help text'),
      'database' => 'databasename',
      'weight' => -10,
   );

```

Where databasename is one of your db\_names defined in settings.php.

For more information, look at this post
> 1 votes

# Answer
Maybe the Forena module is what you're looking for? It is built of the idea of using SQL to get data out of a database (which can be the Drupal database or an external one such as My SQL, Oracle, MS SQL, ...) and use XHTML and CSS to format it into web reports. There are quite some reasons for considering Forena. Visit the Forena HowTos page for some links (near the bottom) to some live demo / showcase links. Refer to its community documentation for a lot more details.

To answer this specific answer, I'd use the views integration of it. Here are some details about that integration, included in the Forena documentation that gets installed with the module also (and shown in the demo site):

> Using the Forena integration with the Views module, it is possible to use Forena reports as a views row style, so that in a view you can use the Forena templating engine to do the formatting. Although this can be done through the views templating engine Forena users may find they have more control with this engine.

Disclosure: I'm a co-maintainer of this module,
I hope this does not violate the site's policy on self-promotion.
> 1 votes

---
Tags: views, database
---


# Question
Title: Allowing one page to be accessed by Anonymous user in restricted site
My site is for logged in users only as "View published content" is unchecked for Anonymous users.

Now the problem is that there is one page that I created which shows a form for a user to fill for applying for a membership. It's been created in Webform and I want to show it to Anonymous user.

Naturally, this page is currently restricted and I am confused as to how to show this page to an Anonymous user.

Any help would be appreciated.

Thanks.

# Answer
The content access module provides per node access.
> 1 votes

---
Tags: 7, webforms, users
---


title: how to give node alias dynamically

text:
# Question
Title: how to give node alias dynamically
Each time I add a content, I see a node number gets created (i.e. node/2). When I go to the node, I see in the address bar as xxx.com/node/2. Is there way node/2 can be replaced by a value of any field(i.e. title) of the node dynamically? In this case new URL will be xxx.com/nissansentra. \[nissansentra is the value of the title field of that node).

I know I can go to config \> url alias and give a alias name manually. Instead, I am trying to make it dynamic so I don't have to manually give a alias to each node.

Thanks.

D

# Answer
> 2 votes
Yes there most definitely is. Checkout Pathauto. There are many contrib modules for this type of common functionality at Drupal.org.

# Answer
> 1 votes
You're looking for Pathauto. It will let you build URL patterns for each content type based on variety of data from the token module.

---
Tags: path-aliases
---


# Question
Title: Allow user A to grant view permission of their node to user B
My website users will have the ability to post pictures in a private photo gallery. I would like for those users to be able to grant "view" permissions for their private gallery to other users.

* Bob (an authenticated user, not an admin) has a private photo gallery
* He wants Dave (another authenticated user, also not an admin) to be able to view his private photo gallery
* Bob grants permission to Dave, allowing Dave to view that gallery
* Bob can revoke permission from Dave at any time

Is there a module/configuration that will this type of user-controlled granting of permissions?

Thanks!

# Answer
Perhaps consider using Organic Groups which allow users to create and control groups of users and curate content for them.

There is also Node Access User Reference which is slightly more specific.

Both should work together but I think you will only need one of them for your stated needs.
> 1 votes

---
Tags: 7, users
---


# Question
Title: Look for documentation about how precisely modules parts are loaded (Drupal 7)
Developping my custom module, I ran several times into misunderstood issues regarding the precise order used by Drupal when loading parts of a module.
Each time, I finally got rid of it after any disabled and suppressed then recreated, but this is obviously not satisfying.

So I'm now looking for sufficient information to be able to understand what happens in those circumstances.

This time the problem I have is as follows:

1. Having my module working fine on a site under D-7.34, I upgraded it to D-7.35, following all necessary steps.
2. After successfully executing update.php (which notified that no update was needed), I clicked to go to front page: this one was properly displayed.
NOTE: **necessarily, my module was already involved at this stage**, since it works during output rendering (so whatever the path indicated by the URL)
3. But from there, then, any attempt to access another page (either public or administrative one) fires a PHP error "Call to undefined function *myfunction()*...", where *myfunction()* belongs to my module.

I can't figure out how it is possible, since my code schematically looks like:

**file: mymodule.module**

```
<?php

module_load_include('inc', 'mymodule', 'mymodule.core');

function mymodule_some_hook() {
    # ...
    myfunction();
    # ...
}

```

**file: mymodule.core**

```
<?php

function myfunction() {
    # ...
}

```

In other words, in my eyes:

* when the error fires, it necessarily means that *mymodule.module* was loaded, since it is where *myfunction()* call resides
* then if *mymodule.module* was loaded, it should have first executed *module\_load\_include()*, so loading *mymodule.core* and defining *myfunction()*

Yet it is clear that, in this case, something is happening differently!

But why this behaviour now, and not at the first access to front page?
And why this behaviour with D-7.35 (where no changes seem to be involved here), and not with D-7.34?

NOTE: I suspected something wrong with caching, so I tried flushing it. But flushing process failed with the same "Call to undefined function".
Then I used directly PhpMyAdmin to truncate all cache tables, without success: behaves the same after that.

Comments greatly welcome, and notably if pointing to any documentation about detailed process of modules load.
Thanks in advance.

# Answer
> 0 votes
After a lot of tests, I'm now pretty convinced that, despite it is not mentioned in the release notes page, a change happened in 7.34, which consists in that, now, the full-bootstrap condition is not reached yet when the MODULE.module file is loaded.

According to module\_load\_include() page, this function **requires Drupal to be fully bootstrapped**: this clearly relies to the use of `drupal_get_path()` (see the function code in this page), which is not available without full-bootstrap.

It is why my (global-scoped) `module_load_include()` calls are executed but without result (see 'file: mymodule.module' in my question above).

I had to modify my module, including a dedicated `module_load_include()` call inside each function which needed it, like this:

```
<?php

function mymodule_some_hook() {
    module_load_include('inc', 'mymodule', 'mymodule.core');
    # ...
    myfunction();
    # ...
}

```

This way, now all works fine anew.

I verified it is the same with Drupal 7.36: my module doesn't work in its original implementation, then it does with this modification.

Hope this helps.

---
Tags: 7
---


# Question
Title: Show block on nodes and only for node author
I am building a simple classifieds style site. Instead of using straight email, I was thinking about creating a simple "make offer" node type. Create a few basic fields (reference to classified listing, message, will buy for X price, would trade, etc...).

Then create a view block and put the nid in to limit those "offer" nodes to only the node being viewed. However, I would like to do two things.

1) Limit the block to only be viewable to administrators and the node author themselves, other users should not be able to see the other offers.

2) Make it so going to /node/{nid} that is an offer content type is hidden from view so users can't just bypass the block and hit the nid of the offer node.

Any help on how to implement this? I am trying to do it with no added modules.

EDIT: The access to the block should be as follows:

Administrators: Should see all "offer" nodes in the block regardless of who they are from.

Listing Author: Should see all "offer" nodes in block.

Offer Author: Should only see "offer" nodes they have submitted to "listing" nodes. They shouldn't see any other "offer" nodes from any other user.

# Answer
1. In views, add a relationship on "Content: Author", then add a filter "User: Current" and configure it so it uses the relationship you added and has "Is the logged in user" = "Yes".
2. Install the Rabbit Hole module and its node sub module and configure it (on the edit page for the offer content type) to give a 404 error for those nodes. Then configure the rabbit hole permissions so that admins can bypass rabbit hole if you need that ability. I would recommend adding this module as opposed to writing some custom code to do this.
> 1 votes

---
Tags: 7, views, blocks, users
---


# Question
Title: "Fetch entity by property" for multi-value term reference field
Node A and user both have a term reference field which referenced to the same vocabulary, the term reference field of Node A is single-value, but that of user is multi-value.

I created a rule: after saving a new Node A , Fetch entity by property, the Entity type is User, the Property is the multi-value term reference field, but I cannot select the single-value field in the node, the page hints the property value should be "Data types: Select data of the type *List of taxonomy term items*." When I select "node:field-problem-category" (the single-value term reference field) and save, the page shows error: The data type of the configured argument does not match the parameter's value requirement. I have to select node:field-problem-category:parent. But thus no entity can be fetched.

I followed the instruction here, but no luck.

Any help would be appreciated!

BTW:It will be best that the "Fetch entity by property" can provide an operator like PHP function *in\_array*.

# Answer
> 0 votes
At last, I solved this problem using Views Rules module, just set the Data type of the Rules parameters (providing to contextual filter) to Text. Then add a view loop in the rule action. A view's multi-value field contextual filter can have only one value.

---
Tags: rules
---


title: New User OpenID identities in Drupal 7

text:
# Question
Title: New User OpenID identities in Drupal 7
Scenario:

Drupal 7 site recently migrated from Drupal 6. Using OpenID connect module. All users login with Google, using a Google account with a company domain name. (user@company.com). All users that were migrated can still log in. When a new user is created, he or she cannot log in, and the OpenID Identities tab for the new user is blank. The new user is directed back to the login page. The site is also using the Require Login module, which states that it works with OpenID.

1. How can I get Drupal to save the OpenID Identity to the user's account? So far my only idea is to give the user a one-time link so he can log in, then ask him to add the https://www.google.com/accounts/o8/id code into the "add identities" field.
2. Would that even work, since it's not actually google.com for the others? All the working users have IDs that state the company name (www.company.com/id=longstring).
3. How can I check to see if the site is using the new OpenID protocol and won't stop working on April 20th?

I am having trouble understanding how OpenId works with Drupal.

# Answer
> 1 votes
For anyone with a similar issue, here is how I solved it.

The problem: using openid signin with a site that shows a splash login page for all anonymous users. You cannot use any splash page configuration that uses redirects, because it interferes with the openid redirect.

Solution: I removed the require login module and enabled the front page module. Then I configured the front page to use an alias with the login page for unauthenticated users, NOT the redirect option. When new users sign in, it automatically uses the company domain to create an openid and then stores it in Drupal.

Sidenote: New users cannot already have an existing account in the Drupal site, even if there is no openid yet assigned. The account is created the first time they sign in . They will not be able to do so if there is already an account attached to their email.

---
Tags: users, authentication-authorization
---


# Question
Title: Best Practices? Create dynamic links with static titles on node full view page
As with anything drupal, there are a million different ways to do something. I am asking this question for 1) Because I actually have to do something similar and 2) Because I would like to know all the different ways this could be achieved and the pros and cons of each. Is creating a custom field the way to go or should you just dump some dynamic code in the node-album.tpl.php template? Which way is the most flexible? Which is the most non-coder friendly?

Scenario: You have two content types (say, photo and album) where photo has a file field for an image and album is a collection of photo nodes.

If a user is viewing an album node type, how would you go about creating a "add photo" link on the full node view to add a photo to that specific album? Using the entity reference prepopulate module.

So how would you give users a way to click on a link/button for:

http://www.domain/node/add/photo?field\_album\_reference=\[node:nid\]

# Answer
> 0 votes
This is how I do mine if it's entity reference prepopulate:

```
<?php
        $l = l( t('Add Photo'), 'node/add/photo',   array('query' => array('field_album_reference' => $nid)  ));
        echo $l;
?>

```

But I usually use node reference widget when for example adding an album coming from venue content type. Code example:

```
<a href="<?php print url('node/add/venue-photo-album/' . $node->nid); ?>">Add Photo album</a>

```

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


# Question
Title: How to add "Size" option in my Commerce Product without adding lot of SKU that differs by size?
The same question was "Module Commerce Product Option. Sizes are not active for selection"

I read here Drupal Commerce Custom Sizes that "it requires you to define a SKU for every possible combination - depending on how many measurements options you have" But I do not want to add many products. I need to add One product display Woman's T-Shirt with 5 SKU with photos: Blue, White, Yellow, Green, Orange. In every SKU I want to check the option sizes like:

* Blue with option sizes: S, L
* White S, M, L, XL,
* Yellow XL, XXL, XXXL
* Green L, XL, XXXL
* Orange S, L

Without adding lot of SKU like: T-Shirt White S, T-Shirt White M, T-Shirt White L.....

The option Sizes should become dropdown or checkboxes when customer is viewing product Womans T-Shirt. How to do this?

Here it is correct: http://demo.commerceguys.com/ck/tops/drupal-commerce-hoodie The user can choose color and size. Is this really neccessary to add all variations with color and sizes?

How to solve my optimization problem?

# Answer
> 1 votes
You're going to create 5 option set.

* White with sizes
* Blue with sizes
* Green with sizes
* Orange with sizes
* Yellow with sizes

Each Option set create you created insert your size field (list type)

On your Shirt product type or whatever your product type is, create your sizes option set reference field

So when you create your 5 SKU you're going to choose which option set the user is going to use.

For Example:

* Woman's T-Shirt WHITE (PRODUCT)
* Option set reference:"White with sizes"

---
Tags: commerce
---


# Question
Title: Ajax HTTP Error Occured in Theming Tables
I have two elements in my form: a `select` element and a `div` with an id of `#myid_table_wrapper`.

```
function myid_print_user_page_form()
{
    $form = array();

    $form['options'] = array(
        '#type' => 'select',
        '#options' => array(
            0 => t('All'),
            1 => t("Printed ID's"),
            2 => t("Unprinted ID's")
        ),
        '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_table_wrapper',
        ),
    );
    $form['myid_table_wrapper'] = array(
        '#type' => 'item',
        '#markup' => '<div id= "myid_table_wrapper"></div>',
    );
    return $form;
}

```

Everytime the select element fires an onchange event it calls a callback function named `myid_print_all_submitted_id_callback`.

```
function myid_print_all_submitted_id_callback($form, $form_state)
{
    // Build the sortable table header.
    $header = array(
        'id_number' => array('data' => t('ID Number'), 'field' => 'id_number','sort' => 'asc'),
        'student' => array('data' => t('Student'), 'field' => 'student', 'sort' => 'asc')
   );

   //Get the node data.
   $query = db_select('student', 't1',array('target' => 'import'));
   $result = $query
       ->fields('t1', array('studid','lastname', 'firstname', 'middlename', 'extname'))
       ->condition('t1.id_status',2,'=')
       ->distinct()
       ->execute();
   //Build the rows.
   $rows = array();
   foreach($result as $record){
       $rows[$record->studid] = array(
           'id_number' => $record->studid,
           'student' => $record->firstname . ' ' . $record->middlename . ' ' . $record->lastname . ' ' . $record->extname,
       );
   }
   return theme('table', array('header' => $header, 'rows'=> $rows));
}

```

The code results to an error:

Whats wrong with my code? How will I debug this?

# Answer
The correct way to do this is to populate the id table inside the form generation function (checking $form\_state\['values'\]). Then the callback should only return the form element.
This is an example of how I would do it:

```
function myid_print_user_page_form($form, $form_state)
{
    $form = array();

    $form['options'] = array(
        '#type' => 'select',
        '#options' => array(
            0 => t('All'),
            1 => t("Printed ID's"),
            2 => t("Unprinted ID's")
        ),
        '#ajax' => array(
            'callback' => 'myid_print_all_submitted_id_callback',
            'wrapper' => 'myid_table_wrapper_div',
        ),
    );
    $table_html = '';

    // Check if option has been selected.
    if(!empty($form_state['values']['options'])){
      // Build the sortable table header.
      $header = array(
          'id_number' => array('data' => t('ID Number'), 'field' =>   'id_number','sort' => 'asc'),
          'student' => array('data' => t('Student'), 'field' => 'student', 'sort' => 'asc')
       );
       //Get the node data.
       $query = db_select('student', 't1',array('target' => 'import'));
       $result = $query
           ->fields('t1', array('studid','lastname', 'firstname', 'middlename', 'extname'))
           ->condition('t1.id_status',2,'=')
           ->distinct()
           ->execute();
       //Build the rows.
       $rows = array();
       foreach($result as $record){
           $rows[$record->studid] = array(
               'id_number' => $record->studid,
               'student' => $record->firstname . ' ' . $record->middlename . ' ' . $record->lastname . ' ' . $record->extname,
           );
       }
       $table_html = theme('table', array('header' => $header, 'rows'=> $rows));

    }

    $form['myid_table_wrapper'] = array(
        '#type' => 'item',
        '#markup' => $table_html,
        '#prefix' => '<div id="myid_table_wrapper_div">',
        '#suffix' => '</div>',
    );
    return $form;
}

function myid_print_all_submitted_id_callback($form, $form_state)
{
    return $form['myid_table_wrapper'];
}

```

This is untested, but you get the idea.
> 1 votes

---
Tags: forms, ajax
---


# Question
Title: Form returned by drupal_get_form() won't submit
I am currently implementing an additional registration page on my drupal site, using drupal\_get\_form(), but I seem to be missing something cucial.

While the registration form is printed at the path I created, I can not submit the form - drupal will clear both the user and the email field and return an error claiming the form could not be submitted, because the fields were empty. They were not.

Do I need to hook up a custom validation handler? Something else?

My code so far:

```
function my_module_menu() {
  $items['customer/register'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_customer_registration'),
    'access callback' => TRUE,
  );

 return $items;
}

function my_module_customer_registration() {
  $form = drupal_get_form('user_register_form');
  return $form;
}

```

# Answer
> 2 votes
It's not working because the form builder function user\_register\_form() is expecting a couple of arguments, `$form_id` & `$form_date`, that you're not passing (see the drupal\_build\_form() docs to know more about what they're for).

If you want to provide a wrapper function around the user reg form, you can do something like this:

```
function my_module_customer_registration($form, &$form_state) {
  $form = user_register_form($form, $form_state);
  return $form;
}

```

# Answer
> 1 votes
Why don't you add `user_register_form` in to hook menu

```
function my_module_menu() {
  $items['customer/register'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('user_register_form'),
    'access callback' => TRUE,
  );
 return $items;
}

```

---
Tags: forms, users
---


# Question
Title: Views Filter to display field only if it matches a certain value
how do I display a field in views ONLY if the value matches a certain specified value?

# Answer
> 3 votes
Example: I have a field name called "Product". Add FILTER CRITERIA. Filter choose content and search Product. Save the views and click the recently added FILTER CRITERIA. You will able set a setting like Product = Book. This will appear if you choose Autocomplete This will appear if you choose select

---
Tags: views
---


title: Adding images to a node

text:
# Question
Title: Adding images to a node
Is there a way to programmatically add an array of images from a particular file path? I want to add all the images from one folder in my drupal site and add fancybox styling to them. Can this be done? I've tried looking on drupal.org with no success.

# Answer
If by 'programmatically' you mean using PHP, then there seem to be two good options.

1. Create a template file, include the fancybox library if not already loaded, load the file path/names from your image directory into an array, tweak the array as needed, and call fancybox with the paths in your array.
2. Create a custom module that does essentially the same thing, but here you can also add an admin view to manage the images, set custom permissions, etc.
> 0 votes

---
Tags: 7, media
---


# Question
Title: How do I create different landing pages?
I am newbie to Drupal and I have deadline to make a website. So, I apologize if this question sounds silly to you..

I wanted to create a website that has one front page and 8 different landing pages. I have created front page. But I am not sure what is the best practice to create 8 different designed landing pages that are going to be use for the entire website.

For example:

* "About" page uses 2 column layout.
* "Contact Us" page uses 3 column layout.
* "News" page has flexible layout and so on. Also, News page has two image boxes with contents.

So, how do I create image box for one of my landing page?

So, can any one please guide me how do I create different landing pages? I know there are several methods like, using panels, views and mini-panels we can create different landing pages. But, can any one suggest me good video tutorial and documentation for that?

Many Many Thanks!!

# Answer
> 0 votes
You have to check this link for theming of different different page.

---
Tags: views, panels
---


# Question
Title: How to remove format description in date_popup form field?
How can I remove format description in date\_popup form field?

```
$form['payable_by'] = array(
    '#type' => 'date_popup',
    '#title' => $amount !== '' ? t('Instalment payable date for instalment @label', array('@label' => $amount)) : t('Instalment payable date for new instalment'),
    '#title_display' => 'invisible',
    '#default_value' => $payable_by,
    '#parents' => array('instalment', $key, 'payable_by'),
        '#date_format' => 'Y-m-d',
        '#date_year_range' => '-0:+1',
  );

```

Please check the image

# Answer
> 13 votes
Normally, you would just set the *#description* property of the form element, and it would be rendered. With the *date\_popup* element implemented by the Date module it seems it is not possible: The form element is made of two sub-elements for which the value of the *#description* property is not taken into consideration.

As there are two branches, I will report what I have noticed in the development snapshot for both the branches.

### Branch 7.x-2

The "date\_popup" element is defined with the following code.

```
function date_popup_element_info() {
  $timepicker = date_popup_get_preferred_timepicker();
  $type['date_popup'] = array(
    '#input' => TRUE,
    '#tree' => TRUE,
    '#date_timezone' => date_default_timezone(),
    '#date_flexible' => 0,
    '#date_format' => variable_get('date_format_short', 'm/d/Y - H:i'),
    '#timepicker' => variable_get('date_popup_timepicker', $timepicker),
    '#date_increment' => 1,
    '#date_year_range' => '-3:+3',
    '#date_label_position' => 'above',
    '#process' => array('date_popup_element_process'),
    '#value_callback' => 'date_popup_element_value_callback',
    '#theme_wrappers' => array('date_popup'),
  );
  if (module_exists('ctools')) {
    $type['date_popup']['#pre_render'] = array('ctools_dependent_pre_render');
  }
  return $type;
}

```

The element has a process function that execute the following code.

```
  $element['#tree'] = TRUE;
  $element['#theme_wrappers'] = array('date_popup');

  if (!empty($element['#ajax'])) {
    $element['#ajax'] += array(
      'trigger_as' => array('name' =>$element['#name']),
      'event' => 'change',
    );
  }

  $element['date'] = date_popup_process_date_part($element);
  $element['time'] = date_popup_process_time_part($element);

```

Looking at the code for `date_popup_process_date_part()`, I notice the following code.

```
  $sub_element['#value'] = $sub_element['#default_value'];
  // TODO, figure out exactly when we want this description. In many places it is not desired.
  $sub_element['#description'] = ' '. t('E.g., @date', array('@date' => date_format_date(date_now(), 'custom', date_popup_date_format($element))));

```

As the code that `date_popup_element_process()` executes before to return the element is the following one, there is still an alternative.

```
  $context = array(
   'form' => $form,
  );
  drupal_alter('date_popup_process', $element, $form_state, $context);

```

Implementing `hook_date_popup_process_alter()` you could remove the description.

```
function mymodule_date_popup_process_alter(&$element, &$form_state, $context) {
  unset($element['date']['#description']);
  unset($element['time']['#description']);
}

```

Similar code is present in the branch 6.x-2.

### Branch 7.x-1

There are few differences with the branch I previously described. (See the code repository.)

The first is the code that in `date_popup_process_date_part()` sets the description, which is the following one.

```
  $sub_element['#value'] = $sub_element['#default_value'];
  // TODO, figure out exactly when we want this description. In many places it is not desired.
  $sub_element['#description'] = ' '. t('Format: @date', array('@date' => date_format_date(date_now(), 'custom', date_popup_date_format($element))));
  return $sub_element;

```

The second difference is that `date_popup_element_process()` (the process function for that element) is not invoking `hook_date_popup_process_alter()`.

```
function date_popup_element_process($element, $form_state, $form) {
  date_popup_add();
  module_load_include('inc', 'date_api', 'date_api_elements');

  $element['#tree'] = TRUE;
  $element['#theme_wrappers'] = array('date_popup');

  $element['date'] = date_popup_process_date($element);
  $element['time'] = date_popup_process_time($element);

  if (isset($element['#element_validate'])) {
    array_push($element['#element_validate'], 'date_popup_validate');
  }
  else {
    $element['#element_validate'] = array('date_popup_validate');
  }
  return $element;
}

```

The only alternative in this case would be to implement hook\_element\_info\_alter() to add a process function to the element.

```
function mymodule_element_info_alter(&$type) {
  if (isset($type['date_popup'])) {
    $type['date_popup']['#process'][] = 'mymodule_date_popup_process';
  }
}

function mymodule_date_popup_process($element, $form_state, $complete_form) {
  unset($element['date']['#description']);
  unset($element['time']['#description']);

  return $element;
}

```

The code for branch 6.x-1 is similar to the code of branch 6.x-2.

In both the cases, the comment reported in the Date module code suggests they will alter the code not to use the description that is now shown. For this reason, I would suggest to implement the necessary code in a custom module, and remove that code once the Date module is changed.

# Answer
> 0 votes
try this:

```
function promo_quote_date_popup_process($element, $form_state, $complete_form) {
      unset($element['date']['#description']);
      unset($element['date']['#title']);
      return $element;
}
function promo_quote_element_info_alter(&$type) {
  if (isset($type['date_popup'])) {
    $type['date_popup']['#process'][] = 'promo_quote_date_popup_process';
  }
}

```

# Answer
> 0 votes
In d 6.x there is no info\_alter hook. But you can solve this by using pre\_render.

In you form definition or by form alter you need to add a pre\_render definition. Like this for example (in form definition):

```
$form['dateformname'] = array(
  '#title' => t('The date'),
  '#type' => 'date_popup',
  '#pre_render' => array('MODULENAME_date_prerender'),
);

```

And then implement that prerender function where you can unset the data sub element description. Example:

```
function MODULENAME_date_prerender($element) {
  unset($element['date']['#description']);
  return $element;
}

```

---
Tags: datetime, input-formats
---


title: geofield map theme markers

text:
# Question
Title: geofield map theme markers
I wonder if (and how) it is possible to have dynamic markers on a geofield map created by views. I'd like to have different colors of markers depending on a field value, and also a count of matches from a proximity filter direktly printed into the markers (not the popup). I'm using the google map layer and cannot find an option to even have (e.g.) green instead of the default red markers. Google search on this topic didn't wield any solutions.

I'm using the following modules: address field, geofield, geophp & geofield maps for map display.

Has anyone done this already? Thanks!

# Answer
An instruction how to do this can be found on: http://purewebmedia.biz/article/2014/08/01/create-multi-layer-map-drupal-7-openlayers-2x
> 1 votes

---
Tags: views, google-maps, location
---


# Question
Title: Add followers' list at the end of discussion
I want to add following functionalities in Drupal 7.

* Any forum-user can have followers, So I want to show followers list on forum-user's profile page. (Like this)
* Those followers should be automatically subscribed to all the posts by that author.

I'm using Advanced Forum module. How to do this using Views module or any other possible way?

# Answer
@NishantP's link helped me to understand a bit, but this post solved the issue perfectly. Its Author has elaborated nicely.

Modules used : Views, Flag, CTools
> -1 votes

# Answer
You can do this using Flag module.

> Flag is a flexible flagging system that is completely customizable by the administrator. Using this module, the site administrator can provide any number of flags for nodes, comments, users, and any other type of entity. Some possibilities include bookmarks, marking important, friends, or flag as offensive. With extensive views integration, you can create custom lists of popular content or keep tabs on important content.

Creating Following & Followers
> 0 votes

---
Tags: users, nodes
---