Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DX) Civi::contactSettings - Add a facade for working with the logged-in user's settings #12879

Merged
merged 2 commits into from
Sep 28, 2018

Conversation

totten
Copy link
Member

@totten totten commented Sep 27, 2018

Before

To read/write a setting for the logged-in user, you need a snippet like this:

$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:

$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.

totten and others added 2 commits September 27, 2018 17:05
…-in user's settings

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.
@colemanw
Copy link
Member

I've tested this out by updating the activity_tab_filter setting code to use new fascade and it all works beautifully.

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

Test fails unrelated

@seamuslee001 seamuslee001 merged commit d612bf8 into civicrm:master Sep 28, 2018
@totten totten deleted the master-contact-settings branch September 28, 2018 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants