public function StatusPreviewController::generate in Heartbeat 8
Generate.
Return value
string Return Hello string.
1 string reference to 'StatusPreviewController::generate'
- statusmessage.routing.yml in modules/
statusmessage/ statusmessage.routing.yml - modules/statusmessage/statusmessage.routing.yml
File
- modules/
statusmessage/ src/ Controller/ StatusPreviewController.php, line 44
Class
- StatusPreviewController
- Class StatusPreviewController.
Namespace
Drupal\statusmessage\ControllerCode
public function generate($url) {
if ($url == 'build') {
$url = \Drupal::request()
->get('data');
$generator = new MarkupGenerator();
if (!strpos($url, 'http://')) {
$url = 'http://' . $url;
}
if ($generator
->parseMarkup($url)) {
$preview = $generator
->generatePreview();
$response = new Response();
$response
->setContent(\GuzzleHttp\json_encode(array(
'data' => $preview,
)));
$response->headers
->set('Content-Type', 'application/json');
return $response;
}
// $contents = file_get_contents('http://' . $url);
// $response = new Response();
// $this->dom = new \DOMDocument;
// $this->dom->loadHTML($contents);
//
// $xpath = new \DomXpath($this->dom);
//
// $anchorAttributes = $this->getAnchorNodeNames();
// $imgAttributes = $this->getImgNodeNames();
// $imgLogos = $this->searchDom('img', 'logo');
// $anchorLogos = $this->searchDom('a', 'logo');
//
}
return false;
}