Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html_entity_decodeを使っている箇所を修正 #45

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 11 additions & 39 deletions Event/OrderPdfLegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,20 @@ public function onRenderAdminOrderPdfBefore(FilterResponseEvent $event)
*/
private function getHtml(Response $response)
{
// 検索結果一覧の下部に帳票出力を追加する
// 受注管理-受注マスターのHTMLを取得し、DOM化
$crawler = new Crawler($response->getContent());
$document = \DOMDocument::loadHTML($response->getContent());

// [Form id="dropdown-form"]の最終項目に追加(レイアウトに依存(時間無いのでベタ))
$html = $this->getHtmlFromCrawler($crawler);
$xpath = new \DOMXPath($document);
$menu = $xpath->query('//li[@id="dropmenu"]//ul[@class="dropdown-menu"]', $document)->item(0);

$parts = $this->app->renderView(
'OrderPdf/Resource/template/admin/order_pdf_menu.twig'
);

try {
// ※商品編集画面 idなりclassなりがきちんとつかないとDOMをいじるのは難しい
// また、[その他]メニューの中に入れ込もうとしたがJQUERYのイベントが動作するので不可
// = = = = = = = = =
// その他メニューに追加するバージョン
$form = $crawler->filter('#dropmenu .dropdown-menu')->last()->html();
$newForm = $form.$parts;

$html = str_replace($form, $newForm, $html);
} catch (\InvalidArgumentException $e) {
log_error('Cannot found .dropdown-menu', array($e->getMessage()));
}

return html_entity_decode($html);
}

/**
* 解析用HTMLを取得.
*
* @param Crawler $crawler
*
* @return string
*/
private function getHtmlFromCrawler(Crawler $crawler)
{
$html = '';
foreach ($crawler as $domElement) {
$domElement->ownerDocument->formatOutput = true;
$html .= $domElement->ownerDocument->saveHTML();
if ($menu) {
$parts = $this->app->renderView(
'OrderPdf/Resource/template/admin/order_pdf_menu.twig'
);
$newNode = \DOMDocument::loadXML($parts)->getElementsByTagName('li')->item(0);
$menu->appendChild($document->importNode($newNode, true));
}

return html_entity_decode($html, ENT_NOQUOTES, 'UTF-8');
$crawler = new Crawler($document);
return $crawler->html();
}
}
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: OrderPdf
event: OrderPdfEvent
code: OrderPdf
version: 1.0.0
version: 1.0.1
service:
- OrderPdfServiceProvider
orm.path:
Expand Down