DOMElement
This is an open discussion with 9 replies, filed under Extensions.
Search
I did something similar a while back in an extension called Version Info (wich is now obsolete since this behaviour has been integrated into the core).
Basically you don’t have to wait until AdminPagePostGenerate
fires and parse the result but you can use AddElementToFooter
and use the $context
variable to modify the markup before it’s being rendered.
Please note that to date the Symphony 2 series uses it’s own proprietary XMLElement
class to replicate what DOMDocument
is doing (Symphony 3 will change that).
Oh, thanks for the information.
Basically you don’t have to wait until AdminPagePostGenerate fires and parse the result but you can use AddElementToFooter and use the $context variable to modify the markup before it’s being rendered.
I’ll try to modifiy $context[parent][Page][Footer][…]
But still, how can I dump a DOMElement variable? I will need this very soon … And I can’t do any XML manipulation with php because I can’t “see” what I’m doing :)
What I am after is changing the “Symphony 2.2RC2” form lower left.
Yup. That’s what
public function getSubscribedDelegates() { return array( array( 'page' => '/backend/', 'delegate' => 'AddElementToFooter', 'callback' => 'AddElementToFooter' ) ); } public function AddElementToFooter($context) { end(Administration::instance()->Page->Footer->getChildren())->setValue("foo"); }
will do.
And I can’t do any XML manipulation with php because I can’t “see” what I’m doing
As I said I didn’t have to use DOMDocument
var_dump(Administration::instance());
did the trick for me.
Thank you for the tip, it solves this problem, but …
How can I dump a DOMElement or DOMNodeList to see what they contain?
I don’t think developers in here (class.localisationmanager.php)
private function __findNavigationStrings() { ... }
or in (extension.driver.php —> Static Section)
private function appendPreferences($context) { ... }
and in some other extensions, coded blindly.
I’m going to chip in and recommend that you do not try and parse backend pages as XML (i.e. converting a Symphony XMLElement to a PHP DOMElement). The backend is not always valid HTML, and so this can fail. I’ve been meaning to send a fix for the Static Section extension which removed this pretty dirty approach.
Subscribe to the AddElementToFooter
delegate and, although the element that is passed in its $context
is the <ul>
only (no version <p>
element), this is the right place in the page lifecycle to do this manipulation.
You can get the footer XMLElement via:
Administration::instance()->Page->Footer
You can render an XMLElement to see its children as XML by calling a generate()
method which returns a string:
echo(Administration::instance()->Page->Footer->generate());
You can iterate over the children:
foreach(Administration::instance()->Page->Footer->getChildren() as $child) { ... }
See /symphony/lib/tooklit/class.xmlelement.php
for other methods.
Romanian proverb: “If two guys tell you that you are drunk, then go to sleep.”
I will walk the XMLElement
path.
Successful with the rename.
Still, is there a way to dump a DOMElement variable?
;;)
Will sure need it in Symphony 3.
You can call saveXML()
on the originating DOMDocument:
Thank you.
Create an account or sign in to comment.
I’m building an extension which replaces the Symphony version in the footer:
Symphony 2.2RC2 -> Something else
This is the delegate:
And this is the function:
My question:
Is there any way to dump the value of $nodeList or $firstElement?
I need to see what they contain so I can change their values. var_dump() and print_r() show “empty” stuff. I noticed that DOMDocument has the saveHTML() method for some sort of output.