Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
924 views
in Q2A Core by
Hi,

I am designing a New Layer in my Plugin. However, there is another already installed plugin, which puts another layer of its own to Page. I read about the Layers on the question2answer website, and it explains that indpependent layers can be installed by plugins simultaneously.

The problem I am facing is this. I am overriding the post_meta_who() method in qa_html_theme_base class. The other plugin's layer, is also overriding the same method. As I can see, both codes are getting executed, but the content it is adding is getting added after my custom content, whereas I want it the other way round.

Can I get some insight on how q2a executes Layer's Codes? In case same method is overridden by multiple Plugins, how does the order of their execution is determined?

Thanks in advance,

Saurabh

2 Answers

+1 vote
by

Overriding theme functions is bad... as you can see.

Just do it like this:

        function post_meta_who($post, $class) {
           <your changes here>
            qa_html_theme_base::post_meta_who($post, $class);
        }

Then everybody gets a turn.

by
Hi NoahY,

Yes, I am doing the same actually, I do call
qa_html_theme_base::post_meta_who($post, $class);
at the end of my function, but so does the plugin's layer, which by chance is the layer of the Badge Plugin developed by you :).

Right now the Badges appear after my Custom Code, but I want them before it. Its obvious that there would be some kind of sequential access here, I want to change the order of that !!
by
I think it's alphabetically... try renaming your plugin folder to z-myplugin and see what happens... I know that's not a solution, but I don't have one right now :)
by
Oh.. well the name of my plugin folder is "rg", which is anyhow alphabetically higher than "NoahY-q2a-badges....". So I guess there is something else. Its something that's not given anywhere I guess in the Documentation.
by
edited by
Huh.  They are registering in alphabetical order for me, but then executing in *reverse* alphabetical order.  Try changing the badges folder to z-badges, and it looks like it will run first.
+1 vote
by

I get it now... the layers register in alphabetical order, and then are added to the script by aggregation, using:

eval('?'.'>'.$layerphp);

to add a new class for each layer - with each class modified to refer back to the previous class as "qa_html_theme_base". 

The last class to be added is then instantiated as the official themeclass. 

What this means, is that the last class is used as the default, and is responsible for allowing the class before it to run for each function, by calling:

qa_html_theme_base::<function>();

which has been modified by the script to read:

qa_html_theme_layer_<x-1>::<function>();

where x is this layer's index.

That layer then is responsible for calling the layer before it, and so on, all the way back to the original, actual "qa_html_theme_base". 

Since each layer "extends" the layer before it (originally "class qa_html_theme_layer extends qa_html_theme_base"), if the layer doesn't contain a function, it looks for the function in the class before it, and so on, again all the way back to the original, actual "qa_html_theme_base".

Hence, the layers are called in reverse alphabetical order.

The easiest way to solve the problem, I guess, is to rewrite the folders in the reverse order you want them to alter the code.  E.g:

01_last

02_next_to_last

...

99_first

by
Hi, Sorry for late reply....
Thanks a lot for the Help....
...