You are here

public function LingotekParagraphsBulkForm::form in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  2. 3.0.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  3. 3.1.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  4. 3.2.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  5. 3.3.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  6. 3.4.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  7. 3.5.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  8. 3.6.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  9. 3.7.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()
  10. 3.8.x src/Form/LingotekParagraphsBulkForm.php \Drupal\lingotek\Form\LingotekParagraphsBulkForm::form()

Adds the parent entity for a paragraph as the first column.

If there are nested paragraphs, it recurses until the parent it's not a paragraph itself.

Parameters

array &$form: The form definition array.

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

Throws

\Drupal\Core\Entity\EntityMalformedException

File

src/Form/LingotekParagraphsBulkForm.php, line 31

Class

LingotekParagraphsBulkForm
Special treatment for Paragraphs in bulk form.

Namespace

Drupal\lingotek\Form

Code

public function form(array &$form, FormStateInterface $form_state) {
  $build_info = $form_state
    ->getBuildInfo();
  if ($form['#form_id'] === 'lingotek_management' && $build_info && isset($build_info['form_id']) && $build_info['form_id'] === 'lingotek_management') {
    $formObject = $build_info['callback_object'];
    if ($formObject
      ->getEntityTypeId() === 'paragraph') {
      $pids = array_keys($form['table']['#options']);

      /** @var \Drupal\paragraphs\Entity\Paragraph[] $paragraphs */
      $paragraphs = Paragraph::loadMultiple($pids);
      $form['table']['#header'] = [
        'parent' => $this
          ->t('Parent'),
      ] + $form['table']['#header'];
      foreach ($paragraphs as $id => $paragraph) {

        /** @var \Drupal\Core\Entity\EntityInterface $parent */
        $parent = $paragraph;
        do {
          $parent = $parent
            ->getParentEntity();
        } while ($parent !== NULL && $parent
          ->getEntityTypeId() === 'paragraph');
        $form['table']['#options'][$id]['parent'] = $parent !== NULL ? $parent
          ->toLink() : '';
      }
    }
  }
}