Skip to content
Permalink
Browse files

only render head elements once, and improve misleading const name

  • Loading branch information
flack committed Nov 30, 2019
1 parent ba39fbc commit f489a465b70d4c9a2f5df5aa3fe7211bf3839a86
Showing with 7 additions and 6 deletions.
  1. +6 −5 lib/midcom/helper/head.php
  2. +1 −1 src/midcom/workflow/dialog.php
@@ -95,7 +95,7 @@ class midcom_helper_head
*/
private $_link_head = [];
const TOOLBAR_PLACEHOLDER = '<!-- MIDCOM_HEAD_ELEMENTS -->';
const HEAD_PLACEHOLDER = '<!-- MIDCOM_HEAD_ELEMENTS -->';
private static $listener_added = false;
@@ -393,7 +393,7 @@ public function print_head_elements()
midcom::get()->dispatcher->addListener(KernelEvents::RESPONSE, [$this, 'inject_head_elements']);
self::$listener_added = true;
}
echo self::TOOLBAR_PLACEHOLDER;
echo self::HEAD_PLACEHOLDER;
}
/**
@@ -410,15 +410,16 @@ public function inject_head_elements(FilterResponseEvent $event)
$response = $event->getResponse();
$content = $response->getContent();
if (strpos($content, self::TOOLBAR_PLACEHOLDER) === false) {
$first = strpos($content, self::HEAD_PLACEHOLDER);
if ($first === false) {
return;
}
$head = $this->render();
$new_content = str_replace(self::TOOLBAR_PLACEHOLDER, $head, $content);
$new_content = substr_replace($content, $head, $first, strlen(self::HEAD_PLACEHOLDER));
$response->setContent($new_content);
if ($length = $response->headers->get('Content-Length')) {
$delta = strlen($head) - strlen(self::TOOLBAR_PLACEHOLDER);
$delta = strlen($head) - strlen(self::HEAD_PLACEHOLDER);
$response->headers->set('Content-Length', $length + $delta);
}
}
@@ -116,7 +116,7 @@ public function js_response(string $script) : Response
midcom::get()->head->add_jsfile(MIDCOM_STATIC_URL . '/midcom.workflow/dialog.js');
midcom::get()->head->add_jscript($script);
midcom::get()->dispatcher->addListener(KernelEvents::RESPONSE, [midcom::get()->head, 'inject_head_elements']);
$content = '<!DOCTYPE html><html><head>' . \midcom_helper_head::TOOLBAR_PLACEHOLDER . '</head><body></body></html>';
$content = '<!DOCTYPE html><html><head>' . \midcom_helper_head::HEAD_PLACEHOLDER . '</head><body></body></html>';
return new Response($content);
}

0 comments on commit f489a46

Please sign in to comment.
You can’t perform that action at this time.