title: /Drupal/ Stopped working

text:
# Question
Title: /Drupal/ Stopped working
I'm running a apache2 server on Ubuntu. While I was in the middle of configuring new content on my local instance of drupal via Firefox, the site suddenly stopped working. My first thought was the the apache2 server was down, so I restarted it. Then I created an index.html, and index.php that both worked (outside the drupal directory).

Now let's say I go to localhost/drupal/ I get a blank page. However, if I go to localhost/drupal/update.php I get the update page. I found that out as I was trying to figure out if any page would load. /index.php does not work.

Any idea to what I should investigate next? What's weird is that I was in the middle of working on the site when it went down. I don't see a reason for that to happen.

Any help is appreciated.

Thank you!

**Update:** I found that apache log can be handy. By typing into the terminal:sudo cat /var/log/apache2/error.log

I found that the log had the following error:

```
PHP Fatal error:  Cannot redeclare class QueryConditionInterface in /var/www/html/drupal/includes/database/query.inc on line 16

```

I tried replacing this file with the file from the original drupal package, didn't work. Nor should it have because I didn't change any code in this file.

**Things I've tried:**

* Restart mysql and appache2 using `sudo service mysql restart`
* Delete /drupal/includes/ and re-populate it with files from the original

package.

# Answer
Sounds like it can't connect to the database any more if it's crashing on /query.inc

Some things to try:

* Check your database daemon is running (`sudo service mysql status` or similar)
* Check that your settings file has the correct db information and permissions
* Check that your drupal *user* in mysql has right level of permissions (and that it exists)
> 0 votes

# Answer
I deleted all files, and dropped the database, then re-did the site. The problem was probably because I mixed and matches between an installation profile and the original package files.
> 0 votes

---
Tags: 7
---


# Question
Title: Missing "operation links" from all content list page
I am currently missing the links that appear next to a piece of content on admin/content, the ones that say "edit / delete" etc. I have all permissions enabled for the user I am logged in as, and I can still edit a piece of content if I go to view it first, just not on the list page.

Any ideas of what could be causing this?

Thanks

# Answer
> 0 votes
The solution was to re-install the latest version of Drupal.

---
Tags: nodes, users
---


# Question
Title: Blank row when adding field collection item
I have a Content Type with a Field Collection that can have multiple entries. Whenever i click on "insert new element" i get instead a blank row with a "delete" button but no fields to fill. (site is in italian, Elimina means "Delete" and "Aggiungi un altro elemento" is the "add new item" button)

Things worth mentioning:
1) This happens when i'm in the frontend template (the node can be edited by anonymous users) but not when i'm in the administration pages, it works fine there
2) This field collection has some special fields: 1 Simple Hierarchical select, 2 computed fields and 1 Geofield. Apart from the SHS field the other fields are not editable by users (and even if they were, those fields are automatically generated so there won't be a widget)
I have tried to change the SHS widget with other widgets but it didn't work.
3) There are other field collections in this content type and adding a new item there works fine and shows me the form
4) I have checked through Firebug the json returned by the ajax call used to add a new item and it contains the HTML for the new form, but it looks like it's not appended to the page
5) Another thing that may be an issue is that on the frontend i'm using jquery 1.9 while in the administration pages i'm using jquery 1.7 (the site uses a bootstrap template) and i have noticed that in the ajax response it says jquery\_version: 1.7, but this won't explain why other fields work.
6) i have tried changing the fields order putting the fields that work over this one but that didn't work either. Those field collections that worked kept working and this one that doesn't work was still not working

# Answer
> 0 votes
At first i thought it was a javascript problem or something like that but as Geoff pointed out it was a permissions problem:

The permissions on the field collection itself were public, the permissions on the fields inside allowed anonymous users to edit existing items but not create new values for those fields so that gave me an empty form when creating a new item of that field collection.

---
Tags: entities
---


# Question
Title: How to style a programmatically created page with a template?
I'm struggling with understanding theming pages with templates. I'm stuck with creating a new template for a programmatically created page. I have a module that shows a download page for a file. The page is basically a form where user can click Submit and get their file downloaded. I construct the whole form programmatically in a page callback. But what if I want to style it with a template? I fail to see how to do it. Here is my (simplified) code:

```
// Implements hook_menu()
function mymodule_menu()
{
    $items = array();
    $items['file/%mymodule_mycustomfile/download'] = array(
    'page callback' => '_mymodule_filedownload',
    'title' => 'Page Title',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    );
    return $items;
}

// Implements autoloader %mymodule_mycustomfile
function mymodule_mycustomfile_load($fid)
{
    return ($fid > 0) ? (object)array('fid' => $fid) : FALSE;
}

// Page callback function
function _mymodule_filedownload($mycustomfile)
{
    return drupal_get_form('_mymodule_filedownload_form', $mycustomfile);
}

// Creates page form
function _mymodule_filedownload_form($form, &$form_state, $mycustomfile)
{
    $form['label'] = array('#type' => 'item', '#markup' => 'File ID');
    $form['fid'] = array('#type' => 'item', '#markup' => $mycustomfile->fid);
    $form['submit'] = array('#type' => 'submit', '#value' => 'Download');
    return $form;
}

// Submit button click handler
function _mymodule_filedownload_form_submit($form, &$form_state)
{
    die('On Submit');
}

```

You can see that I construct my form fully in `_mymodule_filedownload_form()`. But I want to have something like file-download.tpl.php for it and put things like Label there. I fail to see how to do it. My problems are:

1) I stumbled upon `theme_hook_suggestions` and by default Drupal suggests the following template names: page\__file, page\__file\__%, page\__file\__1, page\__file\__download. When I created page--file--download.tpl.php and went to /file/1/download, my screen went blank. I do not know how to output my form in this file and I'm afraid I do not even want to restyle the whole page. I only need to style the page content (the form itself) and leave the page alone. Why can't I have file--download.tpl.php if I have node.tpl.php and comment.tpl.php?

2) As a side note, when you execute `template_preprocess_page(&$variables)` on node pages, you can see the defined `$variables['node']` that contains full node object. How is it done? Can I possibly have something like `$variables['mycustomfile']` on my file download pages?

# Answer
In this case your page is a form, so you need to create a form template this way:

Implement hook\_form\_alter() in a module or template.php and set the form's #theme property:

```
function _mymodule_filedownload_form($form, &$form_state, $mycustomfile)
{
    ...
    $form['#theme'] = array('mymodule_filedownload_form');
    ...

}

```

Then implement new theme:

```
/**
 * Implements hook_theme().
 */
function hook_theme($existing, $type, $theme, $path){
  $path = drupal_get_path('module', 'mymodule');
  return array(
    'mymodule_filedownload_form' => array(
      'render element' => 'form',
      'template' => 'form--mymodule_filedownload_form',
      'path' => $path . '/templates',
    ),
  );
}

```

And then add form--mymodule\_filedownload\_form.php template with follow code to render complete form (you can render it also by components):

```
<?php print drupal_render_children($form) ?>

```
> 1 votes

---
Tags: 7, forms, theming, routes
---


title: Search API View, search relation fields

text:
# Question
Title: Search API View, search relation fields
I am creating a search api view based on Search API (with Database backend for now (will change to solr later)).

I have 2 entities that are being indexed i.e. **project** and **client**.

A **project** contains a *projectnumber* and an entity reference to a client. The **client** contains a *firstname* and *lastname*.

I have added a view that shows the *projectnumbers* and (via relation to client entity) the *first* and *lastname*.

I want my exposed fulltext search to search these 3 fields (*projectnumber*, *firstname* and *lastname*).

The weird thing is that he only seems to search on **projectnumber** and not the *first* and *lastname*.

Does anybody have a workaround/solution for this?

Thanks in advance!

# Answer
There's 2 areas you need to check this is included. It's common to have applied to the search and not realise it needs to applied in views also.

I take it so far you have made the fields in

configuration \> search api \> Operations 'EDIT'

"Fields" tab \> 'Add Related Fields ' at the bottom.

Now you also need to add the Fields in

structure \> views \> your view

Filter Criteria \>

On the right hand side look for 'Searched Fields' - make sure all the fields your searching are in here.

I hope that solves it for you .
> 1 votes

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


# Question
Title: Multi step form with click and state logging in Drupal 7?
I need to create two separate forms flows. Essentially the one case has 3 pages (intro, questions, thank you), while the other has 4 pages (intro, questions, questions, thank you). I want to be able to:

* Log the states of each "step" as the user proceeds
* Keep track of where the user clicks and in what sequence

I am thinking of doing the second part with Google Analytics, as I know it has ways to do this. However, I am not sure what is the best way to go with the multi step form process.

So far it sounds like I would have to create content types for each step and use rules to "guide" the user as he creates the different content types. However, this sounds like a nightmare when it comes to "back" and 'next" functions.

Can anyone please tell me what is the best way to implement a form like this, keeping in mind how important it is that the logging works perfectly.

# Answer
> 0 votes
I decided to follow copy and modify this solution. It allowed me to basically create a way by which I can just add a new "survey-2.php" file, which contains the brains of the various surveys I want to do. The ordering and persistence and all that stuff happens in the main module.

# Answer
> 2 votes
I can't say that this is the best way, but you can achieve that using the Webform module.

You can create multi step form using Webform module. Add *`Page break`* type to form components to split the form.

In Advanced Form Settings you can manage the multi step form actions like 'Automatically save as draft between pages and when there are validation errors' options.

In you want to provide advanced navigation bar for multi step web from you can try the Webform steps module

> This module provides a navigation bar for multi-page webforms. The navigation bar is a set of buttons placed at the top of each webform page. The buttons allow free navigation between steps that have already been visited.

# Answer
> 1 votes
From a sitebuilder's perspective, look at MSNF module with the Conditional Fields module. Doing this programmatically beats the hell out of anything else. Ctools Multipart, Multistep forms is the best that I have come across to do want you are looking for. Have a look at Paul Booker's tutorial for a starter.

# Answer
> -1 votes
I've written a tutorial about how multi step forms in Drupal works. You can read the tutorial on http://brattland.no/blog/drupal/multistep-forms-in-drupal-7

---
Tags: 7, forms
---


title: Rules :0 :1 :2 :3

