# Question
Title: How to use tokens in a filtered text field
In Drupal, when you create a field, there is the option "Text Processing". You can select either "plain text" or "Filtered text".

When I create a field with "Filtered text", I am unable to use it as a token.

For example, on my content type "content\_page", I have a long\_text field called "intro\_text". The "Text Processing" is set to "Filtered text".

If I use this field as a token, it just won't work. This happens in a variety of modules including Meta Tag and Path Auto.

Even if I set the text format in the token, it still does not render. (e.g. \[node:field-intro-text:plain\_text\]).

If I change the "Text Processing" to "Plain text", it works, so the problem lies with "Text Processing".

How can I get the token to work when it set to "Filtered text"?

# Answer
I am using this module Token Insert Text

Perhaps you need this to get it to work. (I know my version is outdated, I did this a long time ago)

Then go to admin/config/content/ckeditor/edit/Advanced and under EDITOR APPEARANCE

Scroll alway the way down and click save.
> 1 votes

# Answer
You want Advanced Text Formatter:

> **Options**
>
> * Trim length: The maximum number of characters the a field can be. Set this to 0 if you don't want to cut the text. Otherwise, input a positive integer.
> * Ellipsis: If checked, a "..." will be added if a field was trimmed.
> * Word Boundary: If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.
> * Token Replace: Run token replace on this field.
> * Filter: Filter the value of this field.

**EDIT**

*Text Processing* on a Text Field or Text Area Field has nothing to do as to whether or not the field can be used as a token.

A `token` is a symbol to be replaced by text. For security reasons tokens are usually sanitized by the system when they are placed into content -- and malicious content is not *cleaned* by the system but usually usually clobbered (destructively) out of the source input.

Eg, a text field with like `<span class="foo">Hello Hello</span>` would not be seen as "hello hello" as a token but an empty value because `<span>` tags are removed by sanitization (removed and not wiped).

If you want to try to use a text field with an `Input Filter` you then have to supply `field formatters` for the item that will display the item cleanly for other fields expecting certain values such as Paths or Meta Tags. Eg, paths do not contain markup, and I assume meta-tags should not contain html entities.

One option is the Formatted Field Tokens. Which would allow you to define a token that uses a field formatter (similiar to your example of `[node:field-intro-text:plain_text]`) but even plain text would not replace ' ' in a title with say '-' or '\_' to be a valid Path *url*. You would likely also need to enable the Transliteration module for your field to assure the text input is valid (and binding transliteration to your custom field(s) may take some code. the FileField Sources module does this for file titles and paths on the filesystem if you want to see example code that does this).
> 0 votes

---
Tags: tokens, input-formats
---


# Question
Title: How to Make File Description Field Required?
Use case: Users who are authorized to use the edit page are required

1. To upload at least one file
2. Must have an associated description with the file.

Plus: How can I edit "Description" to display "Alternative File Name" ?

# Answer
> 0 votes
depending on your needs, this could be accomplished using Field Collection, adding an image field and a description field (which can be made required) to the collection:

> Provides a field-collection field, to which any number of fields can be attached.
>
> A field collection is internally represented as an entity, which is embedded in the host entity. Thus, if desired field collections may be viewed and edited separately too.

---
Tags: files
---


title: Applying image style to Privatemsg

text:
# Question
Title: Applying image style to Privatemsg
Drupal 7: Privatemsg.

The following statement, when included in the *privatemsg-view.tpl.php* template prints the author's picture:

```
print theme('user_picture', array('account' => $message->author));

```

How do I modify it to include an image style?

Any help is greatly appreciated. Thank you. :)

# Answer
> 3 votes
This is off the top of my head with some parts but I think this is the way you would do it.

`print theme('image_style', array('path' => $message->author->picture->uri, 'style_name' => '{image-style}'));`

With {image-style} replaced with image style that you want like thumbnail.

If this doesn't work I will take a second look.

---
Tags: media, privatemsg
---


# Question
Title: How do you add custom help text to content entry/edit screens unrelated to field?
I use field groups to break my fields into "tabbed" areas for my content editors. I would like to be able to put some kind of help text at the beginning of each of those blocks to explain the entire section of entry. Each of the fields already have their own help text, this would be above all the fields.

# Answer
I usually do this with a `form_alter` myself in PHP code or I use the `help` entry for a Field.

Recently I found out about the Markup module. I recommend you try it out. I have no added it to any of my projects yet, but it's on my todo list.

> This module adds the ability for site admins to add "Markup" widgets to the form. These essentially let designers of cck content-types insert additional markup into the node/edit form to display to content-authors. This is the equivalent of adding additional elements to $form of the type '#markup'.
>
> The module does not add anything to the $node object for the content being created, and utilizes form\_alter to remove unnecessary fields from the '\_content\_admin\_field' form when this widget is being created.
> 1 votes

# Answer
One solution would be to create a block for each tabbed section. Then show the block based on the current path/url. Ensure that the block is enabled in the content top region, that way it will be displayed above your fields.
> 0 votes

# Answer
The markup module is pretty easy to use and would do what you're looking for. https://www.drupal.org/project/markup

Other plus is that you can easily move it around on the page with no theming and you can still fine tune the look and feel with css if needed
> 0 votes

---
Tags: nodes
---


title: sort by subject in privatemsg

text:
# Question
Title: sort by subject in privatemsg
Is there any possibility to sort all the messages by subjects? For example, there is a button on the main page "send a message to author". Subject from the sender is defined as "main page". If several users send message with this subject, can i see in my mailbox one subject "main page" and then see the list, who wrote it?

# Answer
Messages in the inbox can be filtered by subject. To do so, if you are on the default path (`messages`), just click the blue link for "Subject" at the top of the table.

Alternately, if you want to always filter by subject, you can change the messages link to this: `messages?sort=asc&order=Subject`.
> 0 votes

---
Tags: privatemsg
---


title: Private message to be saved as a draft

text:
# Question
Title: Private message to be saved as a draft
I want a Functionality in Private message module drupal 7.x. That the message I am creating should be saved as a draft. how do I achieve this ?

# Answer
> 0 votes
There was a patch for this for 6.x but it has not been updated for D7. If you want this feature now, you'll have to build it yourself.

---
Tags: privatemsg
---


# Question
Title: privatemsg and services fully integration
Does there exist any module even sandbox or starting point module (not ublished on drupal.org) to help achieve privatemsg crud operations over services module.

# Answer
There exist a sandbox project pm services clone comand

```
git clone --branch 7.x-1.x    https://git.drupal.org/sandbox/deminy/2413647.git privatemsg_services

```

cd privatemsg\_services

also pm services(profile2) but it needs profile2 to be enabled beore
> 2 votes

# Answer
The current discussion on integrating Privatemsg for Drupal 7 and Services can be found here.
> 1 votes

---
Tags: services, privatemsg
---


# Question
Title: How can I include PHP code from another file in hook_nodeapi()?
I am embedding HTML and loading JavaScript code in a node using `hook_nodeapi()`.

```
function first_order_decay_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($op == 'alter') {
    $path = drupal_get_path('module', 'first_order_decay');
    $path .= '/';
    $code = file_get_contents($path . 'templates/first_order_decay-static.tpl.php', false);
    $code = preg_replace("/[\r\n]*/","",$code);
    $code = preg_replace("/<!--EMBEDREMOVE-->.+<!--EMBEDREMOVE-->/","",$code);
    $pos = strpos($node->body, '[FLOT](kinetics1)');

    if ($pos !== false) {
      $node->body = substr_replace($node->body, $code, $pos, strlen('[FLOT](kinetics1)'));
    }
  }
}

```

How can I parse PHP into HTML from the `$code` variable? It seems that because the page is already in the rendering process, Drupal ignores the PHP code. Is there another phase of `hook_nodeapi()` I can use to do this?

# Answer
> 1 votes
The function used by Drupal to render a template is `theme_render_template()`, used by `theme()`.

```
  extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
  ob_start(); // Start output buffering
  include "./$template_file"; // Include the template file
  $contents = ob_get_contents(); // Get the contents of the buffer
  ob_end_clean(); // End buffering and discard
  return $contents; // Return the contents

```

You can adapt that code to your need.

As for using the code you are using, I am not sure I would do the same. The main problem with your code is handling directly the template files; Drupal 8 changes how the template files are rendered, and your code would need to be changed.
Apart this, there is a better way to achieve what you are trying to achieve, using a theme function that uses a template file. See `node_theme()` and what that function returns for the node theme function. Drupal doesn't uses template files directly, when rendering a node, but it calls the theme hook with `theme('node')`.

The pro of using a theme hook is that the output of your module could be alter from another module, if that would be necessary.

# Answer
> 1 votes
As i get you, you need to implement hook\_theme and use it, instead parsing php code.

Please, see anwser here: https://stackoverflow.com/questions/12985689/how-to-implement-hook-theme-in-drupal-7

---
Tags: nodes, 6
---


# Question
Title: Drupal 8 settings.yml file doesn't reflect changes
So I'm trying to define some additional values in my settings.yml file, but none of my changes are reflected in the code. The config object has the same values in it. I've tried drush cr and other measures to clear the cache, but nothing works.

# Answer
> 1 votes
yml files are just imported on module install time.

If you need runtime changes, during development, have a look at https://www.drupal.org/project/config\_devel

---
Tags: 8
---


title: Changing configuration using form

text:
# Question
Title: Changing configuration using form
I have created a form using which I want to make changes in the configuration.Currently I am submitting form doing something like this:

```
 public function submitForm(array &$form, FormStateInterface $form_state) {
  \Drupal::service('config.factory')
    ->getEditable('module.settings')
    ->set('module_entities', $form_state->getValue('module_entities'))
    ->save();
 }

```

But the problem is when I have submitted the form changes in the configuration are not reflected.But when I clear the cache after submitting the form the changes are reflected.what changes should I make so that when user submits form the changes are reflected thereafter?

Update: I tried to find my mistake and found out that configuration is getting updated but somehow the changes getting lost and not being reflected in the block which I have created. In the block creation code I am creating blocks for different entities depending on the entities present in the configuration.But the configuration is not showing correct values so block for required entities is not being created.Surprisingly when I clear cache the code works(which means configuration becomes updated).Does this mean for block creation I need to clear cache? I am currently using this code:

