All Questions

Filter by
Sorted by
Tagged with
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?
4
votes
2answers
15k views

Get current language in template

In Drupal 7 the current language is a global variable we can access with global $language; $langcode = $language->language; I want to know how can we access the current language in a Twig file ...
8
votes
3answers
341 views

Is there a more performant alternative than overriding template files?

I've got to get rid of a lot of unnecessary markup in a view. In general, I accomplish that by overriding the template files in my theme, but this time the view is really huge and performance is going ...
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
654 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
719 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
2answers
2k views

How to force a redirect (override the destination query string in the URL)

I have a custom form submit callback to redirect users to a specific page: function MYMODULE_authfrontpageredirect_callback(array &$form, FormStateInterface &$form_state) { $url = \Drupal::...
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: ...
2
votes
3answers
905 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 ...
-1
votes
4answers
3k views

is it possible to have one views-view--VIEWNAME--page.tpl for multiple views?

I have 8 content types and 4 of them are the same and the difference is just their name. they all have a page view and the way I display them on screen is the same. instead of having 8 pages. (...
46
votes
7answers
38k 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 ...
47
votes
6answers
31k views

How can I import the configuration on a different site?

I have this error when I try to import the config of an another site: The staged configuration cannot be imported, because it originates from a different site than this site. You can only ...
52
votes
3answers
16k views

Is it possible to replace more than one form element (wrappers) triggered by only one #ajax trigger element?

function ajax_example_simplest($form, &$form_state) { //This is my ajax trigger element $form['element_trigger'] = array( '#type' => 'select', '#options' => array( 'one' =&...
44
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?
50
votes
7answers
44k 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, ...
53
votes
8answers
85k views

How do I get the current path alias or path?

How can I get the current alias and/or path in Drupal 8? In Drupal 7 I did this with drupal_get_path_alias(). What is the equivalent code I should use in Drupal 8?
39
votes
3answers
51k 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 ...
31
votes
2answers
11k views

What's the difference between Page manager and Panels?

I'm writing this question, because I see confusion all over the Drupal community about "what is Page manager", and "what is Panels".
49
votes
4answers
66k views

How do I get the current node ID?

In Drupal 7, if I wanted to get to get the node id of the currently displayed node (e.g. node/145) I could get it with the arg() function. In this case, arg(1) would return 145. How can I achieve the ...
52
votes
2answers
29k views

What are all the directories for in the new Drupal 8 structure?

Drupal 8 re-arranged all the directories and locations of modules/themes etc. Where do things go now?
28
votes
7answers
36k views

How to execute php script using drush?

I am new to Drush. How can I execute this script to remove comments of a specific user? $uid = xx // the spam users id; $query = db_query("SELECT cid FROM {comments} WHERE uid = %d", $uid); while($...
46
votes
10answers
61k 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?
7
votes
3answers
19k views

How do you theme a content type's create/edit form in Drupal 7?

Like it says -- I've got a D7 content type whose editing form needs to be themed. I did this all the time in D6 by registering theme functions in template.php and writing the associated theming ...
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 ...
38
votes
7answers
9k views

Is there a good way to inspect objects whose type is derived from the EntityDrupalWrapper class?

I'm sure this question applies to other complex object types, but EntityDrupalWrapper is the one I'm currently working with. This is the type of object returned by entity_metadata_wrapper() (and ...
31
votes
8answers
17k views

How to make a form required with states?

I have a drop down list that displays various fields based on what is chosen and I know that I can toogle the visibility with states but when I try to use required the * span is display but it isn't ...
19
votes
2answers
976 views

How to use the Features module in a 3 dev environnement?

Working on a project, making heavy use of Features, there is sometimes 3 devs for this application. We have tried a few approaches, but when we merge our git branches it seems we often 'over-write'...
8
votes
2answers
17k views

How can I display a change password form on its own?

I have a need to place a user's password reset form in areas outside the context of the user edit page. This Change Password module looked promising; however, it is only available for drupal 6 and ...
39
votes
9answers
42k views

Manually disable a module

In Drupal 7, I could manually edit the {system} table in the database to disable a stubbon module. In my Drupal 8 site, this table is gone. How can I manually disable a module in Drupal 8?
39
votes
1answer
18k views

Managed file: the file used in the field may not be referenced

I am having some issues with the managed_file type. Whenever I try to edit and save a form that has a managed_file element in it an error occurs: The file used in the Picture field may not be ...
9
votes
1answer
12k views

Send a form to twig template

How I can pass a form to twig template in Drupal 8? For example, I get this: a form: mymodule/src/Form/MyForm.php Then on my Controller: public function myController() { ?????? return [ ...
8
votes
1answer
14k views

How can you render fields from an entity reference in node templates? [Drupal 8]

For context, I'm dealing with two content types: article and team_profile. In article nodes, we have an entity reference field pulling a team_profile node in to serve as the author information. I ...
11
votes
5answers
33k views

how to use hook_views_query_alter() to modify where condition?

I'm trying to modify the where condition of a views query. till now I was successful with altering "order by", but I have no idea how to alter the where condition. I want to check the search_term and ...
19
votes
4answers
9k views

EntityFieldQuery vs Db_select()

Why should I use EntityFieldQuery when I can do the same work with Db_select() to fetch the value. It would be better if someone can provide an example, not only a link.
8
votes
3answers
17k 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 ...
3
votes
3answers
7k views

Implementing CKeditor's plugin

I need to add the Templates plugin into Drupal8 CKeditor. So far it is available on the editor configuration page, but not on a node edit page. The code: namespace Drupal\module_name\Plugin\...
19
votes
7answers
12k views

fast saving single field value

I've got around 70k nodes of specified type on my site. I need to run an update on them. Some operations and setting one field to desired value. node_save is really slow and it causes crashes (too ...
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?
13
votes
2answers
5k views

Override field template with custom module

Instead of adding tpl files (in this case, media-youtube-video.tpl.php) to the theme. How can I override field templates from a custom module? Including when the field is used in a View.
10
votes
5answers
18k 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->...
9
votes
5answers
3k views

Deploying content updates from staging server to live server

We are trying to deploy content updates from our staging server to our live server but are having difficulty finding a good way to do this. We need to be able to deploy new pages, page updates and ...
7
votes
3answers
2k views

Slashes in single route parameter or other ways to handle a menu tail with dynamic number of params

According to the Symfony documentation, a route defined as below should trigger the specified controller for both /hello/bob and /hello/bob/bobby: _hello: path: /hello/{names} defaults: { ...
7
votes
4answers
4k views

Anonymous user cache control

We have written some custom blocks that render dynamic content; unfortunately, the caching defaults cache the first render of this block (and don't refresh for anonymous users). Cache control seems to ...

15 30 50 per page