You are here

function scheduler_form_devel_generate_form_content_alter in Scheduler 8

Implements hook_form_FORM_ID_alter() for devel_generate_form_content.

File

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

Code

function scheduler_form_devel_generate_form_content_alter(array &$form, FormStateInterface $form_state) {

  // Add an extra column to the node_types table to show which type are enabled
  // for scheduled publishing and unpublishing.
  $publishing_enabled_types = array_keys(_scheduler_get_scheduler_enabled_node_types('publish'));
  $unpublishing_enabled_types = array_keys(_scheduler_get_scheduler_enabled_node_types('unpublish'));
  $form['node_types']['#header']['scheduler'] = t('Scheduler settings');
  foreach (array_keys($form['node_types']['#options']) as $type) {
    $items = [];
    if (in_array($type, $publishing_enabled_types)) {
      $items[] = t('Enabled for publishing');
    }
    if (in_array($type, $unpublishing_enabled_types)) {
      $items[] = t('Enabled for unpublishing');
    }
    if (empty($items)) {
      $scheduler_settings = t('None');
    }
    else {
      $scheduler_settings = [
        'data' => [
          '#theme' => 'item_list',
          '#items' => $items,
        ],
      ];
    }
    $form['node_types']['#options'][$type]['scheduler'] = $scheduler_settings;
  }

  // Add form items to specify what proportion of generated nodes should have a
  // publish-on and unpublish-on date assigned. See hook_node_presave() for the
  // code which sets the node values.
  $form['scheduler_publishing'] = [
    '#type' => 'number',
    '#title' => t('Publishing date for Scheduler'),
    '#description' => t('Enter the percentage of randomly selected Scheduler-enabled nodes to be given a publish-on date. Enter 0 for none, 100 for all. The date and time will be random within the range starting at node creation date, up to a time in the future matching the same span as selected above for node creation date.'),
    '#default_value' => 50,
    '#required' => TRUE,
    '#min' => 0,
    '#max' => 100,
  ];
  $form['scheduler_unpublishing'] = [
    '#type' => 'number',
    '#title' => t('Unpublishing date for Scheduler'),
    '#description' => t('Enter the percentage of randomly selected Scheduler-enabled nodes to be given an unpublish-on date. Enter 0 for none, 100 for all. The date and time will be random within the range starting at the later of node creation date and publish-on date, up to a time in the future matching the same span as selected above for node creation date.'),
    '#default_value' => 50,
    '#required' => TRUE,
    '#min' => 0,
    '#max' => 100,
  ];
}