ContentSyncDialogHelper.php in Content Synchronization 8.2
File
src/Utility/ContentSyncDialogHelper.php
View source
<?php
namespace Drupal\content_sync\Utility;
use Drupal\Component\Serialization\Json;
use Drupal\imce\Imce;
class ContentSyncDialogHelper {
protected static $offCanvasTriggerName;
public static function getOffCanvasTriggerName() {
if (isset(self::$offCanvasTriggerName)) {
return self::$offCanvasTriggerName;
}
$main_content_renderers = \Drupal::getContainer()
->getParameter('main_content_renderers');
if (isset($main_content_renderers['drupal_dialog_offcanvas'])) {
self::$offCanvasTriggerName = 'offcanvas';
}
else {
self::$offCanvasTriggerName = 'off_canvas';
}
return self::$offCanvasTriggerName;
}
public static function useOffCanvas() {
return floatval(\Drupal::VERSION) >= 8.300000000000001 && \Drupal::moduleHandler()
->moduleExists('outside_in') && !\Drupal::config('content_sync.settings')
->get('ui.offcanvas_disabled') ? TRUE : FALSE;
}
public static function attachLibraries(array &$build) {
$build['#attached']['library'][] = 'content_sync/content_sync.admin.dialog';
if (\Drupal::moduleHandler()
->moduleExists('imce') && Imce::access()) {
$element['#attached']['library'][] = 'imce/drupal.imce.ckeditor';
$element['#attached']['drupalSettings']['content_sync']['html_editor']['ImceImageIcon'] = file_create_url(drupal_get_path('module', 'imce') . '/js/plugins/ckeditor/icons/imceimage.png');
}
}
public static function getModalDialogAttributes($width = 800, array $class = []) {
if (\Drupal::config('content_sync.settings')
->get('ui.dialog_disabled')) {
return $class ? [
'class' => $class,
] : [];
}
else {
$class[] = 'use-ajax';
if (self::useOffCanvas()) {
return [
'class' => $class,
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => self::getOffCanvasTriggerName(),
'data-dialog-options' => Json::encode([
'width' => $width > 480 ? 480 : $width,
]),
];
}
else {
return [
'class' => $class,
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => $width,
]),
];
}
}
}
}