$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); } /** * Add text field. * * @param string $sKey * @param array $aOptions * @param mixed $oData * * @return $this */ public function AddTextField(string $sKey, array $aOptions, mixed $oData = null) : FormFactory { $this->aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::TEXT, $aOptions); $this->aData[$sKey] = $oData; return $this; } /** * Add select field. * * @param string $sKey * @param array $aOptions * @param mixed $oData * * @return $this */ public function AddSelectField(string $sKey, array $aOptions, mixed $oData = null) : FormFactory { $this->aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::SELECT, $aOptions); $this->aData[$sKey] = $oData; return $this; } /** * Add dynamic ajax select field. * * @param string $sKey * @param array $aOptions * @param string $sAjaxUrl * @param array $aAjaxData * @param string $sValueField * @param string $sLabelField * @param string $sSearchField * @param int $iAjaxThershold * @param mixed $oData * * @return \Combodo\iTop\FormSDK\Service\FormFactory */ public function AddSelectAjaxField(string $sKey, array $aOptions, string $sAjaxUrl, array $aAjaxData, string $sValueField, string $sLabelField, string $sSearchField, int $iAjaxThershold, mixed $oData = null) : FormFactory { // ajax loader options $aAjaxLoaderOptions = [ 'ajax_url' => $sAjaxUrl, 'valueField' => $sValueField ? $sValueField : 'value', 'labelField' => $sLabelField ? $sLabelField : 'label', 'searchField' => $sSearchField ? $sSearchField : 'search', 'preload' => false, ]; // merge options $aOptions = array_merge([ 'placeholder' => 'Select a value...', 'attr' => [ 'data-widget' => 'SelectWidget', 'data-widget-options' => json_encode($aAjaxLoaderOptions) ], 'choice_loader' => new CallbackChoiceLoader(function() use ($sAjaxUrl, $aAjaxData, $iAjaxThershold): array { $curl_data = utils::DoPostRequest($sAjaxUrl, []); $response_data = json_decode($curl_data); if(count($response_data->items) > $iAjaxThershold) return []; $result = []; foreach ($response_data->items as $e) { $result[$e->breed] = $e->breed; } return $result; }), ], $aOptions); return $this->AddSelectField($sKey, $aOptions, $oData); } /** * Add dynamic OQL select field. * * @param string $sKey * @param array $aOptions * @param string $sObjectClass * @param string $sOql * @param array $aFieldsToLoad * @param string $sSearch * @param int $iAjaxThershold * @param mixed $oData * * @return \Combodo\iTop\FormSDK\Service\FormFactory */ public function AddSelectOqlField(string $sKey, array $aOptions, string $sObjectClass, string $sOql, array $aFieldsToLoad, string $sSearch, int $iAjaxThershold, mixed $oData = null) : FormFactory { // $sFieldsToLoad = implode($aFieldsToLoad); $aData = [ 'class' => $sObjectClass, 'oql' => $sOql, 'fields' => json_encode($aFieldsToLoad), 'search' => $sSearch ]; $sUrl = 'http://localhost' . $this->oRouter->generate('formSDK_object_search') . '?' . http_build_query($aData); return $this->AddSelectAjaxField($sKey, $aOptions, $sUrl, $aData, 'id', 'friendlyname', 'friendlyname', $iAjaxThershold, $oData); } }