```
 `public function getDerivativeDefinitions($base_plugin_definition) {
   $this->derivatives[$entity_type] = $base_plugin_definition;
   $this->derivatives[$entity_type]['admin_label'] .= ' (' . $entity_definition->getLabel() .')';
   $this->derivatives[$entity_type]['cache'] = ?;

```

}\`

What should I add over here to make block depend on configuration without clearing cache? In the plugin I am returning:

`public function build() {
return array(
 '#theme' => 'links__entity__module',
 '#links' => $this->linkBuilder->buildLinks($this->request->attributes->get($entity_type)),
 );
}`

# Answer
Blocks are cached by default.

You don't need to manually clear those caches when you change your configuration, but you need to flag/tag your blocks output to tell Drupal that your block output depends on your configuration.

Read the Cacheability documentation. What you need is something like this:

```
$output['#cache']['tags'] = $config->getCacheTags();

```
> 3 votes

# Answer
Something which I did in my form was:

```
    public function submitForm(array &$form, FormStateInterface $form_state) {
        $config = \Drupal::configFactory()->getEditable('module.settings');
        $userInputValues = $form_state->getUserInput();

        $config
            ->set('module_entities', $userInputValues('module_entities'))
            ->save();
        parent::submitForm($form, $form_state);
    }

```
> 0 votes

---
Tags: forms, 8, configuration
---


# Question
Title: Soft and hard copies of a single product in Drupal Commerce?
I am setting up products for an online store using Drupal Commerce. Some of the products (eg. books, music) require an option for both hard copies and soft copies so that customers can choose one or the other. I would like certain products to have a drop down in which customers can choose either "Hard Copy" or Soft Copy" and the price will change accordingly. Then depending on the option chosen, after payment, the customer will get a confirmation email for the hard copy, while for the soft copy they will also get the download link.

I have installed Commerce File to cover the soft copy option, since Drupal Commerce handles the hard copy option out of the box (being a manual shipping process), however I cannot see how this can be done using this module. I have created a commerce file product which allows for soft copies, and a standard product which allows for the hard copies; but how do I create a product that has both of these as an option? Is Commerce File not the module for this?

# Answer
> 0 votes
After some more experimenting I have worked it out. For any sort of product variations you need to edit the Product reference field. Change the field to a select list and also make sure the you set the number of values to unlimited (or at least more than 1). This will then create a drop down list which when changed will switch between the different products within the same node. I hope that this helps!

---
Tags: commerce, files
---


title: Views filter using user field

text:
# Question
Title: Views filter using user field
I have a webform for students to select their teachers. The data displayed in Views to show the submitted values are the following:

----------------------------------
Instructor | student
----------------------------------
teacher A | student name A
teacher B | student name B
teacher A | student name C
teacher A | student name D
--------------------------------

When "teacher A" login, I am expecting "teacher A" can see all his students, without entering filter value "teacher A"

----------------------------------
Instructor | student
----------------------------------
teacher A | student name A
teacher A | student name C
teacher A | student name D
--------------------------------

I want to have something like automatic filter with the field "Instructor", not typing own name in the exposed filter. So every teacher can get his own students automatically in the table.

Is there any specific module to do that, or a way to get that?

# Answer
> 1 votes
if instructor is a user entity (or reference), you can add a contextual filter in your view for your field, like this:

---
Tags: views
---


# Question
Title: How to flag or unflag an entity with multiple flags at once?
I have a large number of user Flags created. When a user performs certain actions on the website a Rule is triggered Flagging them (based on the action) which in turn provides that user with additional access and other privileges. When the user performs an exceptional action on the website the user is Flagged with several Flags all at once, providing them with multiple privileges all at once.

The reason I am using Flags instead of Roles is because there is quite a large number of actions that can be performed on the website; and trying to manage the permissions for such a huge amount or Roles is not only unwieldy but it takes up unnecessary database space, which Flags do not.

So the question then: Is there a way in Rules to Flag a user with multiple flags all at once? For example fetching a list of all Flags based on a Flag property, and then setting all of the flags in this list to "Flagged" for the specific user? At the moment I am setting a single Rules action for every single Flag that needs to Flag the user under certain conditions. This works but is very time consuming. If there is a better to way achieve this without Flags I am open to that as well.

# Answer
> 0 votes
> Is there a way in Rules to Flag a user with multiple flags all at once? For example fetching a list of all Flags based on a Flag property, and then setting all of the flags in this list to "Flagged" for the specific user?

Yes *there a way in Rules to Flag a user with multiple flags all at once* (as in your question), and maybe even by some kind of fetching as you described. However, you can for sure use the Conditional Rules module to flag a user with multiple flags all at once. Here is a sample rule to illustrate how such rule would look like:

```
{ "rules_flag_a_user_with_multiple_flags" : {
    "LABEL" : "Flag a user with multiple flags",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules_conditional", "flag" ],
    "ON" : { "flag_flagged_superuser" : [] },
    "DO" : [
      { "CONDITIONAL" : [
          {
            "IF" : { "NOT flag_flagged_user" : {
                "flag" : "follow",
                "user" : [ "flagged-user" ],
                "flagging_user" : [ "flagging_user" ]
              }
            },
            "DO" : [
              { "flag_flaguser" : {
                  "flag" : "follow",
                  "user" : [ "flagged-user" ],
                  "flagging_user" : [ "flagging_user" ],
                  "permission_check" : "1"
                }
              }
            ]
          },
          {
            "ELSE IF" : { "NOT flag_flagged_user" : {
                "flag" : "friend",
                "user" : [ "flagged-user" ],
                "flagging_user" : [ "flagging_user" ]
              }
            },
            "DO" : [
              { "flag_flaguser" : {
                  "flag" : "friend",
                  "user" : [ "flagged-user" ],
                  "flagging_user" : [ "flagging_user" ],
                  "permission_check" : "1"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

```

Some details about the above rule, which uses flags with machine names `superuser`, `follow` and `friend`:

* Rules Event: A user has been flagged, as "superuser".
* Rules Actions:
    + **If** the flagged user is NOT flagged with flag "follow", by the flagging user, **Then** flag the flagged user, with flag "follow", by the flagging user.
    + **If** the flagged user is NOT flagged with flag "friend", by the flagging user, **Then** flag the flagged user, with flag "friend", by the flagging user.

If you adapt the machine names of the flags to fit your own flag names, you should be able to import it in your own site (provided the Conditional Rules module is enabled also).

So with that, a user that gets flagged with `superuser`, and which is not yet flagged with `follow`, will also be flagged with `follow`. And the similar for the `friend` flag.

BTW, even though this answer is about entities of type "user", you can use a similar technique for any entity.

***Easy, no?***

PS: I'm assuming this question is about D7 ...

---
Tags: rules, flags
---


# Question
Title: Why won't my images appear inside buttons?
In the page displayed, there is a row of buttons that each say "Submit Query."

The HTML for one of these buttons is:

```
<INPUT TYPE="image" SRC="../images/OneLine30px.png" CLASS="select-button" ID="OneLine">`

```

I've also tried slightly modifying the paths to these images. This HTML is in a `.tpl.php` file which is inside the `templates` directory. The `images` directory is a sibling of the `templates` directory.

1. Why is Drupal displaying "Submit Query" instead of the image?
2. How can I get Drupal to display the images?

# Answer
> 2 votes
I'd strongly advise to use CSS for this, it's much more easier to apply and you won't hit path related issues.

# Answer
> 0 votes
Your "src" attribute is a relative path, but on the web, it won't be relative to the "templates" directory where your tpl.php file lives. It will be relative to the current URL path, instead.

Try using absolute paths starting with "/", and see if that gets the images showing.

---
Tags: media
---


# Question
Title: Body field is not displayed in Comment Views
I have a comments listing view. When I make the the row style as comments everything is displaying fine. But when I make the row style as fields and add the comment:comment field to the list, the comment body is not showing up.

Things I have checked

1. There is no field access for this field.
2. The field is using the default template, so it is not being overridden.
3. Checked the body field display settings, it is configured to show and format plain text is enabled.
4. I am previewing the view as admin so there should be no access concerns as well.
5. The view is showing other fields normally.
6. "Exclude this display" box unchecked.
7. Changed the theme to Bartik and also disabled the javascript to be double sure.
8. Comment related modules I have are ajax-comments and onecomment module. I disabled both, rebuilt permissions and cleared the cache :)

# Answer
> 0 votes
Well.. at this point you may have to resort to the following.

First of all, make a backup of your database.

Plan A) Disable views and uninstall it (so all the database tables are erased), then delete the views folder. Download it again, upload the folder and enable it. If this fixes your problem, you can use the view's export/import to quickly import all the view's you had.

Plan B) Disable every module you have in sites/all/modules folder except for Views. Then if it works now, enable them one by one to see which one is causing this.

Plan C) If A or B doesn't work, well... I hate to say it, reinstall Drupal :(

# Answer
> 0 votes
Sometimes permissions are declared as constants... and sometimes constants are declared this way:

```
define(MY_MODULE_PERMISSION,'My module permission');

```

Depending on the PHP configuration the name of the constant will be assumed as 'MY\_MODULE\_PERMISSION'... but not always.

Using this constant in hook permission will lead you to very weird problems. Check your custom modules and make sure you declare constants with its name as string, like this:

```
define('MY_MODULE_PERMISSION','My module permission');

```

Hope that helps.

PD: The code which I'm referring worked fine on Acquia but throw problems on Platform.sh. You can imagine how difficult it was to find the culprit.

---
Tags: comments
---


title: Webform submissions and og_group_ref

text:
# Question
Title: Webform submissions and og_group_ref
We are building a web site that relies heavily on organic groups. We provide in the front page a webform to allow non-authenticated people to submit a request of membership to one of the main groups (there are subgroups also).

What I need is the webform to work as it does out of the box, but as soon as a submission is sent, subscribe it to a group. Inside the group, a user which belongs to a certain role will accept/reject the membership request.

So far, I have learned that if you add the feature 'is group content' to the webform content type, it affects to the webform but not to the submissions (i.e. unauthenticated users can't reach the webform since the group in the og\_group\_ref is configured as 'private' (and it has to be this way).

TLDR: I need the submissions of a webform to be able to be assigned the og\_group\_ref attribute as they are submited. Is it possible?

TIA

# Answer
> 0 votes
Interesting question/challenge (+1 from me ...). What you described about the "is group content" makes those webforms indeed unreachable for anybody who is not part of that group (so that's a "works as designed" ...

However, how about using the Rules module to complete your puzzle? Haven't looked at all the details (yet), to see if it can actually be done (I'm pretty sure it can ...), but I'm thinking of using a rule that looks more or less like this:

**Event**: when Webform is submitted

**Condition**: If membership for group is requested in the submitted form

**Action**: Send eMail to an authorized user to accept / reject the request

# Answer
> 0 votes
Well, I'll provide an abstract of the solution of the sorts I came with for this problem.

* hook\_node\_load: I fill a dropdown box with the suitable groups (db\_select). The anonymous user can fill all the data up and select to which group the submission is 'going to be sent'.
* in the target groups, I've set up a view (panelized) that filters by the value of the group requested by the anonymous user being the same as current.
* in hook\_form\_alter I hide the dropdown box if editing an existing submission. Also, I hide a checkbox ('grant membership') if it is the original submission (meaning anonymous user cannot see it or use it).
* I've set og\_permissions so as to who can edit submissions. The allowed editors can then edit a submission and use the 'grant membership' checkbox to accept the request.
* hook\_webform\_submission\_update: if the 'grant membership' checkbox value is 1, then programmatically create user and assign membership to current group.

I'd hoped for an easier way to solve it, but it is working great.

Cheers

---
Tags: webforms
---


title: Search API Referencing entity relations

text:
# Question
Title: Search API Referencing entity relations
I am working on a project where i would like to be able to create a search api view that has a relation to the referencing entity.

The use case:

I have a content type: **Products page** that holds the commercial information about the product

I then have a content type **Product** that holds all the specifics (article number, serial numbers etc)

I have created a search api view on the content type **Products Page** that shows all the commercial information in the catalog with some facets end an exposed full text search box.

Each product node has an entity reference to the Products page node it belongs to

Of course, i would like visitor to be able to search for article numbers in the fulltext search. The result needs to to show the Products Page node that is being referenced by the product node that holds the article number that was searched for.

However i cannot see how i can create the relation that you would normally use when using a regular view?

Addtionally and example below:

Products Page node: Chairs (with body and image) Product nodes: \- Wooden chair (art nr 123, and entity ref to Chairs) \- Metal chair (art nr 456, and entity ref to Chairs)

So when ppl search art nr 123, i want my view to show the Products page node "chairs".

Thanks in advance!

# Answer
Implement hook\_entity\_property\_info\_alter()

```
function MY_MODULE_entity_property_info_alter(&$info) {
    $info['node']['properties']['article_number'] = array(
        'type' => 'text',
        'label' => t('Article number'),
        'getter callback' => 'MY_MODULE_get_article_number',
    );
}

function MY_MODULE_get_article_number($node) {
    if ($node->type == 'product_page') {
        // Return the article number from the referenced product node
    }
}

```

Go to admin/config/search/search\_api/index/{index\_name}/fields and select the property. Now you can use this property like any other field.

In your case you need to configure this field in you view. I assume you added Search: Fulltext search to your filter criteria. Click on this filter and add the property to the Searched fields settings.

I hope this works for you.
> 1 votes

# Answer
You could also try https://www.drupal.org/project/entityreference\_backreference as a more generic solution.
> 1 votes

# Answer
I've just created this configuration and it worked for me.

Create the index, lets say Products index.

In the Fields Tab, select the fields you want to index from the main content, which in your case should be art nr in full text mode.

Then go to the filters tabs and select Bundle filter then check *Only those from the selected bundles* and select Product.

Then clear all index and index again.

Now you can create a view for the index, then create the relation and add the filelds you want to show checking the relation.

Now expose the fulltext search, and search for the number.

You can't apply a relation to the Rendered entity as you can do to content in normal views but i think you can handle with fields to show the result data.
> 0 votes

# Answer
You can add an extra property to your entity via hook\_entity\_property\_info\_alter(). Return the article ID via the defined getter callback. Select the property in the fields settings of your search api index.

In your view you can add this property to the "Searched fields" setting of the "Fulltext search" filter.

If you need more details, let me know.
> 0 votes

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


title: Boost, not caching

text:
# Question
Title: Boost, not caching
How does HTTP Parallel Request & Threading Library module help with Boost to increase performance ? How buggy is Boost module, cause it is giving me hard time not caching pages faster.

# Answer
> 1 votes
The HTTPRL module doesn't increase Boost performance, per se. It is a requirement for the Boost Crawler submodule. The crawler module ensures all pages are actively cached; it goes through all site content and requests all its pages so that Boost stores them in its cache.

The HTTPRL module is used here to speed up the background crawler requests; it doesn't need to wait for a HTTP response to get the main Boost module to store things in its cache. The performance boost comes from having all your site content cached so that no anonymous user doesn't take cache hit (i.e. they have wait for the site to build the cache since it's not ready).

---
Tags: 7, caching
---


# Question
Title: Options in facets disappear when more than one value is selected
We have setup a custom search with Search Api and Search API Solr Search. In a facet we want to allow the selection of multiple values, with the normal link widget. We have configured the facet to use the `OR` operator. Everything works as expected until we select more than one value. With more than one value selected, the search result is still correct, but all other options disappear. This is not the behaviour we want, we would like to continue displaying all options, in the same way it works after the user selected a single element.

# Answer
This is a bug with solr 3.5 and the `search_api_solr` module, the bug is described here:https://www.drupal.org/node/2474661 the bug report includes a patch that fixes the issue. With the patch in place everything works as expected.
> 1 votes

---
Tags: search
---


# Question
Title: Only one of my site node's doesn't print it's alias
I use the latest version of the famous Pathauto module and my site pages have Automatic alias that are shown well in the URL navigation bar of the browser... All of these pages are in Hebrew, But one of the pages which is in English, doesn't show it's alias and only node/20 is being printed...

For example you could go on all main-menu links and see it, instead of that one...

Here is a live example in my site.

What can cause it? Thanks!

# Answer
See comments - I don't know what was the problem but re-creating the page (took about 40 seconds) fixed the problem.
> 0 votes

# Answer
assuming you are using Pathauto to accomplish this, try:

* check the settings under /admin/config/search/path/settings and make sure the Update action is set to Create a new alias, Delete the old alias
* edit the node, and make sure the 'generate automatic URL alias' is checked and save the node again - this should reset the alias for the node
> 1 votes

---
Tags: path-aliases
---


# Question
Title: Hide the page titles of some content types
I found following code on this website http://codekarate.com/content/hiding-page-titles-specific-node-types-drupal-6 to hide the page titles of some content types.

Can some one help me rewrite this for drupal 7 ??

```
function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('NODETYPE'))) {
    $vars['title'] = '';
  }
}

```

# Answer
> 1 votes
Just wanted to let you know that there is a module that does this Exclude Node Tittle

# Answer
> 1 votes
The code should work just fine in Drupal 7. But note that it only works on node pages (where the URL is `node/[nid]`) and does not work on lists of teases make with Views or the default Drupal frontpage.

I made a small modification to the code below using 'page' and 'article' as example content types instead of `NODETYPE`.

```
function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('article', 'page'))) {
    $vars['title'] = '';
  }
}

```

# Answer
> 1 votes
If you don't want to use exclude\_node\_title you can do this:

on your theme edit the template.php and add/modify this hook:

```
function YORTHEME_preprocess_page(&$vars) {
 $vars['show_title'] = TRUE;
  if (isset($vars['node'])) {
    if ($vars['node']->type == 'YOURTYPE') {
      $vars['show_title'] = FALSE;
    }
  }
}

```

and on your page.tpl look for the part where the title is shown and use the show\_title variable in this way:

```
<?php if ( ($title) && ($show_title) ): ?>
  <h1 id="page-title">
    <?php print $title; ?>
  </h1>
<?php endif; ?>

```

---
Tags: nodes, theming
---


# Question
Title: How to add integer field to content type?
I am trying to add year field to content type. I selected integer as field type, then i see text field as widget. How can I set to 4 digits max and allows only numbers only?

Thanks, D

# Answer
> 1 votes
You could use the Date Module

Then when you add a new field, select Date as your Field Type.

When you configure it use something like this

# Answer
> 0 votes
If I understand correctly, you want a field validator. There is a module for Field Validation.

Here is a nice tutorial on number formats.

I'm curious why you are using Year as an integer type. Did you try using the Date Field Module?

---
Tags: entities
---


title: Deleting field collection items

text:
# Question
Title: Deleting field collection items
There is a content type called *library* which has a field collection type as a field and unlimited number of this field is allowed. I used Devel module to generate 200 nodes of library, so more than 1000 field collection items were generated. after deleting the nodes from `/admin/content` the field collection items were not deleted. How do I can delete these field collection items?

After a few search I found this code

```
for($i = 1 ; $i <= 700 ; $i++)
    entity_delete_multiple('field_collection_item', $i);

```

but it deleted nothing.I also found a few other codes on Drupal Stackexchange but none of them worked.

Thanks

# Answer
You could delete the field collection records from there – either through custom Drupal code, or through direct database access if you have that.

Since you have devel enabled and you are generating content, I'm assuming you're not working on a production site, but it's worth saying that deleting records from the database is a risky proposition.

I'm also assuming that you want to delete **all of the field collection data** for this field collection and not cherry pick just the content that was generated by devel.

You didn't mention what your field collection or its fields were named, but let's say that you have a field collection with the machine-name *testcollection* and in that collection you have two fields with machine-names *collectionfield* and *collectionfield2*.

The data for these will be stored in several tables. In my example, *collectionfield1* and *collectionfield2* are text fields. Therefore the data will be stored like so:

```
{field_data_field_testcollection}        // the field collection
{field_revision_field_testcollection}    // the field collection (revisions)
{field_data_field_collectionfield}       // field attached to "testcollection"
{field_data_field_collectionfield2}      // field2 attached to "testcollection"
{field_revision_field_collectionfield}   // revisions
{field_revision_field_collectionfield2}  // revisions

```

You could remove the fieldcollection content by running the following queries:

```
DELETE FROM field_data_field_collectionfield WHERE bundle = 'field_testcollection';

DELETE FROM field_data_field_collectionfield2 WHERE bundle = 'field_testcollection';

DELETE FROM field_revision_field_collectionfield WHERE bundle = 'field_testcollection';

DELETE FROM field_revision_field_collectionfield2 WHERE bundle = 'field_testcollection';

```

If you have data in the testcollection field even after deleting the generated nodes, you should delete that too:

```
DELETE FROM field_data_field_testcollection;

DELETE FROM field_revision_field_testcollection;

```
> 0 votes

---
Tags: nodes, entities
---


# Question
Title: How can I check the value of an aggregated field without direct access to Solr?
I'm using Search API Solr on Pantheon (which means I don't have direct access to the Solr backend), and I've set up an aggregated field in the UI. This aggregated field is a **Fulltext** aggregation of a boolean field and a Countries module field, but it isn't working as I am expecting.

Search API Views allows the indexed fields to be displayed, but it does not display the values of aggregated fields. I can filter by the value of the aggregated field, but since I don't know what the values look like in the aggregated field, I'm at a loss about what to input. So I need to check the value of the aggregated field somehow, but there appears to be no way to do this through any of the module UIs.

**What I tried**

I have tried running `dpm()` on the `$view` object through a views template, but as far as I can tell the aggregated fields are not stored there; they are queried on the Solr server, so Views doesn't touch them directly.

As an alternate approach, I went to the search index config page (`/admin/config/search/search_api/server/MYINDEX/edit`) and selected *Retrieve result data from Solr*, but that didn't give me the values of the fields, either.

# Answer
> 0 votes
There is a way to do this in Views.

Go to the search index config page (/admin/config/search/search\_api/server/MYINDEX/edit) and selected Retrieve result data from Solr. Then clear all caches a few times to be sure they are really clear.

After that, you can go back to the view and add the aggregated fields as **Fields** to the display.

---
Tags: search
---


# Question
Title: Rule action to remove a product from the cart? (using the commerce module)
I'm using the commerce module to show product in a site.

I need to create a rule on the event of **Calculating the sell price of a product** which should involve removing products from the cart in a given condition.

I see that there is an action to **Add a product to the Cart**. But how do I remove a product from the cart?

Should I use the **Remove from list** action?

# Answer
Check what rszrama, the Drupal Commerce leader, says about this:

> If you find and delete the line item, it should work just fine. You can do this with the "Delete entity" action. You could also just unset the price of the line item you want deleted during "Calculating the sell price of a product." That's what the "Unset the price of disabled products in the cart" default rule does, so you can refer to it for an example. Unsetting the price just involves setting the amount to NULL (i.e. no value, not 0).

http://drupal.org/node/1267156#comment-4937288
> 5 votes

# Answer
Another way of doing this is to follow RFay's great video on using a component and looping. This method can be combined with Commerce Rules Extra to build a lot of complex business workflows for your cart.
> 1 votes

---
Tags: commerce
---


# Question
Title: Struggling with View Slider Image Rotation
I'm struggling to let the images rotate with the View Slider module.

When I add an image of content type of say -\> image\_slider. At the moment it only replaces the current slider image with the latest published content of type image\_slider instead of rotating between the images.

Where can I set/change this?

Thanks in advance!

Edit: I added 2 images to one node and now when I think it wants to rotate between the images I get this error in the console: Uncaught TypeError: Cannot read property 'action' of undefined

# Answer
> 1 votes
The basic setup for the slider depends on two factors:

1.) A collections of nodes of a particular type, in your case image\_slider.

2.) A view that manages the slideshow outputting it as either as a page, block or both.

So, initially go to create (for example) 3 nodes, each containing an image, as the content-type image\_slider.

Then go ahead and access your view under admin/structure/views and ensure that:

* The format (under Format) is set to Slideshow
* You are "showing" (Show:) Fields (under Format)
* That you have selected your image field to be called (under Fields).
* That your filter criteria has the content type set to image\_slider
* **Finally, that under "Pager" (in the second column) you have set the pager to display "All Items" - you can change this later to limit the output but for now this will ensure that all node-fields, which meet the previously mentioned conditions, will be output.**

Once all of these conditions are met, save the view and it should already display the slider in action at the bottom of the page as part of the preview. If everything went smooth, you can now access either your view-page output or set the block under blocks to display your slideshow throughout your website.

---
Tags: views, 7, javascript
---


# Question
Title: How can I serve different view blocks based on media queries?
I have 4 view blocks that I want to show up as carousels on mobile. I'd like to be able to clone them, turn the clones into carousels with this module https://www.drupal.org/project/slick, then serve them in place of the others somehow. I know I can use css to serve both and hide them but that doesn't sound like a good idea.

# Answer
> 0 votes
You can try Browsecap and Browsecap Block modules to show blocks only on mobile devices.

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


# Question
Title: Join two tables (users and userpoints_total)
I'm working with Drupal Commerce, and I am currently developing a new module that displays the best customers that have a maximum points in a single block.

I want to do a join between the two tables (users and userpoints\_total)

```
$query = db_select('users', 'u')
  ->fields('u',array('name','uid'));
$query->join('userpoints_total', 't', 't.uid = u.uid');
$results = $query->execute();

```

That works but in the block views I can't see anything. This is the code:

```
    function best_client_block_view($delta = '') {
      switch ($delta) {
        case 'best_client':
          $block['subject'] = t('Les meilleures Clients Chez nous');
          if (user_access('access content')) {
            // Use our custom function to retrieve data.
            $result = best_client_contents();
            // Array to contain items for the block to render.
            $items = array();
            // Iterate over the resultset and format as links.
        if (is_array($result) || is_object($result))
            {
            foreach ($result as $node) {

              $items[] = array(
                'data' => t($node->name),

              );
            }
        }
           // No content in the last week.
            if (empty($items)) {
              $block['content'] = t('No user available.');
            }
            else {
              // Pass data through theme function.
              $block['content'] = theme('item_list', array(
                'items' => $items));
            }
          }
        return $block;
      }

    }

```

How can I fix that?

# Answer
You don't call a result set method on your query. Try `$results = $query->execute()->fetchAll();` and have a look at the results via devel or something similar.

I believe that `block['content']` defaults to markup but theme functions return HTML strings not renderable arrays so you could try to use the #markup key to make them render.

```
$block['content']['#markup'] = theme('item_list', array('items' => $items));

```

Or use the theme as a part of the render array.

```
$block['content'] = array(
  '#theme' => 'item_list',
  '#type' => 'ul',
  '#items' => $items
)

```
> 1 votes

---
Tags: 7, database
---


title: how do I debug a Drush bootstrap issue?

text:
# Question
Title: how do I debug a Drush bootstrap issue?
Apologies for the length of this post. I have a Drupal install where the drupal files (and all content) is on one server, and the database is on another. The site itself is working fine, and all admin tasks are possible from the admin UI.

However, when I try to execute any commands using Drush, I get output similar to the below.

command used: `drush up --debug`

Output:

```
Starting Drush preflight. [0.04 sec, 4.13 MB]                        [preflight]
Cache HIT cid: 7.0.0-commandfiles-0-7b327cc676585aaed226364ef9373982     [debug]
[0.07 sec, 4.22 MB]
Bootstrap to phase 0. [0.34 sec, 10.28 MB]                           [bootstrap]
Bootstrap to phase 6. [0.34 sec, 10.29 MB]                           [bootstrap]
Drush bootstrap phase : bootstrap_drupal_root() [0.35 sec, 10.86 MB] [bootstrap]
Initialized Drupal 7.34 root directory at                               [notice]
/users/castaff/dfitzpat/public_html [0.37 sec, 10.86 MB]
Find command files for phase 1 (max=6) [0.37 sec, 8.49 MB]               [debug]
Cache HIT cid: 7.0.0-commandfiles-1-3ca83829a6f5d5a7b3d70d3f4652b7de     [debug]
[0.37 sec, 8.5 MB]
Drush bootstrap phase : bootstrap_drupal_site() [0.38 sec, 8.51 MB]  [bootstrap]
Initialized Drupal site default at sites/default [0.38 sec, 8.51 MB]    [notice]
Find command files for phase 2 (max=6) [0.39 sec, 8.51 MB]               [debug]
Cache HIT cid: 7.0.0-commandfiles-2-f17fc6bdab2f74278df75194ca483893     [debug]
[0.39 sec, 8.51 MB]
Drush bootstrap phase : bootstrap_drupal_configuration() [0.4 sec,   [bootstrap]
8.58 MB]
Find command files for phase 3 (max=6) [0.4 sec, 8.59 MB]                [debug]
PDO support is required. [0.41 sec, 8.75 MB]                         [bootstrap]
Bootstrap to phase 5. [0.41 sec, 8.75 MB]                            [bootstrap]
Command pm-update needs a higher bootstrap level to run - you will   [error]
need to invoke drush from a more functional Drupal environment to run
this command. [0.41 sec, 8.75 MB]
The drush command 'up' could not be executed. [0.41 sec, 8.75 MB]    [error]
Drush was not able to start (bootstrap) the Drupal database.         [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a
configured database. In this case you can select another site with a
working database setup by specifying the URI to use with the --uri
parameter on the command line. See `drush topic docs-aliases` for
details.
 * connect the database through a socket. The socket file may be
wrong or the php-cli may have no access to it in a jailed shell. See
http://drupal.org/node/1428638 for details.

Drush was attempting to connect to:
 Drupal version         :  7.34
 Site URI               :  http://default
 Database driver        :  mysql
 Database hostname      :  localhost
 Database port          :
 Database username      :  db_user
 Database name          :  [db_name]
 PHP executable         :  /usr/bin/php
 PHP configuration      :  /etc/php5/cli/php.ini
 PHP OS                 :  Linux
 Drush script           :  /users/castaff/dfitzpat/.composer/vendor
                           /drush/drush/drush.php
 Drush version          :  7.0.0
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /users/castaff/dfitzpat/public_html
 Site path              :  sites/default

 [0.57 sec, 11.43 MB]

```

Intrestingly, the command:

drush sql-cli connects fine.

If anyone can shed light I'd be most grateful. I've tried:

1. replacing localhost with 127.0.0.1;
2. Replacing with the exact ip of the server on which the database is located.

I'd like to find out where this is failing and then (obviously) how to fix it.

Many thanks.

# Answer
Best solution for me is using Xdebug.

Here is a great article for configuring it with PHPstorm

https://www.lullabot.com/blog/article/debugging-drush-commands-xdebug-and-phpstorm
> 1 votes

---
Tags: drush
---


# Question
Title: Is there a way to convert all the uploaded PNG images to JPEG?
Is there a way to convert all the uploaded PNG images in a Drupal 7 site to JPEG?

Manually doing it would require much time. Therefore, I'm looking for an automatic way to convert them.

# Answer
> 4 votes
With imagecache\_actions module you have several actions. One of then is "File Format switcher" so you can serve JPEG instead of png without converting the source images.

For more information: https://www.drupal.org/project/imagecache\_actions

---
Tags: media
---


# Question
Title: Change error message generated by webform for duplicate email submission
I have a webform which takes a name and an email, the email field is set to not accept duplicates.

I have done this by choosing unique in the field settings (which is next to the required checkbox).

The error message it shows when a duplicate email is attempted is

'The value *email* has already been submitted once for the Email field. You may have already submitted this form, or you need to use a different value.'

How can I change this completely?

# Answer
> 1 votes
There's other way if you don't want to code anything.

You can use String Overrides Module

> This module allow override any translatable string on the site.

# Answer
> 0 votes
**Steps to fix this:**

1. You can do a **hook\_form\_alter** on the Webform.
2. Add your own custom validation function.
3. In the custom validation, add your validation on the Email field.

I haven't tried anything, but I think this would solve your problem and will override the messages for you.

---
Tags: webforms
---


# Question
Title: How to add 'style="width:100px"' in Global Custom Text field in a view?
It seems that the **Global Custom Text** field in a view delete part of my text.

I write this:

```
<div class="my-class" style="width:100px">Hello</div>

```

but get this:

```
<div class="my-class">Hello</div>

```

The text removed is this

```
style="width:100px"

```

I need to be able to include it.

The value of the 'width' is provided by a token (\[field\_width\]), that's why I need to add it here. It is dynamic value.

**Update:** I just see that this is a security measure, then how can I make View accept this using a function?

# Answer
Here is a fun and a little naughty solution to this:

1.) Instead of style, set the token as value="\[token\]" - make sure your token is only a number, no alphabetic characters like px etc.

--- Value is set and DIV is spat out ---

```
<div class="my-div" value="100"></div>

```

2.) Use jQuery to get the value of value="" - define it and use it when the page loads:

```
$(document).ready(function(){
var div_width = $('.my-div').val();
$('.my-div').width(div_width);
});

```

The width will now be appended to the div via inline-style using jQuery. Not optimal, not recommended but it should work.

More on adding custom jQuery to your Drupal installation: https://www.drupal.org/node/171213
> 3 votes

---
Tags: views, security, input-formats
---


# Question
Title: Disable client- or proxy-side caching on anonymous pages (Cache-Control header), without disabling server-side caching?
My CDN seems to cache the /user page, which means I can't access my account page after logging in. I could add it to cacheexclude's uncached list, but that would make PHP run for every bot that hits my server.

What could I do so that Drupal serves the /user page with "Cache-Control: no-cache", or something targeted at proxies (CDN), for anonymous users?

# Answer
> 0 votes
I solved this using `context` and `context_http_headers` (`7.x-1.x`) to add custom `Cache-Control:` headers on the user page.

---
Tags: caching
---


# Question
Title: How to assign the user login block to header region
I created a user and I logged in as the user by visiting xxx.com/user. I just visited xxx.com/user. I see the user name but I do not see any log out button. I am not sure how I logout.

Thanks.

D

# Answer
> 0 votes
The Drupal core *User login* block doesn't display a login/logout link; it only displays a form for logging in an anonymous user. If you want a block to display logout, the *User Menu* block displays user-specific menu links that also includes a logout link when a user is logged in.

# Answer
> 0 votes
As Shawn says. Or, create your own logout link in whatever menu you are using (if you are). As an example, using the 'main menu' in Drupal 7: yoursite/admin/structure/menu/manage/main-menu/add Menu link title: Logout Path: user/logout

---
Tags: users
---


title: Make Author Field in Comments Required

text:
# Question
Title: Make Author Field in Comments Required
How I could make from my template.php author/user field in comments required for those who are anonymous users

I tried with this but it didn't work for me

> function MYTHEME\_theme() { $form\['author'\]\['\_author'\]\['#required'\] = TRUE; }

I've been searching around but can't find a proper answer :/

# Answer
> 2 votes
You have to create a little module and implement `hook_form_FORM_ID_alter()` to alter the form.

# Answer
> 0 votes
Make comment name field mandatory

```
function [Your_modulename]_form_alter(&$form, &$form_state, $form_id) {

   if ($form_id == 'comment_node_blog_form') {   //if your content type is blog

      $form['author']['name']['#required'] = TRUE;

    }
}

```

---
Tags: 7, entities, comments
---


# Question
Title: How can I remove javascript from everywhere but the front page?
I tried using this in template.php

```
function MYTHEME_js_alter(&$javascript) {
  if ($!is_front) {
    unset($javascript['path/to/script.js']);
  }
}

```

but it doesn't work. Performance wise, would it be as good to have the javascript that's on every page in theme.info, then use drupal\_add\_js on the front page instead?

# Answer
> 2 votes
You need to update. Below are the update :

```
if (!drupal_is_front_page()) {
      unset($javascript['path/to/script.js']);
    }

```

function drupal\_is\_front\_page

Reference Link : Click Here

---
Tags: 7, theming, javascript
---


# Question
Title: How to add / update a field collection without updating parent node/entity?
I needed to to add / update field collections to node entities without updating the node entities. I tried two ways listed in https://www.drupal.org/node/1842304 and http://alexrayu.com/blog/saveupdate-field-collection-without-nodesave but none of them seems to be working exactly the way I want.

I tried as follows:

```
$node = node_load($nid);
$field_collection_item = entity_create('field_collection_item', array('field_name' => 'field_college_rating_data'));
$field_collection_item->setHostEntity('node', $node);
$field_collection_item->field_text1['und'][0]['tid'] = $form_state['input']['field_text1']['und'];
$field_collection_item->field_text2['und'][0]['value'] = $form_state['input']['field_text2']['und'];
$field_collection_item->save();

```

It added a field collection but it updates the node.

I also tried to alter the field collection form submit and used custom submit handler as follows:

```
function own_custom_field_collection_submit($form,$form_state) {
  $field_collection_item = field_collection_item_form_submit_build_field_collection($form, $form_state);
  $field_collection_item->save(TRUE);
  drupal_set_message(t('The changes have been saved.'));
  $form_state['redirect'] = $field_collection_item->path();
}

```

I have copied this code from core field collection module to change the default argument to "TRUE" in the save function. It added the field collection but didn't associated with the parent node.

I need to save the field collection separately since my node entity form is very large with 50 to 60 fields and field collections and I don't want to update it as many times as I add / update any field collections to the node.

Any help?

# Answer
> 0 votes
You can make use of the Entity API

example will be

```
<?php
// Implements hook_entity_update().
function qmlc_mod_entity_update($entity, $type) {
  if ($type == 'node' && $entity->type == 'event') {
    $link_title = $entity->title;
    $link_url = entity_uri('node', $entity);
    $language = $entity->language;

    foreach ($entity->field_event_images[$language] as $event_images) {
      // Load field collection item.
      $field_collection = field_collection_field_get_entity($event_images);

      $num_of_images = count($field_collection->field_image[$language]);
      for ($i = 0; $i < $num_of_images; $i++) {
        $field_collection->field_image_link[$language][$i]['title'] = $link_title;
        $field_collection->field_image_link[$language][$i]['url'] = $link_url['path'];
        $field_collection->field_image_link[$language][$i]['attributes']= array();
      }

      // Save field collection item. Use TRUE since you are updating a field collection item which is already linked with a node.
      $field_collection->save(TRUE);
    }
  }
}
?>

```

References

1. Programmatically create and update field collection with Entity API
2. Update field collection programmatically

---
Tags: 7, nodes
---


title: How do I process a huge list of files?

text:
# Question
Title: How do I process a huge list of files?
I have a huge list (\> 100 000) of files that need to be processed. I want processing to run in the background and continuously (when it has processed the last, it just restarts on the first).

I've tried to do it with `hook_cron()`. There is a limit on how long cron can run, so to prevent cron timeouts, I throttle cron to process about 1000 files each time it runs (that is about the max cron can handle without timeouts).

To keep track of things between cron runs I use two db variables:

```
$mymodule_huge_array_data = variable_get('mymodule_huge_array_data', array());
$mymodule_counter_index = variable_get('mymodule_huge_array_index', 0);

```

After setting things up, cron get these two variables, and use `$mymodule_counter_index` to know where to start in the list of files. After processing 1000 files, it does:

```
$mymodule_counter_index += 1000;
variable_set('mymodule_huge_array_index', $mymodule_counter_index);

```

My problem is that getting that huge blob of an array from the database at the start of each cron makes the site slow during cron runs - even if I throttle cron to process only a single file.

I've looked at various alternatives. The core batch API (Batch operations) alone can not be run from cron. Job Scheduler just uses *cron* to schedule jobs, so I don't think it will improve anything here.

Should I replace the single db variable holding the huge array blob with a table (with one file per record)?

I am currently looking Background Process and its Background Batch submodule. Is it suitable for this use case? It doesn't look so, it runs in the background, but just like the core batch API (Batch operations) alone, you need to initiate the process manually.

The accepted answer to this also looks like an option: Do I need a cron task for processing a queue?

Are there *other* (better) ways to do this?

What is the *right way* to chop up a large job into smaller bits, keeping track of the state as it progress through operations?

(To prevent this from being closed as "opinion based", let me emphasis that I am not asking for opinions about this. I am asking for the correct way to process a huge list of files with Drupal.)

# Answer
> 1 votes
You can try

**Method I - Using Cron and queue**

* Cron will run the query and push the list of nodes to the queue
* queue will pick the items one by one and Unpublish them

**Method - II Using Cron and batch**

* Cron will run the query and push the list of nodes to the Batch process
* Batch process will be launched programmatically using background\_process module

References

1. Batch API
2. How to create a batch operation in Drupal 7
3. SE Answer
4. D.ORG post

---
Tags: 7, cron
---


title: pager is not working when print views

text:
# Question
Title: pager is not working when print views
I've created one view with used of php code for some fields in it, and set pager on it too. It's working fine whenever i created given link of view but actually I print that same view on another basic page, using this php code:

`<?php print views_embed_view($viewName); ?>`

on that basic page pager is not working, because on that page the pager link is generated with that basic page url link not with views url link. can anyone give solution when i print the same view on basic page and also pager can work over there perfect?

Thanks in advance :)

# Answer
If you used Views PHP, this is a known issue

Views Pager is hidden (7.x-2.x)

Pager disappears when Global: PHP used in Views 3.8

You have to apply one of the patches to fix it.
> 0 votes

# Answer
I got solution from one known issue, and worked properly for me. Here is the link of it and patches.
> 0 votes

---
Tags: 7, views
---


# Question
Title: How to limit Entity Reference to only allow referencing of nodes with the same (or undefined) language?
I know I can simply add language to displayed title of a node in Entity Reference field based on views. What I failed to discover is how to limit possible values to only show and allow matching ones.

* When current node is language independent, all nodes should be listed as possible in reference field.
* When node has language defined, only nodes of the same language, or undefined language, should be available.

I don't really mind wrong selection to be saved in database if language of node will be changed, as it shouldn't happen often enough to be a problem. I simply don't want "wrong" nodes on the list of available reference choices. On-save validation would be nice, but isn't a must-have.

I tried to use view to populate entityreference field's dropdown on node edit form:

My big block is how to access a language of a current node in view that provides list of available entities. I can't find a way other than to guess using current UI language, but that may be wrong for edits and usually is wrong on new node creation. Ideally, the entity reference field should repopulate via AJAX according to the language selected in the node edit from.

For the sake of future visitors I would appreciate complete answer. Of course answer not based on views will be appreciated, too.

# Answer
> 4 votes
Reference field option limit module allows reference fields of several types to have their widgets' available options limited by the values of other fields in the current entity.

> It currently supports taxonomy term and entity reference fields.

# Answer
> 1 votes
I can suggest some "concepts" of solution with Views.

I didn't understood if you succeed to define target node language. (if no, write a comment, I'll update the answer).

**Step1.** You are able to pass arguments to the view that filters entityreference field. Then it's possible to add your language to the field views args programmatically in `$field['settings']['handler_settings']['view']['args'];`.

**Step2.** You can create custom contextual filter programmatically. Filter will pass the language id. This contextual will change View language using agrument value. you can change language in query alter - `query()` method of your child class of `views_handler_argument`.

Then just `dpm($this)` in the `query()` method and change language value to your argument.

# Answer
> 1 votes
Check out Translated Entity Reference module.

Another option is to create your custom view to render your Entity Reference field selectable options. Just:

1. Create a new view
2. Add a new Entity Reference View Widget
3. Add a filter for your content type
4. Add a new contextual filter for field "Language"
5. Select "Provide default value" + "PHP code" (maybe you will need "Views PHP" module for this)
6. Enter this code on "PHP contextual filter code" textarea:

global $language; $lang = $language-\>language;

$node = menu\_get\_object(); if (!empty($node)) { $lang = $node-\>language; } return $lang;
7. Edit your Entity Reference field and select your new custom view as entity selection mode

# Answer
> 0 votes
I'm looking for the same thing.

The closest I got was by using the current user's language. The current user's language will be determined by what you select in `/admin/config/regional/language/configure`.

* add relationship "Entity translation: translations"
* add filter "Entity translation: Language (=Current user's language)"

Also, this link cleared the field\_title issue for me: https://drupal.org/node/1327012.

So, for example, going to `/en/node/add` will populate the entity view with the referenced entities in English. But, if the user changes the language on the edit form the view will remain the same.

This solution would suffice if the referenced entities were the same in all languages and simply translated (like the "localize terms" functionality that that core taxonomy translation provides).

The only other 'quick and dirty' way I can think of is editing the output of the title field in views and adding a css class according to the language. Then writing some jquery that shows/hides the entities by mapping the class of the entity in the view to the language selection field.

****Ideally, the entity view should repopulate via ajax according to the language selected in the node edit from.****

If anybody has any ideas please let us know.

Thanks

# Answer
> 0 votes
Field reference

> Depending on configuration, authors can pick fields from the same node/entity, from other nodes/entities, from specific revisions, from specific languages, or even a specific delta value within the field. Fields can be displayed using either the 'full' or 'teaser' mode from their original node/entity.

---
Tags: views, entities, i18n-l10n
---


title: Image uploading not working in server

text:
# Question
Title: Image uploading not working in server
In a content type have a field image upload.its image upload type is jpg,png,gif. When we upload these image type of images an error is coming :

> The selected file Chrysanthemum.jpg could not be uploaded. The file is not a known image format.

But its running in local not in server. What is the problem ? Please help me. Thanks

# Answer
Below are the two ways. I hope help you to solve your issue.

***1.*** Your files via FTP into the `image_import` directory aren't being given the correct permissions. You have to provide the permission i.e. `chmod 660 *` on them in the `image_import` directory the files were recognized correctly and the import worked.

**OR**

***2.*** In **/includes/image.inc**, change line 117 from:

```
  if (!is_file($file)) {

```

to:

```
if (!is_file($file) && !is_uploaded_file($file)) {

```

Then check is your issue is solved or not. If not then try once updating below with second way :

On the `admin/settings/file-system`, try changing `C:\WINDOWS\Temp` to `sites/default/files/temp` (also made sure it was writeable by the web server).
> 0 votes

# Answer
Have you tried with other images? Do you get the same error with other .jpg files? Or .gif files? Perhaps Chrysanthemum.jpg is a corrupt file.

Can you upload other files? Are /tmp permissions set correctly?

If so, it could be a PHP issue, and not a Drupal issue. Check whether the FileInfo module is installed:

```
pecl install fileinfo

```

Or if you run Apache, check if the `libjpeg.so` module is enabled.
> 0 votes

---
Tags: media
---


# Question
Title: display the multiple value in single field in drupal 7 view
**display the related multiple value in single field to avoid duplication in drupal 7 view**

Guys help me to solve this issue.

## Now it's like this.

## **Name -----------------------------Organization**

## sam --------------------------------Ministry of public Health

## sam ---------------------------------It solution company

## **I want to display like below**

## **Name------------------------------Organization**

**sam----------------------------------Ministry of public Health, It solution company**

# Answer
> 1 votes
1- open your view and select ur field which is filed collections
2- select the following settings

# Answer
> 1 votes
You can do this by "Rewrite results" follow the following steps.

1) Edit the first field and exclude it from display.

