Added event support for `getTextContent()`
authorAlexander Ebert <ebert@woltlab.com>
Wed, 1 Mar 2017 10:41:23 +0000 (11:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 1 Mar 2017 10:41:23 +0000 (11:41 +0100)
Closes #2193

wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index f0c891eb9b03c8b79f1bdbc0eb8de728c6cf9021..4f3c07a54321c8e82060b66893356d0ff2018f27 100644 (file)
@@ -398,7 +398,14 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor {
         * @return      string          raw text content
         */
        public function getTextContent() {
-               return StringUtil::trim($this->getDocument()->getElementsByTagName('body')->item(0)->textContent);
+               // cloning the body allows custom event handlers to alter the contents
+               // without making permanent changes to the document, avoids side-effects
+               $body = $this->getDocument()->getElementsByTagName('body')->item(0)->cloneNode(true);
+               
+               $parameters = ['body' => $body];
+               EventHandler::getInstance()->fireAction($this, 'getTextContent', $parameters);
+               
+               return StringUtil::trim($parameters['body']->textContent);
        }
        
        /**