a1561e3e96241a40c3557f083ca6a57b99e065bb
[yaffs-website] / web / modules / contrib / devel / src / Plugin / Devel / Dumper / DrupalVariable.php
1 <?php
2
3 namespace Drupal\devel\Plugin\Devel\Dumper;
4
5 use Drupal\Component\Utility\Variable;
6 use Drupal\Component\Utility\Xss;
7 use Drupal\devel\DevelDumperBase;
8
9 /**
10  * Provides a DrupalVariable dumper plugin.
11  *
12  * @DevelDumper(
13  *   id = "drupal_variable",
14  *   label = @Translation("Drupal variable."),
15  *   description = @Translation("Wrapper for <a href='https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Utility%21Variable.php/class/Variable/8'>Drupal Variable</a> class.")
16  * )
17  */
18 class DrupalVariable extends DevelDumperBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function export($input, $name = NULL) {
24     $name = $name ? $name . ' => ' : '';
25     $dump = Variable::export($input);
26     // Run Xss::filterAdmin on the resulting string to prevent
27     // cross-site-scripting (XSS) vulnerabilities.
28     $dump = Xss::filterAdmin($dump);
29     $dump = '<pre>' . $name . $dump . '</pre>';
30     return $this->setSafeMarkup($dump);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function exportAsRenderable($input, $name = NULL) {
37     $output['container'] = [
38       '#type' => 'details',
39       '#title' => $name ? : $this->t('Variable'),
40       '#attached' => [
41         'library' => ['devel/devel']
42       ],
43       '#attributes' => [
44         'class' => ['container-inline', 'devel-dumper', 'devel-selectable'],
45       ],
46       'export' => [
47         '#markup' => $this->export($input),
48       ],
49     ];
50
51     return $output;
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public static function checkRequirements() {
58     return TRUE;
59   }
60
61 }