diff --git a/src/ModalPage.php b/src/ModalPage.php index f488e06..8118325 100644 --- a/src/ModalPage.php +++ b/src/ModalPage.php @@ -301,4 +301,116 @@ class ModalPage { return $query->execute(); } + /** + * Import Modal Config to Entity. + */ + public function importModalConfigToEntity() { + + $language = $this->languageManager->getCurrentLanguage()->getId(); + + $config = $this->configFactory->get('modal_page.settings'); + + $modals = $config->get('modals'); + + $modals_by_parameter = $config->get('modals_by_parameter'); + + $allow_tags = $this->getAllowTags(); + + if (empty($modals) && empty($modals_by_parameter)) { + return FALSE; + } + + if (!empty($modals)) { + + $modals_settings = explode(PHP_EOL, $modals); + + foreach ($modals_settings as $modal_settings) { + + $modal = explode('|', $modal_settings); + + $path = $modal[0]; + + if ($path != '') { + $path = Xss::filter($modal[0]); + } + + $path = trim($path); + $path = ltrim($path, '/'); + + $title = Xss::filter($modal[1], $allow_tags); + $title = trim($title); + + $text = Xss::filter($modal[2], $allow_tags); + $text = trim($text); + + $button = Xss::filter($modal[3]); + $button = trim($button); + + $uuid = $this->uuidService->generate(); + + $modal = [ + 'uuid' => $uuid, + 'title' => $title, + 'body' => $text, + 'type' => 'page', + 'pages' => $path, + 'ok_label_button' => $button, + 'langcode' => $language, + 'created' => time(), + 'changed' => time(), + ]; + + $query = $this->database->insert('modal'); + $query->fields($modal); + $query->execute(); + } + } + + if (!empty($modals_by_parameter)) { + + $modals_settings = explode(PHP_EOL, $modals_by_parameter); + + foreach ($modals_settings as $modal_settings) { + + $modal = explode('|', $modal_settings); + + $parameter_settings = Xss::filter($modal[0]); + + $parameter = trim($parameter_settings); + + $parameter_data = explode('=', $parameter); + + $parameter_value = $parameter_data[1]; + + $title = Xss::filter($modal[1], $allow_tags); + $title = trim($title); + + $text = Xss::filter($modal[2], $allow_tags); + $text = trim($text); + + $button = Xss::filter($modal[3]); + $button = trim($button); + + $uuid = $this->uuidService->generate(); + + $modal = [ + 'uuid' => $uuid, + 'title' => $title, + 'body' => $text, + 'type' => 'parameter', + 'parameters' => $parameter_value, + 'ok_label_button' => $button, + 'langcode' => $language, + 'created' => time(), + 'changed' => time(), + ]; + + $query = $this->database->insert('modal'); + $query->fields($modal); + $query->execute(); + + } + } + } + }