You are here

public function LogCommentForm::buildForm in Commerce Core 8.2

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 FormInterface::buildForm

File

modules/log/src/Form/LogCommentForm.php, line 64

Class

LogCommentForm

Namespace

Drupal\commerce_log\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $source_entity_type = NULL, $source_entity_id = NULL, $log_template_id = NULL) {
  if ($source_entity_type === NULL || $source_entity_id === NULL || $log_template_id === NULL) {
    return [];
  }
  if (!$this->logTemplateManager
    ->hasDefinition($log_template_id)) {
    return [];
  }
  $entity_type = $this->entityTypeManager
    ->getDefinition($source_entity_type);
  assert($entity_type !== NULL);
  $form['log_comment'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Comment on this @label', [
      '@label' => $entity_type
        ->getSingularLabel(),
    ]),
    '#open' => FALSE,
  ];
  $form['log_comment']['source_entity_id'] = [
    '#type' => 'hidden',
    '#value' => $source_entity_id,
  ];
  $form['log_comment']['source_entity_type'] = [
    '#type' => 'hidden',
    '#value' => $source_entity_type,
  ];
  $form['log_comment']['log_template_id'] = [
    '#type' => 'hidden',
    '#value' => $log_template_id,
  ];
  $form['log_comment']['comment'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Comment'),
    '#title_display' => 'invisible',
    '#required' => TRUE,
  ];
  $form['log_comment']['actions']['#type'] = 'actions';
  $form['log_comment']['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add comment'),
  ];
  return $form;
}