Greece Bond Market Scandals and JP Morgan Silver Manipulation

December 11, 2010 9 comments

Talks about about the massive fraudulent short position that JP Morgan holds in silver. Also in this video, a very well explained how speculators brought down Greece in April of 2010 with CDS (aka Credit Default Swaps)

Tradition 1

December 10, 2010 Leave a comment

People of Ma’arifat (recognition) see that the worldly people are more concerned about physical death. While more serious is the death of their hearts within their living bodies.”

– Imam Ali (Nahjul Balagha, Sermon 259)

Categories: Ali, Death, Hadith, Spirituality, Tradition Tags: , ,

Drupal 7 – Hook Execution Order

December 6, 2010 5 comments

Although not specified explicitly anywhere, browsing through the code in the function “module_implements” gave me the hint that changing the order in which hooks are called is possible.

Here’s that snippet

 // Allow modules to change the weight of specific implementations but avoid
 // an infinite loop.
 if ($hook != 'module_implements_alter') {
 drupal_alter('module_implements', $implementations[$hook], $hook);
 }

All that needs to be done is to implement the hook hook_module_implements_alter specified here. Effectively by re-ordering the list of modules, you also change the order in which the hooks are called.

Here’s how I did it,

function mymodule_module_implements_alter(&$module_list, $context){
 if($context === "node_insert"){
 $temp = $module_list['mymodule'];
 // Removing the mymodule key/value
 unset($module_list['mymodule']);
 // Adding the mymodule key value as the last member in the list
 $module_list['mymodule'] = $temp;
 }
}

One point to remember is to declare the “module_list” variable as a reference variable with the “&”, or you’ll be modifying a local variable 🙂
Thats it. Done!

Does God Not Exist

December 6, 2010 Leave a comment

Interesting watch.

Drupal 7 – Programatically Create Nodes

December 6, 2010 12 comments

Getting straight to the topic,

From drupal 6, there have been some small changes in the way users can create a node programatically. Like for eg. instead of using the drupal_execute function, we now have to use drupal_form_submit. Both these functions do the same thing, i.e, submit the form programatically.

Since, I experimented with creating book nodes, i’ll be running through the same example.

Minimally, 3 arguments need to be specified to the drupal_form_submit function in this case.

The first one, is the form id. This id can be got by taking a quick look at the form POST parameters while creating a book “normally”. I did that by using firebug on the node/add/book page.

The 2nd argument is an array of form values that should mimic the values posted from the browser. The focus should be to copy the (relevant) variable names that are seen while analyzing the post request. See below,


The values should go within an array keyed by the key ‘values’

global $user;
// Body Structure
// For more information on how this variable is read by the form engine, see
// drupal_array_get_nested_value.
// Substitute the language "en" for the language of the node. Make sure that
// the appropriate locale is enabled
$body["en"][0]['value'] = "Some body text";

$formState['values']['title'] = "Title of the book"
$formState['values']['language'] = "en"; // substitute for the language of the node
$formState['values']['name'] = $user->name;
$formState['values']['body'] = $body;
$formState['values']['status'] = 1;
$formState['values']['promote'] = 0;
$formState['values']['sticky'] = 0;
$formState['values']['op'] = t('Save');

And the last argument is a node object reference that one must create with the necessary information.

$newNode = array(
 'type' => 'book',
 'book' => array(
 'bid' => $node->book['bid'], // use 'new' here if the book page is of a new book
 'plid' => $node->book['mlid'],
 'weight' => $chapNo,
 'options' => array(),
 'has_children' => 0,
 'module' => 'book'
 ),
 'language' => $node->language // This is needed
);

Last thing to do is to call the drupal_form_submit function.

drupal_form_submit('book_node_form', $formState, (object) $newNode);

Thats it! We’re done!

Drupal 7 Field Api Node Reference Field

November 14, 2010 9 comments

Update : (21st May 2011)
The References Module now provides support for Node Reference and User References fields

http://drupal.org/project/references

Seems like the D7 CCK contains nodereference and userreference fields (as of 14th Nov), but don’t know how stable it is at the moment. Another alternative is to use the taxonomy term reference field. Since in D7, taxonomy terms can also fielded, they’re as good as another node and can be addressed independently of the referencing node.

One thing is still a shame though. Synonyms for taxonomy have been removed from the D7 release. See http://drupal.org/node/567572

Although there is synonyms module that uses fields to mimick the synonyms behavior, its still very nascent and needs more work.

Drupal 7 Field Instances Default Value

November 13, 2010 6 comments

Well, it seems like the drupal documentation is not sufficient in describing how to specify a default value for a programatically created field instance. As of drupal 7 beta-2, if a default value is not specified and say you are performing any ajax operation on the page, the form will throw a validation error.

Here’s how its done.
'al_resource_type' => array(
'field_name' => 'al_resource_type',
'label' => $t('Resource Type'),
'required' => TRUE,
'widget' => array(
'type' => 'options_buttons',
),
// Need to specify a default value, else the form throws a validation
// error while uploading files.
// Used by field_get_default_value
'default_value' => array(array('value' => "1")),
)

One can also use a “default_value_function” to return a default value.