Skip to content

Instantly share code, notes, and snippets.

View msankhala's full-sized avatar
🎯
Focusing

mahesh sankhala msankhala

🎯
Focusing
View GitHub Profile
<?php
function THEME_preprocess_page() {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$full_names = field_get_items('user', $user, 'field_full_name');
if ($full_names) {
$vars['full_name'] = check_plain($full_names[0]['value']);
}
}
<?php
function THEME_preprocess_page() {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$wrapper = entity_metadata_wrapper('user', $user);
$vars['full_name'] = $wrapper->field_full_name->value(array('sanitize' => TRUE));
}
@msankhala
msankhala / node title special character.php
Created August 15, 2014 09:15
Show error on node title special character.
<?php
function custom_node_validate($node, $form, $form_state){
// special character list, Add more special character if you want.
$special_character_list = '\'^£$%&*()}{@#~?><>,|=_+¬\-\[\]';
if(preg_match('/[' . $special_character_list . ']/', $node->title) !== 0){
form_set_error('title', t("Special characters !special_character_list are not allowed in title.", array('!special_character_list' => $special_character_list)));
}
}
@msankhala
msankhala / attach-contact-form-to-block.php
Created December 3, 2014 15:41
Attach a site-wide contact form to a block
<?php
//Open template.php in your theme folder and add the following code. Replace [THEME NAME] with the name of your theme. Replace the value of $module and $delta with the actual string values.
//Hint: To locate these values go to admin/structure/block and click on the "configure" link next to the block you want to print. The strings will be shown in the URL as such: admin/structure/block/manage/[module]/[delta]/configure.
/**
* Implements preprocess_block().
*/
function mytheme_preprocess_block(&$vars) {
// Preprocess the Contact form block.
$module = 'block';
@msankhala
msankhala / attach-contact-form-to-node.php
Created December 3, 2014 15:41
Attach a site-wide contact form to a node
<?php
//1. Open template.php in your theme folder and add the following code. Replace [THEME NAME] with the name of your theme. Replace the value of $nid with the actual ID of your node.
/**
* Implements preprocess_node().
*/
function mytheme_preprocess_node(&$vars) {
// Print contact form on contact page.
$nid = 7;
if ($vars['node']->nid == $nid && module_exists('contact')) {
module_load_include('inc', 'contact', 'contact.pages');
# set the "require_auth" var if Host ends with "example2.com"
SetEnvIfNoCase Host example2\.com$ require_auth=true
# Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic
# Setup a deny/allow
Order Deny,Allow
@msankhala
msankhala / mysitename.aliases.drushrc.php
Last active August 29, 2015 14:12
Drush site alias template for local drupal site and remote site.
<?php
$aliases["loc"] = array (
'root' => '/absolute/path/to/local/mywebsite',
'uri' => 'http://default',
'path-aliases' =>
array (
// Change it to your drush installation path.
'%drush' => '/Applications/Dev Desktop/drush/vendor/drush/drush',
// Website folder relative path.
'%site' => 'sites/default/',
@msankhala
msankhala / php-script-arguments.php
Created January 23, 2015 09:28
php script arguments.
#!/usr/bin/php
<?php
print_r(arguments($argv));
function arguments($args) {
$ret = array(
'exec' => '',
'options' => array(),
'flags' => array(),
'arguments' => array(),
);
<?php
function recurse_copy($src, $dst) {
$dir = opendir($src);
$result = ($dir === false ? false : true);
if ($result !== false) {
$result = @mkdir($dst);
if ($result === true) {
<?php
// In custom module
function mymodule_preprocess_html(&$variables) {
// Add conditional stylesheets for admin pages on admin theme.
if (arg(0)=="admin") {
// reference your current admin theme
$theme_path = drupal_get_path('theme', 'commerce_kickstart_admin');
// reference your own stylesheet
drupal_add_css(drupal_get_path('module', 'mymodule') . '/css/mymodule.css', array('weight' => CSS_THEME));
}