/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $backup_migrate_schedule = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Schedule Name'), '#maxlength' => 255, '#default_value' => $backup_migrate_schedule->label(), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $backup_migrate_schedule->id(), '#machine_name' => array('exists' => '\\Drupal\\backup_migrate\\Entity\\Schedule::load'), '#disabled' => !$backup_migrate_schedule->isNew());
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Schedule enabled'), '#default_value' => $backup_migrate_schedule->get('enabled'));
     $bam = backup_migrate_get_service_object([], ['nobrowser' => TRUE]);
     $form['source_id'] = DrupalConfigHelper::getSourceSelector($bam, t('Backup Source'));
     $form['destination_id'] = DrupalConfigHelper::getDestinationSelector($bam, t('Backup Destination'));
     $form['settings_profile_id'] = DrupalConfigHelper::getSettingsProfileSelector(t('Settings Profile'));
     $period = Schedule::secondsToPeriod($backup_migrate_schedule->get('period'));
     $form['period_container'] = array('#parents' => array(), '#type' => 'fieldset', '#title' => $this->t('Frequency'), '#field_prefix' => $this->t('Run every'), '#attributes' => array('class' => array('container-inline', 'fieldgroup', 'form-composite')));
     $form['period_container']['period_number'] = array('#type' => 'number', '#default_value' => $period['number'], '#min' => 1, '#title' => $this->t('Period number'), '#title_display' => 'invisible', '#size' => 2);
     $form['period_container']['period_type'] = ['#type' => 'select', '#title' => $this->t('Period type'), '#title_display' => 'invisible', '#options' => [], '#default_value' => $period['type']];
     foreach (Schedule::getPeriodTypes() as $key => $type) {
         $form['period_container']['period_type']['#options'][$key] = $type['title'];
     }
     //    $form['keep'] = array(
     //      '#type' => 'textfield',
     //      '#title' => $this->t('Number to keep'),
     //      '#default_value' => $backup_migrate_schedule->get('keep'),
     //      '#description' => $this->t('The number of backups to retain. Once this number is reached, the oldest backup will be deleted to make room for the most recent backup. Leave blank to keep all backups.'),
     //      '#size' => 10,
     //    );
     return $form;
 }
Exemple #2
0
 /**
  * Get a backup period type given it's key.
  *
  * @param string $type
  * @return array
  */
 public static function getPeriodType($type)
 {
     return Schedule::getPeriodTypes()[$type];
 }
 /**
  * Convert a number of of seconds into a period array.
  *
  * @param int $seconds
  * @return array An array containing the period definition and the number of them.
  *  ['units' => 123, 'type' => [...]]
  * @throws \BackupMigrate\Core\Exception\BackupMigrateException
  */
 protected static function secondsToPeriod($seconds)
 {
     foreach (array_reverse(Schedule::getPeriodTypes()) as $type) {
         if ($seconds % $type['seconds'] === 0) {
             return ['units' => $seconds / $type['seconds'], 'type' => $type];
         }
     }
     throw new BackupMigrateException('Invalid period.');
 }