2) Edit the second field and click on the "Rewrite results"

3) check "Rewrite the output of this field" checkbox.

4) find your fields in the "replacement Patterns" and put it in the textarea like this \[field1\],\[field2\]

# Answer
> -1 votes
You can use views\_php module. This module adds a field to your module that its content is php code. The rows and results of other fields are also available in the php code.

---
Tags: views
---


# Question
Title: How to add comma separated list for the select list check box field type
For my one site, I added a select list(text) \> check box field type to my content. When I go to manage display tab(using display suite module), in the format column column for the field, I see drop down field with 4 values ( css class, default, key, list). I selected list. Next to that I also see a geared setting where it allows me to make a comma separated list. When I go to front end, I see the values listed separated by commas. It works fine.

I am trying to do the same thing for my other site. But as for the drop down field, I only see default and key. Also, I don't see the geared setting icon to make it comma separated list. I am not sure what I did wrong on my second site. Both site have the same field type.

Please advise.

# Answer
Do you have the Text list formatter module installed on the first site, but not the second site? That would provide the functionality you describe.
> 1 votes

---
Tags: nodes
---


title: How to import webform fields on server?

text:
# Question
Title: How to import webform fields on server?
I want to import fields of webform on server.Features will not include webform fields. Is there any module by which I can import webform fields to server?

