LanguageFlagMappingListBuilder.php in Flags 8
File
src/Entity/LanguageFlagMappingListBuilder.php
View source
<?php
namespace Drupal\flags\Entity;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\flags\Entity\FlagMapping;
use Drupal\flags\FullLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
class LanguageFlagMappingListBuilder extends ConfigEntityListBuilder {
protected $flags;
protected $languageManager;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('flags.language_helper'), $container
->get('flags.manager')
->getList());
}
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, FullLanguageManagerInterface $fullLanguageManager, $flags) {
parent::__construct($entity_type, $storage);
$this->languageManager = $fullLanguageManager;
$this->flags = $flags;
}
public function buildHeader() {
$header['language'] = $this
->t('Language');
$header['flag'] = $this
->t('Flag');
$header['info'] = $this
->t('Info');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$allLanguages = $this->languageManager
->getAllDefinedLanguages();
$id = $entity
->getSource();
$row['language'] = isset($allLanguages[$id]) ? $allLanguages[$id] : $id;
$row['flag']['data'] = [
'#theme' => 'flags',
'#code' => strtolower($entity
->getFlag()),
'#source' => 'language',
];
$row['info'] = $this->flags[$entity
->getFlag()];
return $row + parent::buildRow($entity);
}
public function render() {
$build['description'] = array(
'#markup' => $this
->t("<p>Language to flag mapping allows you to display" . " flags from Flags module next to your language fields, language" . " select form or language switcher links.</p><p>Default mappings" . " can be changed by adding configurations. You can also use the" . " 'Operations' column to edit and delete mappings.</p>"),
);
$build[] = parent::render();
return $build;
}
}