Search

I’m building an extension which replaces the Symphony version in the footer:

Symphony 2.2RC2 -> Something else

This is the delegate:

'delegate' => 'AdminPagePostGenerate',
'page' => '/backend/',
'callback' => 'EditUserAgent'

And this is the function:

public function EditUserAgent($output){
    $dom = DOMDocument::loadHTML($output[output]);
    $xpath = new DOMXPath($dom);

    $nodeList = $xpath->query("//p[@id='version']);
    var_dump($nodeList);
    //outputs = object(DOMNodeList)#370 (0) { }
    print_r($nodeList);
    //outputs = DOMNodeList Object ( ) 

    $firstElement = $nodeList->item(0);
    var_dump($firstElement);
    //outputs = object(DOMElement)#369 (0) { }
    print_r($firstElement);
    //outputs = DOMElement Object ( )

    $output[output] = $dom->saveHTML(); 
    die(print_r($output[output]));
}

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.

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:

http://php.net/manual/en/domdocument.savexml.php

Thank you.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details