View source
<?php
namespace Drupal\scheduler_rules_integration\Plugin\RulesAction;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\rules\Core\RulesActionBase;
class SchedulerRulesActionBase extends RulesActionBase {
protected $entityTypeId;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeId = $plugin_definition['entity_type_id'];
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function notEnabledWarning(EntityInterface $entity, string $process) {
$action = $this
->summary();
$activity = $process == 'publish' ? $this
->t('scheduled publishing') : $this
->t('scheduled unpublishing');
$condition = $this
->t('@bundle_label is enabled for @activity', [
'@bundle_label' => $entity
->getEntityType()
->getBundleLabel(),
'@activity' => $activity,
]);
$bundle_field = $entity
->getEntityType()
->get('entity_keys')['bundle'];
$type_name = $entity->{$bundle_field}->entity
->label();
$type_id = $entity->{$bundle_field}->entity
->bundle();
$url = new Url("entity.{$type_id}.edit_form", [
$type_id => $entity
->bundle(),
]);
$arguments = [
'%action' => "'{$action}'",
'@activity' => $activity,
'%type' => $type_name,
'@group' => $entity
->getEntityType()
->getPluralLabel(),
'%condition' => "'{$condition}'",
'@url' => $url
->toString(),
];
$link = Link::fromTextAndUrl($this
->t('@type settings', [
'@type' => $type_name,
]), $url)
->toString();
\Drupal::logger('scheduler')
->warning('Action %action is not valid because @activity is not enabled for %type @group. Add the condition %condition to your Reaction Rule, or enable @activity via the %type settings.', $arguments + [
'link' => $link,
]);
\Drupal::messenger()
->addMessage($this
->t('Action %action is not valid because @activity is not enabled for %type @group. Add the condition %condition to your Reaction Rule, or enable @activity via the <a href="@url">%type</a> settings.', $arguments), 'warning', FALSE);
}
}