# Answer
> 1 votes
1. Webform Import

> Allows delimited data files to be imported as submission (results) into webforms.
>
> This is useful for importing submissions from other systems in to Webform. Can also be used to Edit submissions via Export / Import as long as the CSV has the SID column filled.

2. Webform Share

> This is a helper module to prepopulate newly created webforms and to export / import webforms between sites.

I think Webform Share module definitely solve your issue.

---
Tags: 7
---


# Question
Title: Is it safe to apply last update when a module has several updates available?
Have an old Drupal 6 site that has a lot of available updates for modules, core and theme.

When a module has several updates available from the currently installed one to the latest, I understand it's safer to apply them in order. Can I skip this and just install the latest version of the module? Is there a way to know when it's safe, and when not? Visiting updating notes tells about bug fixed, but no info about this. Is there a way to know if the update will make changes to database, so if I have a pre-production and production enviroment, can plan accordingly?

Also for core Drupal updates, I think that in that case applying every update in order is mandatory. Am I right?

I've checked official Drupal information abaout updates, but doesn't state anything about it (it says that you can update multiple modules at the same time, but beware of dependencies between them).

# Answer
Installing the latest version straight off should be fine in most cases.**\****

If the module updates only contain minor code changes then there's almost certainly nothing to worry about.

If the module updates contain more major changes such as alterations to the database schema then the module maintainer should be using the hook\_update\_N() function in a "module\_name.install" file which will allow Drupal to determine which updates fall between your currently installed version and the latest version, and apply the necessary modifications in sequence, meaning no breakage should occur. Drupal core is no different to any other module in this respect, so you should also be able to update to the latest core version without any problem.

