drupal

Modules I use


Drupal 7 css overrides - the elegant way


/**
 * Your themes template.php file
 */
function yourtheme_css_alter(&$css) {
  // Turn off some styles from the system module
  unset($css[drupal_get_path('module', 'system') . '/system.messages.css']);
  unset($css[drupal_get_path('module', 'system') . '/system.menus.css']);
}

Drupal installation using drush

Installation

sudo wget --quiet -O -
http://ftp.drupal.org/files/projects/drush-7.x-5.6.tar.gz | sudo tar -zxf - -C
/usr/local/share
sudo ln -s /usr/local/share/drush/drush /usr/local/bin/drush
sudo drush

Install drupal

drush dl
cd drupal-7.19
drush site-install standard --db-
url=mysql://SQLUser:SQLPass@localhost/SQLDatabase

Download newest development version of a module

Fetch the latest release notes:

drush pm-releases

or

drush rl

Download the wanted version:

drush pm-download -7.x-2.x-dev

or

drush dl -7.x-2.x-dev

Organic groups

Create organic group programmatically:

$node = new stdClass();
$node->title = 'Group ' . time();
$node->type = 'group';
node_object_prepare($node);
$node->uid = 1;
// 1 = comments off, 2 = comments on.
$node->comment = 1;
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['value'] = 'Lorem ipsum';
$node->field_group_text[$node->language][0]['value'] = 'Lorem ipsum';
// Group access / visiblity: 0 = pulic, 1 = private
$node->group_access[$node->language][0]['value'] = 1;
// Organic group status: 1 = is organic group, 0 = none organic group.
$node->group_group[$node->language][0]['value'] = 1;
$node = node_submit($node);
node_save($node);

Update organic group:

$nid = 1;
$node = node_load($nid);
$node->title = 'Updated Title Text';
node_save($node);

Node object of a organic group:

stdClass Object
(
  [type] => group
  [uid] => 1
  [title] => Group Node Title 5
  [comment] => 1
  [language] => de
  [created] => 1363422366
  [validated] => 1
  [changed] => 1363422366
  [timestamp] => 1363422366
  [log] =>
  [nid] => 47
  [status] => 1
  [promote] => 0
  [sticky] => 0
  [tnid] => 0
  [translate] => 0
  [vid] => 47
  [group_group] => Array
  (
    [und] => Array
    (
      [0] => Array
      (
        [value] => 1
      )
    )
  )
  [group_access] => Array
  (
    [und] => Array
    (
      [0] => Array
      (
        [value] => 1
      )
    )
  )
)

Add user to a organic group programmatically:

$values['entity'] = 10;
$values['entity type'] = 'user';
$values['state'] = OG_STATE_ACTIVE;
og_group('node', $node->nid, $values);

Delete a user for a organic group:

og_ungroup('node', $node->nid, 'user', 1);

Get all members of a group:

$query = db_select('users', 'u');
$query
->condition('u.uid', 0, '<>')
->condition('u.status', 1, '=') ->fields('u', array('uid', 'name'))
->join('og_membership', 'ogm', "ogm.gid = :gid AND u.uid = ogm.etid AND ogm.entity_type = 'user'", array(':gid' => $gid));
$query->execute();