function JobForm::buildSuggestions

Fills the tableselect with all translation suggestions.

Calls hook_tmgmt_source_suggestions(Job) and creates the resulting list based on the results from all modules.

Parameters

array $suggestions_table: Tableselect part for a $form array where the #options should be inserted.

array $form_state: The main form_state.

1 call to JobForm::buildSuggestions()

File

src/Form/JobForm.php, line 842

Class

JobForm
Form controller for the job edit forms.

Namespace

Drupal\tmgmt\Form

Code

function buildSuggestions(array &$suggestions_table, FormStateInterface $form_state) {
  $options = array();
  $job = $form_state
    ->getFormObject()
    ->getEntity();
  if ($job instanceof Job) {

    // Get all suggestions from all modules which implements
    // 'hook_tmgmt_source_suggestions' and cache them in $form_state.
    if (!$form_state
      ->get('tmgmt_suggestions')) {
      $form_state
        ->set('tmgmt_suggestions', $job
        ->getSuggestions());
    }

    // Remove suggestions which are already processed, translated, ...
    $job
      ->cleanSuggestionsList($form_state
      ->get('tmgmt_suggestions'));

    // Process all valid entries.
    foreach ($form_state
      ->get('tmgmt_suggestions') as $k => $result) {
      if (is_array($result) && isset($result['job_item']) && $result['job_item'] instanceof JobItem) {
        $options[$k + 1] = $this
          ->addSuggestionItem($result);
      }
    }
    $suggestions_table['#options'] = $options;
    $suggestions_table['#empty'] = t('No related suggestions available.');
    $suggestions_table['#header'] = array(
      'title' => t('Label'),
      'type' => t('Type'),
      'reason' => t('Reason'),
      'words' => t('Word count'),
    );
  }
}