text:
# Question
Title: Rules :0 :1 :2 :3
I'm trying to create a price alert rule and as an action I'm trying to fetch users who flagged a product display. My problem is as follows: When I try to fetch users who flagged a node, I can't distinguish between flags; whereas when I do the same thing for a commerce product, I get tokens like `commerce-product:creator:flag-fiyati-dusunce-haber-ver-flagged:` which requires a number at the end. Reading this post, I understand that numbers correspond to variations (am I correct?) but I still have no clue what number to use for any variation (if they indeed correspond to variations). Anyone care to help me with that?

# Answer
> 1 votes
The number corresponds to the index of a multi valued field, a field that can have more then one value (defined in the content type).

For fields that accept one value, you can use 0. For fields that can contain multiple values, `:n` selects the nth entry for that field.

Since a flag either is enabled or not, I suppose you should be safe with :0. (Omitting this parameter usually has the same effect).

---
Tags: commerce, rules
---


title: Why is page tpl not getting detected

text:
# Question
Title: Why is page tpl not getting detected
I have a view with page display's page setting as following:

```
Path: some/path
Menu: No Menu

```

However it was overridden in templates by `page--some--path.tpl.php` for styling purposes. This tpl actually overrides `page--some.tpl.php` which is a base tpl for all pages located at `some/*` path.

I have now been asked to change this the path to `some/path2`. I did the same in views page settings. And created a tpl file `page--some--path2.tpl.php`.

Problem is that this tpl file is not getting detected and Drupal is using `page--some.tpl.php` as the template.

Why so?

# Answer
This is the snippet I wrote for region--login.tpl.php try this once. Hope it meets your requirements. in template.php

```
 <?php
 function yourthemeName_theme() {
   $items = array();
  // create custom user-login.tpl.php
  $items['user_login'] = array(
  'render element' => 'form',
  'path' => drupal_get_path('theme', 'yourthemeName') . '/templates',
  'template' => 'region--login',
   'preprocess functions' => array(
   'yourthemeName_preprocess_user_login'
   ),
   );
   return $items;
  }
  ?>

```
> 0 votes

---
Tags: 7, theming
---


# Question
Title: Content type - field type - Select list: Add options: Existing content on the website
I want to do something in my website, but I can't figure how. Let me explain:

I have a content type called bananas, and I have created a lot of bananas pages.

I want to create a content type called peaches and add a field with a select list called "Existing bananas on this peach" - and I want to be able to **select from all the bananas pages my website has.** Then, if it is not asking too much, I want this field to be a link to the specific bananas page.

Am I making myself clear? For me it's simple, but I don't think there's a way on Drupal to do that. Or maybe there is, but I'm just not seeing it.

Hard or easy, do you have any solution?

Thank you so much in advance, hope you guys can help me.

# Answer
Assuming you are using Drupal 7, I think you need the Entity Reference module.

This module provides a field that you can add to your content type peaches and provides the requested widget that allows you to select from all the bananas nodes your website has. When outputting the peaches node, the standard formatter (that the Entity Reference module offers) creates a link using the selected bananas node's title.
> 1 votes

# Answer
You can't do this with just Drupal core, but this is easy to do with either https://www.drupal.org/project/references and https://www.drupal.org/project/entityreference. Simply download and enable one of these modules (Node Reference is in the References project), add a field of that type to the new Peaches content type called "Existing Bananas", and configure the field's options and display. You'll have a number of options in both the form field configuration (auto complete, list, etc) and the display (render, link, plain text of title, etc). It's hard to say which is better for your site without knowing what else you are doing. I personally use Entity Reference more often, but that's largely because it is a requirement for Organic Groups and Commerce which I often end up using. Entity Reference requires both Entity API and CTools which will add a lot of code if you aren't already using these.

I would test these modules on a development version of your site and see which one works best for you, but either one should work.
> 0 votes

---
Tags: entities
---


# Question
Title: Is Drupal scalable across multiple geographical locations?
I'm investigating how a Drupal site can be scaled across multiple geographical locations. The primary requirement for this is high availability. The site should be able to run despite some sort of outage on a single location.

The site is a "heavy read, low write" site, meaning that users will never create accounts and edit content. All content is edited by moderators only.

The following two options pop into my mind. I'd be interested in hearing if anyone else have experiences with similar setups - or just general feedback on how viable these options are.

# 1 WAN-wide cluster

A WAN-wide cluster could be achieved using a database cluster and a storage cluster. However, the immediate implications - as far as I see it - is latency. If we choose to go with a MariaDB/Galera cluster (which is synchronous replication), performance will be very dependent on network latency. For storage, something like GlusterFS (separate storage tier) could solve our needs. However, this again is latency dependent and I'm not so sure replication across an entire WAN is a good idea. The idea of a synchronous cluster (Galera/GlusterFS) is compelling as it removes a few timing issues (replication lag) which you need to take into account otherwise.

The other option for a WAN-wide cluster would be a "regular" master-slave database cluster, where we would have a single master database where all content editing is made. The master database will be located in one location, and the other geographical location(s) will have slave databases only. However, you can never guarantee that some Drupal node not will attempt to write to a database - so all Drupal nodes regardless of location will need to have the possibility to get in touch with the master database to execute write queries. This could be achieved using the AutoSlave module. However, this design makes the other geographical locations dependent on the single master node. If some sort of outage happens here, the master node will no longer be available and all other sites will possibly fail. This defeats the entire idea of high availability. With regards to storage, something simple like lsyncd/csync2 or BitTorrent sync could solve file replication. This would be asynchronous file replication, but I don't think that would be a problem as the site is "heavy read, low write". Only a couple of images a day gets uploaded. Cached JS/CSS and thumbnails would possible be excluded from synchronization, which would put a little more load on all frontends - but that would be a question of testing how much load that would be.

# 2 Content sharing between locations

I'm not sure how this one could be done, and I'm afraid complexity grows. However, separate - but identical - Drupal installations could be set up at multiple locations. All content editing could be made at one of the sites (master), which would publish content to the other sites. There would be no database or storage dependencies between the sites. However, I'm not sure if this is all that easy to to - especially when content gets complex with multiple fields, media types, images etc.

# Answer
> 2 votes
I'll address your two points one by one and then discuss suggestions. This is a massive question in scope so I'm doing the best I can with what we've been provided.

**WAN-wide cluster**

Galera would be your best option if you wish to do an Active/Active setup. It's a tricky setup though and only the best hosts have figured it out (platform.sh comes to mind). Your other option is, by far, the most common. i.e. Master-Slave replication. You may find support for that in the Drupal community is more prevalent and that is worth its weight in database queries. :)

**Content sharing between locations**

You have some options when it comes to this. If your editors are to be collocated into a single geographical space, then sharing content isn't a problem. If you have a need to allow editors access from many geographical locations, you can do this in a two primary ways:

* Active/Active using a Galera cluster as you indicated.
* Active/Passive sites using a content deployment model using the Deploy module, Migrate module, Feeds module, or some combination of those.

**Suggestions**

* Start thinking in terms of a single site, not sites. Ultimately, you'll employ a CDN of some kind to deliver content across regions. You had mentioned a concern with freshness of content but there are many ways to achieve the balance. i.e. Look to the Drupal modules Purge, Cache Actions, and Rules.
* Consider Edge Side Includes which will allow the static serving of some content on a page but assets served from the edge for others.
* I can't stress the importance of dedicated Memcache servers enough.
* CDNs, Varnish and a module such as Boost are not mutually exclusive concepts. They can all be employed to keep things fast on the anonymous side. Bear in mind, however, the more layers you add; the greater the possible complexity.

Hope this is helpful.

---
Tags: 7, performance
---


# Question
Title: select image from existing folder without programming
I uploaded a folder of images to my drupal7 server using WinSCP. I know the path name to these folders as shown below.

I have a field image0 defined for a image for each node.

The only option I have for defining what image is assigned to the field is to upload a new file from my computer. I don't see any way to select an existing file I already have on my server. The way I would like to do this is to display a list of files for a ceratin path on my server, like File Explorer on Windows. How do I point the field to the path sites/default/files/images/plants/Plant001/photo01.jpg?

# Answer
> 0 votes
There is a community module for this purpose which can be paired with a WYSIWYG. It's called IMCE. Alternately, you can look at the Media module in Drupal 7 which can help accomplish a similar thing.

*P.S. Have to agree with the commenter. I think you might have answered this searching for "File management Drupal". :) Hint: https://www.drupal.org/node/265416*

---
Tags: media
---


title: Url problem due to htaccess

text:
# Question
Title: Url problem due to htaccess
I uploaded my website here . But when I check the url it doesn't change when I click another page. I used the Rewritebase in my .htaccess to have clean urls. The url should be like kantoorleenknegt.be/contact ....

# Answer
This is not really a drupal question. You are seen the website through a frame The real url is `http://31.186.174.215/~leenkneg/` where the urls work as expected.

To answer your question after the info you gave. One solution is to add an A record to the DNS of the domain. So every http traffic will land to your site but without the users notice and the can have the emails where they want.

So you will have the hosting and the can keep the emails.
> 1 votes

---
Tags: .htaccess, uri
---


# Question
Title: Cannot alter output of a view under any circumstances
I am running into a repeat issue with views and the lack of ability to apply or stick additional classes to a field. We have a "view all content" page that renders fields pertaining to a certain content type and its views through a "Custom Text" field and a variety of excluded fields (so we can render them inside our Custom Text field, to better resemble what the front-end team expects). One of these rendered fields is a hyperlink, and the design team would like to see a class added to it so they can limit a broad set of CSS rules for it.

Okay, simple right? Just go into the field, style settings, and customize its HTML. Done, added classes. But they aren't showing up for this hyperlink. I even tried a more untenable approach of applying a class through a tpl.php rewrite and a Regex. But as long as this field is being displayed through a "Custom Text" field, it does not assign any classes.

The design team has informed me there is no other approach for this given the use of Global Text here. Is there any way to alter what the tokens used by other fields in Drupal output in terms of raw HTML markup, including the addition of other attributes such as classes when taking this design approach?

# Answer
> 1 votes
When you use Custom Text, you are telling Views to override anything it does and display only what you have provided it plus the addition of your placeholders. So what you should do here is exclude the original field from the display and write your HTML with the class into the custom text field. Then, include the field placeholder.

