diff --git a/plugin/EstateList.php b/plugin/EstateList.php index 1d224ba5c..2923e3851 100644 --- a/plugin/EstateList.php +++ b/plugin/EstateList.php @@ -251,6 +251,33 @@ private function filterActiveInputFields($inputs): DataView $inputs->setFields($activeInputs); return $inputs; } + + /** + * @param $inputs + * @return DataView + * + */ + + private function filterActiveInputFilterableFields($inputs): DataView + { + $activeInputs = []; + $recordType = onOfficeSDK::MODULE_ESTATE; + $pFieldsCollection = new FieldsCollection(); + $pFieldBuilderShort = $this->_pEnvironment->getContainer()->get(FieldsCollectionBuilderShort::class); + $pFieldBuilderShort + ->addFieldsAddressEstate($pFieldsCollection) + ->addFieldsAddressEstateWithRegionValues($pFieldsCollection) + ->addFieldsEstateGeoPosisionBackend($pFieldsCollection); + + foreach ($inputs->getFilterableFields() as $name) { + if ($pFieldsCollection->containsFieldByModule($recordType, $name)) { + $activeInputs[] = $name; + } + } + $inputs->setFilterableFields($activeInputs); + return $inputs; + } + /** * @param array $estateIds * @throws DependencyException @@ -766,17 +793,18 @@ public function getVisibleFilterableFields(): array $pFieldsCollectionFieldDuplicatorForGeoEstate = $pContainer->get(FieldsCollectionFieldDuplicatorForGeoEstate::class); $pFieldsCollectionFieldDuplicatorForGeoEstate->duplicateFields($pFieldsCollection); + $pDataView = $this->filterActiveInputFilterableFields($this->_pDataView); /** @var DistinctFieldsHandler $pDistinctFieldsHandler */ $pDistinctFieldsHandler = $pContainer->get(DistinctFieldsHandler::class); - $pFieldsCollection = $pDistinctFieldsHandler->modifyFieldsCollectionForEstate($this->_pDataView, $pFieldsCollection); + $pFieldsCollection = $pDistinctFieldsHandler->modifyFieldsCollectionForEstate($pDataView, $pFieldsCollection); $fieldsValues = $pContainer->get(OutputFields::class) - ->getVisibleFilterableFields($this->_pDataView, + ->getVisibleFilterableFields($pDataView, $pFieldsCollection, new GeoPositionFieldHandler); if (array_key_exists("radius",$fieldsValues)) { - $geoFields = $this->_pDataView->getGeoFields(); + $geoFields = $pDataView->getGeoFields(); $fieldsValues["radius"] = !empty($geoFields['radius']) ? $geoFields['radius'] : NULL; } $result = []; diff --git a/plugin/FormPost.php b/plugin/FormPost.php index 7cef8f856..0b9576c21 100644 --- a/plugin/FormPost.php +++ b/plugin/FormPost.php @@ -30,6 +30,7 @@ use onOffice\WPlugin\Field\Collection\FieldsCollectionConfiguratorForm; use onOffice\WPlugin\Field\CompoundFieldsFilter; use onOffice\WPlugin\Field\SearchcriteriaFields; +use onOffice\WPlugin\Field\UnknownFieldException; use onOffice\WPlugin\Form\CaptchaHandler; use onOffice\WPlugin\Form\FormFieldValidator; use onOffice\WPlugin\Form\FormPostConfiguration; @@ -216,6 +217,7 @@ private function buildFormData(DataFormConfiguration $pFormConfig, $formNo): For $formFields = $this->getAllowedPostVars($pFormConfig); $formData = $pFormFieldValidator->getValidatedValues($formFields, $this->_pFieldsCollection); + $requiredFields = $this->getAllowedRequiredFields($requiredFields); $pFormData = new FormData($pFormConfig, $formNo); $pFormData->setRequiredFields($requiredFields); $pFormData->setFormtype($pFormConfig->getFormType()); @@ -233,6 +235,41 @@ protected function getFieldsCollection(): FieldsCollection return $this->_pFieldsCollection; } + /** + * + * @param string $name + * @return string + */ + + private function getModule(string $name): string + { + try { + return $this->_pFieldsCollection->getFieldByKeyUnsafe($name)->getModule(); + } catch (UnknownFieldException $pEx) { + return ''; + } + } + + /** + * + * @param $requiredFields + * @return string[] + * + */ + + protected function getAllowedRequiredFields($requiredFields): array + { + $activeRequiredFields = []; + + foreach ($requiredFields as $name) { + $module = $this->getModule($name); + if ($this->_pFieldsCollection->containsFieldByModule($module, $name)) { + $activeRequiredFields[] = $name; + } + } + return $activeRequiredFields; + } + /** * diff --git a/plugin/Gui/AdminPageEstateListSettingsBase.php b/plugin/Gui/AdminPageEstateListSettingsBase.php index bb10d7b83..59116938e 100644 --- a/plugin/Gui/AdminPageEstateListSettingsBase.php +++ b/plugin/Gui/AdminPageEstateListSettingsBase.php @@ -260,6 +260,12 @@ private function saveCustomLabels(int $recordId, array $row ,string $pCustomsLab $fieldNamesSelected = array_column($fields, 'fieldname'); $pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentEstate(); + foreach ($fieldNamesSelected as $key => $name) { + if (!$pFieldsCollectionBase->containsFieldByModule(onOfficeSDK::MODULE_ESTATE, $name)) { + unset($fieldNamesSelected[$key]); + unset($row['oo_plugin_fieldconfig_estate_translated_labels'][$name]); + } + } /** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */ $pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class); $pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection diff --git a/plugin/Gui/AdminPageFormSettingsBase.php b/plugin/Gui/AdminPageFormSettingsBase.php index 3a6f87f9f..316528ab1 100644 --- a/plugin/Gui/AdminPageFormSettingsBase.php +++ b/plugin/Gui/AdminPageFormSettingsBase.php @@ -584,6 +584,21 @@ private function addFieldConfigurationByModule( } + /** + * + * @param string $name + * @param FieldsCollection $pFieldsCollection + * @return string + */ + + private function getModule(string $name, FieldsCollection $pFieldsCollection): string + { + try { + return $pFieldsCollection->getFieldByKeyUnsafe($name)->getModule(); + } catch (UnknownFieldException $pEx) { + return ''; + } + } /** * @param int $recordId @@ -600,6 +615,13 @@ private function saveDefaultValues(int $recordId, array $row) $fieldNamesSelected = array_column($fields, 'fieldname'); $pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentForm(); + foreach ($fieldNamesSelected as $key => $name) { + $module = $this->getModule($name, $pFieldsCollectionBase); + if (!$pFieldsCollectionBase->containsFieldByModule($module, $name)) { + unset($fieldNamesSelected[$key]); + unset($row['oo_plugin_fieldconfig_form_defaults_values'][$name]); + } + } /** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */ $pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class); $pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection @@ -631,6 +653,13 @@ private function saveCustomLabels(int $recordId, array $row ,string $pCustomsLab $fieldNamesSelected = array_column($fields, 'fieldname'); $pFieldsCollectionBase = $this->buildFieldsCollectionForCurrentForm(); + foreach ($fieldNamesSelected as $key => $name) { + $module = $this->getModule($name, $pFieldsCollectionBase); + if (!$pFieldsCollectionBase->containsFieldByModule($module, $name)) { + unset($fieldNamesSelected[$key]); + unset($row['oo_plugin_fieldconfig_form_translated_labels'][$name]); + } + } /** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */ $pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class); $pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection diff --git a/plugin/Renderer/InputFieldComplexSortableDetailListRenderer.php b/plugin/Renderer/InputFieldComplexSortableDetailListRenderer.php index 1c4dc89d3..aa3ac5774 100644 --- a/plugin/Renderer/InputFieldComplexSortableDetailListRenderer.php +++ b/plugin/Renderer/InputFieldComplexSortableDetailListRenderer.php @@ -25,6 +25,7 @@ use DI\NotFoundException; use onOffice\SDK\onOfficeSDK; use onOffice\WPlugin\Gui\AdminPageAjax; +use onOffice\WPlugin\Model\InputModelBase; use onOffice\WPlugin\Types\FieldsCollection; use function __; use function esc_attr; @@ -126,6 +127,7 @@ private function generateSelectableElement($key, $label, $category, $label = $inactiveFields[$key] ?? null; $deactivatedStyle = ' style="color:red;" '; $deactivatedInOnOffice = ' ('.__('Disabled in onOffice', 'onoffice-for-wp-websites').')'; + $type = InputModelBase::HTML_TYPE_TEXT; } echo '