You are here

class LingotekParagraphsBulkForm in Lingotek Translation 3.4.x

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

Special treatment for Paragraphs in bulk form.

@package Drupal\lingotek\Form

Hierarchy

Expanded class hierarchy of LingotekParagraphsBulkForm

1 string reference to 'LingotekParagraphsBulkForm'
lingotek.services.yml in ./lingotek.services.yml
lingotek.services.yml
1 service uses LingotekParagraphsBulkForm
lingotek.paragraphs_bulk_form in ./lingotek.services.yml
Drupal\lingotek\Form\LingotekParagraphsBulkForm

File

src/Form/LingotekParagraphsBulkForm.php, line 14

Namespace

Drupal\lingotek\Form
View source
class LingotekParagraphsBulkForm {
  use StringTranslationTrait;

  /**
   * 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.
   *
   * @param array &$form
   *   The form definition array.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @throws \Drupal\Core\Entity\EntityMalformedException
   */
  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() : '';
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekParagraphsBulkForm::form public function Adds the parent entity for a paragraph as the first column.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.