Like this.

```
  <a class="my-class" href="[field_link_url]">[field_link_title]</a>

```

I am pretty sure this gets you the intended result. Note I am making up those placeholders and you should see what your available replacement patterns are. :)

---
Tags: 7, views
---


title: panelizer content not displaying

text:
# Question
Title: panelizer content not displaying
I have installed and enabled the panelizer module and enabled the node\_view template system page on the Page Manager administer pages page. I enabled panelizer for the `Basic Page` content type and created a new page. I clicked the panelizer tab and used the builder layout to create a new row below my body content. I added a region to the row and used the menu to add an existing node to that region.

It looked fine it preview so I saved it and went checked out the actual page where I saw the node content but not any of the panelizer content. The content in my added rows and regions did not display.

I tried uninstalling panelizer and re-installing but it still isn't working. Did I forget something?

# Answer
> 3 votes
Make sure you enable panels node template at admin/structure/pages.

# Answer
> 1 votes
Panelizer 7.3.1 I had this same problem.

Panelized content shows preview, but when I view the live page, it looked like a regular, un-panelized node.

Turned on and off everything I could think of. Pulled out my hair...

Finally, I looked at the Display tab of my content type, and clicked open the Custom Display Settings. I turned OFF "use custom display settings for view modes: Full Content and Teaser". Suddenly my nodes were panelized. Click back on "Full Content", and panels disappear.

I don't know why this matters. Also, I'm using only Default-Panelize & Default-Provide Default Panel for my content type in the Panelize Configuration page.

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


# Question
Title: form_set_error() redirects to raw ajax response page
I have a page with a simple view. Above the view there is a menu link that when clicked loads a node form with a required file field. The form is fetched and loaded using ajax\_commands into a div on the current page.

The problem is when I submit the form without providing a file for the required file field (intentionally triggering error), form\_set\_error redirects the user to the menu path originally called to produce the form (sitename-ajax/new-profile), which displays an unrendered ajax response. How do I get the validation response and return it to the target div on the same page - preventing a page redirect? Code pasted below is simplified for reference. Thanks!

In my hook\_menu():

```
$items['sitename-ajax/new-profile'] = array(
  'title' => t('New Profile'),
  'type' => MENU_CALLBACK,
  'page callback' => 'sitename_ajax_new_profile',
  'access arguments' => array('access content'),
);

```

Page callback:

```
function sitename_ajax_new_profile() {
  $form = sitename_forms_prepare_form('ps_profile');

  $output = drupal_render($form);

  $commands = array();
  $commands[] = ajax_command_html('#new-form-target', $output);

  $page = array('#type' => 'ajax', '#commands' => $commands);

  ajax_deliver($page);
}

```

Form helper function:

```
function sitename_forms_prepare_form($type) {
  global $user;
  module_load_include('inc', 'node', 'node.pages');

  $node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => $type,
    'language' => LANGUAGE_NONE
  );

  $output = drupal_get_form($type . '_node_form', $node);
  return $output;
}

```

# Answer
The API page for form\_set\_error() says (emphasis added):

> When a validation error is detected, the validator calls form\_set\_error() to indicate which element needs to be changed and provide an error message. This causes the Form API to not execute the form submit handlers, and instead to **re-display the form to the user** with the corresponding elements rendered with an 'error' CSS class (shown as red by default).

I reckon that's probably where your problem lies. Further down the same page is this:

> Multistep forms not wanting to validate the whole form can set #limit\_validation\_errors on buttons to limit validation errors to only certain elements.

This *looks* like it might help.
> 0 votes

# Answer
Thanks, Darvanen. Your lead helped quite a bit.

After reading through a few similar issues and reading up on ajax\_commands, I think I found a solution. The trick was adding an #ajax property to my submit button that invoked a callback that checked for any form errors. If any form errors were found, the form on the page needed to be replaced by the original target div - the one that was initially replaced by the current form - which then needed to be replaced by the rebuilt form. A similar process had to be followed to get the $messages presented on the current page. I'm not sure this is the right way (or the 'Drupal' way), but it seems to be working. If anyone has any suggestions, I'd be grateful to hear them!

Here's the module file I was playing around with:

```
/**
 * Implements hook_init()
 */
function sandbox_ajax_init() {
  drupal_add_library('system', 'drupal.ajax');
  module_load_include('inc', 'node', 'node.pages');
}

function sandbox_ajax_menu() {
  $items = array();

  $items['ajax/sandbox/get'] = array(
    'title' => 'Ajax Callback',
    'page callback' => 'sandbox_ajax_ajax_callback',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'delivery callback' => 'ajax_deliver',
  );

  $items['sandbox-ajax'] = array(
    'title' => 'Sandbox Ajax Page',
    'page callback' => 'sandbox_ajax_page_callback',
    'access arguments' => array('access content'),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

/**
 * Implements hook_form_alter()
 */
function sandbox_ajax_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#form_id'] == 'sandbox_file_node_form') {
    $form['actions']['submit']['#ajax'] = array(
      'callback' => 'sandbox_ajax_form_submit',
      'wrapper' => 'sandbox-ajax-wrapper',
      'method' => 'replace',
    );
  }
}

/**
 * KEY TO DISPLAYING FORM ERRORS
 *
 * Custom Ajax Submit Callback
 */
function sandbox_ajax_form_submit($form, &$form_state) {
  $commands = array();
  $form_selector = '#sandbox-file-node-form';

  if (form_get_errors()) {

    // Remove old messages
    $commands[] = ajax_command_remove('#messages-wrap');

    // Replace form with the target div for the rebuilt form
    $commands[] = ajax_command_replace($form_selector, '<div id="sandbox-ajax-wrapper"></div>');

    // Add error messages to page
    $commands[] = ajax_command_after('#main-content', '<div id="messages-wrap">' . theme('status_messages') . '</div>');

    // Replace the div with the rebuilt form - errors included :D
    $commands[] = ajax_command_replace('#sandbox-ajax-wrapper', drupal_render($form));

  } else {
    // If we get here, form validation passed. HOWEVER, if error messages were
    // presented before, they're still hanging out in the messages div. Out with
    // the old, in with the new.
    $commands[] = ajax_command_remove('#messages-wrap');
    $commands[] = ajax_command_after('#main-content', '<div id="messages-wrap">' . theme('status_messages') . '</div>');

    // Finally, replace the form wrapper with an empty div with the original
    // target id.
    $commands[] = ajax_command_replace($form_selector, '<div id="sandbox-ajax-wrapper"></div>');
  }

  // Return the page.
  $page = array('#type' => 'ajax', '#commands' => $commands);
  return $page;
}

/**
 * Page callback
 */
function sandbox_ajax_page_callback() {
  $wrapper = array();

  $wrapper['#attached']['js'] = array(
    drupal_get_path('module', 'sandbox_ajax') . '/js/sandbox_ajax.js',
  );

  $wrapper['container'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'id' => 'sandbox-ajax-wrapper',
      'title' => t('Click to load'),
    ),
  );

  $wrapper['container']['content'] = array(
    '#markup' => t('Loading...'),
  );

  return $wrapper;
}

/**
 * Ajax Form Callback
 */
function sandbox_ajax_ajax_callback() {
  $commands = array();
  $output = sandbox_ajax_prep_form('sandbox_file');

  $selector = '#sandbox-ajax-wrapper';
  $html = drupal_render($output);
  $commands[] = ajax_command_replace($selector, $html);

  $page = array('#type' => 'ajax', '#commands' => $commands);
  return $page;
}

/**
 * Form Prep Helper
 */
function sandbox_ajax_prep_form($type) {
  global $user;
  module_load_include('inc', 'node', 'node.pages');

  $node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => $type,
    'language' => LANGUAGE_NONE
  );

  $output = drupal_get_form($type . '_node_form', $node);

  return $output;
}

```

And here's the JS file:

```
(function ($) {
  Drupal.behaviors.sandbox_ajax = {
    attach: function (context, settings) {
      $('#sandbox-ajax-wrapper').once('sandbox-ajax-wrapper', function() {
        var base = $(this).attr('id');
        var argument = $(this).attr('argument');
        var element_settings = {
          url: Drupal.settings.basePath + 'ajax/sandbox/get',
          event: 'click',
          progress: {
            type: 'throbber'
          }
        };
        Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
        $(this).click();
      });
    }
  }
}(jQuery));

```

Similar issues for reference:

#ajax\['wrapper'\] removed by validation errors

AJAX commands and drupal messages
> 0 votes

---
Tags: forms, routes, ajax
---


# Question
Title: "Search Setting" missing from 'Search And MetaData' section on configuration page
I have a problem. I have a project that uses Domain Access. I recently installed the "Search API" module and attempted to set up an indexing configuration. That all went well, but when I tried to index the items I tried going to Drupal 'configuration' page, and under "Search And MetaData" section, there should be a link called "Search Settings", but there is not.

In a different project that did not use Domain Access I set this up and it works fine. Here is an example of the project that has search api set up properly and "Search Settings" shows up under "Search and Metadata"

I can click on "Search Settings" and it takes me to the "Search Settings" page where I can index my nodes, as well as a few other configuration options.

For my new project that uses Domain Access the "Search Settings" section is missing from "Search and Metadata", behold:

I initially thought it might be a permissions problem, and went to permissions section and the both have 'administrator' set under permissions for "administer search api".

