public function ModalPageService::importModalConfigToEntity in Modal 4.0.x
Same name and namespace in other branches
- 5.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::importModalConfigToEntity()
- 4.1.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::importModalConfigToEntity()
Import Modal Config to Entity.
File
- src/
Service/ ModalPageService.php, line 461
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
public function importModalConfigToEntity() {
$language = $this->languageManager
->getCurrentLanguage()
->getId();
$config = $this->configFactory
->get('modal_page.settings');
$modals = $config
->get('modals');
$modalsByParameter = $config
->get('modals_by_parameter');
$allowTags = $this
->getAllowTags();
if (empty($modals) && empty($modalsByParameter)) {
return FALSE;
}
if (!empty($modals)) {
$modalsSettings = explode(PHP_EOL, $modals);
foreach ($modalsSettings as $modal_settings) {
$modal = explode('|', $modal_settings);
$path = $modal[0];
if ($path != '<front>') {
$path = Xss::filter($modal[0]);
}
$path = trim($path);
$path = ltrim($path, '/');
$title = Xss::filter($modal[1], $allowTags);
$title = trim($title);
$text = Xss::filter($modal[2], $allowTags);
$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($modalsByParameter)) {
$modalsSettings = explode(PHP_EOL, $modalsByParameter);
foreach ($modalsSettings 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], $allowTags);
$title = trim($title);
$text = Xss::filter($modal[2], $allowTags);
$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();
}
}
}