/** * Custom logic code here for setting placeholders, etc * @param array $scriptProperties * @return mixed */ public function process(array $scriptProperties = array()) { $placeholders = array(); /* load snippet */ if (empty($scriptProperties['id']) || strlen($scriptProperties['id']) !== strlen((int) $scriptProperties['id'])) { return $this->failure($this->modx->lexicon('snippet_err_ns')); } $this->snippet = $this->modx->getObject('modSnippet', array('id' => $scriptProperties['id'])); if ($this->snippet == null) { return $this->failure($this->modx->lexicon('snippet_err_nf')); } if (!$this->snippet->checkPolicy('view')) { return $this->failure($this->modx->lexicon('access_denied')); } /* get properties */ $properties = $this->snippet->get('properties'); if (!is_array($properties)) { $properties = array(); } $data = array(); foreach ($properties as $property) { $data[] = array($property['name'], $property['desc'], !empty($property['type']) ? $property['type'] : 'textfield', !empty($property['options']) ? $property['options'] : array(), $property['value'], !empty($property['lexicon']) ? $property['lexicon'] : '', false, $property['desc_trans'], !empty($property['area']) ? $property['area'] : '', !empty($property['area_trans']) ? $property['area_trans'] : ''); } $this->snippetArray = $this->snippet->toArray(); $this->snippetArray['properties'] = $data; $this->snippetArray['snippet'] = $this->snippet->getContent(); if (strpos($this->snippetArray['snippet'], '<?php') === false) { $this->snippetArray['snippet'] = "<?php\n" . $this->snippetArray['snippet']; } $this->prepareElement(); /* load snippet into parser */ $placeholders['snippet'] = $this->snippet; /* invoke OnSnipFormRender event */ $placeholders['onSnipFormRender'] = $this->fireRenderEvent(); return $placeholders; }
/** * @return void */ public function testGetContent() { $this->assertEquals($this->snippet->get('snippet'), $this->snippet->getContent()); }