Skip to content

Instantly share code, notes, and snippets.

View danreb's full-sized avatar

Adolfo G. Nasol danreb

View GitHub Profile
When dealing with arrays in PHP, checking for an index like `if ($a['foo'])` throws a PHP warning.
There are two ways to avoid these warnings: one is using isset(), which checks the existance of an array index. The second one is empty(), which not only checks for the existence of the array index, but also that the value that contains is not empty (not NULL, 0, '' or FALSE).
Here are some console examples:
```bash
juampy@juampybox $ php -a
php > $a = array('foo' => 'asdfasd');
php >
<?php
/**
* @file
* Default theme implementation to display the basic html structure of a single
* Drupal page.
*
* Variables:
* - $css: An array of CSS files for the current page.
* - $language: (object) The language the site is being displayed in.
@danreb
danreb / distinct_node.module
Created September 19, 2013 09:15
Useful in removing duplicate node in taxonomy term display page when using views
<?php
/*
* Check node ID to remove duplicate result.
*
*/
function MODULENAME_views_pre_render(&$view) {
//dpm($view->name);
if ($view->name == 'taxonomy_term') {
$nids = array();
@danreb
danreb / custompage.php
Created June 20, 2013 00:20
Using EntityFieldQuery() to get node type and display it on custom php page in Drupal 7
<?php
// Get path of Drupal install.
$drupal_path = $_SERVER['DOCUMENT_ROOT'];
// Defines our path to the Drupal install
define('DRUPAL_ROOT', $drupal_path);
// We need to load the bootstrap.inc file so we can have access to the drupal_bootsrap() function
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
@danreb
danreb / custom.module
Created December 20, 2012 01:53
Hide Drupal Specific module from list of modules in update list at admin/reports/updates
<?php
function custom_update_projects_alter(&$projects) {
// Hide a site-specific module from the list.
unset($projects['custom']);
}
@danreb
danreb / aliases.drushrc.php
Created November 30, 2012 06:23
Drush aliases configuration
<?php
/*
*
* @filename: aliases.drushrc.php
* Drop this php file into your home directory .drush folder
* e.g on my Windows 7 PC, directory looks like this
* c:\Users\Userna\.drush
* and on Linux it should be /home/yourusername/.drush
*
@danreb
danreb / site_specific_module.module.php
Created November 16, 2012 02:38
Hide Drupal Specific module from list of modules in update list at admin/reports/updates
<?php
function commerce_subscriptions_update_projects_alter(&$projects) {
// Hide a site-specific module from the list.
unset($projects['commerce_subscriptions']);
}
@danreb
danreb / template.php
Created November 15, 2012 02:57
Drupal Hook form alter to change user login, register, password page title
<?php
/**
* Implements hook_form_alter
*
*/
function lms_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register_form') {
drupal_set_title(t('Create new account'));
}
@danreb
danreb / template.php
Created November 13, 2012 17:41
This can be on template.php or on a custom module
<?php
/**
* Implementation of hook_form_FORMID_alter().
*/
function arma_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {
$cart_product_ids = arma_get_products_in_cart();
$purchased_product_ids = arma_get_users_purchased_products();
$line_item = $form_state['line_item'];
$product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
@danreb
danreb / template.php
Created November 6, 2012 03:48
Change Add to Cart button label in Drupal Commerce for specific product.
<?php
/**
* Implements hook_form_alter
*
*/
function arma_form_alter(&$form, $form_state, $form_id) {
if ($form_id === 'commerce_cart_add_to_cart_form_2' || $form_id === 'commerce_cart_add_to_cart_form_1') {
$form['submit']['#attributes']['title'] = $form['submit']['#attributes']['value'] = t('Buy Corporate Membership');
}