EditorConfigTranslationSubscriber.php in Drupal 10
File
core/modules/editor/src/EventSubscriber/EditorConfigTranslationSubscriber.php
View source
<?php
namespace Drupal\editor\EventSubscriber;
use Drupal\config_translation\ConfigEntityMapper;
use Drupal\config_translation\Event\ConfigMapperPopulateEvent;
use Drupal\config_translation\Event\ConfigTranslationEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
class EditorConfigTranslationSubscriber implements EventSubscriberInterface {
protected $configFactory;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public static function getSubscribedEvents() : array {
$events = [];
if (class_exists('Drupal\\config_translation\\Event\\ConfigTranslationEvents')) {
$events[ConfigTranslationEvents::POPULATE_MAPPER][] = [
'addConfigNames',
];
}
return $events;
}
public function addConfigNames(ConfigMapperPopulateEvent $event) {
$mapper = $event
->getMapper();
if ($mapper instanceof ConfigEntityMapper && $mapper
->getType() == 'filter_format') {
$editor_config_name = 'editor.editor.' . $mapper
->getEntity()
->id();
if (!$this->configFactory
->get($editor_config_name)
->isNew()) {
$mapper
->addConfigName($editor_config_name);
}
}
}
}