Does anyone have any idea why my new project that uses Domain Access might be missing this page? I tried going to the "Search Settings" page by manually typing the url into my browser, but it said "Access Denied". (I also have Access Denied backtrace set up and no reports were being generated after it gave me the access denied.

The only reason I mention that my new site uses Domain Access is because that is the only major difference between the 2 projects that I can see.

I would really love some help with this, and would consider it my Xmas present. :D

# Answer
I found the answer out. I thought that the "Search Setting" configuration section was created for the "Search API" module, but it is actually for the core "Search" module. Re-enabling the core "Search" module caused the "Search Setting" configuration section to reappear.
> 0 votes

---
Tags: search, domain-access
---


# Question
Title: how to set the author of the feed item to the author of the feed source in feed importer?
I have created a feed importer. I do not know how to set the author of the feed item to name of the original author of the feed? Is there any method to do it? Or will apply any patch? Any patch for this functionality will be welcome.

# Answer
I had a hard time getting this to work.
My current settings work.
Feed Importer
-attached to Feed (content type)
-RSS parser
-Mapping: Description to Description, Title to Title, Item GUID to GUID (Unique), Item URL to URL (Unique), Published Date to Published Date, and Feed Node: User ID to User ID. It is important to have a unique identifier or you get duplicate imports.
The Feed Itself
-Set "Authored By" to a Drupal user on your site. This lets you custom the user. Create a new user if necessary. I created a couple dummy users just to get their names to appear as feed item authors.
> 3 votes

# Answer
Here is the up to date code. Put this code into a custom module to achieve the desired result:

```
<?php

/**
 * Implement hook_feeds_preserve
 */
function MODULE_NAME_feeds_presave(FeedsSource $source, $entity, $item) {
  if ($entity->type == 'WRITE_NODE_MACHINE_NAME_HERE') {
    global $user;
    $entity->uid = $user->uid;
  }
}

?>

```
> 3 votes

# Answer
The Feeds module keeps track of the feed that was used to import each node. All you need is a `nodeapi('presave')` implementation that will pass the feed's author on to the node being imported.

A snippet like this should do it:

```
function YOUR_MODULE_nodeapi(&$node, $op, $a3, $a4) {
  if ($op == 'presave' && !empty($node->feed_node_item)) {
    $feed_node = node_load($node->feed_node_item->feed_nid);
    $node->uid = $feed_node->uid;
  }
}

```
> 1 votes

# Answer
Aaron Kreider gave the right answer. Put it in short, in mapping, set the source "feed node: user id", set the target "user id"; and the node author will be defined as the feed author.

It took me a while to find out this and fulfilled my work. Some people mentioned that you need to do coding, I guess they are talking about previous versions, or perhaps they didn't notice the easy solution.
> 1 votes

# Answer
Importing a CSV file and setting the Author / Authoring field for the node based on a header / column from the CSV file.

Using Drupal 7 with feeds-7.x-2.0-alpha8

1. In my CSV file I have a column with the heading Author.
2. I added a new user with permissions to edit the appropriate content. The user's name came from the Author column in my CSV file. (You must add the user to Drupal before importing the CSV file.)
3. In: Home » Administration » Structure » Feeds » Foo, I set the source field to Author and the target field to Username. (Foo is the name of the custom importer which I created.)
4. I imported the CSV file.
5. Success!
> 1 votes

---
Tags: 7, feeds
---


# Question
Title: How to Configure WebForm to Allow Users to Choose Which CiviCRM Campaign to Contribute to?
Our non-profit currently has a basic donation page via a CiviCRM Contribution page. We would like to add the ability for the user to select which campaign the contribution is directed to.

The Webform CiviCRM Integration Module seems like a necessary component. When configuring a webform, you may direct the contribution to a pre-existing contribution page, but without the ability to expose this to the user. I also looked at apply the Webform Conditional module, but did not see anything that would lead to my desired outcome.

I appreciate any insights in how to create a donation page which provides the user the option to select CiviCRM campaigns.

# Answer
> 5 votes
You can actually do this without Webform-CiviCRM if you like:

* Set up your campaigns in CiviCampaign
* Create a new profile to add a field to (or from the Profiles page, click "Fields" beside an existing profile to add a new field there)
* Add a new "Campaign" field to the profile you are working in (this will list all active campaigns in the profile)
* Add the profile to the Contribution Page in question (note: if you added the field to an existing profile it may already be on the Contrib Page)

# Answer
> 4 votes
You do not need the webform-civicrm module for this, you can use a profile to expose the campaign field to the contribution form. This will add a select dropdown to your form that lists all active, current campaigns.

But if you wish to use webform-civicrm integration, the feature exists there as well. It has the advantage over profiles in that you can configure which campaigns show up in the list, and even rename them on the form if you wish to create more descriptive "user-friendly" names for them.

To add the field, choose "user select" on the contribution campaign field in the civicrm tab of the webform. To configure its options, go back to the webform tab and click "edit" on the campaign field.

---
Tags: civicrm, webforms
---


title: Date Repeat Node Generator Module

text:
# Question
Title: Date Repeat Node Generator Module
I have a Drupal 6 site and am looking for a way to allow my content admins to set up repeat events. I have that set up, but all the repeats are not their own node. I want them to be their own node, so they will appear in my calendar block and in my views on their respective dates.

I've not been able to find a solution in Drupal 6. I found several modules and this one looks promising, but it doesn't seem to be working: https://www.drupal.org/project/date\_repeat\_nodegen

The module's page on Drupal says:

> As part of the node editing form, you'll see a question prompting you to "Generate each date as a single node". Answering yes (the default) will ceate one node for each date in the repeating pattern you've specified, as determined by the Date Repeat API. Each node may be edited separately after creation and used in views. Answering no will create a single node using the repeating pattern, essentially disabling this feature for the node.

But once I activate the module and create a new event, I don't see this question in my form. :-(

Can anyone help me be either showing me a better way of doing this or by helping get this module working?

Thanks!

# Answer
OK, I wanted to post that I figured this out. You have to go to the content type and enable "Repeat". For me it was in the vertical tabs of the Events content type. Once I did that and set it to the date field it worked. BUT the Date Repeat section in the Events content type edit form did NOT work. I just ignored this section altogether and once I create the single event and save, a tab appears above the content titled "Repeat." When I click on that, I see basically the same settings as I did when creating the node, but this time they actually work!!! –
> 0 votes

---
Tags: datetime
---


# Question
Title: How to show search results in view within panels?
I created view & content pane that has many filters and also search term field. In addition, I created a page with page manager and panels, that present this search view (content pane), with more different panels.

My goal is to have search field, on the header of the site, that will be available to user in any time. when the user will decide to use this search field, it will direct them to the search page I created (using page manger & panels), and will show the search results on this specific page.

Can I do that? If so, can you please explain me how?

I read on how to that using views alone, but I couldn't understand how to that with the use of page manager and panels all together.

Thanks.

# Answer
If I understand the question correctly, you would like to send users from a search form to a specific (custom) search results page (which happens to also have some other panels etc on it).

I do not believe the panels/page manager aspect really affects how the search box operates, in which case all we have to do is specify where you would like the search form to send the user.

The following code (~~for an imaginary module entitled customsearch~~ just found existing module entitled custom\_search, not related).

1. creates a block to hold a search form (you can then place this wherever you want)
2. constructs a simple textfield search form to go in the block
3. defines a custom submit to pass the search argument to your customised search results page

## 1)

```
// Implements hook_block_view().
function customsearch_block_view($delta = '') {
  if (user_access('search content')) {
    $block['content'] = drupal_get_form('customsearch_block_form');
    return $block;
  }
}

```

## 2)

```
// Implements hook_forms().
function customsearch_forms() {
  $forms['customsearch_block_form']= array(
    'callback' => 'customsearch_box',
    'callback arguments' => array('customsearch_block_form'),
  );
  return $forms;
}

// Form builder; Output a search form for the search block's search box.
function customsearch_box($form, &$form_state, $form_id) {
  $form['customsearch_form'] = array(
    '#type' => 'textfield',
    '#title' => '',
    '#title_display' => 'invisible',
    '#default_value' => '',
    '#attributes' => array(
      'title' => t('Search the website'),
      'placeholder' => t('search the website'),
    ),
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search'));

  // define function to determine search destination
  $form['#submit'] = array('customsearch_search_box_form_submit');

  return $form;
}

```

## 3)

```
// overide submission of search query from block
function customsearch_search_box_form_submit($form, &$form_state) {
  $searchterm = $form_state['values']['plus_search_form'];
  $search_path = 'specialcustomsearch'// replace with the path to your search results page
  // pass search term to your search results page as argument
  drupal_goto($searchpath .'/'. $searchterm);
}

```
> 1 votes

# Answer
Unless there is a special need, you won't have to add any custom coding. It's even possible to use the standard Drupal search block. If you are using Panels to build your site, you can place it in the header region in the Panels interface, and use CSS to style it.

One caveat, though (I've learned this through experience)--some content displayed in Panels that isn't part of the Node Content may not be properly indexed if not set up correctly. It may be good to reference this other article.

Hope this helps.
> 1 votes

---
Tags: views, panels, search, chaos-tool-suite
---


# Question
Title: Gating/Redirecting anonymous user back to an origin page after logging in/registration
I have a use case where I need to redirect a user visiting a page, let's say `sprockets/order` when a user clicks on an "order" link. We take them to a page with a login field (not `user/login`, but something with that form). Once they log in, we need to redirect them to that page, or for that matter, any origin page they click from to the login page.

I've looked into a couple of modules, right now Login Destination is the one i'm experimenting with, with no real success, even when its routing is configured to fire from this origin page. I'll keep experimenting with it, but I can't imagine its the only option at hand.

The question ultimately is, with the logic below, is there an approach I can take with how I send users to this specialized login page, and have them return to the origin?

The logic I have for this is as follows:

```
/**
 * Implements hook_menu()
 */
function hook_sprocket_menu() {
  $items['order/%order_id'] = array(
    "title" => t("Order Sprocket"),
    "page callback" => "example_order_sprocket",
    "page arguments" => array(1),
    'access arguments' => array('interact with orders'),
    "type" => MENU_LOCAL_TASK,
  );

  return $items;
}

/**
 * Routes the order call based on click
 */
function example_order_sprocket($orderid) {
  global $user;

  if(user_is_anonymous()) {
    drupal_goto("custom/user/login"); //The custom login/reg page
  } else {
    //Continue with Order logic here
  }
}

```

# Answer
> 0 votes
You can have destination parameter in url. Something like below.

```
drupal_goto('custom/user/login', array('query' => array('destination' => current_path())));

```

---
Tags: 7, users
---


# Question
Title: What is the best way to pass values from one form to another with fapi?
I have one form that is just an options input. When I select a value then go to the next page there is another form that I want to have three hidden values based upon the chose value of the first form.

With Form API, what is the best way to pass the value from the first form to the next and have three values from the second form be determined by the single value chosen from the first form?

# Answer
> 1 votes
You can do a multistep form, there is a clear usage example in the Examples module. Here is an excerpt about it from the module's project page:

> The Examples for Developers project aims to provide high-quality, well-documented API examples for a broad range of Drupal core functionality.
>
> The Examples project contains many modules which hopefully illustrate best practices for implementing various Drupal APIs. These modules can be enabled individually, and will typically add menu items to your site, which should guide you through their features. You can then look through the code to see what they are doing.
>
> Developers can learn how to use a particular API quickly by experimenting with the examples, and adapt them for their own use.
>
> Note also that these modules demonstrate internals for Drupal development in PHP (and some JavaScript). Not all Drupal users will need these examples. There are many contributed modules which will do the majority of what a Drupal site-builder could need. Be sure and explore other contributed modules to see if you can find one that meets your needs.

# Answer
> 1 votes
Though multi-step form is your best choice, you can do it with two separate forms as well, using bit of trickery.

Say you have **form\_id\_1** on your **path1** URL. And another **form\_id\_2** on your **path2**.

If you want pass values from the first form to the second, you have 2 options:
1) encode your values in form page path, like **path2/arg1/arg2/arg3**. Obvious downside is that arguments are visible to the user.
2) hijack Batch\<-\>Form workflow. In **form\_id\_1** submit handler use following code:

