Site icon CleanTalk's blog

7 useful functions Drupal API that everyone should know!

In this article we will look at 7 Drupal API functions that are very helpful in the development of sites to Drupal 7.

check_plain($text) – re-encodes special characters to HTML entities.

Parameters:

The return value: the processed string to display as HTML.

This function can be used to treat all kinds of data coming to the site from a variety of sources: user input, import data from another site, Twitter, etc.

t($string, array $args = array(), array $options = array()) – converts the string to the user-selected language.

Parameters:

The return value: the translated string.

Example of the function t():

t('Good afternoon, @first_name @last_name. ', array('@first_name' => 'Jhon', '@last_name' => 'Smith')); // Returns 'Good afternoon, Jhon Smith.'

There are three types of wildcard patterns:

format_plural($count, $singular, $plural, array $args = array(), array $options = array()) – creates a string containing quantitative value.

Parameters:

The return value: a string translated by using the function t(), depending on the parameter $count selected string that will be used for translation.

Example:

$comment_count=1;
format_plural($comment_count, '1 comment', '@count comments'); // return '1 comment'

$comment_count=5;
format_plural($comment_count, '1 comment', '@count comments'); // return '5 comments'

drupal_get_title() – returns the current page title.

This function can be used in combination with drupal_set_title() to process the header and install a new one.

drupal_set_title($title = NULL, $output = CHECK_PLAIN) – sets the title of the page.

Parameters:

The return value: updated page title.

url($path = NULL, array $options = array()) – forms an internal or external URL.

Parameters:

The returned value: formed URL.

drupal_goto($path = ”, array $options = array(), $http_response_code = 302) – produces redirect the user to another page.

Parameters:

This text is a translation of the article “7 полезных функций Drupal API который должен знать каждый!” published on drupal-learning.com.

Forums and blogs without spam

CleanTalk is a SaaS spam protection service for Web-sites. CleanTalk uses protection methods which are invisible for site visitors. Connecting to the service eliminates needs for CAPTCHA, questions and answers and other methods of protection, complicating the exchange of information on the site.

7 useful functions Drupal API that everyone should know!
Exit mobile version