Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
1.0k views
in Q2A Core by
edited by

Hi, I need to override one function which is in app/format.php, by default it can't be override. Then How one can be override ?

I added the overridable condition to the original function, but it's not working.


I'm trying to change following thing from admin to user specific

So that,

These checkboxes can be loaded by default with user specific.

These options available in user account page.

in app/format.php, By editing following function, I got the output as I like.

function qa_set_up_notify_fields(&$qa_content, &$fields, $basetype, $login_email, $innotify, $inemail, $errors_email, $fieldprefix = ''){}

Modifying the original functions --- lost when updating Q2A. So I want to override it.


qa-include/base.php file having following functions

function qa_call_override($function, $args)

function qa_to_override($function)

which are actually calling overrides. So I added override condition manually for my required function. But it's not working.

Q2A version: 1.8

1 Answer

+1 vote
by
selected by
 
Best answer

If the function doesn't support overriding (as per the documentation) it cannot be overridden. I highly doubt that you can just add the qa_to_override() condition to the function and it will magically become overridable. That most likely requires other provisions elsewhere in the code.

What you can do is modify the original function, although that is not recommended, b/c your changes will be lost when updating Q2A.

If you're creating or modifying a theme or plugin it might be more viable to implement your own formatting function in the theme/plugin, and use that instead of the system-provided ones. But that depends on what you actually want to accomplish in the end.


Edit (in response to updated question):

I don't see a way to directly override the function without modifying core code. However, the function appears to be used in functions that populate a_form/c_form/q_form fields in the content data structure, so you might be able to modify those fields (more specifically the "notify" field within those) in your theme.

Try overriding the methods a_form(), c_form() and q_form() in your theme, so that they manipulate the "notify" field in the way you desire before it's being rendered.

Example:

function a_form($a_form) {
  $a_form['fields']['notify'] = ...; // change notify field elements here
  parent::a_form($a_form);           // then invoke original method with modified data
}

by
yes, modifying original function is not work when q2a updates.

But there should be someway to override.
by
Not that I'm aware of. Depending on what you want to do/change you can implement your own formatting functions in your plugin or theme and use those instead of using the system-provided ones, though.
Speaking of which, what *are* you trying to accomplish with this override anyways?
by
Thank you. let me check by defining my own function and calling it via theme.php
by
Writing my own function is not working due to, original function called in more than 2 pages.
by
I will check it sir.
by
sir, there's no q_form() in theme file
by
You need to add it yourself if it's not present. A theme only needs to contain methods that the theme author wants to override (IOW wants to work differently). For everything else Q2A automatically uses the implementation of the base theme.
...