aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::TEXT, $aOptions); $this->aData[$sKey] = $oData; return $this; } /** * Add select. * * @param string $sKey * @param array $aOptions * @param mixed $oData * * @return $this */ public function AddSelect(string $sKey, array $aOptions, mixed $oData) : FormFactory { $this->aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::SELECT, $aOptions); $this->aData[$sKey] = $oData; return $this; } /** * @return array{descriptions:array, data:array} */ public function GetFormDescriptionsAndData() : array { // prepare data $aResult = [ 'descriptions' => $this->aDescriptions, 'data' => $this->aData, ]; // append plugin data foreach ($this->GetAllPlugins() as $oPlugin){ $aResult['descriptions'] = array_merge($aResult['descriptions'], $oPlugin->GetFormDescriptions()); $aResult['data'] = array_merge($aResult['data'], $oPlugin->GetFormData()); } return $aResult; } /** * Create an object plugin. * * @param \DBObject $oDBObject * @param bool $bGroup * * @return \Combodo\iTop\FormSDK\Service\FactoryPlugin\FormFactoryObjectPlugin */ public function CreateObjectPlugin(DBObject $oDBObject, bool $bGroup = true) : FormFactoryObjectPlugin { $oObjectBuilder = new FormFactoryObjectPlugin($oDBObject, $bGroup); $this->AddPlugin(get_class($oDBObject) . '_' . $oDBObject->GetKey(), $oObjectBuilder); return $oObjectBuilder; } /** * Add a plugin. * * @param string $sKey * @param \Combodo\iTop\FormSDK\Service\FactoryPlugin\FormFactoryPluginInterface $oPlugin * * @return $this */ public function AddPlugin(string $sKey, FormFactoryPluginInterface $oPlugin) : FormFactory { $this->aPlugins[$sKey] = $oPlugin; return $this; } /** * Get all plugins. * * @return \Combodo\iTop\FormSDK\Service\FactoryPlugin\FormFactoryPluginInterface[] */ public function GetAllPlugins() : array { return $this->aPlugins; } /** * Get form. * * @return \Symfony\Component\Form\FormInterface */ public function GetForm(): FormInterface { ['descriptions' => $aDescriptions, 'data' => $aData] = $this->GetFormDescriptionsAndData(); return $this->oSymfonyBridge->GetForm($aDescriptions, $aData); } }