* @package tao */ class tao_actions_form_Export extends tao_helpers_form_FormContainer { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * @var array */ private $exportHandlers; /** * @var tao_helpers_form_Form */ private $subForm; // --- OPERATIONS --- public function __construct($exportHandlers, $subForm, $data) { $this->exportHandlers = $exportHandlers; $this->subForm = $subForm; parent::__construct($data); } public function setInfoBox(string $msg): void { $infoElement = tao_helpers_form_FormFactory::getElement('infoBox', 'Free'); $infoElement->setValue($msg); $this->form->addElement($infoElement); } /** * Short description of method initForm * * @access public * @author Joel Bout, * @return mixed */ public function initForm() { $this->form = new tao_helpers_form_xhtml_Form('exportChooser'); $this->form->setDecorators([ 'element' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div']), 'group' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-group']), 'error' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-error ui-state-error ui-corner-all']), 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']), //'actions-top' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')) ]); $exportElt = tao_helpers_form_FormFactory::getElement('export', 'Free'); $exportElt->setValue('' . __('Export') . ''); $this->form->setActions([$exportElt], 'bottom'); } /** * Short description of method initElements * * @access public * @return mixed * @throws common_Exception * @author Joel Bout, */ public function initElements() { if (count($this->exportHandlers) > 1) { //create the element to select the import format $formatElt = tao_helpers_form_FormFactory::getElement('exportHandler', 'Radiobox'); $formatElt->setDescription(__('Choose export format')); //mandatory field $formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $formatElt->setOptions($this->getFormats()); if (isset($_POST['exportHandler'])) { if (array_key_exists($_POST['exportHandler'], $this->getFormats())) { $formatElt->setValue($_POST['exportHandler']); } } $this->form->addElement($formatElt); $this->form->createGroup('formats', '

' . __('Supported export formats') . '

', ['exportHandler']); } if (isset($this->data['instance'])) { $item = $this->data['instance']; if ($item instanceof core_kernel_classes_Resource) { //add an hidden elt for the instance Uri $uriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden'); $uriElt->setValue($item->getUri()); $this->form->addElement($uriElt); } } if (isset($this->data['class'])) { $class = $this->data['class']; if ($class instanceof core_kernel_classes_Class) { //add an hidden elt for the class uri $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); $classUriElt->setValue($class->getUri()); $this->form->addElement($classUriElt); } } $idElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden'); $this->form->addElement($idElt); foreach ($this->subForm->getElements() as $element) { $this->form->addElement($element); } foreach ($this->subForm->getGroups() as $group) { $this->form->createGroup($group['title'], $group['title'], $group['elements'], $group['options']); } } private function getFormats() { $returnValue = []; foreach ($this->exportHandlers as $exportHandler) { $returnValue[get_class($exportHandler)] = $exportHandler->getLabel(); } return $returnValue; } }