Skip to content
  • totten's avatar
    (DX) Civi::contactSettings - Add a facade for working with the logged-in user's settings · 01d70c56
    totten authored
    Before
    ------
    
    To read/write a setting for the logged-in user, you need a snippet like this:
    
    ```php
    $cid = CRM_Core_Session::getLoggedInContactID();
    $myFilter = Civi::service('settings_manager')
      ->getBagByContact(NULL, $cid)
      ->get('activity_tab_filter');
    ```
    
    After
    -----
    
    To read/write a setting for the logged-in user, you can use a snippet like this:
    
    ```php
    $myFilter = Civi::contactSettings()->get('activity_tab_filter');
    ```
    
    Technical Details
    -----------------
    
    * A convenience function like this is liable to be used in lazy circumstances where
      the developer is unlikely to check their conditions carefully. Therefore, the
      errors are reported as exceptions so that mistakes are easiliy revealed.
    * This is technically a small contract change to `SettingsManager::getBagByContact()`
      because it now interprets `$contactId===NULL` as meaning "the logged-in user".
      However, I don't think NULL was a sensible value before, and this interface
      isn't widely known/used.
    01d70c56