You are here

GridStackVariantListBuilder.php in GridStack 8.2

File

modules/gridstack_ui/src/Controller/GridStackVariantListBuilder.php
View source
<?php

namespace Drupal\gridstack_ui\Controller;

use Drupal\Core\Entity\EntityInterface;

/**
 * Provides a listing of GridStack optionsets.
 */
class GridStackVariantListBuilder extends GridStackListBuilder {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'gridstack_variant_list_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = [
      'source' => $this
        ->t('Source'),
    ];
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['source'] = [
      '#markup' => $entity
        ->source(),
    ];
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build[] = parent::render();
    $build[0]['description'] = [
      '#markup' => '<p>' . $this
        ->t("Manage the GridStack layout variants. Add variants via Layout Builder, not here. Use this page as a convenient way to apply changes globally to all pages. Each variant may be re-used at different pages, and their change will apply globally. To have unique variant per page, simply create memorable labels, such as: <code>Twain: About</code> to apply at About page. To edit original layouts, hit <code>Source</code> under <code>Operations</code>.") . '</p>',
    ];
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    if (isset($operations['duplicate'])) {
      unset($operations['duplicate']);
    }
    $operations['edit'] = [
      'title' => $this
        ->t('Configure'),
      'url' => $entity
        ->toUrl('edit-form'),
    ];
    $operations['delete'] = [
      'title' => $this
        ->t('Delete'),
      'url' => $entity
        ->toUrl('delete-form'),
    ];
    $access = $this->currentUser
      ->hasPermission('administer gridstack');
    if ($access && ($gridstack = $entity
      ->getOptionset())) {
      $operations['source'] = [
        'title' => $this
          ->t('Source'),
        'url' => $gridstack
          ->toUrl('edit-form'),
      ];
    }
    return $operations;
  }

}

Classes

Namesort descending Description
GridStackVariantListBuilder Provides a listing of GridStack optionsets.