CkeditorTemplateListBuilder.php in Ckeditor templates user interface 8
Namespace
Drupal\ckeditor_templates_ui\ControllerFile
src/Controller/CkeditorTemplateListBuilder.phpView source
<?php
namespace Drupal\ckeditor_templates_ui\Controller;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Builds the list of ckeditor templates for the ckeditor template form.
*/
class CkeditorTemplateListBuilder extends DraggableListBuilder {
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* CkeditorTemplateListBuilder constructor.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entityType
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(EntityTypeInterface $entityType, EntityStorageInterface $storage, MessengerInterface $messenger) {
parent::__construct($entityType, $storage);
$this->messenger = $messenger;
}
/**
* {@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('messenger'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ckeditor_templates_ui_form';
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this
->t('Template');
$header['id'] = $this
->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['id']['#markup'] = $entity
->id();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->messenger
->addStatus($this
->t('The template settings have been updated.'));
}
}
Classes
Name | Description |
---|---|
CkeditorTemplateListBuilder | Builds the list of ckeditor templates for the ckeditor template form. |