```
$new_form_state = array();
// list path arguments that usually go into form_id_2 constructor from path2
$new_form_state['build_info']['args'] = array();
$new_form_state['method'] = 'post';
// list values you want to pass.
$new_form_state['values'] = array();
$_SESSION['batch_form_state'] = $new_form_state;
drupal_goto("path2");

```

User will be redirected to **path2** and when **form\_id\_2** is built for that page it will have your values in its $form\_state.

---
Tags: 7, forms
---


# Question
Title: How to treat textfield as integer field while adding sorting in views?
I have a textfield in my content type. It have values like `1, 2, 3, ..., 10`. While I adding sorting it sorts the content `like 1, 10, 2, ...`

I can write the custom handler for it, But how can I treat it as integer in sorting while adding a query. Currently sort handler implements the following query :

```
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);

```

What change I have to do?

# Answer
> 2 votes
Solved it by adding a custom handler and used CAST Functions of mysql and changing the query to :

```
$this->query->add_orderby(NULL, 'CAST(' . $this->real_field . ' AS SIGNED)', $this->options['order']);

```

---
Tags: 7, views
---


# Question
Title: How to attach files to node instead of uploading?
I have 2 content types, Files and Events. Files content type is used to upload files like Image, PDF, Doc etc.

Events content type has a field to attach a document which is uploaded by files content type. The requirement, in event content type I need a field called 'attach files' with maximum five attachment. On click of 'attach files' button, needs to open a page which lists all files uploaded by files content type. On hover of any files an attach button will appear and while clicking it will get attached to the event newly creating event node.

# Answer
> 1 votes
You can achieve the desired results by implementing the *Entity Reference View Widget Module* & *Entity Reference Module*.

# Answer
> 1 votes
Try the Attachment Links module

> The Attachment Links module provides permanent links to files attached to a node. A single, easy-to-remember URL can be used to retrieve the preferred (canonical) or newest version of a file regardless of how many versions of that file have been attached to a node.
>
> Typically, users will want to create a "File" content type and enable the Attachment Links module for that content type. Each "File" node should refer to a single file: "Handbook," "Company logo," "Team roster," etc. Though each node could contain multiple versions of the file, Attachment Link provides permanent link to access the preferred or newest versions.

It seems you can also use the IMCE for FileField module to get the uploaded files from other content type. check this answer posted by me.

---
Tags: 7, files
---


# Question
Title: Main menu not showing on cck type content items
I have that annoying issue with my main menu not showing on nodes of one specific cck content type. The menu shows everywhere else and is set to do so in the block settings by using the Menu Block module.

I just don't get why it's behaving like this. Display of the node is done by using views & context / nothing special in the end. All fields which are visible are generated through views (in content type display settings, all are set 'hidden' - changing this, doesn't help).

Displaying the `$page` variable, the menu's aren't there, too. So which function should I have a closer look on for debugging?

The menu settings allow display everywhere (no restrictions), cache is disabled in the browser / doing drush cc often.

I'm accessing with user 1. (system is D7)

# Answer
> 0 votes
Issue was that the url patterns changed and I still had some old items - so for these the menu didn't display. Don't know why, but updating all content items of that type with the new url pattern solved the issue.

---
Tags: routes, entities, 7
---


# Question
Title: Manual crop is not working when authenticated user adds a new content
I am using the Manual Crop module in my site. Admin and authenticated user can add a content. If admin adds a new content, manual crop enable after picture uploading. But when authenticated user adds a new content manual crop module is disable.

It enable only after save content. After saving content error message comes like this: "Chose cropping styles".

What can I do in this moment in order to do enable cropping after uploading.

# Answer
Manual Crop (currently) doesn't have any permissions of itself, the File entity permissions are only required if you're using the Media module. If you're using an administration theme for node adding and editing, then the users that are allowed to edit nodes should have access to it.
> 0 votes

---
Tags: media
---


title: Alternation of Log in Form in drupal 7

text:
# Question
Title: Alternation of Log in Form in drupal 7
I want to alter the User login form of drupal 7. I want only two fields Email ID and password. I don't want a username field. Please any one have idea to how to do these changes in User login form.

# Answer
> 0 votes
In order to delete the field in a form you have to print the form either using dpm($form) or print\_r($form) and there you will get the field of username use that field to unset in form\_alter .

function hook\_form\_alter(&$form, &$form\_state, $form\_id){

```
  if (form_id=="Your_form_id"){

      unset($form['the_field_you_dont_want']);

        }
   }

```

---
Tags: users, forms
---


# Question
Title: Unable to set file upload destination private when programmatically creating new content type with file field
I am creating a module to upload video to an in house media converter - as part of the module installation I create a new content type called "user video" which has a file field as part of it.

I need to set this file field so it saves to the private files directory, however I am unable to do so. I can create the content type and add the file field - but never manage to get the upload destination to be private.

Sometimes I am able to change this via the admin interface, but sometimes this option is greyed out.

I have included the code below and would be grateful for any assistance.

```
//Create the file upload for the video to be converted
  $field_name = 'uploaded_video';

  //  Create the field definition array.
  $field = array(
   'field_name' => $field_name,
  'type' => 'file',
  );

  $field = field_create_field( $field );

 //  Create the field instance definition array.
  $instance = array(
      'field_name' => $field[ 'field_name' ],
      'entity_type' => 'node',
      'bundle' => 'user_video',
      'description' => 'A field for uploading video and audio content.',
      'label' => 'Video to upload',
      'settings' => array(
          'file_extensions' => 'mp4 avi wmv qti mov',
          'uri_scheme' => 'private',
          ),
      'widget' => array(
          'type' => 'file',
      ),
  );

//  Create an instance of the field and bind it to the bundle.
field_create_instance($instance)

```

# Answer
If your issue is that the radio buttons are greyed out when trying to select the 'private' folder.

I needed SQL access for this one; I emptied the SQL table that relates to the field that stores the images. In my case deleting all items was not enough and I need to manually remove all rows from the table and then put them back after the next stages. in my case table field\_data\_field\_upload\_private files .
> 0 votes

---
Tags: 7, nodes, files
---


# Question
Title: How to correctly sort on accented letters when using the Lexicon module?
I'm facing an issue with the Lexicon module which I still can't figure out.

I have a glossary of French terms, **sorted** alphabetically. And I notice that the **accented letters** are considered as different letters and make the words appear at the end of the list.

Example:

* Dettes
* Dividende
* Droit de souscription
* D**é**bit/crédit
* D**é**pôt de bilan

I found an issue reported here, that seems to match with my own problem.

I tried to apply the last validated patch, using my `.make` file like this:

```
projects[lexicon][patch][] = "https://www.drupal.org/files/lexicon-transliteration_for_lexicon-1275954-13.patch"

```

And proceeding to a deployment, using `phing` like this:

```
phing clean
phing dev-deploy
drush cc all
drush updatedb -y
drush fra -y
drush cc all

```

But it changed nothing.

**EDIT:**

* The patch is applied correctly.
* **In the DB**, when I sort the terms by "name", it appears in the **right order**.

Any clue is welcome!

# Answer
> 1 votes
If you want to find out whether or not the patch is applied correctly, open up `lexicon.admin.inc` and look for this code

```
if ($form_state['values']['lexicon_clear_filter_cache_on_submit'] == 1) {
 _lexicon_clear_filter_cache(NULL, TRUE);
function lexicon_alphabet_form($form, &$form_state) {
 '#type' => 'textarea',
 '#title' => t('Enter all the digits of your alphabet, in the correct order.'),
 '#default_value' => implode(' ', variable_get('lexicon_digits', range('0', '9'))),
 '#description' => t("Separate the digits by a blank. If you don't want terms to start with digits, leave this blank."),
);

```

If the patch has been applied successfully it will look like this

```
function lexicon_alphabet_form($form, &$form_state) {
  '#type' => 'textarea',
  '#title' => t('Enter all the digits of your alphabet, in the correct order.'),
  '#default_value' => implode(' ', variable_get('lexicon_digits', range('0', '9'))),
  '#description' => t('Separate the digits by a blank. If you don\'t want terms to start with digits, leave this blank.'),
  '#rows' => 1,
 );

$form['transliteration'] = array(
  '#type' => 'textarea',
  '#title' => t('Enter transliteration rules used for indexing terms.'),
  '#default_value' => _lexicon_transliteration_ruleset_encode(variable_get('lexicon_transliteration', array())),
  '#description' => t('Use the syntax "é:e,è:e,ê:e,...". Transliteration rules are only applied internaly for indexing. Terms are displayed unchanged.'),
  '#rows' => 1,
);

```

Notice inside the function `lexicon_alphabet_form`, in the `'#description'` attribute `don't` changed to `don\'t` and also the `$form['transliteration']` was added in the patch. If you don't see these changes inside `lexicon.admin.inc` then the patch was not applied correctly. If you do, then the patch did not fix your problem. Hopefully this will help you narrow down where the problem is.

EDIT:

If the patch has been applied successfully, go into the lexicon administration page and set the transliteration rules. Looking at the patch, it looks like it added a textfield for defining the rules you want to use in the following syntax `é:e,è:e,ê:e,...`

---
Tags: 7, drush
---


# Question
Title: Right way to start with a Bootstrap subtheme?
I create my first Bootstrap subtheme (version 7.x-3.0) and I have 3 questions:

**1)** Theres is the file css/style.css which has more than 6400 lines, is this normal. I expected to it to be an empty page to start adding my custom css styles. Is this right?

**2)** I guess that I should not add anything in css/style.css and create my own files.E.g: blocks.css, prodcuct.css. Am I right?

