All Questions

22
votes
8answers
58k views

How can I find the form ID of a form?

How do I get the form id of my form? I've just begun to make my modules and I'm at a standstill. I got this code from someone else and am trying to customize it: function hook_form_alter(&$form, &...
23
votes
5answers
18k views

How to programmatically create a custom token in a module

How would you go about programmatically creating a token? I wish to add some custom tokens for my module.
9
votes
2answers
18k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
15
votes
2answers
6k views

How to create a empty module? [closed]

What is the most basic valid module one can create in Drupal? It would be useful to have a simple blueprint available, for anyone just getting started with Drupal.
13
votes
5answers
12k views

Cache Form table size is enormous

Cache table's size had increased to 10+ GB last month, and I had fixed it temporarily by truncating it. Last time I checked it was around 1GB. So in couple of months it will hit 10GB again. How should ...
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 ...
13
votes
3answers
10k views

How do I alter the route defined by another module?

In other words, what is the Drupl 8 equivalent of hook_menu_alter()? Drupal 8 still uses hook_menu(), but for what I can see, the information returned by the hook is different from what the hook ...
10
votes
13answers
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 ...
6
votes
5answers
4k views

Cannot edit my views.. I get a JSON string?

I'm using Drupal v7.22 and whenever I try to Modify the Display on views, and press the 'Add and configure' button on adding a field, or any button that sends data to the server, the page reloads and ...
6
votes
5answers
14k views

How to create a node with submissions of a webform?

I'm using Drupal 7 and created a content type 'NewArticle' with the fields 'Title', 'Text' and 'Image'. Users have the permission to create a 'NewArticle', but I don't like the way of displaying the ...
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 ...
13
votes
7answers
17k views

How do I call the menu_rebuild function in Drupal 7?

I would like to call the menu_rebuild() function, but I am not sure of where exactly paste the code snippet. I can't find the update.php file anywhere in my local instance. The reason I would like ...
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 ...
8
votes
2answers
4k views

Show node IDs along with titles in Entity reference Autocomplete list

I'll like to add this functionality to the autocomplete widget in Entityreference field to show node ID next to the titles in the dropdown list. The reason behind the idea is to differentiate between ...
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?
3
votes
2answers
2k views

Search results only for the current language

I have a site with 4 languages and am using the builtin search to look for content on the site. How is it possible to restrict the search results only to the currently selected language? I tried ...
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
4k 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 ...
18
votes
1answer
4k views

How can I change the active theme programmatically?

How can I change the active Drupal 8 theme programmatically? In Drupal 6, we used the following code. global $custom_theme; $custom_theme = 'garland'; In Drupal 7, we used hook_custom_theme(). In ...
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
829 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
573 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?
60
votes
9answers
113k views

How do I access a field value for an entity (e.g. node) object?

node_load((int) $nid) loads a fully-populated node entity. $node->title->value gets the title, but how do I access field values in Drupal 8?
41
votes
15answers
62k views

Getting the image URL from a field_image on a node

So I have this Node: object(Drupal\node\Entity\Node)[1862] protected 'values' => array (size=17) 'vid' => array (size=1) 'x-default' => string '7' (length=1) ...
38
votes
9answers
42k 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
30k 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?
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?
26
votes
10answers
30k views

How do I set the page title?

I know I could change the page title with drupal_set_title(t('Amy page title')), but when I try it in Drupal 8 I get the There is no such function error. How can I change page title in Drupal 8?
16
votes
2answers
12k views

How to debug EntityMalformedException?

I've got fatal error EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7700 of .\includes\common.inc) when trying to access user/xyz. I tried to ...
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 ...
6
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://...
5
votes
2answers
3k views

Change a normal submit 'input' type to 'button' type with button tag

Is it possible in Drupal 8 to change a regular form submit button from Drupal into a button tag? This is the output I need to achieve: <button type="button" class="search-box__button"> <...
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->...
9
votes
4answers
16k 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
14k views

Expose single filter of combination of two fields in views

I have two user profile fields "Last Name" and "First Name". I also have a user list views. I want to expose "Name" as filter which can search for both Last Name and First Name. How can I do single ...
18
votes
1answer
26k views

Contextual filter with a block view

I have a page view("/news") with contextual filter for the topics ("news/design","news/coding"...) which are taxonomy terms and this worked fine. Due to some changes for the mobile theming, I need a ...
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 ...
6
votes
4answers
17k views

how to get the translated taxonomy term programmatically? [duplicate]

I have tried this $term = taxonomy_term_load($tid); and this: $term = i18n_taxonomy_localize_terms(taxonomy_term_load($tid)); Both return the default language (English) term I am using D7.
17
votes
3answers
22k views

Filtering on node whose user ID is equal to the current user

In Drupal 6 you can have a filter node.uid = current user. How do you do this in Drupal 7?
9
votes
5answers
17k views

How to get the translated term name by tid?

I'm looking for a working method to get the translated term name by tid. The following code returns the original term name but not the translation. global $language; $lang_name = $language->...
8
votes
2answers
14k views

How do I get a block to use a URL to configure a contextual filter?

Blocks do not have paths so how can I pass a context to the block to get the correct results for a page? I am new and do not have enough reputation to answer my own question for eight hours (Go ...
4
votes
6answers
7k views

How to print paragraphs in twig template

I have a content type, basic, where i have added a Paragraph field (field_pr) that has two fields: field_text, field_color. I have a twig template node--basic--full.html.twig where i want to print the ...
15
votes
13answers
14k views

How to remove the “No front page content has been created yet.” message from the front page?

I only want blocks on the homepage. Because I don't have any nodes, and I want to keep the homepage as /node I am getting a "No front page content has been created yet." message on my page. How do I ...
5
votes
3answers
23k views

Solving “MySQL server has gone away”, mysql error 2006 [duplicate]

I have a site at hostgator, using their "Business account". It's cheap, and comes with a private SSL cert. HOWEVER, their MySQL settings are such that any db connection goes stale fairly quickly, and ...
11
votes
5answers
39k views

How to print fields in node.tpl.php?

I need to print individual fields from the $content variable in node.tpl.php file in separate div tags. How do I do that and how do I find out what the field's names are?
10
votes
2answers
19k views

Programatically print blocks in twig [duplicate]

In drupal 8 I want to print the block programatically. For this I have tried the below code but not working. function theme_preprocess_page(&$variables) { $block = \Drupal\block\Entity\Block::...

15 30 50 per page