Esempio n. 1
0
 /**
  * Element's can have parameters which point to a specific element ID. We need to update those parameters
  * to use the cloned element's ID
  *
  * @param   array $elementMap
  *
  * @return bool  True if all elements successfully saved
  */
 private function mapElementIdParams($elementMap)
 {
     $return = true;
     $formModel = $this->listModel->getFormModel();
     $pluginManager = FabrikWorker::getPluginManager();
     foreach ($elementMap as $origId => $newId) {
         // The XML Dom object describing the element's plugin properties
         $pluginManifest = $pluginManager->getPluginFromId($newId)->getPluginForm()->getXml();
         // Get all listfield parameters where the value format property is no 'tableelement'
         $listFields = $pluginManifest->xpath('//field[@type=\'listfields\'][(@valueformat=\'tableelement\') != true()]');
         $paramNames = array();
         foreach ($listFields as $listField) {
             if ((string) $listField->attributes()->valueformat !== '') {
                 $paramNames[] = (string) $listField->attributes()->name;
             }
         }
         if (!empty($paramNames)) {
             $elementModel = $formModel->getElement($newId, true);
             $element = $elementModel->getElement();
             $elementParams = new Registry($element->params);
             foreach ($paramNames as $paramName) {
                 $orig = $elementParams->get($paramName, null);
                 if (!is_null($orig)) {
                     $elementParams->set($paramName, $elementMap[$orig]);
                 }
             }
             $element->set('params', (string) $elementParams);
             $return = $return && $element->store();
         }
     }
     return $return;
 }