class SchedulerRulesActionBase in Scheduler 2.x
Provides base class on which all Scheduler Rules actions are built.
Hierarchy
- class \Drupal\scheduler_rules_integration\Plugin\RulesAction\SchedulerRulesActionBase extends \Drupal\rules\Core\RulesActionBase
Expanded class hierarchy of SchedulerRulesActionBase
File
- scheduler_rules_integration/
src/ Plugin/ RulesAction/ SchedulerRulesActionBase.php, line 13
Namespace
Drupal\scheduler_rules_integration\Plugin\RulesActionView source
class SchedulerRulesActionBase extends RulesActionBase {
/**
* The entity type id.
*
* @var string
*/
protected $entityTypeId;
/**
* Constructs a SchedulerRulesActionBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeId = $plugin_definition['entity_type_id'];
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* Gives a warning when an entity is not enabled for Scheduler.
*
* This is called from actions that attempt to set or remove a Scheduler date
* value when the entity type is not enabled for that process.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object being processed by the action.
* @param string $process
* The process that is not enabled, either 'publish' or 'unpublish'.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SchedulerRulesActionBase:: |
protected | property | The entity type id. | |
SchedulerRulesActionBase:: |
public static | function | ||
SchedulerRulesActionBase:: |
public | function | Gives a warning when an entity is not enabled for Scheduler. | |
SchedulerRulesActionBase:: |
public | function | Constructs a SchedulerRulesActionBase object. |