forked from wallabag/wallabag
Add display article configurator (font family, font size, line height and max width)
This commit is contained in:
26
src/Wallabag/CoreBundle/Event/ConfigUpdatedEvent.php
Normal file
26
src/Wallabag/CoreBundle/Event/ConfigUpdatedEvent.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Event;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
use Wallabag\CoreBundle\Entity\Config;
|
||||
|
||||
/**
|
||||
* This event is fired as soon as user configuration is updated.
|
||||
*/
|
||||
class ConfigUpdatedEvent extends Event
|
||||
{
|
||||
public const NAME = 'config.updated';
|
||||
|
||||
protected $config;
|
||||
|
||||
public function __construct(Config $entry)
|
||||
{
|
||||
$this->config = $entry;
|
||||
}
|
||||
|
||||
public function getConfig(): Config
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Event\Subscriber;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use ScssPhp\ScssPhp\Compiler;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Wallabag\CoreBundle\Event\ConfigUpdatedEvent;
|
||||
|
||||
class GenerateCustomCSSSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $em;
|
||||
private $compiler;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, Compiler $compiler)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->compiler = $compiler;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
ConfigUpdatedEvent::NAME => 'onConfigUpdated',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate custom CSS.
|
||||
*/
|
||||
public function onConfigUpdated(ConfigUpdatedEvent $event)
|
||||
{
|
||||
$config = $event->getConfig();
|
||||
|
||||
$css = $this->compiler->compileString(
|
||||
'h1 { font-family: "' . $config->getFont() . '";}
|
||||
#article {
|
||||
max-width: ' . $config->getMaxWidth() . 'em;
|
||||
font-family: "' . $config->getFont() . '";
|
||||
}
|
||||
#article article {
|
||||
font-size: ' . $config->getFontsize() . 'em;
|
||||
line-height: ' . $config->getLineHeight() . 'em;
|
||||
}
|
||||
;
|
||||
')->getCss();
|
||||
|
||||
$config->setCustomCSS($css);
|
||||
|
||||
$this->em->persist($config);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user