FlagMappingListBuilder.php in Flags 8
File
src/Entity/FlagMappingListBuilder.php
View source
<?php
namespace Drupal\flags\Entity;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
class FlagMappingListBuilder extends ConfigEntityListBuilder {
protected $flags;
protected $countries;
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('country_manager')
->getList(), $container
->get('flags.manager')
->getList());
}
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, $countries, $flags) {
parent::__construct($entity_type, $storage);
$this->flags = $flags;
$this->countries = $countries;
}
public function buildHeader() {
$header['country'] = $this
->t('Country');
$header['flag'] = $this
->t('Flag');
$header['info'] = $this
->t('Info');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$id = strtoupper($entity
->getSource());
$row['country'] = isset($this->countries[$id]) ? $this->countries[$id] : $id;
$row['flag']['data'] = [
'#theme' => 'flags',
'#code' => strtolower($entity
->getFlag()),
'#source' => 'country',
];
$row['info'] = $this->flags[$entity
->getFlag()];
return $row + parent::buildRow($entity);
}
public function render() {
$build['description'] = array(
'#markup' => $this
->t("<p>Country to flag mapping allows you to display" . " flags from Flags module next to your country fields or" . " country select forms.</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;
}
}