3 namespace Drupal\slick_ui\Controller;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityStorageInterface;
8 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Config\Entity\DraggableListBuilder;
10 use Drupal\Component\Utility\Html;
11 use Drupal\blazy\BlazyGrid;
12 use Drupal\slick\SlickManagerInterface;
13 use Symfony\Component\DependencyInjection\ContainerInterface;
16 * Provides a listing of Slick optionsets.
18 class SlickListBuilder extends DraggableListBuilder {
23 * @var \Drupal\slick\SlickManagerInterface
28 * Constructs a new SlickListBuilder object.
30 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
31 * The entity type definition.
32 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
33 * The entity storage class.
34 * @param \Drupal\slick\SlickManagerInterface $manager
37 public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, SlickManagerInterface $manager) {
38 parent::__construct($entity_type, $storage);
39 $this->manager = $manager;
45 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
48 $container->get('entity_type.manager')->getStorage($entity_type->id()),
49 $container->get('slick.manager')
56 public function getFormId() {
57 return 'slick_list_form';
63 public function buildHeader() {
65 'label' => $this->t('Optionset'),
66 'breakpoints' => $this->t('Breakpoints'),
67 'group' => $this->t('Group'),
68 'lazyload' => $this->t('Lazyload'),
69 'skin' => $this->t('Skin'),
72 return $header + parent::buildHeader();
78 public function buildRow(EntityInterface $entity) {
79 $skins = $this->manager->getSkins()['skins'];
80 $skin = $entity->getSkin();
82 $row['label'] = Html::escape($entity->label());
83 $row['breakpoints']['#markup'] = $entity->getBreakpoints();
84 $row['group']['#markup'] = $entity->getGroup() ?: $this->t('All');
85 $row['lazyload']['#markup'] = $entity->getSetting('lazyLoad') ?: $this->t('None');
88 if (isset($skins[$skin]['description'])) {
89 // No need to re-translate, as already translated at SlickSkin.php.
90 $markup .= '<br />' . Html::escape($skins[$skin]['description']);
93 $row['skin']['#markup'] = $markup;
95 return $row + parent::buildRow($entity);
101 public function getDefaultOperations(EntityInterface $entity) {
102 $operations = parent::getDefaultOperations($entity);
104 if (isset($operations['edit'])) {
105 $operations['edit']['title'] = $this->t('Configure');
108 $operations['duplicate'] = array(
109 'title' => t('Duplicate'),
111 'url' => $entity->toUrl('duplicate-form'),
114 if ($entity->id() == 'default') {
115 unset($operations['delete'], $operations['edit']);
122 * Adds some descriptive text to the slick optionsets list.
127 public function render() {
128 $manager = $this->manager;
130 $build['description'] = [
131 '#markup' => $this->t("<p>Manage the Slick optionsets. Optionsets are Config Entities.</p><p>By default, when this module is enabled, a single optionset is created from configuration. Install Slick example module to speed up by cloning them. Use the Operations column to edit, clone and delete optionsets.<br /><strong>Important!</strong> Avoid overriding Default optionset as it is meant for Default -- checking and cleaning. Use Duplicate instead. Otherwise messes are yours.<br />Slick doesn't need Slick UI to run. It is always safe to uninstall Slick UI once done with optionsets.</p>"),
134 $availaible_skins = [];
135 $skins = $manager->getSkins()['skins'];
137 foreach ($skins as $key => $skin) {
138 $name = isset($skin['name']) ? $skin['name'] : $key;
139 $group = isset($skin['group']) ? Html::escape($skin['group']) : 'None';
140 $provider = isset($skin['provider']) ? Html::escape($skin['provider']) : 'Lory';
141 $description = isset($skin['description']) ? Html::escape($skin['description']) : $this->t('No description');
143 $markup = '<h3>' . $this->t('@skin <br><small>Id: @id | Group: @group | Provider: @provider</small>', [
147 '@provider' => $provider,
150 $markup .= '<p><em>— ' . $description . '</em></p>';
152 $availaible_skins[$key] = [
153 '#markup' => '<div class="messages messages--status">' . $markup . '</div>',
157 ksort($availaible_skins);
158 $availaible_skins = ['default' => $availaible_skins['default']] + $availaible_skins;
161 $settings['grid'] = 3;
162 $settings['grid_medium'] = 2;
163 $settings['blazy'] = FALSE;
164 $settings['style'] = 'column';
166 $header = '<br><hr><h2>' . $this->t('Available skins') . '</h2>';
167 $header .= '<p>' . $this->t('Some skin works best with a specific Optionset, and vice versa. Use matching names if found. Else happy adventure!') . '</p>';
168 $build['skins_header']['#markup'] = $header;
169 $build['skins_header']['#weight'] = 20;
171 $build['skins'] = BlazyGrid::build($availaible_skins, $settings);
172 $build['skins']['#weight'] = 21;
173 $build['skins']['#attached'] = $manager->attach($settings);
174 $build['skins']['#attached']['library'][] = 'blazy/admin';
176 $build[] = parent::render();
183 public function submitForm(array &$form, FormStateInterface $form_state) {
184 parent::submitForm($form, $form_state);
186 drupal_set_message($this->t('The optionsets order has been updated.'));