You are here

public function IsotopeController::demo in Isotope (with Masonry and Packery) 8

Returns a demo page

@TODO: This should be in an example sub-module.

Return value

array A #type 'page' render array containing the block region demo.

1 string reference to 'IsotopeController::demo'
isotope.routing.yml in ./isotope.routing.yml
isotope.routing.yml

File

src/Controller/IsotopeController.php, line 131
Contains \Drupal\isotope\Controller\IsotopeController.

Class

IsotopeController
Controller routines for admin block routes.

Namespace

Drupal\isotope\Controller

Code

public function demo() {
  $render[] = [
    '#markup' => $this
      ->t('<p>You can explore this example for yourself at <strong>___</strong>.</p>'),
  ];

  // The label can be anything, including images, etc. Filtering happens on the
  // key.
  $colors = [
    'blue' => 'Blue',
    'red' => '<span class="thisIsCustomisedLabel">Red</span>',
    'yellow' => 'Yellow',
  ];
  $render[] = [
    '#theme' => 'isotope_filter',
    '#items' => $colors,
    // Optional filter_name: unique to distinguish it from the other filters on
    // the page.
    '#filter_name' => 'color',
    // Optional filter_title: displayed as a list title.
    '#filter_title' => $this
      ->t('Colour'),
  ];
  $sizes = [
    'small' => 'Small',
    'wide' => 'Wide',
    'big' => 'Big',
    'tall' => 'Tall',
  ];
  $render[] = [
    '#theme' => 'isotope_filter',
    '#items' => $sizes,
    '#filter_name' => 'size',
    '#filter_title' => $this
      ->t('Size'),
  ];
  $shapes = [
    'round' => 'Round',
    // Transliterate non-latin characters.
    'square (naïve jalapeño pâté)' => 'Square',
  ];
  $render[] = [
    '#theme' => 'isotope_filter',
    '#items' => $shapes,
    '#filter_name' => 'shape',
    '#filter_title' => $this
      ->t('Shapes'),
    '#instance' => 1,
  ];
  $sorts = [
    'Size' => 'size',
    'shape',
    'color',
    [
      'color',
      'size',
    ],
    'Color then Shape' => [
      'color',
      'shape',
    ],
  ];
  $render[] = [
    '#theme' => 'isotope_sorter',
    '#sorts' => $sorts,
    '#default_label' => $this
      ->t('Original'),
    '#instance' => 1,
  ];

  // Create items of every size shape and color.
  $items = [];
  foreach ($sizes as $size => $label1) {
    foreach ($shapes as $shape => $label2) {
      foreach ($colors as $color => $label3) {
        $items[] = [
          'value' => '<p>Item</p>',
          'data' => [
            'size' => $size,
            'shape' => $shape,
            'color' => $color,
          ],
        ];
      }
    }
  }
  $render['grid'] = [
    '#theme' => 'isotope_grid',
    '#items' => $items,
    '#instance' => 1,
    '#attached' => [
      'library' => [
        'isotope/isotope-example',
      ],
    ],
  ];
  return $render;
}