**\****If the module has seen a major version increase, for example, you have 6.x-1.7 installed and the latest version is 6.x-3.2, then you should check the module's project page and documentation for any compatibility notes or special instructions for updating. In some cases the versions may not be compatible and would need to be manually migrated, or some dependency may have changed, which the module maintainer should inform you about somewhere.

The only other problem I can think of is the unlikely situation where an API change has occurred in Drupal core at some point and one of your modules was abandoned and never updated to take account of the API change. In that case, you may need to find a patch in the module's issue queue, disable the module, or find an alternative module.

Also, this may be stating the obvious, but if your site is running on Drupal 6, you won't be able to install any module updates with version numbers beginning 7.x- because those are for Drupal 7 and won't be backwards compatible. You'll have to stick to the latest 6.x- version.

**Having said all that, you should always carry out a test run of the update process in a testing environment before you go anywhere near the production server. Make sure to clone the live database and all the Drupal files from your production server to your test environment so that you can safely determine exactly what effects the updates will have.**
> 2 votes

# Answer
In my opinion it will not hamper your site when you update a module or core skipping a few upgrades. Though it is necessary to test out the changes in a test environment after installing upgrades.

You can follow the instruction here https://www.drupal.org/node/250790
> 0 votes

---
Tags: 7, updating
---


