You are here

private function StringoverridesAdminForm::buildFormTranslationRow in String Overrides 8

Simplify buildForm function.

Parameters

array $strings: Data for all translations.

int $row_no: Row number.

Return value

array One row for form table.

1 call to StringoverridesAdminForm::buildFormTranslationRow()
StringoverridesAdminForm::buildForm in src/Form/StringoverridesAdminForm.php
Form constructor.

File

src/Form/StringoverridesAdminForm.php, line 128

Class

StringoverridesAdminForm
Class StringoverridesAdminForm.

Namespace

Drupal\stringoverrides\Form

Code

private function buildFormTranslationRow(array $strings, $row_no) {
  if (!empty($strings[$row_no])) {
    $string = $strings[$row_no];
  }
  else {
    $string = [
      'enabled' => TRUE,
      'source' => '',
      'translation' => '',
      'context' => '',
    ];
  }
  $row = [];
  $row['enabled'] = [
    '#type' => 'checkbox',
    '#maxlength' => 255,
    '#default_value' => $string['enabled'],
    '#attributes' => array(
      'title' => t('Flag whether this override should be active.'),
    ),
  ];
  $row['source'] = [
    '#type' => 'textarea',
    '#default_value' => $string['source'],
    '#rows' => 1,
    '#attributes' => array(
      'title' => t('The original source text to be replaced.'),
    ),
  ];
  $row['translation'] = [
    '#type' => 'textarea',
    '#default_value' => $string['translation'],
    '#rows' => 1,
    '#attributes' => array(
      'title' => t('The text to replace the original source text.'),
    ),
    // Hide the translation when the source is empty.
    '#states' => [
      'invisible' => [
        "#edit-translations-table-{$row_no}-source" => [
          'empty' => TRUE,
        ],
      ],
    ],
  ];
  $row['context'] = [
    '#type' => 'textfield',
    '#maxlength' => 255,
    '#default_value' => $string['context'],
    '#attributes' => [
      'title' => t('Strings sometimes can have context applied to them. Most cases, this is not the case.'),
    ],
    '#size' => 5,
    // Hide the context when the source is empty.
    '#states' => [
      'invisible' => [
        "#edit-translations-table-{$row_no}-source" => [
          'empty' => TRUE,
        ],
      ],
    ],
  ];
  return $row;
}