Code contribution - Please add

Bauer

Well-Known Member
Per this from the Wiki....
There are two options available for making contributions to Fabrik in the form of code submissions, bug fixes and language files:
  • Create your contribution on your own system and send the updated files to the developers via the forums.
Below are a few simple changes I add to code that will change the way fabrik automatically creates labels for new elements when a list is created from an existing table. I had complained in the past that having to edit those labels is very aggravating - especially if you add an existing table with a few dozen elements.

Personally, I would prefer that these new labels be created/displayed as 'proper names' - i.e. user_name becomes "User Name".

So I wrote the code needed to create a new global default setting to determine just how those labels will get created. It is very simple and basic and I hope someone who contributes to github will add my code - as I'm sure many other Fabrik users would welcome this added feature.

Add this to create a new fieldset (tab) in the Fabrik global configuration. (Put this between the 'elements' and 'forms' fieldset tags in administrator/components/com_fabrik/config.xml - to create a new tab named 'labels' which the language file labels as "Labels".)
Code:
    <fieldset label="COM_FABRIK_LABELS" name="labels">
        <field name="format_labels"
            type="radio"
            default="0"
            description="COM_FABRIK_LABELS_DESC"
            label="COM_FABRIK_LABELS_LABEL">
                <option value="0">COM_FABRIK_LABELS_DEFAULT</option>       
                <option value="1">COM_FABRIK_LABELS_LOWERCASE</option>
                <option value="2">COM_FABRIK_LABELS_UCWORDS</option>
                <option value="3">COM_FABRIK_LABELS_CAPFIRST</option>
                <option value="4">COM_FABRIK_LABELS_CAPS</option>           
        </field>
    </fieldset>
Sorry, I only changed the English language file - but for example, this would be added to
the bottom of administrator/components/com_fabrik/language/en-GB/en-GB.com_fabrik.ini ...
Code:
COM_FABRIK_LABELS="Labels"
COM_FABRIK_LABELS_LABEL="Default action for creation of labels"
COM_FABRIK_LABELS_DESC="When you create a new list from an existing database table, new elements are automatically created and the label becomes the element name with any underscores replaced with a space. Set the default formatting used to create these element labels below."
COM_FABRIK_LABELS_DEFAULT="Default (e.g. user_Name becomes 'user Name')"
COM_FABRIK_LABELS_LOWERCASE="Lowercase (e.g. user_Name becomes 'user name')"
COM_FABRIK_LABELS_UCWORDS="Proper name (e.g. user_Name becomes 'User Name')"
COM_FABRIK_LABELS_CAPFIRST="Capitalize first letter (e.g. user_Name becomes 'User name')"
COM_FABRIK_LABELS_CAPS="All Caps (e.g. user_name becomes 'USER NAME')"
Then finally, in administrator/components/com_fabrik/models/list.php - in protected function makeElementsFromFields() - Near the bottom of the function, just above the line $element->store();
Insert this code...
PHP:
            //Format Label
            $labelConfig = $fbConfig->get('format_labels','0');   
            switch($labelConfig)
            {
                case '1':
                    $element->label = strtolower($element->label);
                    break;
                case '2':
                    $element->label = ucwords($element->label);
                    break;
                case '3':
                    $element->label = ucfirst($element->label);
                    break;
                case '4':
                    $element->label = strtoupper($element->label);
                    break;   
                default:
                    break;
            }
I have tested and it works as expected.
 
And just think ... it being 4am, and I'm so tired I can barely keep my eyes open ... if I could just go to github and hit "Merge" on a PR, it'd be done right now.

As it is, I'll leave this tab open, and hopefully remember to do it by steam in the "morning" when I wake up.

One of these days I'd be *more* than happy to give you a one-on-one tutorial on how to set up and run a github fork, so you can just do this stuff by submitting PR's. I know we've had this discussion before, and I know you really don't want to deal with github ... but it honestly, Cub Scouts Honor, would save both of us a lot of time and effort.

Anyway, hopefully I'll remember to do this when I wake up, and thanks for the contribution.

-- hugh
 
Well I waited patiently for over 4 months - then finally figured how to add this code myself as a request via github last week - and did so.
But still, all I hear is crickets. :confused:

This is the final thing on my list of "things I need to do every time I update from github". So a merge of my changes would surely be appreciated - and I'd like to think many users would also appreciate this added feature.
 
I was solving the same little snippet problem recently. One particular element I just could not imagine I would give users the freedom to mess with upper and lower cases due to filters and sorting. Just imagine, Football FOOTBALL football ;-) ... [the soccer thing with ball :-D]. Thanks, Bauer!
 
We typically do PR merges once a week or so, when one of us has the time to sit down and go through them.

If it hasn't been merged yet, give me a URL to the PR. I don't see anything in the pending queue which looks like this though. But then, a quick look through the "done" list doesn't show anything looking like this either.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top