title: template.php stop js on admin pages

text:
# Question
Title: template.php stop js on admin pages
I am using the following to put js on my site...

```
drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/js/custom.js');

```

But I have noticed that this is also adding the js to pages like update.php and other admin pages. Is there a if variable I can use to only load the js on customer facing pages?

Ive used `drupal_is_front_page()` before, which is great, is there a `drupal_not_admin_page()` or something like that?

A google search for "drupal is not admin page" isnt getting me anywhere.

# Answer
> 3 votes
You can use `path_is_admin()`:

```
if (!path_is_admin(current_path())) {
  // Do something...
}

```

Or check the theme:

```
if ($GLOBALS['theme'] == 'some_theme') {
  // Do something...
}

```

# Answer
> 0 votes
Try below code :

```
function mytheme_preprocess_page(&$vars) {
  // clean script from the admin pages
  if (arg(0) != 'admin' || !(arg(1) == 'add' && arg(2) == 'edit') || arg(0) != 'panels' || arg(0) != 'ctools') {
    drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/js/custom.js');
  }
}

```

---
Tags: 7, theming
---


title: Image upload permissions problem

text:
# Question
Title: Image upload permissions problem
I have my local site running on my Win 7 machine using Acquia Dev Desktop.

I also have a "live" version of the site.

