q2a / question2answer

Question2Answer is a free and open source platform for Q&A sites, running on PHP/MySQL.
http://www.question2answer.org/
GNU General Public License v3.0
1.64k stars 629 forks source link

Rewrite of function page_title_error() #217

Closed q2apro closed 9 years ago

q2apro commented 9 years ago

I run into the problem of how to insert a DOM element directly after the h1.

Currently in public function main() you find:

    $this->page_title_error();

    $this->widgets('main', 'high');

    $this->main_parts($content);

Where page_title_error() creates the h1:

public function page_title_error()
{
    if (isset($this->content['title'])) {
        $favorite = isset($this->content['favorite']) ? $this->content['favorite'] : null;

        if (isset($favorite))
            $this->output('<form ' . $favorite['form_tags'] . '>');

        $this->output('<h1>');
        $this->favorite();
        $this->title();
        $this->output('</h1>');

        if (isset($favorite)) {
            $formhidden = isset($favorite['form_hidden']) ? $favorite['form_hidden'] : null;
            $this->form_hidden_elements($formhidden);
            $this->output('</form>');
        }
    }
    if (isset($this->content['error']))
        $this->error($this->content['error']);
}

I could override title() or favorite() but this would inject the element within the h1 tag.

I could also override the main_parts(), however it gives me a "bad feeling".

For now, I see now way of how to change this.

PS: How I came to this issue: http://www.question2answer.org/qa/44681/new-free-plugin-ajax-user-search-finally?show=44855#a44855

svivian commented 9 years ago

Can't you add it at the end of page_title_error() ? So you can have

function page_title_error()
{
    parent::page_title_error();
    // insert your code here
}
svivian commented 9 years ago

@q2apro does my suggestion above solve your issue?

q2apro commented 9 years ago

Yes, I did so. Before I thought there is even more html output in the page_title_error() function. The name is still confusing to me...

Just then I have seen that I can call it first and then add my plugin's html.

    function page_title_error() {
        qa_html_theme_base::page_title_error();
        // my code
    }

Thanks.