You are here

protected function JobItemForm::buildSource in Translation Management Tool 8

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 1049

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 (!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 ($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,
    );
  }
  else {
    $item_element['source'] = array(
      '#type' => 'textarea',
      '#default_value' => $source_text,
      '#title' => t('Source'),
      '#disabled' => TRUE,
      '#rows' => $rows,
    );
  }
  return $item_element;
}