You are here

function scheduler_feeds_processor_targets_alter in Scheduler 2.x

Same name and namespace in other branches
  1. 8 scheduler.module \scheduler_feeds_processor_targets_alter()
  2. 7 scheduler.module \scheduler_feeds_processor_targets_alter()

Implements hook_feeds_processor_targets_alter().

This function exposes publish_on and unpublish_on as mappable targets to the Feeds module.

@todo Port to Drupal 8.

See also

https://www.drupal.org/project/feeds

https://www.drupal.org/project/scheduler/issues/2651354

File

./scheduler.module, line 948
Scheduler publishes and unpublishes entities on dates specified by the user.

Code

function scheduler_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {

  // The plugins processing has not been tested, because the function has not
  // been converted to Drupal 8. The processing below will need to be adjusted
  // depending on whether $entity_type is a string or an object.
  // See scheduler_entity_extra_field_info() for an example.
  // May need to use $scheduler_manager->getThirdPartySetting.
  $plugins =& drupal_static(__FUNCTION__);
  if (empty($plugins)) {
    $plugins = \Drupal::service('scheduler.manager')
      ->getPluginEntityTypes();
  }
  if (in_array($entity_type, $plugins)) {
    $config = \Drupal::config('scheduler.settings');

    // @todo Get the entity object if $entity_type is a string.
    $publishing_enabled = $entity_type
      ->getThirdPartySetting('scheduler', 'publish_enable', $config
      ->get('default_publish_enable'));
    $unpublishing_enabled = $entity_type
      ->getThirdPartySetting('scheduler', 'unpublish_enable', $config
      ->get('default_unpublish_enable'));
    if ($publishing_enabled) {
      $targets['publish_on'] = [
        'name' => t('Scheduler: publish on'),
        'description' => t('The date when the Scheduler module will publish the content.'),
        'callback' => 'scheduler_feeds_set_target',
      ];
    }
    if ($unpublishing_enabled) {
      $targets['unpublish_on'] = [
        'name' => t('Scheduler: unpublish on'),
        'description' => t('The date when the Scheduler module will unpublish the content.'),
        'callback' => 'scheduler_feeds_set_target',
      ];
    }
  }
}