| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\FormDataProviderInterface;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper;
- /**
- * Form DataProvider related functions
- *
- * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
- */
- trait FormDataProvider
- {
-
- /**
- * Providing save and load data functionalities for Forms
- * @var \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\FormDataProviderInterface
- */
- protected $dataProvider = null;
- protected $providerClass = '';
- public function loadProvider()
- {
- if ($this->providerClass != '' && !is_object($this->dataProvider))
- {
- $this->setProvider(Helper\di($this->providerClass));
- }
-
- return $this;
- }
- /**
- * Sets data provider for Form
- * @return $this
- */
- public function setProvider(FormDataProviderInterface $provider)
- {
- $this->dataProvider = $provider;
- if (method_exists($this, 'getFormType'))
- {
- $this->dataProvider->setParentFormType($this->getFormType());
- }
-
- return $this;
- }
-
- public function getFormData()
- {
- if($this->dataProvider === null)
- {
- $this->loadProvider();
- }
- return $this->dataProvider->getData();
- }
- }
|