public function EventDeriver::getDerivativeDefinitions in Scheduler 2.x
Gets the definition of all derivatives of a base plugin.
Parameters
array $base_plugin_definition: The definition array of the base plugin.
Return value
array An array of full derivative definitions keyed on derivative id.
Overrides DeriverBase::getDerivativeDefinitions
See also
getDerivativeDefinition()
File
- scheduler_rules_integration/
src/ Event/ EventDeriver.php, line 73
Class
- EventDeriver
- Derives Rules events for all non-node entities supported by Scheduler.
Namespace
Drupal\scheduler_rules_integration\EventCode
public function getDerivativeDefinitions($base_plugin_definition) {
// Get all entity types supported by Scheduler plugins.
foreach ($this->schedulerManager
->getPluginEntityTypes() as $entity_type_id) {
// Node events are the originals, and for backwards-compatibility those
// event ids must remain unchanged, which cannot be done with the deriver.
// So they remain defined in scheduler_rules_integration.rules.events.yml.
if ($entity_type_id == 'node') {
continue;
}
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
// Define the values that are the same for all events of this entity type.
$defaults = [
'entity_type_id' => $entity_type_id,
'category' => $entity_type
->getLabel() . ' (' . $this
->t('Scheduler') . ')',
'context_definitions' => [
$entity_type_id => [
'type' => "entity:{$entity_type_id}",
'label' => $this
->t('The object representing the scheduled @entity_type', [
'@entity_type' => $entity_type
->getLabel(),
]),
],
],
];
// Create six events for this entity type.
$this->derivatives["new_{$entity_type_id}_is_scheduled_for_publishing"] = [
'label' => $this
->t('After saving a new @entity_type that is scheduled for publishing', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
$this->derivatives["new_{$entity_type_id}_is_scheduled_for_unpublishing"] = [
'label' => $this
->t('After saving a new @entity_type that is scheduled for unpublishing', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
$this->derivatives["existing_{$entity_type_id}_is_scheduled_for_publishing"] = [
'label' => $this
->t('After updating a @entity_type that is scheduled for publishing', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
$this->derivatives["existing_{$entity_type_id}_is_scheduled_for_unpublishing"] = [
'label' => $this
->t('After updating a @entity_type that is scheduled for unpublishing', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
$this->derivatives["{$entity_type_id}_has_been_published_via_cron"] = [
'label' => $this
->t('After Scheduler has published a @entity_type', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
$this->derivatives["{$entity_type_id}_has_been_unpublished_via_cron"] = [
'label' => $this
->t('After Scheduler has unpublished a @entity_type', [
'@entity_type' => $entity_type
->getSingularLabel(),
]),
] + $defaults + $base_plugin_definition;
}
return $this->derivatives;
}