Drupal

The taxonomy module uses the default_nodes_main variable to decide how many to show per page (this happens around line 55 of taxonomy.pages.inc in case you're interested). Usually you would implement a custom module and provide a form to override that variable for your users. But you don't have to do that, if you just want to set the variable once and be done with it use one of the following methods instead: Use Drush (drush vset default_nodes_main 20) Add a PHP snippet somewhere that will be run in your site (you only need to do it once) variable_set('default_nodes_main', 20); Use the Devel variable editor # hook_menu() function hook_menu() { $items['example'] = array( 'title' => 'Example Page', 'page callback' => 'example_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); $items['example/feed'] = array( 'title' => 'Example RSS feed', 'page callback' => 'example_feed', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } drupal_add_css(drupal_get_path('module', 'custom') . '/css/custom.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));

DRUSH DL

# path auto transliteration - je za hrvatska slova drush dl pathauto, transliteration drush dl drupal-8 drush dl drupal --drupal-project-rename=helpium-web bez pswd-a drush si --db-url=mysql://root:@localhost/helpium-web a ako je pswd pass drush si --db-url=mysql://root:pass@localhost/helpium sudo chgrp -R www-data sites/default/files/ sudo chmod -R g+w sites/default/files/ drush 10 drush dl drupal --drupal-project-rename=metasys-drupal cd metasys-drupal cp sites/default/default.settings.php sites/default/settings.php chmod -R o+w sites/defaultwww drush si --db-url=mysql://root:@localhost/metasys_drupal #!/bin/bash if [ $(id -u) != 0 ]; then printf "This script must be run as root.\n" exit 1 fi drupal_path=${1%/} drupal_user=${2} httpd_group="${3:-www-data}" # Help menu print_help() { cat <<-HELP This script is used to fix permissions of a Drupal installation you need to provide the following arguments: 1) Path to your Drupal installation. 2) Username of the user that you want to give files/directories ownership. 3) HTTPD group name (defaults to www-data for Apache). Usage: (sudo) bash ${0##*/} --drupal_path=PATH --drupal_user=USER --httpd_group=GROUP Example: (sudo) bash ${0##*/} --drupal_path=/usr/local/apache2/htdocs --drupal_user=john --httpd_group=www-data HELP exit 0 } # Parse Command Line Arguments while [ $# -gt 0 ]; do case "$1" in --drupal_path=*) drupal_path="${1#*=}" ;; --drupal_user=*) drupal_user="${1#*=}" ;; --httpd_group=*) httpd_group="${1#*=}" ;; --help) print_help;; *) printf "Invalid argument, run --help for valid arguments.\n"; exit 1 esac shift done if [ -z "${drupal_path}" ] || [ ! -d "${drupal_path}/sites" ] || [ ! -f "${drupal_path}/core/modules/system/system.module" ] && [ ! -f "${drupal_path}/modules/system/system.module" ]; then printf "Please provide a valid Drupal path.\n" print_help exit 1 fi if [ -z "${drupal_user}" ] || [ $(id -un ${drupal_user} 2> /dev/null) != "${drupal_user}" ]; then printf "Please provide a valid user.\n" print_help exit 1 fi cd $drupal_path printf "Changing ownership of all contents of "${drupal_path}":\n user => "${drupal_user}" \t group => "${httpd_group}"\n" chown -R ${drupal_user}:${httpd_group} . printf "Changing permissions of all directories inside "${drupal_path}" to "rwxr-x---"...\n" find . -type d -exec chmod u=rwx,g=rx,o= '{}' \; printf "Changing permissions of all files inside "${drupal_path}" to "rw-r-----"...\n" find . -type f -exec chmod u=rw,g=r,o= '{}' \; printf "Changing permissions of "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n" cd sites find . -type d -name files -exec chmod ug=rwx,o= '{}' \; printf "Changing permissions of all files inside all "files" directories in "${drupal_path}/sites" to "rw-rw----"...\n" printf "Changing permissions of all directories inside all "files" directories in "${drupal_path}/sites" to "rwxrwx---"...\n" for x in ./*/files; do find ${x} -type d -exec chmod ug=rwx,o= '{}' \; find ${x} -type f -exec chmod ug=rw,o= '{}' \; done echo "Done settings proper permissions on files and directories"

Block

/** * Implements hook_block_info(). */ function example_block_info() { $blocks['ad_banner1'] = array( 'info' => t('Ad Banner 1'), ); $blocks['ad_banner2'] = array( 'info' => t('Ad Banner 2'), ); return $blocks; } /** * Implements hook_block_view(). */ function example_block_view($delta = '') { $block = array(); switch ($delta) { case 'ad_banner1': $block['content'] = 'shtuffenins'; break; case 'ad_banner2': $block['content'] = 'shtuffenins2'; break; } return $block; }

Bredcrumb

$menu = menu_get_object(); if (isset($menu->type) && $menu->type == 'events') { // Sad kreiram bredcrumb za events Početna->Skupovi->Trenutni_node $bcmb = array( l('Početna', '<front>'), l('Skupovi', 'skupovi'), l( $menu->title, 'node/' . $menu->nid), ); drupal_set_breadcrumb($bcmb);

Directory permisions

Navigate to /sites/default chown -R :www-data files chmod g+ws files Navigate to /sites/default/files find . -type d -exec chmod g+ws {} \; find . -type f -exec chmod 664 {} \;

Form

# submit $form['submit'] = array('#type' => 'submit', '#value' => t('Import')); # textfield $form['title'] = array( '#type' => 'textfield', '#title' => t('Subject'), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => TRUE, ); # select $form['selected'] = array( '#type' => 'select', '#title' => t('Selected'), '#options' => array( 0 => t('No'), 1 => t('Yes'), ), '#default_value' => $category['selected'], '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'), ); # checkbox $form['copy'] = array( '#type' => 'checkbox', '#title' => t('Send me a copy.'), ); # checkboxes $form['high_school']['tests_taken'] = array( '#type' => 'checkboxes', '#options' => drupal_map_assoc(array(t('SAT'), t('ACT'))), '#title' => t('What standardized tests did you take?'), ... ), # textarea $form['keywords'] = array( '#title' => t('Keywords'), '#type' => 'textarea', '#description' => t('The comment will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, "Company, Inc."'), '#default_value' => isset( $context['keywords']) ? drupal_implode_tags($context['keywords']) : '', ); $form['vid'] = array('#type' => 'value', '#value' => $node->vid);

Autocomplete

function module_name_form() { $form = array(); $form['city'] = array( '#title' => t('City'), '#type' => 'textfield', '#autocomplete_path' => 'example/autocomplete', ); $form['submit'] = array( '#type' => 'submit', '#value' => 'Save', ); return $form; } function module_name_menu() { $items['example/autocomplete'] = array( 'page callback' => '_module_name_autocomplete', 'access arguments' => array('access example autocomplete'), 'type' => MENU_CALLBACK ); return $items; } function _module_name_autocomplete($string) { $matches = array(); // Some fantasy DB table which holds cities $query = db_select('cities', 'c'); // Select rows that match the string $return = $query ->fields('c', array('city')) ->condition('c.city', '%' . db_like($string) . '%', 'LIKE') ->range(0, 10) ->execute(); // add matches to $matches foreach ($return as $row) { $matches[$row->city] = check_plain($row->city); } // return for JS drupal_json_output($matches); }

db

// Retrieve all records into an indexed array of stdClass objects. $result->fetchAll(); // Retrieve all records into an associative array keyed by the field in the result specified. $result->fetchAllAssoc($field); // Retrieve a 2-column result set as an associative array of field 1 => field 2. $result->fetchAllKeyed(); // You can also specify which two fields to use by specifying the column numbers for each field $result->fetchAllKeyed(0,2); // would be field 0 => field 2 $result->fetchAllKeyed(1,0); // would be field 1 => field 0 // If you need an array where keys and values contain the same field (e.g. for creating a 'checkboxes' form element), the following is a perfectly valid method: $result->fetchAllKeyed(0,0); // would be field 0 => field 0, e.g. [article] => [article] // Retrieve a 1-column result set as one single array. $result->fetchCol(); // Column number can be specified otherwise defaults to first column $result->fetchCol($column_index); $query = db_select('node', 'n') ->condition('type', 'article') ->fields('n'); $query = $query->extend('PagerDefault')->limit(2); $result = $query->execute(); while($record = $result->fetchAssoc()) { print_r($record); } $output .= theme('pager', array('tags' => array()));