Retrieve entities based on entity properties, field values, and generic entity metadata (bundle, entity type, entity ID, and revision ID). It is not possible to query across multiple entity types....
You are here
Drupal is a free and open source Content Management System (CMS) and Content Management Framework (CMF) written in PHP. It's use as a back-end system varies from personal blogs to corporate, political, and government sites.
24 Jul, 2018
Exclude content from these tables, to get clean db backup(backup_migrate module usage). You can even use git to store your database, when you don't export cache tables.
16 May, 2018
This snippet shows you how to load a file by uri. Basically this option is available with file_load_mulitple only.
4 May, 2018
Field group lets you do some amazing forms. Still when you have empty element or the form just is too long and needs some custom modifications, you can then use prefix and suffix from form api to...
26 Mar, 2018
Delete all terms from all vocabularies in Drupal 7. This is ran by Drush, but you can run it from wherever Drupal is initialised.
12 Mar, 2018
Example for how to create product variation types programmatically.
24 Feb, 2016
You can use "group by" in views to group data by a field. When you start writing css for it, or even use accordion. You need to wrap the rows into a container. This can be achieved by creating a...
29 Nov, 2015
Changing line item price is not as easy as you could think. It can seem that the price has changed, but there are multiple places where you have to actually change it. Especially when you compute the...
19 Nov, 2015
Just a snippet that shows how to check if current user has edit permissions for some node in Drupal 7. Using node_access function like in the example you are also able to check permissions for...
9 Nov, 2015
This nifty little snippet will scan your module for tpl.php files.
13 Jul, 2015
Snippet shows how to uninstall modules programmatically. This is not deleting the files, but doing a full uninstall.
23 Mar, 2015
Getting URL query parameters array where unwanted elements are removed. For that you can use drupal_get_query_parameters function. In default q parameter will be removed. That parameter includes...
4 Mar, 2015
Sending data using POST to external url should be done by using drupal_http_request.
18 Feb, 2015
Edit field output after the field module has performed the operation. This gives you possibility to alter the field output before rendered in your module. This works with display suite and other...
10 Feb, 2015
Since this snippet includes a lot of information the title is simply a bunch of keywords. Basically we are using file uri to determine if it exists and is managed or needs to be saved as new managed...
5 Feb, 2015
The idea would be that you don't take any values directly from node_load result. You can either use entity wrapper(is not a part of this tutorial) or field get and view functions.
3 Feb, 2015
Entity API provides wrapper classes that make dealing with the values of an entity's properties and fields easier. This post is to make the information easy to learn by examples.
24 Oct, 2014
This is how you can load menu items children. Also the example / snippet is about how you can get the first child, but the menu has to be in a single language tough. It takes access and being hidden...
2 Oct, 2014
This snippet shows you how to get menu link id (mlid) from node id (nid) using a simple query generated by abstraction layer in Drupal 7.
30 Sep, 2014
This snippet shows you how to get a single query result as string in Drupal 7, using database abstraction layer select.
25 Aug, 2014
There are many functions for menus, but since Drupal is not hierarchical but is modular, that's why menu doesn't have node requirement and the opposite way around. So this snippet shows how to get...
28 May, 2014
PHP array of iso country list. This list includes Kosovo (KV) and Democratic People's Republic of Korea (KP). That I found hard to find from somewhere else.
1 May, 2014
This snippet shows you how to create contextual links in Drupal 7. If you don't know what contextual links are then those are the links in front end that come up from the ratchet.
29 Apr, 2014
How to install any version of Drupal using Drush the Drupal Shell. You can replace the version name with the version you like. Also feel free to replace words in caps to get an installation that you...
24 Mar, 2014
Sometimes menu gets messed up and all the new links go on the admin menus first level. Or you have other reasons to rebuild menu. You also need devel module to do this.
24 Mar, 2014
This shows code examples of what I had to do to create custom pane programmatically for Panels in Drupal 7. In this example I create new pane where you can pick your node and display it.
14 Mar, 2014
First you need to add the connection information of the other database. This way you can use drupal database abstraction layer for altering any database.
10 Mar, 2014
This tutorial describes how you can group the results of a view by first letter of their title. This might not suit for you in two cases, first if you need to order them by ascii not utf-8, secondly...
7 Mar, 2014
There is a module called migrate that enables you to migrate content to Drupal. This snippet shows you how to migrate image from URL to Drupal 7. You have to get file name from the importing source...
26 Feb, 2014
I had a problem with path breadcrumbs where I couldn't get taxonomy therms through commerce product reference. So I had to disable the path breadcrumb for the node and do it manually. I didn't want...
21 Feb, 2014
Add content to view header, footer, before or after using hook_views_pre_render() in Drupal 7. Using hook_views_pre_render gives you the opportunity to use values from executed views query.
20 Feb, 2014
Change or update field instance programmatically in Drupal 7. For more information check out Field CRUD API in drupal.org.
2 Jan, 2014
Use hook_page_build() instead of hook_init() to add CSS or JS to every page. The reason is that hook_init() runs on every request that goes to Drupal (AJAX requests, private file requests, boost /...
15 Nov, 2013
This snippet shows you how to change date format for better exposed filters in Drupal 7. I was not able to use strtotime with the default setting.
14 Nov, 2013
Installing module programmatically in Drupal 7 can be achieved with just one step, using module_enable function.
5 Nov, 2013
Converts URLs in text into links in Drupal 7 automatically. Three types of "links" get converted. URLs like http://example.com, e-mail addresses like email@example.com and urls without the "http://"...
7 Oct, 2013
This snippet shows how to get taxonomy vocabulary id (vid) by machine name of taxonomy vocabulary Drupal 7.
3 Oct, 2013
This snippet shows you an example of using image_scale_and_crop function to scale and crop image as in image styles.
2 Sep, 2013
List of useful hooks and functions in Drupal 7. You can find here something new or just bookmark it for your reference.
21 Aug, 2013
Change or add file icons to Drupal 7. First you have to define your mime type of a file, if it isn't done already. Then add icon URL to that mime type (16x16).
8 Aug, 2013
This example shows you how to create time field using date module and Field API in Drupal.
30 Jul, 2013
This example shows how to alter filter in views exposed filters using form_alter in Drupal 7.
14 Jul, 2013
This snippet shows you how to customize views RSS feed title in Drupal. This example shows you how to create title for taxonomy feed, so that the title would be the term with it's parents.
12 Jul, 2013
How to use colorbox module programmatically. Colorbox module provides with loading inline content, explained here: https://drupal.org/node/1971564. Since that didn't work for me, I tok a different...
12 Jul, 2013
This tutorial shows you how to exclude current node from view. For an example, if you need a block that shows related content by taxonomy then you want to exclude current node from the list.
7 Jun, 2013
This snippets shows you how to create lists the right way using theme_item_list.
28 May, 2013
This simple snippet shows you how to add body class programmatically from your module in Drupal 7.
20 May, 2013
Creating views view in your module is really simple.
5 Apr, 2013
Sometimes you have to make button that skips form field validations. For an example Cancel button. This snippets shows how to skip form validation for button. Works in Drupal 7.
3 Apr, 2013
How to translate localized taxonomy terms in Drupal 7.
19 Feb, 2013
How to override page title in your theme, after all modules have done their jobs.
8 Feb, 2013
This snippet shows how to remove form elements in Drupal. I am using hook_form_alter and access parameter from form api.
27 Jan, 2013
Changing page titles in your theme. There is also hook_page_title_alter hook. If for some reason you still want to do it your theme, then this is how.
23 Jan, 2013
How to use select query as where clause in Drupal views module query alter. You can't use hook_views_query_alter, because it places single quotes around the value. So you can't use query instead of...
1 Dec, 2012
This snippet shows you how to Localize taxonomy term in Drupal 7.
28 Nov, 2012
You can only change event colors by content type or taxonomy terms in Calendar view. More advanced coloring requires some programming.
23 Nov, 2012
How to turn plain text URLs into active links in Drupal.
25 Oct, 2012
This snippet shows how to use jQuery datepicker in Drupal. Drupal already includes jQuery and jQuery UI in its core. So you just have to make sure it's loaded and then you can use it in your scripts.
30 Aug, 2012
Creating email field. The field is still textfield, you just have to make validation for the field.
23 Aug, 2012
Creating your own template files that you can use in your modules in Drupal 7. Template files are for separating HTML from PHP. This tutorial shows you how to create and use tpl.php files. Template...
22 Aug, 2012
Programmatically create menu link language relation in Drupal 7. This example takes a certain taxonomy vocabulary by id and creates language relations to menu links by terms relations. You might need...
21 Aug, 2012
This query gets node created dates and selects all years of nodes that has been made. Also there are filters: node.status equals 1 is published filter, node.type is content type filter and node...
14 Aug, 2012
How to make sure your cron task runs once per day in Drupal? You can set crontab once per day, but you still might want to run cron manually every now and then. Also you might have to change the cron...
12 Jul, 2012
Create table using theme table in Drupal. This is the simplest example of creating table. In the code I added link to the documentation. You can do things like add classes, caption, colgroups etc.
25 Jun, 2012
Show Drupal 404 page programmatically. Just return this function from your page function.
2 May, 2012
How to add node to nodequeue using a little code. You can make it automatic using Rules and PHP filter module(in core that adds option to add PHP code to textarea).
2 May, 2012
Translate block title in Drupal 7 using this theme hook.
20 Apr, 2012
Drupal SQL query examples, includes regular query and select, insert, update and insert or update using abstraction layer. Explanations of different data return types like fetchassoc, fetchall and...
6 Apr, 2012
How to fix page titles for taxonomy term pages. It creates title from term hierarchy. You have to remove the views title override.
6 Apr, 2012
Load taxonomy term object by name or tid. Also how to get term parents from top to bottom.
13 Mar, 2012
How to get term name in right language in Drupal? Internationalization (i18n) module is used for localization.
3 Mar, 2012
How I set up my multi-site in localhost so that my different sites would be in different sub-folders. I did it on my windows machine.
9 Feb, 2012
How to remove language links from node links in Drupal 7
26 Jan, 2012
How to change file name programmatically after file is saved in Drupal 7.
23 Jan, 2012
First you need to create a filter to your views. Add "Feeds log: Importer id" filter to All entries display / tab. Then this code snippet alters the form so there won't be textfield, but selection.
16 Jan, 2012
How to remove views view filter programmatically in Drupal.
19 Dec, 2011
This code snippet is about creating languages form field in Drupal 7 using field api.
13 Dec, 2011
How you can add field to an entity programmatically in Drupal 7.
8 Dec, 2011
Adding body classes in Drupal 7. Just a little code snippet that can be useful in some cases.
29 Nov, 2011
How to display eck form anywhere you wish, just few lines of PHP can make you a big head ache.
15 Nov, 2011
Redirect users to their main language first visit. I needed it only on the front page, but you can simply remove the if statement if you need the functionality on every page. The language detection...
23 Oct, 2011
How to create forms that are submitted via ajax. To understand this tutorial you have to have a basic knowledge of Drupal programming and its form api.
19 Sep, 2011
To change breadcrumb in module you can use two functions. You can change breadcrumbs separators or the whole logic using theme_breadcrumb in your templates template.php file.
18 Sep, 2011
This function embeds views view in Drupal. This function doesn't display the title of the view.
8 Sep, 2011
How to get taxonomy term depth or level in Drupal 7.
8 Sep, 2011
How to get vid - vocabulary id by vocabulary name in Drupal 6. You can get it by using this little function.
20 Aug, 2011
How to get taxonomy vocabulary id(vid) by machine name in Drupal.
20 Aug, 2011
Sometimes it's hard to set the title you want for your views. So you have to do this programmatically in your module. This snippet shows you how.
17 Aug, 2011
How to edit views content before rendering the view. This is what you need in your Drupal 7 module.
9 Aug, 2011
How to hide default /node page from viewers. It's useful to do this if you don't use the page. People might access to some unwanted places.
8 Aug, 2011
How to make enter insert br tag instead of p tag. Works when using WYSIWYG module and ckeditor or tinymce.
8 Aug, 2011
This menus page shows child menus under that menu item.
7 Aug, 2011
This snippet shows how to change page title on search page. For this example the title will be the content of search box(search string).
4 Aug, 2011
How to include module file to anywhere. For an example if you want to spread up your functions in different files for structure and readability then this is the right way of including module files.
29 Jul, 2011
How to print sub-menus or any level menus in Drupal 7. You get only sub-menus of the current page you are on.
27 Jul, 2011
I used theme hook called theme_css_alter. There is an array where are the css files. Foreach loop to go through them and unset ones that shouldn't be there. This one goes to your themes template.php...
22 Jul, 2011
Menu delimiters or separators in Drupal. Tested on Drupal version 6.
21 Jul, 2011
By placing this code to your themes template.php file, you get search results grouped by node/content type.
19 Jul, 2011
This snippet shows you how to load a blocks content programmatically. You can use this way to display a block anywhere you want.
18 Jul, 2011
This snippet shows how to redirect form after submitting and saving in Drupal 7. You can also use Rules module for this.
17 Jul, 2011
16 Jul, 2011
This little snippet shows you how to create roles programmatically in Drupal 7.
16 Jul, 2011
Creating content types programmatically in Drupal 7. If you add this code to install hook then this way you can define your own content types in a module for an example.
10 Jul, 2011
Save file or image programmatically. First get file from directory or URL. Then save the image and assign it to the field you wish.
7 Jul, 2011
How to create custom language switcher. You can write your own tags and classes to get completely custom language switcher.
23 Jun, 2011
How to get node ids of certain content type in Drupal.
21 Jun, 2011
To add add dependencies to Drupal modules you have to open your modules .info file. Add new line "dependencies = module_machine_name" and you are done.
19 Jun, 2011
How to order views programmatically. You might need to do this on special occasions. This hook initializes before query is built so it goes for all data, not just current page.
17 Jun, 2011
This snippet is a code from my module that just makes a simple menu item into my admin menu in Drupal 7. I am using menu_hook function to achieve this.
15 May, 2011
How to get node path alias in Drupal. All you need to know is node id(nid).
14 May, 2011
How to add taxonomy terms programmatically in Drupal 7.
10 May, 2011
How to place Drupal node comment form to anywhere in your module or theme.
22 Apr, 2011
ColorBox for images is loaded on first load, so all images loaded by ajax are colorBox free. To enable ColorBox for ajax loaded images you have to scan the html for images after load is complete....
21 Apr, 2011
You can enable or disable comments programmatically. Get node using node_load, set comment value and save node.
17 Apr, 2011
First find this line: $form['path']['pathauto_perform_alias'] = array( Then add: '#value' => 1,
6 Apr, 2011
This tutorial shows how to get taxonomy terms names in Drupal 7. First how to get all taxonomy terms, how to get categories by a parent and with a little effort, you can turn it into a treeview.
17 Mar, 2011
I needed to get some xml data and generate nodes out of them. This shows how I created nodes programmatically from my module in Drupal 7. I also suggest looking into creating a node using entity...
14 Mar, 2011
How to get profile fields in Drupal 7. Profile fields are made with Profile2 module.
12 Mar, 2011
This beginners tutorial shows how to create a durpal module. We will set up a module, create a menu item and a "Hello World" page.
11 Mar, 2011
How to get full/absolute url of the page you are currently visiting.
22 Feb, 2011
29 Dec, 2010
How to make Internet Explorer only CSS files for Drupal themes.
6 Dec, 2010
This tutorial shows you how to make a custom node layout. Which is a custom placement of node fields. Also we do it without any coding.