public function ContentLanguageAccessAdminForm::buildForm in Content Language Access 8
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/ ContentLanguageAccessAdminForm.php, line 48
Class
- ContentLanguageAccessAdminForm
- Administration form for content language access module.
Namespace
Drupal\content_language_access\FormCode
public function buildForm(array $form, FormStateInterface $form_state = NULL) {
$form = [];
$config = $this
->config('content_language_access.settings');
$form['content_language_access'] = [
'#type' => 'details',
'#title' => $this
->t('Permissions'),
'#open' => TRUE,
];
$languages = \Drupal::languageManager()
->getLanguages();
foreach ($languages as $language) {
if (!$language
->isLocked()) {
$form['content_language_access'][$language
->getId()] = [
'#type' => 'details',
'#title' => $this
->t('Drupal language: @language', [
'@language' => $language
->getName(),
]),
'#open' => TRUE,
];
foreach ($languages as $language_perm) {
if (!$language_perm
->isLocked()) {
$form['content_language_access'][$language
->getId()][$language
->getId() . '_' . $language_perm
->getId()] = [
'#type' => 'checkbox',
'#title' => $this
->t('Content language: @language', [
'@language' => $language_perm
->getName(),
]),
'#default_value' => (bool) $config
->get($language
->getId() . '_' . $language_perm
->getId()),
];
// Only shows the same language for better visualization.
if ($language
->getId() == $language_perm
->getId()) {
$form['content_language_access'][$language
->getId()][$language
->getId() . '_' . $language_perm
->getId()]['#disabled'] = TRUE;
$form['content_language_access'][$language
->getId()][$language
->getId() . '_' . $language_perm
->getId()]['#value'] = TRUE;
}
}
}
}
}
return parent::buildForm($form, $form_state);
}