**3)** How to create and declare a new **.less** file. E.g: blocks.less, products.less, etc. I know that the .css files must be declared in the .info file, but not sure about this kind of files.

I uploaded a capture where you can see the folder structure of the subtheme.

# Answer
First of all, there is a guide to begin with subtheming with Bootstrap here. And I recommand you to download the **starter kit** to get ready-to-use subtheme.

**1) and 2)** To create a subtheme, you don't have to edit any files in your base theme. Just create a custom theme, in `sites/all/themes/`, just next your `bootstrap` folder, and declare the `yourtheme.info` file like this:

```
name = yourtheme
description = Custom Bootstrap subtheme
core = 7.x
base theme = bootstrap
stylesheets[all][] = css/style.css

```

It is going to make the **heritance** of all your bootstrap files automatically.

You can create a **new empty css** file, in `yourtheme/css/style.css`, and customize.

You can also create multiple css files, as you said, but you have to declare it in the `.info` file aswell.

3) LESS is supported by Bootstrap. You just have to follow the guide I told you and have a local LESS compiler to generate CSS.

**======**

**BIG EDIT:**

**======**

**How to set up a new Bootstrap subtheme**

**A)** Download Bootstrap project (7.3 is fine to me). Place the bootstrap folder in `sites/all/themes/`.

**B)** Download jQuery Update project, which is required by Bootstrap. Go to `yoursite/admin/config/development/jquery_update` and set the default jQuery version to **1.9**.

**C)** In your `bootstrap` folder, you're gonna find `bootstrap_subtheme` folder. Move it to `sites/all/themes/` and **name** it `banana` (let's suppose your custom theme is called Banana). So you have `bootstrap` and `banana` folders at the **same level**.

**D)** In `banana`, **rename** the `bootstrap_subtheme.info.starterkit` file to `banana.info`. And edit its content like this:

```
name = Banana, a Bootstrap Sub-theme
description = A Bootstrap Sub-theme called Banana.
core = 7.x
base theme = bootstrap

```

**E)** Now you have a pretty new Banana theme, inheriting all from Bootstrap theme, and that you can **activate** in `yoursite/admin/appearance/`.

**F)** If you want to try a customization, go to `sites/all/themes/banana/css` and make a little change to `style.css` (see, it is not 6400+ lines ;-)). Refresh your site and see if it is applied.

**G)** If you want to work with **LESS**, you have to set up a local LESS compiler on your computer. This one seems to be simple to install and configure. *Personaly, I use SASS and Ruby Gem to compile, so I cannot give your further information about another compiler here. Maybe someone will.*

**H)** Once you're ready with your compiler, you just need to make your **edit** in `sites/all/themes/banana/less/` folder. All the `.less` files that appear here are included in `style.less`. This is the one you have to compile (only this one) to generate `css/style.css`. Bootstrap gives you **3 empty files** where you can put your code, `content.less`, `footer.less`, `header.less`. You can use them or just **create new ones** (don't forget to import them in `style.less` if you add new files).

**I)** Make some **changes**, **compile** and **refresh** your site. See if it is applied.

I wish you good luck (and a merry Christmas ^^)
> 12 votes

---
Tags: theming
---


# Question
Title: Can't login: user/login redirects to index page
My Drupal 7 user, user login and admin pages all redirect to the index page. I am unable to login at all. This problem came up recently after the site had been unchanged for months. I can't think of a single reason this started happening all of a sudden.

Nothing looks funny when I debug in my browser. I have the following details based on my research:

* No errors are appearing.
* There were no updates, automatic or manual, to the site or modules.
* I'm not using Secure Pages, Ubercart SSL, or any other SSL modules that might interfere. The site is pretty basic, simple Zurb Foundation theme, Views, and a couple other small modules, nothing fancy.
* `$base_url = 'http://sohp.us'; // NO trailing slash!` Is specified in my `settings.php` file (located in root/public\_html)
* The Drupal instance was installed through cPanel's Softaculous
* I downloaded the default `.htaccess` for Drupal 7 and replaced the existing one (no changes required).

It seems like the PHP for bringing up the login isn't working correctly, but I could definitely be missing something obvious or compeltely different from what I've been trying. If anyone has any suggestions on things to test out to get myself back in, it is much appreciated.

Thank you.

# Answer
Do you have drush installed? I would try clearing cache as a first step, probably won't fix it but worth a shot. After that try renaming the theme that you are using to force Drupal to use a different theme, or change the theme manually in the database. Try disabling modules one by one to see if any of them might be interfering. Start with any module that changes paths (like PathAuto...). I also noticed that no matter what your site will not throw a 404 page not found error. If that was intended, then whichever process you used to redirect 404's to index.php could possibly be causing an issue.
> 0 votes

---
Tags: users
---


# Question
Title: Create a view with user filter by default and all users after reset
I come here because i want to create a view who display all content of type "Document" of my website, but by default i want to show the content of type "Document" of the user connected. And after when i click on the button reset of the view, i want to see all content of type "Document" of all users.

For example the view when i come on the page :

Me | document 1
Me | document 3
Me | document 4
Me | document 6

When i reset the view :

Me | document 1
Jean | document 2
Me | document 3
Me | document 4
Jean | document 5
Me | document 6
Mickael | document 7

this is possible ?

Thanks

# Answer
This is possible. What you want to look into here is the concept of Views Contextual Filters. So you'll set this up something like this:

This will allow you to have a default view that works on the currently logged in user. Then you can setup another Exposed Filter which shows all authors. Hope this helps.

*Thanks to this somewhat related post for the image.*
> 0 votes

---
Tags: views, users
---


# Question
Title: Views: how to enable Title Link per role?
In Drupal 7 Views, there is an option to Link title field to the original piece of content. How can I enable the link per role? I only want to show the link for administrator and staff, so it will be much easier to modify.

# Answer
Drupal 6 had a view node permission, but it was removed from Drupal 7 for some reason.
This module adds it to Drupal 7:
https://www.drupal.org/project/node\_view\_permissions

If only the administrator and staff have the view node permission, only they should see the link in your view.

This of course will also only allow administrators and staff to view the node page too.

You could also create a template for that view field.
In the view settings, under advanced, there should be a 'theme' link. Click it to see what your field theme file should be named.
> 2 votes

---
Tags: views, entities, navigation, users
---


# Question
Title: Problem dynamically populating a select field based on the selection of another select field
I have seen quite a few questions on here about the "Illegal choice has been detected" error when trying to load a select field with AJAX in Drupal 7. I have not yet been able to find an answer to solve my issue though. I have 3 select boxes Year, Make, and Model. When I select a year the makes populate fine. When I select a Make, I get the Illegal choice detected error and the models do not populate. But if I choose another make everything works fine. Can anyone help me figure out why the first attempt doesn't work? Here is the code that I have

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

  $form['year'] = array(
    '#type' => 'select',
    '#options' => _load_years(),
    '#ajax' => array(
      'callback' => 'formblock_make_loader',
      'wrapper' => 'make_div',
    ),
  );

  $makes = array('empty' => 'Select Make',);
  if (isset($form_state['values']['year'])) {
    $makes = drupal_map_assoc(_load_make($form_state['values']['year']));
  }

  $form['make'] = array(
    '#type' => 'select',
    '#options' => $makes,
    '#prefix' => '<div id="make_div">',
    '#suffix' => '</div>',
    '#ajax' => array(
      'callback' => 'formblock_model_loader',
      'wrapper' => 'model_div',
    ),
  );

  $models = array("empty" => "No Model");
  if (isset($form_state['values']['make'])) {
    $models = drupal_map_assoc(_load_model($form_state['values']['year'], form_state['values']['make']));
  }

  $form['model'] = array(
    '#type' => 'select',
    '#options' => t($models),
    '#prefix' => '<div id="model_div">',
    '#suffix' => '</div>',
  );

  if (isset($form_state['values']['make'])) {
    $form['model']['#options'] = _load_model($form_state['values']['year'], $form_state['values']['make']);
  }

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

  return $form;
}

function formblock_make_loader($form, $form_state) {
  // The form has already been submitted and updated. We can return the replaced
  // item as it is.
  return $form['make'];
}

function formblock_model_loader($form, $form_state) {
  return $form['model'];
}

function formblock_submit($form, &$formstate){

}

function _load_years(){
  $thisyear = date('Y');
  $years = array();

  foreach(range(1990, $thisyear) as $year) {
    $years[$year] = $year;
  }
  return $years;  // array
}

function _load_make($year) {
  $makes = array();

  // Make API call and get an array of makes

  return $makes;  // array
}

function _load_model($year, $make) {
  $models = array();

  // Make API call and get an array of models

  return $models;  //array
}

```

# Answer
> 0 votes
I got it working finally. I don't fully understand it, if anyone sees what happened and can explain it I would appreciate it. To fix it I changed

```
$makes = array('empty' => 'Select Make',);
if (isset($form_state['values']['year'])) {
  $makes = drupal_map_assoc(_load_make($form_state['values']['year']));
}

```

to

```
if(isset($form_state['values']['year'])) {
  $makes = drupal_map_assoc(_load_make($form_state['values']['year']));
}
else {
  $makes = array('' => 'Select Make');
}

```

and

```
$models = array("empty" => "No Model");
if (isset($form_state['values']['make'])) {
  $models = drupal_map_assoc(_load_model($form_state['values']['year'], form_state['values']['make']));
}

```

to

```
$models = array('' => 'Select makes');
if (!empty($form_state['values']['make'])) {
  $models = drupal_map_assoc(_load_model($form_state['values']['year'], $form_state['values']['make']));
}

