You are here

public function StatusForm::buildForm in Heartbeat 8

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/statusmessage/src/Form/StatusForm.php, line 67

Class

StatusForm
Form controller for Status edit forms.

Namespace

Drupal\statusmessage\Form

Code

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

  /* @var $entity \Drupal\statusmessage\Entity\Status */
  $form['#attached']['library'][] = 'statusmessage/status';
  if (\Drupal::moduleHandler()
    ->moduleExists('heartbeat')) {
    $friendData = \Drupal::config('heartbeat_friendship.settings')
      ->get('data');
    $form['#attached']['library'][] = 'heartbeat/heartbeat';
    $form['#attached']['drupalSettings']['friendData'] = $friendData;
  }
  $form['message'] = array(
    '#type' => 'textarea',
    '#description' => 'Status Message',
    '#attributes' => array(
      'placeholder' => t('Post a status update'),
    ),
    '#ajax' => [
      'event' => 'change, paste, keyup',
      'callback' => '::generatePreview',
      'progress' => array(
        'type' => 'none',
        'message' => t('Generating preview'),
      ),
    ],
  );
  $form['post'] = array(
    '#type' => 'submit',
    '#description' => 'Post',
    '#value' => t('Post'),
    '#ajax' => [
      'callback' => '::statusAjaxSubmit',
      'progress' => array(
        'type' => 'throbber',
        'message' => t('Posting Message'),
      ),
    ],
  );
  $form['mediatabs'] = [
    '#type' => 'radios',
    //      '#description' => $this->t('User selectable feeds'),
    '#prefix' => '<div class="status-media-upload"></div>',
    '#options' => $this->mediaTabs,
    '#theme' => 'status-form-element',
  ];
  $form['media'] = [
    '#type' => 'managed_file',
    '#upload_location' => 'public://statusmessage/',
    //      '#multiple' => TRUE,
    '#states' => array(
      'visible' => array(
        ':input[name="File_type"]' => array(
          'value' => t('Upload Your File'),
        ),
      ),
    ),
  ];
  return $form;
}