0
こんにちはすべてDrupal 8 EventSubscriberクラスはdrupalSettingsをDrupal 8 JavaScript設定に添付することになっていました。しかし、残念ながら、この\ Drupal :: service( 'renderer') - > renderRoot($ js_data); drupalのjavascript設定を添付していません。Drupal 8 #attachedはeventsubscriber内で動作しません
namespace Drupal\ejectorseat\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Drupal\Core\Url;
class EjectorseatSubscriber implements EventSubscriberInterface {
public function customEjector(GetResponseEvent $event) {
$account = \Drupal::currentUser();
$ejectorseat_interval = \Drupal::config('ejectorseat.settings')->get('ejectorseat_interval');
if(empty($ejectorseat_interval)){
$ejectorseat_interval = 60;
}
$ejectorseat_background = \Drupal::config('ejectorseat.settings')->get('ejectorseat_background');
if(empty($ejectorseat_background)){
$ejectorseat_background = 0;
}
if ($account->id() > 0 && (int) $ejectorseat_interval) {
$js_data = array();
$js_data['#attached']['drupalSettings']['ejectorSeat']['interval'] = $ejectorseat_interval;
$js_data['#attached']['drupalSettings']['ejectorSeat']['url'] = Url::fromRoute('ejectorseat/check');
$js_data['#attached']['drupalSettings']['ejectorSeat']['ignoreFocus'] = $ejectorseat_background ? TRUE : FALSE;
\Drupal::service('renderer')->renderRoot($js_data);
}
}
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('customEjector');
return $events;
}
}