protected function JobItemForm::buildSource

Builds the source form elements for a data item.

Parameters

array $item_element: The form element for the data item.

string $source_text: The source's text to display in the item element.

array $data_item: The data item.

int $rows: The number of rows that should be displayed.

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

Return value

array The form element for the data item.

1 call to JobItemForm::buildSource()
JobItemForm::reviewFormElement in src/Form/JobItemForm.php
Build form elements for the review form using flattened data items.

File

src/Form/JobItemForm.php, line 1072

Class

JobItemForm
Form controller for the job item edit forms.

Namespace

Drupal\tmgmt\Form

Code

protected function buildSource($item_element, $source_text, $data_item, $rows, FormStateInterface $form_state) {
  if ($source_text && !empty($data_item['#format']) && $this
    ->config('tmgmt.settings')
    ->get('respect_text_format') && !$form_state
    ->has('accept_item')) {
    $item_element['source'] = array(
      '#type' => 'text_format',
      '#default_value' => $source_text,
      '#title' => t('Source'),
      '#disabled' => TRUE,
      '#rows' => $rows,
      '#allowed_formats' => array(
        $data_item['#format'],
      ),
    );
  }
  elseif ($source_text && $form_state
    ->has('accept_item')) {
    $item_element['source'] = array(
      '#type' => 'textarea',
      '#title' => t('Source'),
      '#value' => t('This field has been disabled because you do not have sufficient permissions to edit it. It is not possible to review or accept this job item.'),
      '#disabled' => TRUE,
      '#rows' => $rows,
    );
  }
  elseif ($source_text) {
    $item_element['source'] = array(
      '#type' => 'textarea',
      '#default_value' => $source_text,
      '#title' => t('Source'),
      '#disabled' => TRUE,
      '#rows' => $rows,
    );
  }
  elseif (isset($data_item['#file'])) {
    $item_element['source'] = array(
      '#type' => 'managed_file',
      '#default_value' => !empty($data_item['#file']) ? [
        $data_item['#file'],
      ] : NULL,
      '#title' => t('Source'),
      '#disabled' => TRUE,
    );
  }
  return $item_element;
}