The following piece of code creates a new node of a subscriber content type. This subscriber has two textfields which called First Name and Last Name. In this example, we make use of the node_object_prepare() function which helps preparing the node object.
Continue reading Drupal 7 – Create node programmatically
Tag Archives: Drupal
Drupal 7 – Apply different theme based on path
Recently i have created a mobile website using Drupal. I would like to use another theme instead of the mobile theme in certain pages such as the user login page. This can be done by the ThemeKey module.
1. Instead and enable ThemeKey.
2. Go to admin/config/user-interface/themekey.
Continue reading Drupal 7 – Apply different theme based on path
Drupal 7 – Create a webform programmatically
The following piece of code demonstrate how to create a webform programmatically.
Continue reading Drupal 7 – Create a webform programmatically
Drupal 7 – Override the limit of 7 shortcuts per shortcut set
In Drupal 7, only 7 shortcuts are allowed in one shortcut set. If you want to have more slots, add the following line in the settings.php.
$conf['shortcut_max_slots'] = 10;
&anbsp;
It will raise the limit to 10.
Done =)
Reference: Remove the default limit of 7 shortcuts per shortcut set
Drupal 7 – Group form fields in div
Most common task in Drupal development is creating or altering forms. It could save a lot of CSS code if we group the form fields in div.
Here is an example.
Continue reading Drupal 7 – Group form fields in div
Drupal 7 – Check if a path exists
Drupal 7 – Show YouTube video in LightBox2
The following HTML allows you to show a video in LightBox2.
<a href="http://www.youtube.com/embed/<VIDEO ID>?autoplay=1" rel="lightframe">Click me</a>
We could control the size of the popup.
<a href="http://www.youtube.com/embed/<VIDEO ID>?autoplay=1" rel="lightframe[|width:320px; height:240px;]">Click me</a>
Done =)
Reference:
Drupal 7 – Menu item is disabled after saving the node in different language
i found a bug with the i18n module. Assume i have a node in Traditional Chinese and i edit it in English. The menu item set Menu settings will be disabled after save.
A simple workaround is to alter the node edit form such that the user will be redirected to the language same as the node.
Continue reading Drupal 7 – Menu item is disabled after saving the node in different language
Drupal 7 – Create your own theme function on your custom block
More than a year ago, we have talked about some basic theming in Drupal 6.
- Drupal – Introduction to Drupal Theming @ 1
- Drupal – Introduction to Drupal Theming @ 2
- Drupal – Introduction to Drupal Theming @ 3
In Drupal 7, there are some changes on the theming functions as well as the block hooks. So here is a slightly modified versions from the example of Drupal – Introduction to Drupal Theming @ 3. The logic behind is exactly the same.
ykyuen.info
Continue reading Drupal 7 – Create your own theme function on your custom block
Drupal – Apply and Reverse a patch to a module
1. Upload the patch to the module directory.
2. Go to the module directory.
3. Run the following command.
patch -p1 < <file.patch>
4. To revert the change, run the following command.
patch -p1 -R < <file.patch>
Done =)
Reference: StackOverflow – Appliying patch in drupal modules