JanrainMarkupBuilder.php in Janrain Registration 8
File
src/JanrainMarkupBuilder.php
View source
<?php
namespace Drupal\janrain_capture;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
class JanrainMarkupBuilder {
protected $screenLoaderManager;
protected $janrainCaptureSettings;
public function __construct(ConfigFactoryInterface $config_factory, ScreenLoaderManager $screen_loader_manager) {
$this->janrainCaptureSettings = $config_factory
->get('janrain_capture.settings');
$this->screenLoaderManager = $screen_loader_manager;
}
public function getPageAttachment() : array {
global $base_url, $base_path;
$settings = $this->janrainCaptureSettings
->get();
unset($settings['capture']['client_secret']);
foreach ([
'redirect_uri' => 'janrain_capture.oauth',
'federate_logout_uri' => 'janrain_capture.simple_logout',
] as $setting => $route) {
$settings['capture'][$setting] = Url::fromRoute($route)
->setAbsolute()
->toString();
}
$settings['capture']['federate_xd_reciever'] = $base_url . $base_path . drupal_get_path('module', 'janrain_capture') . '/xdcomm.html';
$settings['capture']['stylesheets'][] = file_create_url(drupal_get_path('module', 'janrain_capture') . '/janrain-capture-screens/stylesheets/janrain.css');
if (isset($settings['screens']['folder'])) {
$settings['capture']['stylesheets'][] = file_create_url($settings['screens']['folder'] . '/stylesheets/janrain.css');
}
if (isset($settings['capture']['federate_supported_segments'])) {
$settings['capture']['federate_supported_segments'] = json_encode(explode(',', $settings['capture']['federate_supported_segments']));
}
return [
'library' => [
'janrain_capture/janrain_init',
],
'drupalSettings' => [
'janrain' => $settings,
'acquia_env' => $_ENV['AH_SITE_ENVIRONMENT'] ?? 'local',
],
];
}
public function getScreenRenderArray(string $name) : array {
$build = [];
$build["{$name}_screen_html"] = [
'#markup' => '',
'#children' => $this->screenLoaderManager
->getScreen($name, 'html'),
];
$build["{$name}_screen_js"] = [
'#tag' => 'script',
'#type' => 'html_tag',
'#value' => Markup::create($this->screenLoaderManager
->getScreen($name, 'js')),
];
return $build;
}
}