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

Issue #3282982 by DieterHolvoet, jonathan1055: Simplify the scheduler plugin implementations

parent c76da6c0
Loading
Loading
Loading
Loading
+2 −0
Changes for scheduler.services.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ services:
  plugin.manager.scheduler:
    class: Drupal\scheduler\SchedulerPluginManager
    parent: default_plugin_manager
    arguments:
      - '@entity_type.manager'
  scheduler.route_subscriber:
    class: Drupal\scheduler\Routing\SchedulerRouteSubscriber
    tags:
+1 −60
Changes for src/Plugin/Scheduler/CommerceProductScheduler.php: 1 added line, 60 removed lines.
Original line number Diff line number Diff line
@@ -15,69 +15,10 @@ use Drupal\scheduler\SchedulerPluginBase;
 *  label = @Translation("Commerce Product Scheduler Plugin"),
 *  description = @Translation("Provides support for scheduling Commerce Product entities"),
 *  entityType = "commerce_product",
 *  typeFieldName = "type",
 *  dependency = "commerce_product",
 *  schedulerEventClass = "\Drupal\scheduler\Event\SchedulerCommerceProductEvents",
 *  publishAction = "commerce_publish_product",
 *  unpublishAction = "commerce_unpublish_product"
 * )
 */
class CommerceProductScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * Get the available types/bundles for the entity type.
   *
   * Do not use static or drupal_static here, because changes to third-party
   * settings invalidate the saved values during phpunit testing.
   *
   * @return array
   *   The commerce product bundle objects, keyed by bundle name, or an empty
   *   array if Commerce is not enabled.
   */
  public function getTypes() {
    if (!\Drupal::moduleHandler()->moduleExists('commerce')) {
      return [];
    }
    $productTypes = \Drupal::entityTypeManager()->getStorage('commerce_product_type')->loadMultiple();
    return $productTypes;
  }

  /**
   * Get the form IDs for commerce product add/edit forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Commerce is not enabled.
   */
  public function entityFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('commerce')) {
      return [];
    }
    static $ids;
    if (!isset($ids)) {
      $ids = [];
      $types = array_keys($this->getTypes());
      foreach ($types as $typeId) {
        $ids[] = 'commerce_product_' . $typeId . '_add_form';
        $ids[] = 'commerce_product_' . $typeId . '_edit_form';
      }
    }
    return $ids;
  }

  /**
   * Get the form IDs for commerce product type forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Commerce is not enabled.
   */
  public function entityTypeFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('commerce')) {
      return [];
    }
    return [
      'commerce_product_type_add_form',
      'commerce_product_type_edit_form',
    ];
  }

}
class CommerceProductScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {}
+1 −60
Changes for src/Plugin/Scheduler/MediaScheduler.php: 1 added line, 60 removed lines.
Original line number Diff line number Diff line
@@ -15,68 +15,9 @@ use Drupal\scheduler\SchedulerPluginBase;
 *  label = @Translation("Media Scheduler Plugin"),
 *  description = @Translation("Provides support for scheduling media entities"),
 *  entityType = "media",
 *  typeFieldName = "bundle",
 *  dependency = "media",
 *  develGenerateForm = "devel_generate_form_media",
 *  userViewRoute = "view.scheduler_scheduled_media.user_page",
 * )
 */
class MediaScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * Get the available types/bundles for the entity type.
   *
   * Do not use static or drupal_static here, because changes to third-party
   * settings invalidate the saved values during phpunit testing.
   *
   * @return array
   *   The media bundle objects, keyed by bundle name, or an empty array if
   *   Media is not enabled.
   */
  public function getTypes() {
    if (!\Drupal::moduleHandler()->moduleExists('media')) {
      return [];
    }
    $mediaTypes = \Drupal::entityTypeManager()->getStorage('media_type')->loadMultiple();
    return $mediaTypes;
  }

  /**
   * Get the form IDs for media add/edit forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Media is not enabled.
   */
  public function entityFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('media')) {
      return [];
    }
    static $ids;
    if (!isset($ids)) {
      $ids = [];
      $types = array_keys($this->getTypes());
      foreach ($types as $typeId) {
        $ids[] = 'media_' . $typeId . '_add_form';
        $ids[] = 'media_' . $typeId . '_edit_form';
      }
    }
    return $ids;
  }

  /**
   * Get the form IDs for media type forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Media is not enabled.
   */
  public function entityTypeFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('media')) {
      return [];
    }
    return [
      'media_type_add_form',
      'media_type_edit_form',
    ];
  }

}
class MediaScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {}
+1 −52
Changes for src/Plugin/Scheduler/NodeScheduler.php: 1 added line, 52 removed lines.
Original line number Diff line number Diff line
@@ -15,61 +15,10 @@ use Drupal\scheduler\SchedulerPluginBase;
 *  label = @Translation("Node Scheduler Plugin"),
 *  description = @Translation("Provides support for scheduling node entities"),
 *  entityType = "node",
 *  typeFieldName = "type",
 *  dependency = "node",
 *  develGenerateForm = "devel_generate_form_content",
 *  collectionRoute = "system.admin_content",
 *  userViewRoute = "view.scheduler_scheduled_content.user_page",
 * )
 */
class NodeScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * Get the available types/bundles for the entity type.
   *
   * Do not use static or drupal_static here, because changes to third-party
   * settings invalidate the saved values during phpunit testing.
   *
   * @return array
   *   The node type objects, keyed by node type name.
   */
  public function getTypes() {
    $nodeTypes = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
    return $nodeTypes;
  }

  /**
   * Get the form IDs for node add/edit forms.
   *
   * @return array
   *   The list of form IDs.
   */
  public function entityFormIds() {
    static $ids;
    if (!isset($ids)) {
      $ids = [];
      $types = array_keys($this->getTypes());
      foreach ($types as $typeId) {
        // The node add form is named node_{type}_form. This is different from
        // other entities, which have {entity}_{type}_add_form.
        $ids[] = 'node_' . $typeId . '_form';
        $ids[] = 'node_' . $typeId . '_edit_form';
      }
    }
    return $ids;
  }

  /**
   * Get the form IDs for node type forms.
   *
   * @return array
   *   The list of form IDs.
   */
  public function entityTypeFormIds() {
    return [
      'node_type_add_form',
      'node_type_edit_form',
    ];
  }

}
class NodeScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {}
+1 −57
Changes for src/Plugin/Scheduler/TaxonomyTermScheduler.php: 1 added line, 57 removed lines.
Original line number Diff line number Diff line
@@ -15,66 +15,10 @@ use Drupal\scheduler\SchedulerPluginBase;
 *  label = @Translation("Taxonomy Term Scheduler Plugin"),
 *  description = @Translation("Provides support for scheduling Taxonomy Term entities"),
 *  entityType = "taxonomy_term",
 *  typeFieldName = "vid",
 *  dependency = "taxonomy",
 *  develGenerateForm = "devel_generate_form_term",
 *  collectionRoute = "entity.taxonomy_vocabulary.collection",
 *  schedulerEventClass = "\Drupal\scheduler\Event\SchedulerTaxonomyTermEvents",
 * )
 */
class TaxonomyTermScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * Get the available types/bundles for the entity type.
   *
   * Do not use static or drupal_static here, because changes to third-party
   * settings invalidate the saved values during phpunit testing.
   *
   * @return array
   *   The Taxonomy Term bundle objects (vocabularies), keyed by bundle name, or
   *   an empty array if Taxonomy is not enabled or there are no vocabularies.
   */
  public function getTypes() {
    if (!\Drupal::moduleHandler()->moduleExists('taxonomy')) {
      return [];
    }
    return \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->loadMultiple();
  }

  /**
   * Get the form IDs for Taxonomy Term add/edit forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Taxonomy is not enabled.
   */
  public function entityFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('taxonomy')) {
      return [];
    }
    static $ids;
    if (!isset($ids)) {
      $ids = [];
      $types = array_keys($this->getTypes());
      foreach ($types as $typeId) {
        $ids[] = 'taxonomy_term_' . $typeId . '_form';
      }
    }
    return $ids;
  }

  /**
   * Get the form IDs for Taxonomy Term type forms.
   *
   * @return array
   *   The list of form IDs, or an empty array if Taxonomy is not enabled.
   */
  public function entityTypeFormIds() {
    if (!\Drupal::moduleHandler()->moduleExists('taxonomy')) {
      return [];
    }
    return [
      'taxonomy_vocabulary_form',
    ];
  }

}
class TaxonomyTermScheduler extends SchedulerPluginBase implements ContainerFactoryPluginInterface {}
Loading