Builds the source form elements for a data item.
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.
array The form element for the data item.
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;
}