CustomLanguageListBuilder.php in Custom Language field 8
File
src/CustomLanguageListBuilder.php
View source
<?php
namespace Drupal\languagefield;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
class CustomLanguageListBuilder extends DraggableListBuilder {
public function getFormId() {
return 'languagefield_custom_language_form';
}
public function buildHeader() {
$header['label'] = $this
->t('Language name');
$header['langcode'] = $this
->t('Language code');
$header['native_name'] = $this
->t('Language native name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['langcode'] = [
'#markup' => $entity
->id(),
];
$row['native_name'] = [
'#markup' => $entity
->getNativeName(),
];
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if ($entity
->hasLinkTemplate('edit-form')) {
$operations['edit'] = [
'title' => $this
->t('Edit'),
'weight' => 20,
'url' => $entity
->toUrl('edit-form'),
];
}
return $operations;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->messenger()
->addStatus($this
->t('The language has been updated.'));
}
public function render() {
$build = parent::render();
$build['#empty'] = $this
->t('There is no custom language.');
return $build;
}
}