Forums | Mahara Community

Developers /
Modify the mahara forms


Osbel Rondón's profile picture
Posts: 23

23 February 2017, 12:18

Hello everyone
I am working on a mahara customization and I am using version 16.04.3 in which I want to remove some elements from the contact forms and add others.
I have tried modifying the file htdocs \ artefact \ internal \ lib.php but somehow a loop is created that paralyzes the system.
I am new to these programming terms and am trying to understand the architecture and operation of mahara.
I would greatly appreciate if someone could help me.
Thank you

Robert Lyon's profile picture
Posts: 749

24 February 2017, 8:32

Hi Osbel,

Good to hear you want to customize Mahara - are you able to paste some code that you tried to modify so I can see what you may have done to create the problem loop?

And I will see if I can help you

Cheers

Robert

Osbel Rondón's profile picture
Posts: 23

24 February 2017, 9:51

Thank you very much for your attention
I was already able to add a new field called company to the profile form
First, in the htdocs \ artefact \ internal \ index.php file, I added the company element to the array of profile elements.


$elements = array(
    'profile' => array(
        'type' => 'fieldset',
        'legend' => get_string('aboutme', 'artefact.internal'),
        'class' => 'has-help' . $fieldset != 'aboutme' ? 'collapsed' : '',
        'elements' => get_desired_fields($items, array('company','firstname', 'lastname', 'studentid', 'preferredname', 'introduction'), 'about'),
    ),
    'contact' => array(
        'type' => 'fieldset',
        'legend' => get_string('contact', 'artefact.internal'),
        'class' => $fieldset != 'contact' ? '' : '',
        'elements' => get_desired_fields($items, array('email', 'maildisabled', 'officialwebsite', 'personalwebsite', 'blogaddress', 'address', 'town', 'city', 'country', 'homenumber', 'businessnumber', 'mobilenumber', 'faxnumber'), 'contact'),
    )
);

Then in the htdocs \ artefact \ internal \ lib.php file I added the company element to the following functions: get_profile_artefact_types (), progressbar_link ($ artefacttype), get_all_fields () and get_field_element_data ().

In the function progressbar_link ($ artefacttype) I added it in the following way:

public static function progressbar_link($artefacttype) {
        switch ($artefacttype) {
            case 'company':
            case 'firstname':
            case 'lastname':
            case 'studentid':
            case 'preferredname':
            case 'introduction':
                return 'artefact/internal/index.php';
                break;
            case 'email':
            case 'officialwebsite':
            case 'personalwebsite':
            case 'blogaddress':
            case 'address':
            case 'town':
            case 'city':
            case 'country':
            case 'homenumber':
            case 'businessnumber':
            case 'mobilenumber':
            case 'faxnumber':
                return 'artefact/internal/index.php?fs=contact';
                break;
            default:
                return 'view/index.php';
        }
    }
}

However the system still does not recognize the company element as an internal artifact because the get_string () function returns [[company / artefact.internal]] when it should return only company.

What do you think I am missing so that the system recognizes the company field as an element of the profile form ?

I keep abreast

Osbel

Robert Lyon's profile picture
Posts: 749

28 February 2017, 9:50

Hi Osbel

For the get_string() problem  - have you defined the 'company' string?

To define it in English you will need to edit

htdocs/artefact/internal/lang/en.utf8/artefact.internal.php

And add $string['company'] = 'Company';

If you need to define it in another language you will need to edit the artefact.internal.php files under your dataroot/language/ section.

 

Also have you defined your class for the new field? Something like

  class ArtefactTypeCompany extends ArtefactTypeProfileField {

  }

I've been working on making it a bit easier to add custom profile fields to Mahara without hacking core code and have a couple of patches in progress to achieve this - not production ready yet

But if you look at patch https://reviews.mahara.org/#/c/7433/4

You should be able to see the different places that an Profile field (artefact/internal) needs to touch to fully work - not all of the places will be relevant for core code.

Cheers

Robert

Osbel Rondón's profile picture
Posts: 23

28 February 2017, 14:50

Hello, Robert
With your explanation I solved what I needed exactly, thank you very much for your help.
Osbel

5 results