public function LingotekSettingsTabContentForm::buildForm in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 4.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.0.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.1.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.2.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.3.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.4.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.5.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.6.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.7.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::buildForm()
- 3.8.x src/Form/LingotekSettingsTabContentForm.php \Drupal\lingotek\Form\LingotekSettingsTabContentForm::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/ LingotekSettingsTabContentForm.php, line 32 - Contains \Drupal\lingotek\Form\LingotekSettingsTabContentForm.
Class
- LingotekSettingsTabContentForm
- Configure Lingotek
Namespace
Drupal\lingotek\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
$entity_type_definitions = \Drupal::entityManager()
->getDefinitions();
// Get the profiles
$this
->retrieveProfileOptions();
// Retrieve bundles
$this
->retrieveBundles();
// Retrieve translatable bundles
$this
->retrieveTranslatableBundles();
$form['parent_details'] = array(
'#type' => 'details',
'#title' => t('Translate Content Entities'),
);
$form['parent_details']['list']['#type'] = 'container';
$form['parent_details']['list']['#attributes']['class'][] = 'entity-meta';
// If user specifies no translatable entities, post this message
if (empty($this->translatable_bundles)) {
$form['parent_details']['empty_message'] = array(
'#markup' => t('There are no translatable content entities specified. You can enable translation for the desired content entities on the <a href=":translation-entity">Content language</a> page.', [
':translation-entity' => \Drupal::url('language.content_settings_page'),
]),
);
}
// I. Loop through all entities and create a details container for each
foreach ($this->translatable_bundles as $entity_id => $bundles) {
$entity_key = 'entity-' . $entity_id;
$form['parent_details']['list'][$entity_key] = array(
'#type' => 'details',
'#title' => $entity_type_definitions[$entity_id]
->getLabel(),
'content' => array(),
);
$bundle_label = $entity_type_definitions[$entity_id]
->getBundleLabel();
$header = array(
$this
->t('Enable'),
$bundle_label,
$this
->t('Translation Profile'),
$this
->t('Fields'),
);
$table = array(
'#type' => 'table',
'#header' => $header,
'#empty' => $this
->t('No Entries'),
);
// II. Loop through bundles per entity and make a table
foreach ($bundles as $bundle_id => $bundle) {
$row = array();
$row['enabled'] = [
'#type' => 'checkbox',
'#label' => $this
->t('Enabled'),
'#default_value' => $lingotek_config
->isEnabled($entity_id, $bundle_id),
];
$row['content_type'] = array(
'#markup' => $bundle['label'],
);
$row['profiles'] = $this
->retrieveProfiles($entity_id, $bundle_id);
$row['fields'] = $this
->retrieveFields($entity_id, $bundle_id);
$table[$bundle_id] = $row;
}
// III. Add table to respective details
$form['parent_details']['list'][$entity_key]['content'][$entity_id] = $table;
}
if (!empty($this->translatable_bundles)) {
$form['parent_details']['note'] = array(
'#markup' => t('Note: changing the profile will update all settings for existing nodes except for the project, workflow, vault, and storage method (e.g. node/field)'),
);
$form['parent_details']['actions']['#type'] = 'actions';
$form['parent_details']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#button_type' => 'primary',
);
}
$form['#attached']['library'][] = 'lingotek/lingotek.settings';
return $form;
}