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

50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 MinutesAzim Kurt
 
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 UnConRafael Dohms
 
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 CairoMohamed Mosaad
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Coding for Scale and Sanity
Coding for Scale and SanityCoding for Scale and Sanity
Coding for Scale and SanityJimKellerES
 
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óvilesLuis Curo Salvatierra
 
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 2016Colin O'Dell
 
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 1Acquia
 
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 JavascriptDarren Mothersele
 
Instant Dynamic Forms with #states
Instant Dynamic Forms with #statesInstant Dynamic Forms with #states
Instant Dynamic Forms with #statesKonstantin 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

Fieldwork presentation
Fieldwork presentationFieldwork presentation
Fieldwork presentationRafique Qien
 
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 IndustryColosi Marketing
 
Rainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teaserRainforest guatemala for Glastonbury teaser
Rainforest guatemala for Glastonbury teasermiguelba13
 
Internet research chinese
Internet research chineseInternet research chinese
Internet research chinesepoeticmizz
 
про питание
про питаниепро питание
про питание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 seasonZakaria Jusoh
 
Behind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resourcesBehind the Blackboard-e-learning resources
Behind the Blackboard-e-learning resourceseliggett01
 
Video tour sevilla
Video tour sevillaVideo tour sevilla
Video tour sevillathesin
 
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 2009Fiona Claisse
 
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 CaseEmanuele Quinto
 
Presentation 4 Linkend
Presentation 4 LinkendPresentation 4 Linkend
Presentation 4 Linkendjulieguiney
 
TIC MAGAZINE Edition N°07
TIC MAGAZINE Edition N°07TIC MAGAZINE Edition N°07
TIC MAGAZINE Edition N°07TIC MAGAZINE
 
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 ?Nouha Belaid
 
openGAS - 2011 09 22 - Verona
openGAS - 2011 09 22 - VeronaopenGAS - 2011 09 22 - Verona
openGAS - 2011 09 22 - VeronaEmanuele Quinto
 

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

laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutesBarang CK
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8kgoel1
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
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)Arnaud Langlade
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
The State of Lithium
The State of LithiumThe State of Lithium
The State of LithiumNate Abele
 
WordPress Capabilities Magic
WordPress Capabilities MagicWordPress Capabilities Magic
WordPress Capabilities Magicmannieschumpert
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
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.5Leonardo Proietti
 
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 FrameworksNate Abele
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency InjectionRifat Nabi
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form componentSamuel ROZE
 
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 apiMatthieu Aubry
 

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

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 FresherRemote DBA Services
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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