In both environments I cannot upload an image for an article. I must have messed something up because it was working several days ago.

This link https://www.drupal.org/documentation/modules/image was useful, but the suggestions on Troubleshooting/The image doesn't show up didn't fix the problem. I'm sure it's because I don't really understand what I'm doing.

I'm wondering if a disable of the image module then a re-enable would solve the problem?

# Answer
> 0 votes
I was rumaging through the module listing and found Debut Article. On the oft-chance that this might be causing problems I went to the debut article page on drupal.org and found drupal.org/node/1473574. It states that because fields are not true exportables, the resulting approach may be fragile and prone to breakage if, e.g., debut\_media is not enabled prior to the article implementing the hook\_alter, i.e., in this case, debut\_article. I enabled debut media and it worked!

# Answer
> 0 votes
Have you checked **Home » Administration » Configuration » Media** IN this **Public file system path** should be "sites/default/files" and **Temporary directory** should be "/tmp". And check whether you files folder has read/write permissions and its subfolder's where you are saving image.

---
Tags: media
---


# Question
Title: Image shows on home page, but not on article page
I am using Open Outreach. When I create an article the image I uploaded appears on the home page, but does not appear when I click the link for that article.

From what I've read, it looks like it has something to do with Configuration/Media/File System. My public file system path is set as sites/openoutreach-7-x-1-19.dd/files. Do I need to change this? If so, what do I change it to?

Log message:

Type page not found Date Thursday, June 4, 2015 - 9:43am User admin Location http://openoutreach-7-x-1-19.dd:8083/sites/openoutreach-7-x-1-19.dd/files/styles/medium\_large/public/Portulaca%20grandiflora.jpg?itok=OP-6w24x Referrer http://openoutreach-7-x-1-19.dd:8083/article/june-3-2015-newsletter Message sites/openoutreach-7-x-1-19.dd/files/styles/medium\_large/public/Portulaca grandiflora.jpg Severity warning Hostname 127.0.0.1

There is no medium\_large folder in my styles folder. Do I need to create one?

Thanks!

# Answer
> 0 votes
I was rumaging through the module listing and found Debut Article. On the oft-chance that this might be causing problems I went to the debut article page on drupal.org and found drupal.org/node/1473574. It states that because fields are not true exportables, the resulting approach may be fragile and prone to breakage if, e.g., debut\_media is not enabled prior to the article implementing the hook\_alter, i.e., in this case, debut\_article. I enabled debut media and it worked!

# Answer
> 1 votes
When contrib images are missing in drupal the cause more often than not is that you have permissions problems with regards to your filesystem.

Make sure that your **webserver can write to** your **files and files/styles directories.**

If permissions are ok then drupal will create your medium\_large directory and subdirectories.

Check the drupal setup documentation here (see the paragraph **"Create the files directory"**).
As mentioned there make sure that you have write permissions on your sites/default/files directory.

---
Tags: media
---


title: The login form isn't rendered

text:
# Question
Title: The login form isn't rendered
I am newbie to drupal. Recently I changed blocks of my theme and set main page content block to none.I logged out of my site. I tried to access admin panel by appending /user at URL. It redirected to login page but it login form is not appearing as displayed in image below. I am unable to enter my username and password.

Any helps are welcomed.

# Answer
You are going to need to open phpmyadmin from your hosting, and look in the "block" table.

Look for the "main" block, and edit the status to "1" and the region to "content" (or whatever your main region is defined as in your themes .info file).

It seems strange that disabling the main content block would hide the login form though, I thought they were separate.
> 0 votes

---
Tags: forms
---


title: Location latitude longitude

text:
# Question
Title: Location latitude longitude
I am trying to update a website from Drupal 5 to 7 and I have to use location field for one of my content types. On Drupal 5, I can see the latitude and longitude fields but on drupal 7 I can not. Please check the image below.

# Answer
In the Drupal 7 field settings for that location field, make sure you have enabled the longitude and latitude fields.

I believe there is also an option to "allow user to choose co-ordinates".
> 0 votes

---
Tags: 7, nodes
---


title: Where do twig files find variables?

text:
# Question
Title: Where do twig files find variables?
for example for the file node.html.twig has a giant comment saying

```
* Available variables:
* - node: Full node entity.
 *   - id: The node ID.
 *   - bundle: The type of the node, for example, "page" or "article".
 *   - authorid: The user ID of the node author.
 *   - createdtime: Formatted creation date. Preprocess functions can
 *     reformat it by calling format_date() with the desired parameters on
 *     $variables['node']->getCreatedTime().
 * - label: The title of the node.
 * - content: All node items. Use {{ content }} to print them all,
 *   or print a subset such as {{ content.field_example }}. Use
 *   {{ content|without('field_example') }} to temporarily suppress the printing
 *   of a given child element.
 * - author_picture: The node author user entity, rendered using the "compact"
 *   view mode.
 * - metadata: Metadata for this node.
 * - date: Themed creation date field.
 * - author_name: Themed author name field.
 * - url: Direct URL of the current node.
 * - display_submitted: Whether submission information should be displayed.
 * - attributes: HTML attributes for the containing element.
 *   The attributes.class element may contain one or more of the following
 *   classes:
 *   - node: The current template type (also known as a "theming hook").
 *   - node--type-[type]: The current node type. For example, if the node is an
 *     "Article" it would result in "node--type-article". Note that the machine
 *     name will often be in a short form of the human readable label.
 *   - node--view-mode-[view_mode]: The View Mode of the node; for example, a
 *     teaser would result in: "node--view-mode-teaser", and
 *     full: "node--view-mode-full".
 *   The following are controlled through the node publishing options.
 *   - node--promoted: Appears on nodes promoted to the front page.
 *   - node--sticky: Appears on nodes ordered above other non-sticky nodes in
 *     teaser listings.
 *   - node--unpublished: Appears on unpublished nodes visible only to site
 *     admins.
 * - title_attributes: Same as attributes, except applied to the main title
 *   tag that appears in the template.
 * - content_attributes: Same as attributes, except applied to the main
 *   content tag that appears in the template.
 * - author_attributes: Same as attributes, except applied to the author of
 *   the node tag that appears in the template.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 * - view_mode: View mode; for example, "teaser" or "full".
 * - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'.
 * - page: Flag for the full page state. Will be true if view_mode is 'full'.
 * - readmore: Flag for more state. Will be true if the teaser content of the
 *   node cannot hold the main body content.
 * - logged_in: Flag for authenticated user status. Will be true when the
 *   current user is a logged-in member.
 * - is_admin: Flag for admin user status. Will be true when the current user
 *   is an administrator.

```

Where would these come from?

When I write my own template file how do I know what variables are available in my new template file?

# Answer
> 2 votes
Variables can be added and manipulated in preprocess functions just as with .tpl.php files.

Twig has a `dump()` command that can allow you to see the available variables.

# Answer
> 1 votes
That's more or less just like in D7, just that it's a twig template in the end instead of PHPTemplate.

Initially, variables are defined in hook\_theme(). Then someone calls a certain theme function and passes those arguments in, usually as part of a render array, something like:

```
$output = ['#theme' => 'item_list' => '#items' => [1, 2, 3]]

```

When that is rendered, then the preprocess functions are called which can process the initial variables and add more things. For node.html.twig, most of those things are added by template\_preprocess\_node().

More information: Theme system overview

# Answer
> 1 votes
You can see the variables available on your template:

