Update360.php in Lightning Media 8.3
File
src/Update/Update360.php
View source
<?php
namespace Drupal\lightning_media\Update;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\lightning_roles\ContentRoleManager;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Update360 implements ContainerInjectionInterface {
use StringTranslationTrait;
private $entityBrowserStorage;
private $embedButtonStorage;
private $contentRoleManager;
public function __construct(EntityStorageInterface $entity_browser_storage, EntityStorageInterface $embed_button_storage, TranslationInterface $translation = NULL, ContentRoleManager $content_role_manager = NULL) {
$this->entityBrowserStorage = $entity_browser_storage;
$this->embedButtonStorage = $embed_button_storage;
if ($translation) {
$this
->setStringTranslation($translation);
}
$this->contentRoleManager = $content_role_manager;
}
public static function create(ContainerInterface $container) {
$entity_type_manager = $container
->get('entity_type.manager');
$arguments = [
$entity_type_manager
->getStorage('entity_browser'),
$entity_type_manager
->getStorage('embed_button'),
$container
->get('string_translation'),
];
if ($container
->has('lightning.content_roles')) {
$arguments[] = $container
->get('lightning.content_roles');
}
return (new \ReflectionClass(static::class))
->newInstanceArgs($arguments);
}
public function cloneMediaBrowser(StyleInterface $io) {
$button = $this->embedButtonStorage
->load('media_browser');
$browser = $this->entityBrowserStorage
->load('media_browser');
if (empty($button) || empty($browser)) {
return;
}
if ($browser
->getDisplay()
->getPluginId() !== 'iframe') {
return;
}
if ($button
->getTypePlugin()
->getConfigurationValue('entity_browser') !== $browser
->id()) {
return;
}
$variables = [
'@browser' => $browser
->label(),
];
$question = (string) $this
->t('Do you want to display the @browser entity browser in a modal dialog? This will create a duplicate of the entity browser, specifically for use by CKEditor.', $variables);
if ($io
->confirm($question) === FALSE) {
return;
}
$clone_id = $io
->ask((string) $this
->t('Enter the machine name of the CKEditor-only duplicate.'), 'ckeditor_media_browser');
$clone_label = $io
->ask((string) $this
->t('Enter the label of the CKEditor-only duplicate.'), (string) $this
->t('@browser (CKEditor)', $variables));
$clone = $browser
->createDuplicate()
->setName($clone_id)
->setLabel($clone_label);
$this->entityBrowserStorage
->save($clone);
$permissions = [
"access {$clone_id} entity browser pages",
];
user_role_grant_permissions('media_creator', $permissions);
user_role_grant_permissions('media_manager', $permissions);
if ($this->contentRoleManager) {
$this->contentRoleManager
->grantPermissions('creator', $permissions);
}
$settings = [
'entity_browser' => $clone
->id(),
];
$button
->set('type_settings', $settings + $button
->getTypeSettings());
$this->embedButtonStorage
->save($button);
$browser
->setDisplay('modal')
->getDisplay()
->setConfiguration([
'width' => '',
'height' => '',
'link_text' => (string) $this
->t('Add media'),
'auto_open' => FALSE,
]);
$this->entityBrowserStorage
->save($browser);
}
}
Classes
Name |
Description |
Update360 |
Contains optional updates targeting Lightning Media 3.6.0. |