GeocoderProviderListBuilder.php in Geocoder 8.3
Namespace
Drupal\geocoderFile
src/GeocoderProviderListBuilder.phpView source
<?php
declare (strict_types=1);
namespace Drupal\geocoder;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\geocoder\Form\GeocoderProviderCreationForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a listing of Geocoder providers.
*/
class GeocoderProviderListBuilder extends ConfigEntityListBuilder {
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* Constructs a new EntityListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, FormBuilderInterface $form_builder) {
parent::__construct($entity_type, $storage);
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
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('form_builder'));
}
/**
* {@inheritdoc}
*/
public function buildHeader() : array {
$header['label'] = $this
->t('Label');
$header['id'] = $this
->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) : array {
/** @var \Drupal\geocoder\GeocoderProviderInterface $entity */
$row['label'] = $entity
->label();
$row['id'] = $entity
->id();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function render() : array {
$build['geocoder_provider_creation_form'] = $this->formBuilder
->getForm(GeocoderProviderCreationForm::class);
$build['geocoder_provider_header']['#markup'] = '<h3>' . $this
->t('Active providers') . '</h3>';
$build['geocoder_provider_table'] = parent::render();
return $build;
}
}
Classes
Name | Description |
---|---|
GeocoderProviderListBuilder | Provides a listing of Geocoder providers. |