You are here

public function ScheduleForm::buildForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Form/ScheduleForm.php \Drupal\business_rules\Form\ScheduleForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/ScheduleForm.php, line 19

Class

ScheduleForm
Form controller for Schedule edit forms.

Namespace

Drupal\business_rules\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /* @var $entity \Drupal\business_rules\Entity\Schedule */
  $form = parent::buildForm($form, $form_state);
  if (!$this->entity
    ->isNew()) {
    $form['new_revision'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Create new revision'),
      '#default_value' => TRUE,
      '#weight' => 10,
      '#required' => TRUE,
    ];
  }
  $entity = $this->entity;
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name'),
    '#default_value' => $entity
      ->getName(),
    '#required' => TRUE,
  ];
  $form['status'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Executed'),
    '#default_value' => $entity
      ->isExecuted(),
  ];
  $scheduled_time = $entity
    ->isNew() ? '' : DrupalDateTime::createFromTimestamp($entity
    ->getScheduled());
  $form['scheduled'] = [
    '#type' => 'datetime',
    '#title' => $this
      ->t('Scheduled'),
    '#default_value' => $scheduled_time,
    '#required' => TRUE,
  ];

  // Ask for the action to execute.
  $form['triggered_by'] = [
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('Triggered by'),
    '#description' => $this
      ->t('Action that has supposed triggered this schedule.'),
    '#target_type' => 'business_rules_action',
    '#selection_handler' => 'default:business_rules_item_by_field',
    '#selection_settings' => [
      'filter' => [
        'type' => 'schedule_a_task',
      ],
    ],
    '#default_value' => $entity
      ->getTriggeredBy(),
    '#required' => TRUE,
  ];
  return $form;
}