Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / vendor / jcalderonzumba / gastonjs / src / Browser / BrowserRenderTrait.php
1 <?php
2
3 namespace Zumba\GastonJS\Browser;
4
5 /**
6  * Trait BrowserRenderTrait
7  * @package Zumba\GastonJS\Browser
8  */
9 trait BrowserRenderTrait {
10   /**
11    * Check and fix render options
12    * @param $options
13    * @return mixed
14    */
15   protected function checkRenderOptions($options) {
16     //Default is full and no selection
17     if (count($options) === 0) {
18       $options["full"] = true;
19       $options["selector"] = null;
20     }
21
22     if (isset($options["full"]) && isset($options["selector"])) {
23       if ($options["full"]) {
24         //Whatever it is, full is more powerful than selection
25         $options["selector"] = null;
26       }
27     } else {
28       if (!isset($options["full"]) && isset($options["selector"])) {
29         $options["full"] = false;
30       }
31     }
32     return $options;
33   }
34
35   /**
36    * Renders a page or selection to a file given by path
37    * @param string $path
38    * @param array  $options
39    * @return mixed
40    */
41   public function render($path, $options = array()) {
42     $fixedOptions = $this->checkRenderOptions($options);
43     return $this->command('render', $path, $fixedOptions["full"], $fixedOptions["selector"]);
44   }
45
46   /**
47    * Renders base64 a page or selection to a file given by path
48    * @param string $imageFormat (PNG, GIF, JPEG)
49    * @param array  $options
50    * @return mixed
51    */
52   public function renderBase64($imageFormat, $options = array()) {
53     $fixedOptions = $this->checkRenderOptions($options);
54     return $this->command('render_base64', $imageFormat, $fixedOptions["full"], $fixedOptions["selector"]);
55   }
56
57   /**
58    * Sets the paper size, useful when saving to PDF
59    * @param $paperSize
60    * @return mixed
61    */
62   public function setPaperSize($paperSize) {
63     return $this->command('set_paper_size', $paperSize);
64   }
65 }