Skip to main content

Programmatically creating/deleting/modifying field-collection

Submitted by amitsedai on
Enough Said , visit the link: http://rajanmayekar.com/blog/programmatically-creating-deleting-modifying-field-collection-item-node One change wrt to deleting Field Collections is as follows: <?php $node = node_load($node_id); $field_collection_item_value = array(); foreach ($node->field_collection_field[LANGUAGE_NONE] as $key => $value) { $field_collection_item_value[] = $value['value']; } entity_delete_multiple('field_collection_item', array($field_collection_item_value)); ?>

Using Git

Submitted by amitsedai on
Version control of code files is important. Also important is to ensure that it is accessible throughout and also to the community from which we gain. I tried creating an account in GitHub, create and fork a repository and add files via commandline using git in Github. Setting Up Git: https://help.github.com/articles/set-up-git
Forking a Repo: https://help.github.com/articles/fork-a-repo
Creating adding and Commiting: http://media.pragprog.com/titles/tsgit/chap-005-extract.html
Help Docs: https://help.github.com/

Module Specific styling and javascripts

Submitted by sunildhimal on
Its not a good practice to add a module related theming details(css/jquery) in a /sites/all/themes/your_theme folder. In Drupal 7 one can use a module's .info file for including module-specific css/javascripts. Example given below: Filename: ji_indicator.info name = Range Idicator
description = Indicates range values & out of range values in different color.
core = 7.x
package = "Jagriti Innovations"
stylesheets[all][] = ji_indicator.css
dependencies[] = custom_formatters

Debug you PHP code using DRUSH

Submitted by sunildhimal on
Drush is a very handy tool which makes development in Drupal very fast and easy. Almost everyting is JACA("just a command away"). This particualr tip will help you to evaluate your php code using Drush. Examples: Consider a function: ji_custom($node). To evaluate/debug this function I type following in Drush: drush php-eval "ji_custom($node);"
Aliases for php-eval are: eval, ev N.B: JACA is invented while writing this post :)

Provide a link to add content from VIEWS

Submitted by sunildhimal on
I found out a better way to provide "Add content" link at the footer region of a VIEW. We can achieve followings: - Pass any number of arguments. - User can access link only if he/she has permission. N.B- use Entity Reference for prepopulating valued from URL Example: <?php
global $user;
$view = views_get_current_view();
$args = $view->args[0];
if (user_access('create test_report content', $user)) {
$output=l(t('Add new Biochemistry Test '), 'node/add/test-report', array(
'query' => array(
'field_tr_patient_ref' =>$args,

Batch Process Images in Linux

Submitted by amitsedai on
Sometimes its a pain when you want to modify, resize multiple files at once in Linux. Fortunately ImageMagick comes with a handy command called convert that makes the work simpler Install ImageMagick in Ubuntu
sudo apt-get install imagemagick
Batch Process set of files in a folder and resize them to 1024X768
for file in *.jpg; do convert "$file" -resize 1024x768 "$file"; done
You may also try an app called as phatch for GUI related batch processing of images. Snippet to bulk rename files by replacing strings in filename

Clear Sendmail Queue

Submitted by system on
To clear the sendmail queue, one can manually delete the contents of the folder: /var/spool/mqueue. To see the contents of the queue,one can type the command.
mailq
-- Source: http://www.cyberciti.biz/faq/linux-unix-bsd-clear-sendmail-queue/

Update File Path in Drupal

Submitted by amitsedai on
We have a site that we had been migrating since Drupal 4. Few days back when we tried to migrate the same from Drupal 6 to Drupal 7. There was an issue with respect to file location that was present since previous upgrades. To resolve that a symlink was created called "files" with linked to sites/default/files during D6 upgrade. This led to first loss of many files as Drupal does not handle symlink based file saving well. Secondly the files created were saved under public://files/filename.ext instead of public:://filename.ext which caused created files not being accessible.

Saving Form Selection using Form API

Submitted by amitsedai on
During custom form submission we would want to remember the previous selection. There are many ways to do that, which includes using Sessions and variable_set to set the default value but this is an overkill if you wanted to simply preserve/remember the selection in the next page or after submission. The best way is to use $form_state['storage'] in your submit handler to hoard values between steps. Consider an example: <?php function custom_form_submit($form, &$form_state) { $start_date = $form_state['values']['startdate']; $end_date = $form_state['values']['enddate'];

Executing PHP in command line

Submitted by amitsedai on
There are times when one needs to execute PHP in command like, for example trying the date command output or a one line execution. For trivial tasks, executing the same at the command line without the need for writing and executing at a file level is a great tool for time saving. The argument to be used is : -r Example: php -r '
$a = range(0,2);
foreach($a as $b) {
echo "entry: $b\n";
}
'
The output is:
entry: 0
entry: 1
entry: 2

Another example:
php -r '
> echo date("d-m-Y");
> echo "\n";
> '
14-01-2013