VocabularyListBuilder.php in Termcase 8
File
src/VocabularyListBuilder.php
View source
<?php
namespace Drupal\termcase;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class VocabularyListBuilder extends DraggableListBuilder {
protected $entitiesKey = 'vocabularies';
public function getFormId() {
return 'taxonomy_overview_vocabularies';
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
$operations['edit']['title'] = $this
->t('Edit vocabulary');
}
$operations['list'] = [
'title' => $this
->t('List terms'),
'weight' => 0,
'url' => $entity
->toUrl('overview-form'),
];
$operations['add'] = [
'title' => $this
->t('Add terms'),
'weight' => 10,
'url' => Url::fromRoute('entity.taxonomy_term.add_form', [
'taxonomy_vocabulary' => $entity
->id(),
]),
];
unset($operations['delete']);
return $operations;
}
public function buildHeader() {
$header['label'] = $this
->t('Vocabulary name');
$header['termcase'] = $this
->t('Case Conversion');
$header = $header + parent::buildHeader();
return $header;
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$vocab_machine_name = $entity
->get('vid');
$config = \Drupal::config('termcase.settings');
$mode_id = $config
->get('termcase_options_' . $vocab_machine_name);
$termcase_mode = termcase_get_mode($mode_id);
$row['termcase'] = [
'#markup' => $termcase_mode,
];
$row = $row + parent::buildRow($entity);
return $row;
}
public function render() {
$entities = $this
->load();
if (count($entities) <= 1) {
unset($this->weightKey);
}
$build = parent::render();
$build['table']['#empty'] = $this
->t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [
':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')
->toString(),
]);
return $build;
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['vocabularies']['#attributes'] = [
'id' => 'taxonomy',
];
$form['actions']['submit']['#value'] = $this
->t('Save');
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
\Drupal::messenger()
->addMessage($this
->t('The configuration options have been saved.'));
}
}