DigestInterval.php in Message Digest 8
File
message_digest_ui/src/Plugin/Action/DigestInterval.php
View source
<?php
namespace Drupal\message_digest_ui\Plugin\Action;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\flag\FlagServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DigestInterval extends ActionBase implements ContainerFactoryPluginInterface {
protected $flagService;
protected $flag;
protected $intervalPluginId;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FlagServiceInterface $flag_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->flagService = $flag_service;
$this->flag = $this->flagService
->getFlagById($configuration['flag_id']);
$this->intervalPluginId = $configuration['value'];
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('flag'));
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = $this->flag
->actionAccess('flag', $account, $object);
return $return_as_object ? $result : $result
->isAllowed();
}
public function execute($entity = NULL) {
$flagging = $this->flagService
->getFlagging($this->flag, $entity);
if (!$flagging) {
$flagging = $this->flagService
->flag($this->flag, $entity);
}
$flagging->message_digest = $this->intervalPluginId;
$flagging
->save();
}
}