Commit ff446afa authored by Dieter Holvoet's avatar Dieter Holvoet Committed by Jonathan Smith
Browse files

Issue #3259200 by jonathan1055, DieterHolvoet: Plugin to support Paragraphs entity type

parent 0b292a76
Loading
Loading
Loading
Loading
+4 −1
Changes for scheduler.api.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -111,9 +111,12 @@ function hook_scheduler_publishing_allowed(EntityInterface $entity) {
    // If the time is in the past it means that the action has been prevented,
    // so write a dblog message to show this.
    if ($entity->publish_on->value <= \Drupal::time()->getRequestTime()) {
      if ($entity->id() && $entity->hasLinkTemplate('canonical')) {
        $link = $entity->toLink(t('View'))->toString();
      }
      \Drupal::logger('scheduler_api_test')->warning('Publishing of "%title" is prevented until approved.', [
        '%title' => $entity->label(),
        'link' => $entity->id() ? $entity->toLink(t('View'))->toString() : '',
        'link' => $link ?? NULL,
      ]);
    }
  }
+7 −0
Changes for scheduler.install: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -217,3 +217,10 @@ function scheduler_update_8204() {
    . '<br>' . implode('<br>', $rules_updated);
  return $output;
}

/**
 * Add date fields to any newly supported entity types, specifically Paragraphs.
 */
function scheduler_update_8205() {
  return scheduler_update_8201();
}
+1 −1
Changes for scheduler.module: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -717,10 +717,10 @@ function scheduler_entity_base_field_info(EntityTypeInterface $entity_type) {
      ->setTranslatable(TRUE)
      ->setRevisionable(TRUE)
      ->addConstraint('SchedulerUnpublishOn');
  }

  return $fields;
}
}

/**
 * Implements hook_action_info_alter().
+96 −0
Changes for src/Event/SchedulerParagraphEvents.php: 96 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\scheduler\Event;

/**
 * Lists the six events dispatched by Scheduler relating to Paragraph entities.
 */
final class SchedulerParagraphEvents {

  /**
   * The event triggered after a paragraph is published immediately.
   *
   * This event allows modules to react after an entity is published
   * immediately when being saved after editing. The event listener method
   * receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const PUBLISH_IMMEDIATELY = 'scheduler.paragraph_publish_immediately';

  /**
   * The event triggered after a paragraph is published by cron.
   *
   * This event allows modules to react after an entity is published by Cron.
   * The event listener receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const PUBLISH = 'scheduler.paragraph_publish';

  /**
   * The event triggered before a paragraph is published immediately.
   *
   * This event allows modules to react before an entity is published
   * immediately when being saved after editing. The event listener method
   * receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const PRE_PUBLISH_IMMEDIATELY = 'scheduler.paragraph_pre_publish_immediately';

  /**
   * The event triggered before a paragraph is published by cron.
   *
   * This event allows modules to react before an entity is published by Cron.
   * The event listener receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const PRE_PUBLISH = 'scheduler.paragraph_pre_publish';

  /**
   * The event triggered before a paragraph is unpublished by cron.
   *
   * This event allows modules to react before an entity is unpublished by Cron.
   * The event listener receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const PRE_UNPUBLISH = 'scheduler.paragraph_pre_unpublish';

  /**
   * The event triggered after a paragraph is unpublished by cron.
   *
   * This event allows modules to react after an entity is unpublished by Cron.
   * The event listener receives a \Drupal\Core\Entity\EntityInterface instance.
   *
   * @Event
   *
   * @see \Drupal\scheduler\Event\SchedulerEvent
   *
   * @var string
   */
  const UNPUBLISH = 'scheduler.paragraph_unpublish';

}
+21 −0
Changes for src/Plugin/Scheduler/ParagraphScheduler.php: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\scheduler\Plugin\Scheduler;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\scheduler\SchedulerPluginBase;

/**
 * Plugin for Paragraphs entity type.
 *
 * @package Drupal\Scheduler\Plugin\Scheduler
 *
 * @SchedulerPlugin(
 *  id = "paragraph_scheduler",
 *  label = @Translation("Paragraphs Scheduler Plugin"),
 *  description = @Translation("Provides support for scheduling paragraphs entities"),
 *  entityType = "paragraph",
 *  dependency = "paragraphs",
 * )
 */
class ParagraphScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {}
Loading