```

# Answer
> 0 votes
You're wrapping your model select options array in `t()`

i.e: `'#options' => t($models)` vs `'#options' => $models`

Try this instead, it might work:

```
  $form['model'] = array(
    '#type' => 'select',
    '#options' => $models,
    '#prefix' => '<div id="model_div">',
    '#suffix' => '</div>',
  );

```

---
Tags: 7, ajax
---


# Question
Title: Is Windows XP and XAMPP able to render complex development sites in Drupal 7?
I am developing a site, and in the Linux server it goes very fast, with peaks of memory of 40 MBytes, according to Devel module. However, when I test it exactly the same in Windows XP and Xampp, it takes a long time to serve each page, even if the memory usage is a little less - (25 Mb !? ). When Drupal 7 is freshly installed, with default configuration, it is very fast, but when I add modules, etc., it takes ages to load any page, even if the memory usage is low as I said. Memory limit of PHP is 128 Megabytes.

# Answer
Sorry if my question was not well formatted. It happens that the theme installed was rebuilding on every page load, and that consumed lots of RAM. I switched off the rebuild, and it worked very fast, as expected. It was not a specific OS problem, but a performance one due to theme rebuilding
> 0 votes

---
Tags: debugging
---


# Question
Title: How to validate an AJAX form which uses CTools?
I have a form which opens in a modal CTools window. The forms submits perfectly, but when I try to use the my\_form\_validate() function, it never goes to that function, it always go directly to my\_form\_submit() function? I have tried to "uncode" the CTools modal windows example provided with the module, but I am not able to decipher it.

# Answer
I have just discovered that I had mistyped mymodule\_my\_form\_validate as my\_module\_my\_form\_validate. Your reply has made me look into the function and now it works perfectly. Somehow I thought the method was much more convoluted as involved AJAX. Sorry, this is very embarrasing. In any case, your reply saved me a lot of time.
> 1 votes

---
Tags: forms, ajax, chaos-tool-suite
---


# Question
Title: How to add to the commerce order the author's email? Cannot theme nor add anything to it!
I have this order at /admin/commerce/orders/oid/view

By default, the order won't display the user's email nor username, so I wanted to know how to access them and printed them out.

I created a tpl file called: **page--admin--commerce--orders.tpl.php** and typed into it:

```
print "<pre>";
$vars = get_defined_vars();
print_r($vars);
print "</pre>";

