ParagraphsCategoryListBuilder.php in Paragraphs Editor Enhancements 8
File
src/Controller/ParagraphsCategoryListBuilder.php
View source
<?php
namespace Drupal\paragraphs_ee\Controller;
use Drupal\Core\Config\ConfigFactoryInterface;
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;
class ParagraphsCategoryListBuilder extends DraggableListBuilder {
protected $entitiesKey = 'categories';
protected $configFactory;
protected $messenger;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigFactoryInterface $config_factory, MessengerInterface $messenger) {
parent::__construct($entity_type, $storage);
$this->configFactory = $config_factory;
$this->messenger = $messenger;
}
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('config.factory'), $container
->get('messenger'));
}
public function getFormId() {
return 'paragraphs_category_admin_overview';
}
public function buildHeader() {
$header['label'] = $this
->t('Label');
$header['description'] = $this
->t('Description');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['description']['data'] = [
'#markup' => $entity
->getDescription(),
];
return $row + parent::buildRow($entity);
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['actions']['submit']['#value'] = $this
->t('Save');
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->messenger
->addStatus($this
->t('The Paragraphs category ordering has been saved.'));
}
}