You are here

function _scheduler_devel_generate_form_alter in Scheduler 2.x

Form alter handling for Devel Generate forms.

1 call to _scheduler_devel_generate_form_alter()
scheduler_form_alter in ./scheduler.module
Implements hook_form_alter().

File

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

Code

function _scheduler_devel_generate_form_alter(array &$form, FormStateInterface $form_state, $form_id, $entityTypeId) {

  // Add an extra column to the table to show which types are enabled for
  // scheduled publishing and unpublishing.
  $scheduler_manager = \Drupal::service('scheduler.manager');
  $publishing_enabled_types = $scheduler_manager
    ->getEnabledTypes($entityTypeId, 'publish');
  $unpublishing_enabled_types = $scheduler_manager
    ->getEnabledTypes($entityTypeId, 'unpublish');
  $type_table = $entityTypeId . '_types';
  $form[$type_table]['#header']['scheduler'] = t('Scheduler settings');
  foreach (array_keys($form[$type_table]['#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[$type_table]['#options'][$type]['scheduler'] = $scheduler_settings;
  }

  // Add form items to specify what proportion of generated entities should have
  // a publish-on and/or unpublish-on date assigned. See hook_entity_presave()
  // for the code that sets these values in the generated entity.
  $form['scheduler_publishing'] = [
    '#type' => 'number',
    '#title' => t('Publishing date for Scheduler'),
    '#description' => t('Enter a percentage for randomly selecting Scheduler-enabled entities 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 entity creation date, up to a time in the future matching the same span as selected above for 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 a percentage for randomly selecting Scheduler-enabled entities 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 entity creation date and publish-on date, up to a time in the future matching the same span as selected above for creation date.'),
    '#default_value' => 50,
    '#required' => TRUE,
    '#min' => 0,
    '#max' => 100,
  ];
}