```
<ol>
  {% for key, value in _context  %}
    <li>{{ key }}</li>
  {% endfor %}
</ol>

```

---
Tags: 8, theming
---


# Question
Title: LIghtbox2 hide header and footer regions
I had created a lightbox which contains the node title and body content. But it shows the Admin bar of drupal , Header and Footer regions. I want to remove these from the lightbox and showing only the content of node on lightbox.

I am using Lightbox2 module for this.

# Answer
Not answering directly but proposing an alternative solution here:

If possible, switch to Colorbox, extend it with Colorbox Node and use it to easily display your nodes without header and footer like this:

```
<a class="colorbox-node" href="blogs/my-example?width=600&height=600">My Example</a>

```
> 0 votes

---
Tags: javascript
---


# Question
Title: How can I manually edit the search options in a facet block?
I have a facet for a field, the values of which are:

(FACETAPI DEFAULT)

* *yes* (db: **y**)
* *no* (db: **n**)
* *maybe* (db: **m**)

By default, the facet shows all three of these options. However, I only want to show *yes* or *no* to the user, and I want to include the value of *maybe* in both:

(WHAT I WANT)

* *yes* (db: **y** or **m**)
* *no* (db: (**n** or **m**)

**What I have tried**

I know I could try to do an OR search with the facet and rewrite my links to search both, but I don't want to give users the option to search just "maybe"; I only want two options, not three.

It would be great if there was a stable version of the Apachesolr Facet Builder for D7. One can dream...

I am using the Facet API Bonus module but this allows me to "Rewrite items" or "Exclude items," not combine three items into two as I described above.

I read this wunderkraut article on extending Facet API but it covers adding sorts, plugins, widgets, dependencies, and the like-- not the facets themselves.

I also looked at this wunderkraut article, which suggests I should use something like `hook_facetapi_facet_info_alter()`, but I don't know how to edit the field values to combine them.

# Answer
> 0 votes
I decided to implement this by creating a new facet instead of editing an existing one. This article describes the process.

The basic code looks like this:

```
/**
 * Implements hook_entity_property_info_alter().
 */
function MYMODULE_entity_property_info_alter(&$info) {
  $info['user']['properties']['agg_gender'] = array(
    'type' => 'text',
    'label' => t('Search API Agg Gender'),
    'sanitized' => TRUE,
    'getter callback' => 'MYMODULE_search_agg_gender_getter_callback',
  );
}

/**
 * Getter callback for agg gender property.
 */
function MYMODULE_search_agg_gender_getter_callback($item) {
  // Need to load the user object to get fields
  $account = user_load($item->uid);
  switch ($account->field_gender['und'][0]['value']) {
    case 'F':
      return 'f';
      break;
    case 'M':
      return 'm';
      break;
    case 'O':
      return 'fm';
      break;
  }
}

```

---
Tags: search
---


# Question
Title: Views, Contextual Filters, and Path Alias
First, a disclaimer: I am less than a year into learning Drupal just to give you a frame of reference. I am probably using incorrect terminology in my searches so if there is an answer out there, a point in the right direction would be greatly appreciated.

I am building a site that will have multiple "categories." In each category, there will be page content. So, my URL will (should) look like this:

```
www.example.com/category/page

```

All of my pages have been put into their respective subdirectories which are named for their categories. For example:

```
widgets/page1  (node 10)
widgets/page2 (node 13)
widgets/page3 (node 24)
services/page1 (node 12)
services/page2 (node 15)
services/page3 (node 17)

```

If I type the url /widgets/page1 I get the "article" not the view. If I type in the url with node id:

```
www.example.com/widgets/13

```

The view works perfectly and shows me widgets/page2

I created a page view for widges and set its path to "widgets" so the url would be:

```
www.example.com/widgets

```

I have created a view that displays all my relevant info. I also created an "attachment" that shows me related content from the same category. This actually works quite well - it displays all the relevant content with linkable titles.

**The problem that I am running into is when I click on one of the titles (or type the link directly) it no longer goes through the page view.**

How do I structure this so that all links go through the views? I am missing something, I just don't know what.

Screenshot of my Views Page

# Answer
Ok, under Fields, click on the Title, then tick "Link this field to the original piece of content", then under "Rewrite results" tick "Output this field as a link", then in Link Path below it try "widgets/\[nid\]" then save obviously!
> 0 votes

---
Tags: views
---


title: Views Block Doesn't Show on Views Page

text:
# Question
Title: Views Block Doesn't Show on Views Page
I have a Views Page that displays content from articles matching a particular criteria. That views page works as expected.

I also have a views block that is supposed to pull related content from the article (think taxonomy, but I am using content types instead). I have placed this block on all pages (no exclusions) on the right sidebar (Garland).

My content URL paths are set up as such:

```
example.com/section/page-name

```

My views page is set up as:

```
example.com/section

```

When I access the article directly via .com/section/page-name, the block shows up properly with all of the correct relevant links. This means I have configured my relationships and context filters correctly.

When I hit my views page and render the content there, the content gets rendered, but the block never shows up. (Just for grins and giggles, I put a test block with some garbage and it shows up every time; views page and article)

I am assuming it is due to passing a filter or something in the URL, but I am just assuming and even if I was right, I have no idea how to pass that info to the block so that it gets rendered.

A point in the right direction here would be greatly appreciated!

# Answer
> 0 votes
This sounds a little like it's due to your contextual settings. Not sure if you set these based on some info you found on the net, but the settings given online can lead to your view block not rendering content because you are currently looking at that exact content to begin with.

The thought behind this is for example if you load a bunch of articles of the same content-type, that it will not list the same article in that list etc.

What you CAN try is to go into your views block (which is causing trouble) and under "advanced" set a simple "Global Text" under NO VIEW RESULTS BEHAVIOUR saying something like "Cannot load" or similar, to look if the block loads now with that message. If that is the case then the issue is more than likely in your contextual filters or in the field filter settings.

---
Tags: 7, views
---


# Question
Title: How to insert social share buttons in drupal 7 using Bootstrap Social Sharing Buttons?
I am using module Bootstrap Social Sharing Buttons in my D7 site.

I can show e-mail, twitter, facebook and google+ but I don´t know how to insert others social buttons like linkedIn.

# Answer
This module implements networks by harcoding in the module's code. Because it is not much clean way how to implement modules for this use-case and this module is not widely used, I recommend you to use somethink different.

If you dont't want to include third party scripts to your site (they can spy your users and slows down page) you can use this module: https://www.drupal.org/project/service\_links It is also widely used, so should be better developed and maintained in the future.
> 4 votes

# Answer
Consider using the ShareThis module ... Some more details about this module (from its project page):

> * Customize your ShareThis code using the STAPI
> * Select node types you wish to display ShareThis module on
> * Choose to display in $teaser view or not
> * Choose to display the ShareThis link in either the $link items, or in the $node-\>content itself
> * Customize the weight of the ShareThis link if in $node placement
> * Uses the ShareThis jQuery plugin so the ShareThis servers are queried after page rendering
> * Place a ShareThis block anywhere on your site
> 1 votes

---
Tags: 7, social-network
---


# Question
Title: Google/search engine links to Drupal site broken, why is domain missing a slash?
I noticed that links to my site from search engines don't work. Google links me to `https://www.site.comcontent/page-title-1`. I am using Pathauto and Clean URLs. The slash is missing at the end of the domain. Is there something obvious I have misconfigured? I can navigate around my site just fine once I am there.

Edit: originally mis-typed the problem - note https instead of http.

# Answer
> 2 votes
This ended up being a problem introduced with the freshly installed SSL cert and redirecting to https, in combination with using Clean URLs. Turns out there is documentation on configuring Clean URLs and HTTPS with Apache.

# Answer
> 0 votes
Go to the edit page of the node and check for the url of the node. There are chances that you have overridden the path of the node.

So instead of using pattern from path auto you might have manually added that url.

I actually am curious to know the reason.

# Answer
> 0 votes
Something is causing search engines to think those are valid URLs. Google/Bing are pretty vigilant about not display 404 links to users, so they are getting those bad URLs from somewhere. The solution probably isn't Drupal-centric unless it's supplying these bad URLs to search engines.

Try using search engine tools like Google Webmaster Tools & Bing Webmaster Tools to find the source. You should also look at the XML Sitemap module to supply search engines your valid URLs and a module like Metatag & Global Redirect to make sure your site is sending out canonical URL sources that will be used in search results.

---
Tags: 7, uri
---


# Question
Title: Joining 2 uids in custom table with users table
I have a custom table. Inside that table I have 2 uids.

Using hook\_views\_data\_alter I know how to make a join with users table. My field is called also "uid".

The join looks like this:

```
    $data['ofertas_producto']['table']['join'] = array(
        'users' => array(
            'left_field' => 'uid',
            'field' => 'uid',
        ),
    );

    $data['ofertas_producto']['uid']['relationship'] = array(
        'base' => 'users',
        'field' => 'uid',
        'handler' => 'views_handler_relationship',
        'label' => 'Creador del Producto',
    );

```

As you can see the join defined in the first array has only one possible definition with the users table and one left field inside of it. So if I want to define another join with a second field "uid\_2" it will override the first declared join.

Am I right? Thanks for your knowledge.

# Answer
It will not be overridden. It will be another relationship. See the example at the API docs: https://api.drupal.org/api/views/views.api.php/function/hook\_views\_data\_alter/7

See also the example here: https://stackoverflow.com/a/11103419/2467536
> 2 votes

---
Tags: 7, views
---


title: How to check if a View was cached?

text:
# Question
Title: How to check if a View was cached?
Is there a simple way to check (example: see from UI or browser developer tools) if a rendered View was retrieved from cache or just generated on the page load?

This would need to work for every view display, like a View Content pane embedded in a Panels page.

Would this need custom code or is there a module or any-other-simple-way for this?

Thanks

# Answer
> -1 votes
Caching only works for anonymous users (people who are not logged in).

So, a simple test would be to add new content to your view or make a change to your view. Ex: change your view title.

On another browser have your page open, but as anonymous. If your view doesn't change, it means the cache worked.

The View will NOT change to anonymous users until you clear the cache.

---
Tags: views, caching
---