You are here

Variant.php in GridStack 8.2

File

src/Plugin/gridstack/engine/Variant.php
View source
<?php

namespace Drupal\gridstack\Plugin\gridstack\engine;

use Drupal\gridstack\GridStackEnginePluginBase;
use Drupal\gridstack\Entity\GridStackVariant;

/**
 * Provides a shadow variant layout engine.
 *
 * @GridStackEngine(
 *   id = "variant",
 *   group = "gridstack",
 *   hidden = "true",
 *   version = "2",
 *   label = @Translation("Variant engine")
 * )
 */
class Variant extends GridStackEnginePluginBase {

  /**
   * Allows layout variants to override the original optionset.
   */
  public function override(&$optionset, array &$settings) {
    $variant = NULL;
    if (isset($settings['vid']) && ($vid = $settings['vid'])) {
      $variant = GridStackVariant::load($vid);
      if ($variant && ($breakpoints = $variant
        ->getBreakpoints())) {
        $optionset
          ->setOptions([
          'breakpoints' => $breakpoints,
        ]);
        $settings['_variant'] = $variant
          ->label();
      }
    }
    return $variant;
  }

}

Classes

Namesort descending Description
Variant Provides a shadow variant layout engine.