CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • I can't seem to get the "new" way of defining a settings variable working
Pages: [1]

Author Topic: I can't seem to get the "new" way of defining a settings variable working  (Read 609 times)

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
I can't seem to get the "new" way of defining a settings variable working
June 18, 2015, 05:48:50 pm
I am working on https://issues.civicrm.org/jira/browse/CRM-16401 Allow admin to set which day is the first day of the week.

It seems sensible to do this now, before Jon and (perhaps) I get into the final stage of https://issues.civicrm.org/jira/browse/CRM-16195 which will allow admins to create their own relative date filters.

I got it working the 'old' way by adding a new variable $weekBegins to CRM/Core/Config/Variables.php. ( screenshot attached)  :)

Then I found out about the 'new' way s outlined in Adding A New Setting to CiviCRM Core at http://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference.

I have been following through the steps as best I can ( I am still at the copy, paste, change stage and there are not a lot of example of the 'new' way for what I want to do  :(  ).

To settings/localization.settings.php I have added:

Code: [Select]
'weekBegins' => array(
    'group_name' => 'Localization Preferences',
    'group' => 'localization',
    'name' => 'weekBegins',
    'type' => 'String',
    'quick_form_type' => 'Element',
    'html_type' => 'select',
    'option_values' => array(
      ts('Sunday'),
      ts('Monday'),
      ts('Tuesday'),
      ts('Wednesday'),
      ts('Thursday'),
      ts('Friday'),
      ts('Saturday'),
    ),
    'default' => '1',
    'add' => '4.7',
    'title' => 'Week begins on',
    'is_domain' => 1,
    'is_contact' => 0,
    'description' => "",
    'help_text' => NULL,
  ),
   
and at the beginning of CRM/Admin/Form/Setting/Date.php I have added:

 
Code: [Select]
protected $_settings = array(
    'weekBegins' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
  );

No changes were made automatically in templates/CRM/Admin/Form/Setting/Date.tpl  so I added   

Code: [Select]
<fieldset><legend>{ts}Week Begins{/ts}</legend>
   <table class="form-layout-compressed">
       <tr class="crm-date-form-block-weekBegins">
          <td class="label">{$form.weekBegins.label}</td>
          <td>{$form.weekBegins.html}</td>
       </tr>
   </table>
</fieldset>


But when I try to go to /civicrm/admin/setting/date?reset=1  I get a WSOD

The debugging information I have located so far is:

Quote
This page has no sources

and

Quote
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

My debugging skills are somewhat limited ( I haven't managed to get phpstorm and git to work together :( )

What I do know is:

 
  • I (not unexpectedly) get the date settings page with the Week Begins heading visible not a WSOD  if I delete from CRM/Admin/Form/Setting/Date.php

     
Code: [Select]
protected $_settings = array(
    'weekBegins' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
  );
    [/li]
  • changing localization.settings.php to have
Code: [Select]
'type' => 'Boolean,
    'quick_form_type' => 'YesNo',
    so that I don;t need to include 'html_type'  still gives me a WSOD
    [/li]


Any suggestions on what I should try next would be greatly appreciated
« Last Edit: June 18, 2015, 09:06:05 pm by joanne »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: I can't seem to get the "new" way of defining a settings variable working
June 18, 2015, 08:15:51 pm
Your code looked fine to me so I tried it out and it works :)
It did require clearing caches before the new setting showed up on the form.
I took the liberty of moving the field inside another set to improve grouping, and used a function to retrieve the names of the days instead of hard-coding them.
Feel free to checkout my branch locally, add your own commits to it, and submit a new PR. This one is incomplete in that the new setting doesn't actually do anything!
https://github.com/civicrm/civicrm-core/pull/6055
Try asking your question on the new CiviCRM help site.

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
Re: I can't seem to get the "new" way of defining a settings variable working
June 18, 2015, 08:36:50 pm
Thanks Coleman, clearing caches is something I have to add to my  remember-to list.

I did think there would be a way to get the days of the week without the list, but was wanting a working selector before pursuing that.

Yes, at the moment this setting isn't used, but in adding the ability to let people create their own relative date filters (https://issues.civicrm.org/jira/browse/CRM-16195), the filters based on "week"  will make use of, say, Previous "DayName". Rather than have everything based on weeks starting Sunday (ie Previous Sunday), it makes sense to be able to use "Previous $weekBegins"  (Although there might be another step in there somehow as $weekBegins might be a number rather than the name of the day. Sigh... so much I don't know.)
« Last Edit: June 18, 2015, 09:06:58 pm by joanne »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: I can't seem to get the "new" way of defining a settings variable working
June 19, 2015, 10:56:30 am
I've updated the Pull-Request so that it actually does do something :)
Maybe we could merge it in and then you could continue your work.
Try asking your question on the new CiviCRM help site.

joanne

  • Administrator
  • Ask me questions
  • *****
  • Posts: 852
  • Karma: 83
  • CiviCRM version: 4.4.16
  • CMS version: Drupal 7
Re: I can't seem to get the "new" way of defining a settings variable working
June 19, 2015, 10:36:08 pm
Certainly, merge away.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • I can't seem to get the "new" way of defining a settings variable working

This forum was archived on 2017-11-26.