Get list options of a field
Submitted by system on Wed, 07/16/2014 - 11:14We may want to get the options available for a field in content type. This can be achieved using Field API.
We may want to get the options available for a field in content type. This can be achieved using Field API.
This post will illustrate various handy file operations available in Drupal
Get Absolute Path of a file from URI : drupal_realpath()
A URI in drupal looks like: private://donor_registration/somefile.csv for a private file
Absolute Path: /srv/www/example.com/public_html/sites/default/private/files/donor_registration/somefile.csv
There are times when we would want to create similar data structures across multiple drupal sites for common functionalities. Although this can be done using features but when the effort involves one time exercise and involves just few fields to be exported, using custom code for creating export definitions for importing in the other site can be a simpler alternative.
If you want export a field definition, you can use the handy field_info_field and field_info_instance functions. Taking our example above, here's how you would call these two functions:
Drupals internal batch API can be really helpful for handling large cumbersome processes on your web server. Rather than submitting a form and waiting for one of these processes to finish before reaching the next page, the batch API can be utilized to break the process down across multiple page loads. This not only cuts down on the server load, but will prevent the page from timing out. Progress bars will be displayed to the user while the process runs which will keep them informed of where they are at in the process.
Display a group fieldset using form state api.
The task was to change text field to a select list with a given set of option. The text field was an integer field and the select options were numbers to select from 0 to 30.
There are times when the serial field needs to start from a number other than 1. To do so the following sql query will do the task. It sets the start number to be 100404.
alter table serial_table_field_name auto_increment = 100404;
The Entity API provides wrapper classes you may use to make dealing with the values of an entities properties and fields easier. Wrappers make it easier to get and set the values of fields and properties as well as to programmatically retrieve additional information about these elements and iterate over lists of values in a consistent manner.
This implies that one need not worry about fetching a node property in the format:
$node->field_name['und'][0]['value']
The following is a snippet on how to enable fields to appear and/or disappear based on the state of other fields.
<?php
/**
* Modifications for including State API functionalities. The idea is to hide the fields field_referme_industry
* and field_referme_major_skills, based on the value of another field.
* The functionality can be implemented during the after_build phase
*/
function jc_form_alter(&$form, &$form_state, $form_id) {
//drupal_set_message("Form Id is: $form_id ");
if($form_id == 'referme_node_form') {
The idea is to modify another CCK field based on selection of an item via a select list in another field.
Let us consider a content type called article containing 2 additional fields: article_test_entity - which is an entity reference that displays node titles of all nodes and article_test_entity_type - which is a select list that contains Content Type names list with its key as the actual machine name of the content type. The idea is to restrict the list of node titles displayed on article_test_entity based on the content type selected via article_test_entity_type.
<?php
/*