Questions tagged [7]

Version tags should be used only for questions that apply to a version only, not to merely say what version a site is using.

Filter by
Sorted by
Tagged with
84
votes
8answers
16k views

When is it appropriate to create an Entity versus just adding a new content type?

What is the benefit to creating new entity types over just building a new content type? It seems a bit overkill to do all of the custom coding that is required to create a new entity when you have ...
61
votes
5answers
63k views

Print the query which is built using db_select()

I want to print the query which is built using db_select() in a programmatical way. Is there any API function provided by Drupal Abstraction Layer? It is similar to query output in Views, but I want ...
51
votes
2answers
37k views

Better understanding of Drupal behaviors

I read about Drupal behaviors today, and I tried writing the following code. (function ($) { Drupal.behaviors.mymodule = { attach: function (context, settings) { $('#mymodule_id', ...
39
votes
9answers
29k views

Count of nodes by type [closed]

I am looking for a snippet that lets me display the total count for a specific node type, e.g. "Pages = 167" or "Products = 10630." What code should I use to achieve this?
56
votes
8answers
48k views

How to programmatically create Fields?

How can I approach implementing the following in Drupal 7? What I need to do is create a module which defines a new fieldable entity, called 'Company'. I have a list of, let's say, 20 fields that ...
36
votes
3answers
57k views

Adding CSS and JS to form with attachments

I need to add some external and local CSS and JavaScript files to a form, but I can't seem to find the right way to do this. Do I simply add the paths and URLs for the JS and CSS files? I assume $...
21
votes
7answers
58k views

How do I clear cache using an SQL query?

After a module update, my site has become unusable, and only shows a php error message. I tried circumventing the problem with drush cc, but that didn't help. Also tried with a custom php script but ...
21
votes
4answers
11k views

Relation vs. References vs. Entity Reference for managing node-reference-type relationships

References Entity Reference Relation It seems like there are several active modules that all have similar functionality. Can anyone offer any information as to which branch appears to be the most ...
11
votes
10answers
6k views

How do I enable comments for user profiles?

With users being entities in D7 I assumed the user type would would have built in "comment" option. That doesn't seem to be the case. I just want to allow users to leave comments on the user profile ...
5
votes
6answers
4k views

How to add a custom icon or symbol to a flag link?

I'm working on a 'sample request' implementation for a commerce site using Flag, Views, sessions and a little custom code. I'd like to add an icon or a symbol to let people know that an item they are ...
10
votes
6answers
6k views

Drush installed and running; No Drupal site found even with uri specified

After much trial and tribulation, I thought I had drush all ready to roar. Much excitement. But then, no joy... Drush is working. The sites operate fine via MAMP. Regardless, a "drush cc all" command ...
4
votes
2answers
3k views

Alter a Views query to use “OR” through the user interface

I have a view with a few different displays, each of them with slightly overridden filters, like this one used in a panel. How do you add this pseudocode via the UI? AND (node.type='story' OR node....
3
votes
5answers
2k views

How to bulk update select list fields?

I have a content type and it has a select list field. There are two options Yes or No and this field is not a required field. The website has about 100,000 nodes and I want to bulk update all nodes ...
2
votes
1answer
5k views

Extracting URI value from Image in Views - Getting Index Error

I am trying to create a custom slideshow using Views. Please not that I am not using the Views Slideshow Module What I need to accomplish is to wrap the the relative URL for the images within a ...
5
votes
3answers
10k views

Change menu link title dynamically?

I'm trying to alter the text of a menu item dynamically based upon certain variables. I'm using hook_menu_alter like this: function mymodule_menu_alter(&$items) { $items['toggle-review-process'...
3
votes
1answer
835 views

“Allowed memory size” errors on common tasks [duplicate]

I get this error all the time when I'm doing common admin tasks, such as enabling modules. PHP Fatal error: Allowed memory size of 33554432 bytes exhausted How can I fix this?
1
vote
1answer
508 views

How to access commerce_product field of line-items using Rules to flag the Commerce Product?

Related to this question: How to mark product if it has already been purchased by current user? I have a Drupal Commerce shop, where I'm trying to use the Flag module to mark products to inform users ...
1
vote
1answer
649 views

How to make content translation available for front page?

On my front page I have a language selector (English / French). The default language is French. The translation works only in the content of page (in the views) i want make the translation work in the ...
69
votes
3answers
11k views

Given that db_select is much slower than db_query, why would I want to use it?

For the background on this, please see http://drupal.org/node/1067802. Given all that, what situations exists where I might want to use db_select(), or should I be relying solely on db_query?
47
votes
5answers
63k views

How do I get the node ID from the URL?

So far, I came across these 3 functions in Drupal 7, but I am not really sure what the difference between them is, and which is more appropriated to get the node ID in a block preprocess function. ...
38
votes
9answers
43k views

How do I change a theme based on the URL?

I have a Drupal instance running on example.org. Which has a theme X installed and activated. Now for a limited period an event is supposed to be held on the site for which a special section has been "...
35
votes
6answers
12k views

How do I avoid checking for updates for a specific module?

In a current project I have had to patch the life out of a few modules (node hierarchy, workbench access and a few more). These modules are now absolutely perfect for the project's needs and are very ...
30
votes
5answers
27k views

Best practice for language key for “und” in hook_form_alter

I'm modifying in a form in my custom module. Code looks like: function my_module_form_alter(&$form, &$form_state, $form_id) { if ($form_id == "someID") { $form['...
9
votes
4answers
31k views

How do I render a field value including its format?

I'm reading a field value and its format from the database. How would I render that value with the format?
19
votes
4answers
30k views

How do I add additional view modes for a node?

I am creating a custom content type. By default, nodes support only two view modes (full and teaser): function mymodule_view($node, $view_mode) { if ($view_mode == 'full') { $node->...
22
votes
2answers
4k views

What are “#” properties?

While reading the Ajax framework documentation I came across mention of the #ajax property. I know from poking through the code that there are others of these properties with hash signs in front of ...
7
votes
2answers
8k views

Change templates based on path alias

What is the easiest way to select a template based on path alias. For example, if I have the following URLs: http://www.example.com/mydirectory/page1 http://www.example.com/mydirectory/page2 http://...
10
votes
4answers
17k views

Autofilling fields based on another field

I have a very complex situation where I need some advice. I have a content type my_content, which has a field collection field attached to it field_mycollection, which has an entity reference field ...
24
votes
5answers
17k views

How to set value of file field with entity_metadata_wrapper

How do you set the value of a file field when using the entity_metadata_wrapper? I've tried doing this in code: $file = new stdClass(); $file->uid = 1; $file->uri = $file_path; $file->...
15
votes
2answers
19k views

Form within a block

I'm using drupal_get_form('event_signup_form') to embed my custom form inside a block. The form is being rendered as intended, but submitting the form triggers nothing. The form function itself is ...
9
votes
3answers
18k views

What is the purpose of Views “Attachment”, “Content pane” & “Context”?

I've just made a Views for a content type. In one views, I need a page for the content type and a preview of 4 newest posts on the front page. Page is not the problem. For front page preview, I just ...
6
votes
7answers
18k views

How can I enable clean URLs?

I installed Drupal 7 on Wamp Server. I can't find any checkbox or link to enable clean URLs; I see only the Run the Clean URL Test button. How can I enable clean URLs?
6
votes
2answers
7k views

EntityFieldQuery display pager

How do I display pager using EntityFieldQuery for fetch results? I can't find complete example. I am doing simmilar to: Sortable, paged table retrieved using EntityFieldQuery But I miss part to ...
4
votes
3answers
655 views

How to prevent access to Views-only content?

When I'm developing sites in Drupal, I create various content types and taxonomy vocabularies that I use with Views to build displays. I might not ever want the nodes to be viewable in their own right ...
3
votes
2answers
7k views

Date popup form field doesn't show the default value correctly

I am creating a custom form with "date_popup" form fields. The only issue I have is that the default_value for the date popup form field shows only the first digit of the year, not the whole date. ...
2
votes
3answers
720 views

How to check whether one's current User Points are negative with the Rules module?

My question is pretty straightforward: how can I check whether a user's current amount of User Points is negative with the Rules module? I'd like to create an action that should be activated when the ...
2
votes
3answers
937 views

How to add up all items of a field collection field using Rules?

I have a field collection with unlimited values. Inside this field collection, there is a field called Price (field_price). I would like to addup all prices that are inside the field collection to ...
2
votes
2answers
2k views

How to fix entity property X doesn't support writing, when setting content type field values?

I've got a D7 content type with a few fields; nothing particularly special. I want to be able to programattically change the values of those fields from time to time, and so wrote a function like so: ...
46
votes
7answers
39k views

How to change the length of field settings?

I have set once to a website a lenght limit to a field. And now the client wants to put more characters to that field. I cannot change the maximum size from Drupal because I get the following error ...
45
votes
4answers
38k views

How to programmatically send an email?

I'd like to use Drupal's email system to programmatically send an email from my custom module. Is that possible?
41
votes
7answers
40k views

How do I programmatically log in a user?

I am looking for the API that will let me login a user by passing it the username and password. Does anyone have experience with this? To clarify, I am trying to make an AJAX login box that appears ...
35
votes
5answers
16k views

Bulk field update?

I added a new (text) field to a Drupal 7 content type that already has many nodes. How can I fill the field with a default value for all these nodes?
51
votes
7answers
45k views

“OR” condition in db_select()

I am studying the new database layer, and I am glad it is changed to an OOP layer. I need to implement a query with db_select(). I found I can add a WHERE statement with $query->condition(), but by ...
30
votes
2answers
33k views

Eliminate render-blocking JavaScript and CSS in above-the-fold content

I am building a Drupal 7 site. These are some of the modules I use: Adaptivetheme (theme), Views and Content Panes, Panels, Mini panels, Panels everywhere, Page manager, Superfish for menus, Addthis, ...
39
votes
3answers
52k views

How do I customize the search result page?

I have customized the teaser view of my content types and the page view. Now I need to use the teaser view for the search results page. By default, Drupal displays a full text jumbled mess for each ...
46
votes
10answers
62k views

Check if a user has a role

How can I check if a user has a certain role? I found this but it is for Drupal 6.
23
votes
4answers
10k views

Are views cached through the core caching mechanisms or should I be setting the caching directly in each view?

I see there are cache settings in each of my views. Do I need to set these or does the core caching mechanisms in /admin/config/development/performance automatically do some of this and these "extra ...
19
votes
2answers
15k views

Using views with a custom table/schema

I need to set up some views that will pull some data from a custom table I created. Some views will need to pull content the regular way and from my custom table (where I may query for a particular ...
14
votes
2answers
16k views

Where is links__system_main_menu defined?

I searched for links__system_main_menu, but just find usages of this theme. Where is it defined?
21
votes
6answers
13k views

How to find orphaned files and images which are not linked from any css stylesheet or from any node?

Is there a way to list all unused files which reside inside public file system and inside a theme directory and list them, or maybe even have an option to delete them automatically? I mean files ...