public function LingotekSettingsContentSingleForm::buildForm in Lingotek Translation 3.2.x
Same name and namespace in other branches
- 8.2 src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 4.0.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.0.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.1.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.3.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.4.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.5.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.6.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.7.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
- 3.8.x src/Form/LingotekSettingsContentSingleForm.php \Drupal\lingotek\Form\LingotekSettingsContentSingleForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ LingotekSettingsContentSingleForm.php, line 34
Class
- LingotekSettingsContentSingleForm
- Configure Lingotek
Namespace
Drupal\lingotek\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $entity_type = NULL, $bundle = NULL) {
$this->entity_type_id = $entity_type;
$this->bundle_id = $bundle;
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$entity_type_definitions = \Drupal::entityTypeManager()
->getDefinitions();
// Get the profiles
$this
->retrieveProfileOptions();
// Retrieve bundles
$this
->retrieveBundles();
// Retrieve translatable bundles
$this
->retrieveTranslatableBundles();
$form['parent_details'] = [
'#type' => 'details',
'#title' => t('Translate Content Entities'),
'#open' => TRUE,
];
$form['parent_details']['list']['#type'] = 'container';
$form['parent_details']['list']['#attributes']['class'][] = 'entity-meta';
$entity_key = 'entity-' . $entity_type;
/** @var \Drupal\lingotek\Moderation\LingotekModerationFactoryInterface $moderationFactory */
$moderationFactory = \Drupal::service('lingotek.moderation_factory');
/** @var \Drupal\lingotek\Moderation\LingotekModerationSettingsFormInterface $moderationForm */
$moderationForm = $moderationFactory
->getModerationSettingsForm();
$bundle_label = $entity_type_definitions[$entity_type]
->getBundleLabel();
$header = [
$this
->t('Enable'),
$bundle_label,
$this
->t('Translation Profile'),
'moderation' => $moderationForm
->getColumnHeader(),
$this
->t('Fields'),
];
if (!$moderationForm
->needsColumn($entity_type)) {
unset($header['moderation']);
}
$table = [
'#type' => 'table',
'#header' => $header,
'#empty' => $this
->t('No Entries'),
];
$row = [];
$row['enabled'] = [
'#type' => 'checkbox',
'#label' => $this
->t('Enabled'),
'#default_value' => $lingotek_config
->isEnabled($entity_type, $bundle),
'#ajax' => [
'callback' => [
$this,
'ajaxRefreshEntityFieldsForm',
],
'progress' => [
'type' => 'throbber',
'message' => NULL,
],
'wrapper' => 'container-' . str_replace('_', '-', $entity_type) . '-' . $bundle,
],
];
$row['content_type'] = [
'#markup' => $this->bundles[$entity_type][$bundle]['label'],
];
$row['profiles'] = $this
->retrieveProfiles($entity_type, $bundle);
$moderation = $moderationForm
->form($entity_type, $bundle);
if (!empty($moderation)) {
$row['moderation'] = $moderation;
}
$row['fields_container'] = $this
->generateFieldsForm($form_state, $entity_type, $bundle);
$table[$bundle] = $row;
$form['parent_details']['list'][$entity_key]['content'][$entity_type] = $table;
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#id' => 'submit-settings-content-single-form',
'#value' => $this
->t('Save Lingotek content settings'),
'#button_type' => 'primary',
];
$form['#attached']['library'][] = 'lingotek/lingotek.settings';
return $form;
}