Drupal: Set any image as User profile image

×

Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseCondition::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 1652 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property MergeQuery::$condition is deprecated in MergeQuery->__construct() (line 1344 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).

This CodeLet allows you to set any image associated with certain contant type to be used as user profile image. This CodeLet particularly uses 'galleryimage' content type.

CodeLet: 

<?php
//$Id$

/**
* @file
*
* Display upcoming events of a user
*
* @author DrupalD
*/

/**
* Implementation of hook_menu
*
* @author DrupalD
*/
function upcoming_events_menu() {
$item = array();
$item['picture/set/%node'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'upcoming_events_picture',
'page arguments' => array(2),
'access callback' => 'upcoming_events_validate',
'access arguments' => array(2),
);

return $item;
}

/**
* Implementation of hook_nodeapi
*
* @param $node
* @param $op
* @param $a3
* @param $a4
* @author DrupalD
*/
function upcoming_events_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
global $user;
switch ($op) {
case 'view':
if ($node->type == 'galleryimage') {
$destination = drupal_get_destination();
$node->content['set_profile_image'] = array(
'#type' => 'item',
'#value' => l(t('Set as my profile picture'), 'picture/set/'. $node->nid, array('query' => $destination)),
'#weight' => 0,
);

$node->content['addimages'] = array(
'#type' => 'item',
'#value' => l(t('Upload more photos'), "node/add/gallery-image"),
'#weight' => 10,
);
}
break;
}
}

/**
* upcoming_events_picture
*
* @param unknown_type $variables
* @author DrupalD
*/
function upcoming_events_picture($node) {
global $user;
db_query("UPDATE {users} set picture = '%s' WHERE uid = %d", $node->field_gallery_image[0]['filepath'], $user->uid);
drupal_set_message(t('Picture has been set as your profile picture'));
drupal_goto($_GET['destination']);
}
?>

Compatibility: 
Is CodeLet useful?: 
Drupal: Set any image as User profile image | Drupal Developer

Error

The website encountered an unexpected error. Please try again later.