All Questions

Filter by
Sorted by
Tagged with
29
votes
2answers
21k views

What is the meaning of the field:delta content type offered in contextual filters in views?

When creating a new contextual filter for a view the list of types includes options such as content:spec (field_spec:delta) where spec is the name of a field I have attached to the content type ...
29
votes
8answers
10k views

How do I migrate block content from a dev to a production site?

I've finally started looking at Drupal 8 seriously and I'm particularly interested in the configuration management. I've come across something that could be a little bit problematic and that's ...
29
votes
2answers
8k views

Programmatical use of Search API

Problem: Need to run my own searches programmatically with Search API. Every google result I find is geared toward teaching non-developers how to use the module with Views with no results on doing it ...
28
votes
11answers
53k views

List of all active modules used in a site

Is there a way of having a list of all the used (active) modules on a site ? I am in the process of documenting a site and would like to list all the active modules, I know I can take them from admin/...
28
votes
8answers
49k views

Iterate through multiple value content field in Twig template

I need to take control over the rendering of a field_admin_tags field in a node.html.twig template. This WORKS: {{ content.field_admin_tags }} — Renders everything (label + all field values) {{ ...
28
votes
3answers
68k views

Get path to theme assets in Twig template

I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png". In ...
28
votes
5answers
30k views

Load term by name

In Drupal 7, we can load the term using name for ex. taxonomy_get_term_by_name($name) Is there any way to load term via given name in Drupal 8?
28
votes
7answers
51k views

How to programmatically trigger a click on an AJAX enabled form submit button?

I'm trying to programmatically (with jQuery) trigger a click on button with AJAX behavior in a Drupal form, but so far jQuery('#edit-submit').click() doesn't do anything. A real mouse click on that ...
28
votes
3answers
51k views

Programatically render a block in a twig template

I need to render a views block in my page.html.twig template. In D7 I would do this: <?php $block = module_invoke('module_name', 'block_view', 'block_delta'); print render($block['content']); ?...
28
votes
3answers
43k views

Programmatically update an entity reference field

I know I can update (or set a value for) an entity reference field in Drupal 7 with code similar to the following. $node['field_code_used_by'][LANGUAGE_NONE][0]['target_id'] = $id; I want to ...
28
votes
2answers
24k views

How to create test_endpoint?

I am new to drupal and I am using services module for using REST and RESTWS module. I used RESTWS and could get the content of the node by http://base_url/node/1.xml and now I need to add a node ...
28
votes
6answers
16k views

Debug EntityFieldQuery?

I have a module which is misbehaving. An EFQ is returing unexpected results, but I can't see why just by looking at the code. Is there a dpq() equivalent for EFQs? Other ways of debugging them?
28
votes
5answers
37k views

How do I use "NOT IN" in a query?

What is the proper way to write a query containing 'NOT IN' using a condition statement? My query is the following one: SELECT DISTINCT nid FROM node WHERE language NOT IN (SELECT language ...
28
votes
6answers
24k views

drush updatedb for a single module

Is it possible to perform a single module's update function via drush? I can see drush updatedb which does not take an modulename as argument and runs all available updates. Then there is drush pm-...
28
votes
3answers
18k views

Is there a function to get the current user object that avoids accessing the global variable?

I've always gone with this global $user;. However, I seem to remember seeing something in a contributed module that returned the current user object without using the global $user. Does such a ...
28
votes
5answers
22k views

How do I override a taxonomy/term/% list with a view?

I have a vocabulary attached to a content type. Only one term can be selected to categorize a node made with this content type. The vocabulary is called Vehicles and has terms 'cars, trucks, boats.' ...
27
votes
4answers
20k views

Difference between create new and edit node in form alter

I have an alter section for a particular content type. In the form alter how can I find out whether it is create new form or edit form? With dsm($form) in from alter I can get results with several ...
27
votes
2answers
51k views

List all terms from a vocabulary

I have a taxonomy called services and want to list out all the terms. I can load the vocab with $vocabulary = taxonomy_vocabulary_machine_name_load('Services') but cannot seen to get all the terms ...
27
votes
8answers
82k views

How do I get only one result using db_query()

I am transitioning from 'old school' PHP MySQL methods of using mysql_fetch_array(), etc. and I am trying to be more Drupally by using the Database API in my modules. I simply want to return and ...
27
votes
11answers
13k views

How can I find out a list of available $string values for user_access($string) function?

user_access($string, $account = NULL) $string: The permission, such as "administer nodes", being checked for. How can I find out a list of available $string values for user_access() function?
27
votes
4answers
9k views

Adding components to a feature via Drush

I understand using 'drush fu' to look for changes to any components of an existing feature, but is there a way to add a component to an existing feature using drush? Right now I have to use the /admin ...
27
votes
11answers
6k views

How to prevent Devel module to be installed on production environments

Using the new Drupal 8 Configuration manager, how can I prevent it from installing the Devel module on certain environments? As far as I know, installing it on my local means the next time I export ...
27
votes
4answers
17k views

Database general error: 2006 MySQL server has gone away

Recently I started getting an error every time I try and add a content no matter what type. This is the error that shows up in the browser: Additional uncaught exception thrown while handling ...
27
votes
2answers
26k views

How do I set allowed extensions for a managed_file form field?

Not having any luck find this in Drupal documentation or developer examples. I need to set a managed_file form field to only allow zip files in a Drupal 7 custom module.
27
votes
6answers
30k views

How to add module to admin/config page?

I'm working on a module in Drupal 7. I've added a hook_menu implementation: $items['admin/config/content/mymodule'] = [ 'title' => 'MyModule', 'description' => 'Configure ...
27
votes
1answer
12k views

what is the difference between render() and drupal_render()?

what is the difference between render() and drupal_render() anyway ? Is there a reason to use only drupal_render()?
27
votes
1answer
21k views

How to create a view type of Entity reference display?

I have an entity which contains a field collection of entity references and can edit the entity references with the Entity selection mode is Simple (with optional filter by bundle), but only Entity ...
26
votes
7answers
58k views

How to programmatically get the NID of the current node

I've pored over this old thread on drupal.org and it just kind of makes my head spin around. Pulling down the path and trying to parse out the NID from within it? There has to be a better way. And ...
26
votes
3answers
60k views

Add a custom submission handler to a form

How can I add a custom form submission handler? I tried adding $form['#submit'][] = 'mymodule_form_submit'; or $form['actions']['submit']['#submit'][] = 'mymodule_form_submit'; to hook_form_alter(). ...
26
votes
2answers
21k views

How can I check if a module is enabled?

In Drupal 7, you can use module_exists() to check whether a module is enabled (as well as whether it exists). For example, if (module_exists('devel')) { How can you check whether a module is ...
26
votes
6answers
24k 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.
26
votes
3answers
19k views

How to assign permissions to roles programmatically?

I have some permissions that I would like to assign to some roles programmatically for easier installation. Because I'm installing the module and creating both permission and roles, I don't have the ...
26
votes
5answers
21k views

Using OR with EntityFieldQuery

I have never had the need to do this before today, but it doesn't seem like you can make OR queries with EntityFieldQuery, since db_or is used for select queries. An example would get to all entities ...
26
votes
4answers
32k views

How to theme a custom block

I've created a block using hook_block_info and hook_block_theme and the like. But how can I theme it? I have it working to return an array with the keys 'subject' and 'content'. But I created the ...
26
votes
5answers
38k views

How to send HTML email

I am creating a simple module which will be sending HTML emails to users for deals in our website. I have searched a lot, but I can't find a solution proper solution for Drupal. Now I can send mails ...
26
votes
3answers
6k views

How can I programmatically change the active theme?

How can I programmatically change the active Drupal 8 theme? In Drupal 6, we used the following code. global $custom_theme; $custom_theme = 'garland'; In Drupal 7, we used hook_custom_theme(). In ...
26
votes
5answers
10k views

Node translation vs. Entity (field) translation

I would like to know what you guys recommend for a multilanguage site. For example, consider the following case: A page and its content should be available in 3 languages (e.g. German, English, and ...
25
votes
14answers
15k views

How can I stop Drupal from sending e-mails of any kind?

I have a dev, staging, and live server workflow set up on Pantheon. My site has a lot of rules that cause members to be e-mailed for various reasons. I sometimes need to work on these on my dev/...
25
votes
9answers
74k 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, &...
25
votes
10answers
55k views

Get taxonomy terms

I wanted to retrieve taxonomy terms from a certain vocabulary in Drupal 8. Apparently I can still do it using taxonomy_get_tree but it's deprecated. I now have to use TermStorageInterface::loadTree ...
25
votes
7answers
49k views

Adding form placeholders to text input fields

Is there a way to convert a regular form and add placeholders with a module, or should this be done with a form template or with jQuery?
25
votes
3answers
45k views

How do I get the node URL in a Twig template?

I am trying to get the node URL in a Twig template. {{ content.node_link }} returns the full link, but I only need the URL. How do I retrieve the node URL?
25
votes
7answers
42k views

How to redirect to a page after submitting a form

I have a custom module that displays a form. Upon submitting the form, I want to redirect the user to a different page. How can I do that?
25
votes
5answers
40k views

How do I programmatically render a view with contextual filters?

How do I programmatically render a view with contextual filters in Drupal 8? In Drupal 7, I generally use the following code. $view = views_get_view('test_view'); //test_view is the view machine ...
25
votes
7answers
23k views

How to see the error messages when I get the white screen of death?

How can I see the error messages when the site I am working on gets a white screen?
25
votes
4answers
30k views

How to completely turn off caching?

I am developing a site in Drupal 7 and caching slows my work significantly. For example, I had a theming function for a form. I was puzzled, why doesn't it work. Until I cleared the cache and it was ...
25
votes
1answer
14k views

Can regions be printed within a node template?

Can regions be printed within a node template, or are regions strictly confined to page templates?
25
votes
5answers
24k views

Preprocess function per content type

I have a couple of content types which I need to preprocess in different ways. So template.php in my theme foo currently looks like: function foo_preprocess_node(&$variables) { if ('news' ==$...
25
votes
3answers
15k views

Which should I use and when: node_load() or entity_load()?

Title says it all. I understand that entity_load provides a performant and efficient means to load multiple nodes whilst reducing database queries, so I presume in that instance I should be using ...
25
votes
5answers
16k 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 ...

15 30 50 per page