Novice

Troubleshoot internet connection problems with the ping command

The ping command

Ping is a command line network utility tool to test network connectivity. ​It tests the connection between a sender and a receiver node. It reports whether the receiver node responds by sending an echo request. The receiving node responds with an echo reply.

Ping simply sends a signal to another computer and waits for a response.

Set weight on a module


**
 * Implements hook_install().
 */
function MY_MODULE_install() {
	
  // Set module weight in order to invoke module after other modules.
  db_update('system')
  ->fields(array('weight' => 100))
  ->condition('name', 'MY_MODULE')
  ->execute();
}

Show one image on a node teaser

Hook_process_field can be used inside template.php to render only one image on a multiple image field.

Create a simple countdown object


/**
 * Create and process a new Countdown object.
 * 
 * @param seconds
 *  Integer
 */
function Countdown(seconds) {
	
	$('#timer').html(seconds);
	
	var timer = window.setInterval(function() {
	  if (seconds === 0) {
        clearInterval(timer);
        return;
	  }
      seconds -= 1;
      $('#timer').html(seconds);
	}, 1000);
	
	this.stop = function() {
      clearInterval(timer);
	}
	
}

Create a simple timer object


/**
 * A Timer object.
 */
function Timer() {
	
	var time = 0;
	$('#timer').html(time);
	
	var timer = window.setInterval(function() {
      time += 1;
      $('#timer').html(time);
	}, 1000);
	
	this.stop = function() {
      clearInterval(timer);
      $('#timer').html(time);
	}
	
}

HTML5 Geolocation - Locate a user's position


// Does the browser support geolocation?
// @see http://www.w3schools.com/html/html5_geolocation.asp.
if(navigator.geolocation) {
	// When clicked on deny, error function is triggered.
	navigator.geolocation.getCurrentPosition(success,error);
} else {
	console.log('Browser doesn\'t support geolocation, default geolocation unsupported action.');
}

function success(pos) {
	console.log('User allows, location specific action.');
}
function error(error) {
	console.log('User denies, default geolocation supported action.');
}

Export all user mail addresses to CSV



/**
 * Implements hook_menu().
 */
function export_mails_menu() {
  return array(
    'export_mails.csv' => array(
      'page callback' => '_export_mails',
      'access callback' => 'user_is_logged_in',
    ),
  );
}

/**
 * Implements hook_block_info().
 */
function export_mails_block_info() {

  $blocks['export_mails'] = array(
    'info' => t('Export mails'),
  );

  return $blocks;

}

/**
 * Implements hook_block_view().
 */
function export_mails_block_view($delta) {
  switch ($delta) {
    case 'export_mails' :
      return array(

Create a content type programatically Drupal 8

​Basic creation of a content type in Drupal 8. Content type is created in code in a custom module called dribbit_create_content_type.

module_directory_node.png

As seen on the left, an install directory located in the config directory is needed to store the content types yaml file. Human readable data is used to preconfigure the content types settings.

Pages

Subscribe to RSS - Novice