```

I got this result (it's trimmed, but you can read that the uid is 76 -there's no name though-, and the user's email is demo@example.com):

```
Array
(
    [template_file] => themes/seven/page--admin--commerce--orders.tpl.php
    [variables] => Array
        (
            [page] => Array
                (
                    [#show_messages] => 1
                    [#theme] => page
                    [content] => Array
                        (
                            [devel_execute_php] => Array
                                (
                                    [execute] => Array
                                        (
                                            [#type] => fieldset
                                            [#title] => Execute PHP Code
                                            [#collapsible] => 1
                                            [#collapsed] => 1
                                            ...

                            [system_main] => Array
                                (
                                    [commerce_order] => Array
                                        (
                                            [2340] => Array
                                                (
                                                    [commerce_line_items] => Array
                                                        (
                                                            [#theme] => field
                                                            [#weight] => 0
                                                            [#title] => Line items
                                                            [#access] => 1
                                                            [#label_display] => hidden
                                                            [#view_mode] => administrator
                                                            [#language] => und
                                                            [#field_name] => commerce_line_items
                                                            [#field_type] => commerce_line_item_reference
                                                            [#field_translatable] => 0
                                                            [#entity_type] => commerce_order
                                                            [#bundle] => commerce_order
                                                            [#object] => stdClass Object
                                                                (
                                                                    [order_number] => 2340
                                                                    [revision_id] => 7766
                                                                    [revision_uid] => 1
                                                                    [mail] => demo@example.com
                                                                    [status] => pending
                                                                    [log] =>
                                                                    [revision_timestamp] => 1418617139
                                                                    [revision_hostname] => 190.191.78.169
                                                                    [data] => Array
                                                                        (
                                                                        )

                                                                    [order_id] => 2340
                                                                    [type] => commerce_order
                                                                    [uid] => 76
                                                                    [created] => 1409009029
                                                                    [changed] => 1418617139
                                                                    [hostname] => 201.255.45.102
                                                                    [commerce_line_items] => Array
                                                                        (
                                                                        ....

```

After reading-some-information-around-the web, and the book Drupal 7 Module Development (chapters 3 and 4), I tried (unsuccessfully) all these:

```
print render($content['#object']);
print render($content['#object']['mail']);
print render($content['#object']['uid']);
print render($variables['content']['#object']['uid']);
echo render($content['content']['#object']['uid']);
print render($variables['page']['content']['system_main']['commerce_order']['2340']['commerce_line_items']['#object->mail']);

```

# Answer
> 1 votes
Try

```
print render(commerce_order_load(2340));

```

I'm thinking the user id will be something like

```
$order = commerce_order_load(2340);
$order['uid'];

```

from there you can do

```
$customer = user_load($order['uid']);
print render($customer->name);
print render($customer->email);

```

But try to print commerce\_order\_load and take a look at that output first.

---
Tags: entities, commerce, theming
---


# Question
Title: Custom entity, entity_save() leads to PDO Exception?
I have built a custom entity called 'person'.

In a module called 'beautify' I use a hook.

Inside this hook I want to create an instance of this object with bundle 'person'. (entity: 'person', bundle: 'person')

In my bundle person I have different fields created by the fields UI. One of these fields is called 'field\_person\_copy'. The colums of this table called 'fields\_data\_fields\_person\_copy' are created by the drupal system: entity\_type, bundle, deleted, entity\_id, revision\_id, language, delta, field\_copy\_person\_value. The field is required.

I want to use the drupal system to create new persons, not a db\_inject.

```
  function beautify_contact_person($message){
  // dpm($message);
  $e = entity_create ('person', array(
    $entity->name = $message['params']['last_name'],
    $entity->field_person_copy['und'][0]['value'] = 'NO',
    ));
  //dpm($e,'Instanziiert eine entity');
  entity_save('person', $e);

```

(Testing with entity-\>save let the system say that this method is undefined.)

This leads to the following error message:

```
  PDOException: SQLSTATE[23000]: Integrity constraint violation:
  1048 Column 'entity_id' cannot be null: INSERT INTO {field_data_field_person_copy}
  (entity_type, entity_id, revision_id, bundle, delta, language, field_person_copy_value)
  VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2,
 :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5,
 :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] =>
 person[:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3]
 => person [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und
[:db_insert_placeholder_6] => NO ) in  field_sql_storage_field_storage_write()
(Line 451 von /home/duke/sites/mia-casa/modules/field/modules/field_sql_storage/field_sql_storage.module).

```

which means that the system doesn't generate the entity\_id and fuels it in the function.

So is that a bug of the entity\_api or from me? (I hope the latter) ;)

In my custom\_module to build the entity, I only overwrote the function "buildContent" in the class EntityApiController, so create, save and update is not influenced by me.

Thx in advance,

maen

# Answer
> 1 votes
The problem is centred around this bit of code:

```
$e = entity_create ('person', array(
  $entity->name = $message['params']['last_name'],
  $entity->field_person_copy['und'][0]['value'] = 'NO',
));

```

It's sort-of-technically-valid PHP (though you don't have a variable named `$entity` in scope), but certainly isn't doing what you expect. It's almost like you're trying to apply a feature from another language (like object initialisers from C# maybe).

I'm guessing somewhat, but I imagine what you're trying to do is:

```
$e = entity_create ('person', array(
  'BUNDLE_KEY' => 'BUNDLE_NAME',
  'name' => $message['params']['last_name'],
));

$e->field_person_copy[LANGUAGE_NONE][0]['value'] = 'NO';

entity_save('person', $e);

```

Or maybe

```
$e = entity_create ('person', array(
  'BUNDLE_KEY' => 'BUNDLE_NAME',
));

$e->name = $message['params']['last_name'];
$e->field_person_copy[LANGUAGE_NONE][0]['value'] = 'NO';

entity_save('person', $e);

```

Where `BUNDLE_KEY` and `BUNDLE_NAME` are whatever you have set up for your entity type.

# Answer
> 0 votes
Thx for your input! All of you, because your criticism helped me a lot!

I could solve it like this:

```
function beautify_contact_person($message){
$e = entity_create ('person', array(
    'name' => $message['params']['last_name'],
    'prename' => $message['params']['name'],
    'customer' => 0,
    'type' => 'person',
    'field_person_copy' => array(
        LANGUAGE_NONE => array(
            0 => array(
                'value' => 'NO',
            )
        )
    ),
    'field_person_tel_privat' => array(
        LANGUAGE_NONE => array(
            0 => array(
                'value' => $message['params']['phone'],
            )
        )
    ),... `
 )->save();
}

```

It was the 'type' that irritates me ...

---
Tags: entities
---


# Question
Title: How to retrieve the order id of an order in drupal commerce?
Is there a way to do it from the tpl?

ie: **page--admin--commerce--orders.tpl.php**

I've tried this, but naturally, I get an undefined **$order\_id** variable

```
if (commerce_order_load($order_id)) {
  echo $order->uid;
}

```

# Answer
> 4 votes
If you're looking for the order ID related to the current cart you can use `commerce_cart_order_id()`:

```
$order = commerce_order_load(commerce_cart_order_id());

```

But you shouldn't use it directly in a template file. Use a preprocess hook instead, it's better all round.

---
Tags: commerce
---


# Question
Title: Transferring default user picture field to new user picture field
Drupal 7.

I have a site where users can upload a picture of themselves (default Drupal field: user picture.) This field is used in different views.

I would like to use the *User Picture Field* module and use the field provided by the module instead of the default Drupal user picture field.

Switching fields in the views is a simple operation and it works well with newly uploaded pictures. However, with pictures uploaded before the installation of the module, the pictures displayed are no longer the users' pictures but the default "no photo" image.

Is there a way to have the (older) photos of the default user picture field transferred to (or at least displayed by) the new field?

Thanks. :)

# Answer
I think the easiest way would be to do it at the database level. Copy the old field contents into the new field.
> 1 votes

---
Tags: users
---


# Question
Title: 3 vocabulary and taxonomies in this vocabularies
I want to use vocabulary and stored in separate taxonomy vocabularies to create urls, and breadcumbs; is it possible?

Drupal 7

I want to get the schema: a vocabulary 1 a taxonomy 1 a taxonomy 2 b vocabulary 1 b taxonomy 1 b taxonomy 2 c vocabulary 1 c taxonomy 1 c taxonomy 2 effect to get :

User type in 1 node a vocabulary 1 a taxonomy 1 b vocabulary 1 b taxonomy 2 c vocabulary 1 c taxonomy 1

breadcrumbs (diff vocabularies ) a taxonomy 1 \>\> b taxonomy 1 \>\> c taxonomy 1

url path for taxonomy:

a taxonomy 1 / b taxonomy 1 / c taxonomy 1 /

# Answer
> 2 votes
Your question is not well-asked but this is the answer:

1. Yes, you can have multiple vocabularies, multiple taxonomy terms in these vocabularies and also multiple child-terms in these taxonomy terms. It's one of the **core** functionality of Drupal.
2. Yes, the breadcrumbs can show the taxonomy hierarchy as you wanted but it depends on the **theme** you use.
3. Yes, it's possible to show taxonomy terms in url with Pathauto module.

---
Tags: taxonomy-terms, uri, breadcrumbs
---


# Question
Title: Can I tell CKeditor to NOT TOUCH my HTML code?
I am using the CKeditor module only as an administrator, so I don't need any security protection.

When I add Google Adsense code into a block, CKeditor stripes away the `<ins>` tag. I am aware of this solution though I rather want CKeditor to not stripe away anything. In other words: I don't want to whitelist any tags, I just want to be sure that nothing gets deleted. Is there a solution for this?

Another way might be: Can I configure the *Switch to plain text editor* toggle to START with a plain text editor as default, allowing me to *Switch to rich text editor*?

**UPDATE:** Some additional info: I'm using the latest version of CKeditor, loaded from: `//cdn.ckeditor.com/4.4.3/full-all`

The profile in use is "Full HTML". In its settings at ADVANCED CONTENT FILTER "disabled" is checked. In ADVANCED OPTIONS, Custom JavaScript configuration, I have set:

```
config.fillEmptyBlocks = false;
config.autoParagraph = false;
config.allowedContent = true;

```

To reproduce the problem, just toggle to plain text, paste the following HTML, toggle to rich text and to plain text again. Only "foo bar" will remain.

```
foo <ins class="adsbygoogle" style="display:inline-block" ></ins> bar

```

# Answer
Even 'Full HTML' does some html tampering - you could try creating a new text format for Admins only without any restriction at all - this is what I usually do for adsense and it has always worked great without the need for another module.
> 2 votes

# Answer
Depending on your CKEditor version, it may be the "Advanced Content Filter" at work there.

> ACF is a highly configurable CKEditor core feature available since CKEditor 4.1. It limits and adapts input data (HTML code added in source mode or by the editor.setData method, pasted HTML code, etc.) so it matches the editor configuration in the best possible way. It may also deactivate features which generate HTML code that is not allowed by the configuration.

In particular

> If you want to disable Advanced Content Filter, set `CKEDITOR.config.allowedContent` to `true`. All available editor features will be activated and input data will not be filtered. Note that you cannot use `CKEDITOR.config.disallowedContent` when ACF is disabled.

Documentation on configuration of ACF can be found here: http://docs.ckeditor.com/#!/guide/dev\_advanced\_content\_filter
> 1 votes

# Answer
Partial solution/workaround: I found the option to start the plain/rich text toggle with the plain text editor. That way, I can edit the Google Adsense blocks without them being messed up, and on other blocks I just switch on the CKeditor if I need it.

Where the setting is: `config/content/ckeditor` -\> Profiles, Edit -\> EDITOR APPEARANCE -\> Default editor state: Disabled
> 0 votes

---
Tags: wysiwyg
---


# Question
Title: Drush sql-sync failing with Ubuntu 14.04
I'm having no luck with sql-sync, there's two seemingly unrelated errors it's throwing at me which I'll detail below.

I've been successfully sql-sync'ing the same site to another server, so I'm pretty sure it's the remote server, not the local server, that is causing the problems. The remote server MySQL version is: 5.6.19-0ubuntu0.14.04.1 (Ubuntu)

1) Adding the `--create-db` switch gives me:

`ERROR 1044 (42000) at line 1: Access denied for user 'user'@'localhost' to database 'database'`

2) Regardless of whether or not I use the `--create-db` switch, I always get this:

```
ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode is enabled and mysql is run in non-interactive mode. Set --binary-mode to 1 if ASCII '\0' is expected. Query: '��T'.

```

Any ideas?

# Answer
> 2 votes
So it turns out I'd installed Drush 6 on the remote server, while my local version was Drush 7. Upgrading solved the problem.

---
Tags: database, drush
---


# Question
Title: How to theme a preprocess function output with a default, without the need of a .tpl file?
I created this simple function in order to print out the commerce order author UID and email.

**How may I add the output of the function inside the messages area, without creating a special .tpl?** I want that information to be in a special place regardless of the theme implementation.

This is the preprocess function (the only way I manage to get to know if I was inside an order)

```
function MYMODULE_preprocess_page(&$variables) {
    //si estamos dentro de la orden, lo sabemos sólo en función del link en el que estamos!
    $uri = request_uri();
    $find = '/admin/commerce/orders/';
    $pos = strpos($uri, $find);
    if ($pos !== false){
        //usando if (commerce_order_type_get_name($type = 'order')) no andaba
        //obtenemos el número de orden: obtenemos el link con request_uri()
        //y de ahí lo explotamos en un array. Sabemos que el número será siempre
        //la última parte del link (4).
        //usamos commerce_order_load('id de la orden') para obtener el usuario que la completó
        $uri = request_uri();
        $partes = explode('/', $uri);
        $usuario = commerce_order_load($partes[4])->uid;
        $correo = commerce_order_load($partes[4])->mail;
        $estado = commerce_order_load($partes[4])->status;
        echo "<div class='messages status'><a href='/user/".$usuario."'>".$correo."</a> (".$estado.")</div>";

    }

}

```

As you can see, I've tried with this horrible:

```
echo "<div class='messages status'><a href='/user/".$usuario."'>".$correo."</a> (".$estado.")</div>";

```

Even when the classes are the same as the rest of the drupal messages, the output keeps appearing at the very top of the page.

How may I do it the right way? (Maybe it necessarily involves template.tpl file?)

# Answer
I didn't realize that I could simply use drupal\_set\_message()!

```
drupal_set_message(t("<a href='/user/".$usuario."'>".$correo."</a> (".$estado.")"), 'status');

```
> 0 votes

---
Tags: theming
---


# Question
Title: Why are comments not a node content type?
So Drupal has a 'special' commenting system.

> Comments are second-class citizens in Drupal compared to nodes...

But why did the core team not just create a default Content Type, Block and View for comments, and allow the site administrator add in a comment block as necessary? Just like the 'Article' and 'Basic Page' content types, which we can create blocks and views for. Why are comments so different?

# Answer
To answer this, I first had to understand one thing: ***Entities are not nodes***.

**Entity Types** are special groupings of fields.

**Node** is an entity type, which *requires* some fields, such as 'Title', 'Author' and 'Publish Date'.

**Content Types** are instances of Node which further define more fields. So a 'blog post' content type can have 'Hook', 'Introduction', 'Summary' and 'Related posts' fields, in addition to 'Title', 'Author' and 'Publish Date'.

Node is an entity type specialized for content. A comment is not designed to be a node because it is too different from a typical content. It's not necessary to have a 'Title', 'Author' or 'Publish Date' field in a comment. Because it is so different, it is created as another *Entity type* instead.

For more details, see this article on Drupal.
> 8 votes

# Answer
In Drupal 8 nodes and comments (and custom blocks and user added menu links and users and taxonomy terms and...) are entities both. While in D7 an entity was indeed just for a bundle of fields -- I still remember when they were simply `$object` and there was no API at all. In Drupal 8 entities have a proper CRUD API; they are classed objects with save, load etc. And comment settings are now a field so everything fieldable is commentable. The mind boggles at the possibilities (commented comments? Commentception! even that is possible AFAIK).
> 0 votes

# Answer
Just as a sidenote, sometimes perhaps you really do not need the power of the core Comments entity, but just a simple list of comments or notes (without replies) associated to the Content Type or Entity.

In these cases, you may lighten your system load disabling the Comments for that Content Type, and using just a field for storing the comments or notes.

At least 2 contrib modules provide this kind of field:
> 0 votes

---
Tags: 7, nodes, comments
---


title: Strip caption from image using css

text:
# Question
Title: Strip caption from image using css
I am adding a caption to images by using the following module: https://www.drupal.org/project/image\_field\_caption

For the front page I am using views. There, I also show the images but I do NOT want to show the captions. I guess the captions can be stripped away by using CSS...

How is that done? I do not know CSS and the "interaction" of Drupal and CSS very well.

My questions: 1. Where do I have to add the CSS code? 2. What do I have to write there? 3. How is this CSS snipped included in views to get the effect of stripping caption away?

Thanks!

# Answer
if this is strictly a css question, I believe it's off-topic here, but...

I've never worked with that module, so this may or may not be an option:

If you output your View as a table, you can modify how fields are represented. Unless the module overwrites the default image formatter, you should be able to choose the Image formatter instead for that field and bypass the module.
> 0 votes

---
Tags: views, theming
---


# Question
Title: How can I get a list of all available entity view modes?
I need to have a list of all available view modes for an entity type so I can use it as the `#options` in a select field.

Any ideas? Thanks

# Answer
I think you are talking about view modes for entities.

```
$entity_info = entity_get_info('node');
debug(array_keys($entity_info['view modes']));

```

It would result as

```
array (
  0 => 'full',
  1 => 'teaser',
  2 => 'rss',
  3 => 'search_index',
  4 => 'search_result',
)

```
> 14 votes

# Answer
You may also want to use this function...

```
field_view_mode_settings($entity_type, $bundle);

```

https://api.drupal.org/api/drupal/modules!field!field.module/function/field\_view\_mode\_settings/7
> 2 votes

---
Tags: 7, entities
---