1<?php 2/** 3 * Javascript builder used when rendering a repeat prototype 4 * 5 * PHP version 5 6 * 7 * LICENSE 8 * 9 * This source file is subject to BSD 3-Clause License that is bundled 10 * with this package in the file LICENSE and available at the URL 11 * https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE 12 * 13 * @category HTML 14 * @package HTML_QuickForm2 15 * @author Alexey Borzov <avb@php.net> 16 * @author Bertrand Mansion <golgote@mamasam.com> 17 * @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com> 18 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License 19 * @link https://pear.php.net/package/HTML_QuickForm2 20 */ 21 22/** Javascript aggregator and builder class */ 23require_once 'HTML/QuickForm2/JavascriptBuilder.php'; 24 25/** 26 * Javascript builder used when rendering a repeat prototype 27 * 28 * Instead of returning form setup code and client-side rules as normal 29 * Javascript code, it returns them as Javascript string literals. These are 30 * expected to be eval()'d when adding a new repeat item. 31 * 32 * This class is not intended for normal use. 33 * 34 * @category HTML 35 * @package HTML_QuickForm2 36 * @author Alexey Borzov <avb@php.net> 37 * @author Bertrand Mansion <golgote@mamasam.com> 38 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License 39 * @version Release: 2.2.2 40 * @link https://pear.php.net/package/HTML_QuickForm2 41 * @internal 42 */ 43class HTML_QuickForm2_Container_Repeat_JavascriptBuilder 44 extends HTML_QuickForm2_JavascriptBuilder 45{ 46 /** 47 * Fake "current form" ID 48 * @var string 49 */ 50 protected $formId = 'repeat'; 51 52 /** 53 * Empty list of javascript libraries, base one(s) are in original builder 54 * @var array 55 */ 56 protected $libraries = []; 57 58 59 /** 60 * Returns rules and element setup code as Javascript string literals 61 * 62 * @return array array('rules', 'setup code') 63 */ 64 public function getFormJavascriptAsStrings() 65 { 66 return [ 67 self::encode( 68 empty($this->rules['repeat']) 69 ? '' : "[\n" . implode(",\n", $this->rules['repeat']) . "\n]" 70 ), 71 self::encode( 72 empty($this->scripts['repeat']) 73 ? '' : implode("\n", $this->scripts['repeat']) 74 ) 75 ]; 76 } 77 78 /** 79 * Passes Javascript libraries added by repeat prototype 80 * 81 * @param HTML_QuickForm2_JavascriptBuilder $recipient original Javascript builder 82 */ 83 public function passLibraries(HTML_QuickForm2_JavascriptBuilder $recipient) 84 { 85 foreach ($this->libraries as $name => $library) { 86 $recipient->addLibrary( 87 $name, $library['file'], $library['webPath'], $library['absPath'] 88 ); 89 } 90 } 91} 92?>