SlideShare a Scribd company logo
1 of 34
Drupal @ CSU
atrium_username feature
               Emanuele Quinto
     Identity Management/Portal
atrium_username




2
atrium_username
     • a Drupal feature for managing user name display;
     • a lightweight alternative to realname module;
     • "works" before theme layer
     • uses the node title of the user profile
    function atrium_username_get_name($uid) {
      static $users = array();
      if (!isset($users[$uid])) {
        // get data from db DIRECTLY
        $users[$uid] = db_result(db_query("SELECT title
    FROM {node} WHERE type='profile' AND uid=%d", $uid));
      }
      return $users[$uid];
    }

    It doesn't implements its own theme_username allowing another theme to
                                    override it.
3
Account Block




4
Account Block




5
Account Block
 Preprocess injection
  // Preprocess block.
  // Inject custom preprocessor before tao/ginkgo.
  $preprocess_function = $theme_registry['block']
['preprocess functions'];
  $preprocess_theme = array_slice($preprocess_function,
2);
  array_unshift($preprocess_theme,
'atrium_username_preprocess_block');
  array_splice($preprocess_function, 2,
count($preprocess_function), $preprocess_theme);

  $theme_registry['block']['preprocess functions'] =
$preprocess_function;
  $theme_registry['block']['include files'][] =
$atrium_username_path . '/atrium_username.theme.inc';

     Insert atrium_username_preprocess_block before other preprocess
 6
Account Block
 Preprocess implementation
        function atrium_username_preprocess_block(&$variables)
{
  // atrium-account
  if($variables['block']->bid == "atrium-account") {
    global $user;
    if ($user->uid) {
       $atrium_username = atrium_username_get_name($user-
>uid);
       $user_name = $atrium_username ? $atrium_username :
check_plain($user->name);
       $variables['block']->subject =
theme('user_picture', $user) . $user_name;
    }
  }
}

                   Don't use theme_username, it adds a link!
    7
User Profile




8
User Profile




9
User Profile

Hook views_pre_render

function atrium_username_views_pre_render(&$view) {

  // set title for profile_display
(http://drupal.org/node/1176080)
  if($view->name == 'profile_display' && $view-
>current_display == 'page_1') {
    $uid = $view->args[0];
    $atrium_username = atrium_username_get_name($uid);
    if(!empty($atrium_username)) {
      drupal_set_title($atrium_username);
    }
  }
}



 10
User Name Field




11
User Name Field




12
User Name Field
 render_link() method
function render_link($data, $values) {

       // get uid field name
       $field_uid = isset($this->aliases['uid']) ? $this->aliases['uid'] : 'uid';

    if (!empty($this->options['link_to_user']) || !empty($this-
>options['overwrite_anonymous'])) {
      $account = new stdClass();
      $account->uid = $values->{$field_uid};
      if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
         // This is an anonymous user, and we're overriting the text.
         return check_plain($this->options['anonymous_text']);
      }
      elseif (!empty($this->options['link_to_user'])) {
         $account->name = $values->{$this->field_alias};
         return theme('username', $account);
      }
    }
    // Otherwise, there's no special handling, so try to return atrium_username.
    if(isset($values->{$field_uid})) {
      $atrium_username = atrium_username_get_name($values->{$field_uid});
      return $atrium_username ? $atrium_username : $data;
    }
    else {
        return $data;
    }
  }


  13
Casetracker




14
Casetracker – issue page




15
Casetracker – issue page

 Function atrium_username_theme_casetracker_comment_changes

case 'assign_to':
  $old->{$field} = atrium_username_get_name($old-
>{$field}) ? atrium_username_get_name($old->{$field}) :
check_plain(casetracker_get_name($old->{$field}));
  $new->{$field} = atrium_username_get_name($new-
>{$field}) ? atrium_username_get_name($new->{$field}) :
check_plain(casetracker_get_name($new->{$field}));
  break;




 Unfortunately we have to rewrite everything as the lines to be changed are
                inside a switch/case with no other options.
                   Only the case 'assign_to' is modified.

 16
Casetracker – assign to




17
Casetracker – issue page
 hook_form_alter
if(!empty($form['casetracker']['assign_to']['#options'])) {
       $assign_to = $form['casetracker']['assign_to']
['#options'];
       foreach($assign_to as $key => $value) {
         $uid = casetracker_get_uid($key);
         $atrium_username = atrium_username_get_name($uid);
         $name = $atrium_username ? $atrium_username : $value;
         $form['casetracker']['assign_to']['#options'][$key] =
$name;
       }
    }




                   Radio options are set at theme level
        (theme_casetracker_case_form_common) but this is a form
              (comment_form()) so we can hook_form_alter:

 18
Casetracker – issue filter




19
Casetracker – issue filter
 hook_form_alter
 if($form_id=='views_exposed_form' && $form['#id']=='views-
exposed-form-casetracker-cases-page-1') {
    foreach($form['assign_to']['#options'] as $uid => $value) {
      if(is_int($uid) && $uid>0) {
        $atrium_username = atrium_username_get_name($uid);
        if(!empty($atrium_username)) {
          $form['assign_to']['#options'][$uid] =
$atrium_username . "~";
        }
      }
    }
  }



  The "Filter results" block is an exposed filter from the casetracker_cases​
                                                           ​
                                      view.
       It's a form so we user hook_form_alter to modify user names

 20
Casetracker – assigned column




21
Casetracker – assigned column
    Override field handler
class atrium_username_casetracker_views_handler_field_user_name
extends views_handler_field {

  function render($values) {
    $uid = $values->{$this->field_alias};
    if($uid==0) {
      return casetracker_get_name($uid);
    }
    else {
      $atrium_username = atrium_username_get_name($uid);
      return $atrium_username ? $atrium_username :
casetracker_get_name($uid);
    }
  }

}

         Override Casetracker Module implementation of views_handler_field
                   (casetracker_views_handler_field_user_name):
    22
Theming User Name




23
Theming User Name




24
Theming User Name
 Simulate preprocess
// Simulate a preprocess function for theme("username").
  $_SESSION['theme_registry_username_function'] =
$theme_registry['username']['function'];
  $theme_registry['username']['function'] =
'atrium_username_preprocess_username';
  $theme_registry['username']['include files'] =
array($atrium_username_path '/atrium_username.theme.inc');


       Override theme but apply original theme (saved in $_SESSION)

function atrium_username_preprocess_username($object) {
 $theme_username = $_SESSION['theme_registry_username_function'] ?
$_SESSION['theme_registry_username_function'] : 'theme_username';
  $user = drupal_clone($object);
  if($user->uid) {
    $atrium_username = atrium_username_get_name($user->uid);
    $user->name = $atrium_username ? $atrium_username : $user->name;
  }
  return $theme_username($user);}

 25
Notifications




26
Notifications




27
Notifications
 hook_form_alter
// Change notification_team form options
  if(!empty($form['notifications']['notifications_team']
['options']['#value'])) {
    foreach($form['notifications']['notifications_team']
['options']['#value'] as $uid => $name) {
      $atrium_username = atrium_username_get_name($uid);
      $name = $atrium_username ? $atrium_username : $name;
      $form['notifications']['notifications_team']['options']
['#value'][$uid] = $name;
    }
  }




 28
Autocomplete




29
Notifications




30
Autocomplete
    hook_menu_alter
function atrium_username_menu_alter(&$callbacks) {
  $callbacks['members/add/autocomplete']['page callback'] = 'atrium_username_autocomplete';
  $callbacks['members/add/ajax']['page callback'] = 'atrium_username_addform_ajax';
}



    callback
function atrium_username_autocomplete($string = '') {
  $matches = array();
  if ($string) {
    $query = "SELECT u.uid, u.name, n.title
              FROM {users} u LEFT JOIN {node} n ON (n.uid=u.uid AND n.type='profile')
              WHERE LOWER(n.title) LIKE LOWER('%s%%') OR LOWER(u.name) LIKE LOWER('%s%%')";
    $query = db_rewrite_sql($query, 'users', 'uid', array($string, $string));

         $result = db_query_range($query, array($string, $string), 0, 10);
         while ($user = db_fetch_object($result)) {
           $user_name = $user->title ? check_plain($user->title) : check_plain($user->name);
           $matches[$user_name] = $user_name;
         }
    }
    drupal_json($matches);
}




    31
Files




32
Q&A

     Thank you
33
About




                             Emanuele Quinto
                                    equinto@sfsu.edu
             http://www.linkedin.com/in/emanuelequinto
                                              @emaV


                              atrium_username
              http://drupal.org/project/atrium_username
             https://github.com/emaV/atrium_username
34

More Related Content

What's hot

Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Acquia
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #states
Konstantin Käfer
 

What's hot (20)

50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
12. edit record
12. edit record12. edit record
12. edit record
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
 
11. delete record
11. delete record11. delete record
11. delete record
 
10. view one record
10. view one record10. view one record
10. view one record
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Laravel
LaravelLaravel
Laravel
 
Coding for Scale and Sanity
Coding for Scale and SanityCoding for Scale and Sanity
Coding for Scale and Sanity
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
Coding website
Coding websiteCoding website
Coding website
 
Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1Drupal Step-by-Step: How We Built Our Training Site, Part 1
Drupal Step-by-Step: How We Built Our Training Site, Part 1
 
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 JavascriptjQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #states
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 

Viewers also liked

Rainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teaserRainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teaser
miguelba13
 
Internet research chinese
Internet research chineseInternet research chinese
Internet research chinese
poeticmizz
 
про питание
про питаниепро питание
про питание
Sergey Esenin
 
Don't judge life by one season
Don't judge life by one seasonDon't judge life by one season
Don't judge life by one season
Zakaria Jusoh
 
Behind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resourcesBehind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resources
eliggett01
 
Video tour sevilla
Video tour sevillaVideo tour sevilla
Video tour sevilla
thesin
 

Viewers also liked (18)

Hopefuls 032411
Hopefuls 032411Hopefuls 032411
Hopefuls 032411
 
Fieldwork presentation
Fieldwork presentationFieldwork presentation
Fieldwork presentation
 
Inbound Marketing for the Design + Construction Industry
Inbound Marketing for the Design + Construction IndustryInbound Marketing for the Design + Construction Industry
Inbound Marketing for the Design + Construction Industry
 
Rainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teaserRainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teaser
 
Internet research chinese
Internet research chineseInternet research chinese
Internet research chinese
 
про питание
про питаниепро питание
про питание
 
Don't judge life by one season
Don't judge life by one seasonDon't judge life by one season
Don't judge life by one season
 
Vermont
VermontVermont
Vermont
 
Behind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resourcesBehind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resources
 
Ppt
PptPpt
Ppt
 
Video tour sevilla
Video tour sevillaVideo tour sevilla
Video tour sevilla
 
Presentacion prueba
Presentacion pruebaPresentacion prueba
Presentacion prueba
 
Progression Insight & Analysis: Kitesurfing Participation Survey 2009
Progression Insight & Analysis: Kitesurfing Participation Survey 2009Progression Insight & Analysis: Kitesurfing Participation Survey 2009
Progression Insight & Analysis: Kitesurfing Participation Survey 2009
 
Drupal & Continous Integration - SF State Study Case
Drupal & Continous Integration - SF State Study CaseDrupal & Continous Integration - SF State Study Case
Drupal & Continous Integration - SF State Study Case
 
Presentation 4 Linkend
Presentation 4 LinkendPresentation 4 Linkend
Presentation 4 Linkend
 
TIC MAGAZINE Edition N°07
TIC MAGAZINE Edition N°07TIC MAGAZINE Edition N°07
TIC MAGAZINE Edition N°07
 
Comment pourrai-je trouver un emploi via les réseaux sociaux ?
Comment pourrai-je trouver un  emploi via les réseaux sociaux ?Comment pourrai-je trouver un  emploi via les réseaux sociaux ?
Comment pourrai-je trouver un emploi via les réseaux sociaux ?
 
openGAS - 2011 09 22 - Verona
openGAS - 2011 09 22 - VeronaopenGAS - 2011 09 22 - Verona
openGAS - 2011 09 22 - Verona
 

Similar to Drupal csu-open atriumname

Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
 

Similar to Drupal csu-open atriumname (20)

laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)Code moi une RH! (PHP tour 2017)
Code moi une RH! (PHP tour 2017)
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of Lithium
 
WordPress Capabilities Magic
WordPress Capabilities MagicWordPress Capabilities Magic
WordPress Capabilities Magic
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form component
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Drupal csu-open atriumname

  • 1. Drupal @ CSU atrium_username feature Emanuele Quinto Identity Management/Portal
  • 3. atrium_username • a Drupal feature for managing user name display; • a lightweight alternative to realname module; • "works" before theme layer • uses the node title of the user profile function atrium_username_get_name($uid) { static $users = array(); if (!isset($users[$uid])) { // get data from db DIRECTLY $users[$uid] = db_result(db_query("SELECT title FROM {node} WHERE type='profile' AND uid=%d", $uid)); } return $users[$uid]; } It doesn't implements its own theme_username allowing another theme to override it. 3
  • 6. Account Block Preprocess injection // Preprocess block. // Inject custom preprocessor before tao/ginkgo. $preprocess_function = $theme_registry['block'] ['preprocess functions']; $preprocess_theme = array_slice($preprocess_function, 2); array_unshift($preprocess_theme, 'atrium_username_preprocess_block'); array_splice($preprocess_function, 2, count($preprocess_function), $preprocess_theme); $theme_registry['block']['preprocess functions'] = $preprocess_function; $theme_registry['block']['include files'][] = $atrium_username_path . '/atrium_username.theme.inc'; Insert atrium_username_preprocess_block before other preprocess 6
  • 7. Account Block Preprocess implementation function atrium_username_preprocess_block(&$variables) { // atrium-account if($variables['block']->bid == "atrium-account") { global $user; if ($user->uid) { $atrium_username = atrium_username_get_name($user- >uid); $user_name = $atrium_username ? $atrium_username : check_plain($user->name); $variables['block']->subject = theme('user_picture', $user) . $user_name; } } } Don't use theme_username, it adds a link! 7
  • 10. User Profile Hook views_pre_render function atrium_username_views_pre_render(&$view) { // set title for profile_display (http://drupal.org/node/1176080) if($view->name == 'profile_display' && $view- >current_display == 'page_1') { $uid = $view->args[0]; $atrium_username = atrium_username_get_name($uid); if(!empty($atrium_username)) { drupal_set_title($atrium_username); } } } 10
  • 13. User Name Field render_link() method function render_link($data, $values) { // get uid field name $field_uid = isset($this->aliases['uid']) ? $this->aliases['uid'] : 'uid'; if (!empty($this->options['link_to_user']) || !empty($this- >options['overwrite_anonymous'])) { $account = new stdClass(); $account->uid = $values->{$field_uid}; if (!empty($this->options['overwrite_anonymous']) && !$account->uid) { // This is an anonymous user, and we're overriting the text. return check_plain($this->options['anonymous_text']); } elseif (!empty($this->options['link_to_user'])) { $account->name = $values->{$this->field_alias}; return theme('username', $account); } } // Otherwise, there's no special handling, so try to return atrium_username. if(isset($values->{$field_uid})) { $atrium_username = atrium_username_get_name($values->{$field_uid}); return $atrium_username ? $atrium_username : $data; } else { return $data; } } 13
  • 16. Casetracker – issue page Function atrium_username_theme_casetracker_comment_changes case 'assign_to': $old->{$field} = atrium_username_get_name($old- >{$field}) ? atrium_username_get_name($old->{$field}) : check_plain(casetracker_get_name($old->{$field})); $new->{$field} = atrium_username_get_name($new- >{$field}) ? atrium_username_get_name($new->{$field}) : check_plain(casetracker_get_name($new->{$field})); break; Unfortunately we have to rewrite everything as the lines to be changed are inside a switch/case with no other options. Only the case 'assign_to' is modified. 16
  • 18. Casetracker – issue page hook_form_alter if(!empty($form['casetracker']['assign_to']['#options'])) { $assign_to = $form['casetracker']['assign_to'] ['#options']; foreach($assign_to as $key => $value) { $uid = casetracker_get_uid($key); $atrium_username = atrium_username_get_name($uid); $name = $atrium_username ? $atrium_username : $value; $form['casetracker']['assign_to']['#options'][$key] = $name; } } Radio options are set at theme level (theme_casetracker_case_form_common) but this is a form (comment_form()) so we can hook_form_alter: 18
  • 20. Casetracker – issue filter hook_form_alter if($form_id=='views_exposed_form' && $form['#id']=='views- exposed-form-casetracker-cases-page-1') { foreach($form['assign_to']['#options'] as $uid => $value) { if(is_int($uid) && $uid>0) { $atrium_username = atrium_username_get_name($uid); if(!empty($atrium_username)) { $form['assign_to']['#options'][$uid] = $atrium_username . "~"; } } } } The "Filter results" block is an exposed filter from the casetracker_cases​ ​ view. It's a form so we user hook_form_alter to modify user names 20
  • 22. Casetracker – assigned column Override field handler class atrium_username_casetracker_views_handler_field_user_name extends views_handler_field { function render($values) { $uid = $values->{$this->field_alias}; if($uid==0) { return casetracker_get_name($uid); } else { $atrium_username = atrium_username_get_name($uid); return $atrium_username ? $atrium_username : casetracker_get_name($uid); } } } Override Casetracker Module implementation of views_handler_field (casetracker_views_handler_field_user_name): 22
  • 25. Theming User Name Simulate preprocess // Simulate a preprocess function for theme("username"). $_SESSION['theme_registry_username_function'] = $theme_registry['username']['function']; $theme_registry['username']['function'] = 'atrium_username_preprocess_username'; $theme_registry['username']['include files'] = array($atrium_username_path '/atrium_username.theme.inc'); Override theme but apply original theme (saved in $_SESSION) function atrium_username_preprocess_username($object) { $theme_username = $_SESSION['theme_registry_username_function'] ? $_SESSION['theme_registry_username_function'] : 'theme_username'; $user = drupal_clone($object); if($user->uid) { $atrium_username = atrium_username_get_name($user->uid); $user->name = $atrium_username ? $atrium_username : $user->name; } return $theme_username($user);} 25
  • 28. Notifications hook_form_alter // Change notification_team form options if(!empty($form['notifications']['notifications_team'] ['options']['#value'])) { foreach($form['notifications']['notifications_team'] ['options']['#value'] as $uid => $name) { $atrium_username = atrium_username_get_name($uid); $name = $atrium_username ? $atrium_username : $name; $form['notifications']['notifications_team']['options'] ['#value'][$uid] = $name; } } 28
  • 31. Autocomplete hook_menu_alter function atrium_username_menu_alter(&$callbacks) { $callbacks['members/add/autocomplete']['page callback'] = 'atrium_username_autocomplete'; $callbacks['members/add/ajax']['page callback'] = 'atrium_username_addform_ajax'; } callback function atrium_username_autocomplete($string = '') { $matches = array(); if ($string) { $query = "SELECT u.uid, u.name, n.title FROM {users} u LEFT JOIN {node} n ON (n.uid=u.uid AND n.type='profile') WHERE LOWER(n.title) LIKE LOWER('%s%%') OR LOWER(u.name) LIKE LOWER('%s%%')"; $query = db_rewrite_sql($query, 'users', 'uid', array($string, $string)); $result = db_query_range($query, array($string, $string), 0, 10); while ($user = db_fetch_object($result)) { $user_name = $user->title ? check_plain($user->title) : check_plain($user->name); $matches[$user_name] = $user_name; } } drupal_json($matches); } 31
  • 33. Q&A Thank you 33
  • 34. About Emanuele Quinto equinto@sfsu.edu http://www.linkedin.com/in/emanuelequinto @emaV atrium_username http://drupal.org/project/atrium_username https://github.com/emaV/atrium_username 34