You are here

GridStackDefault.php in GridStack 8.2

Same filename and directory in other branches
  1. 8 src/GridStackDefault.php

Namespace

Drupal\gridstack

File

src/GridStackDefault.php
View source
<?php

namespace Drupal\gridstack;

use Drupal\blazy\BlazyDefault;

/**
 * Defines shared plugin default settings for field formatter and Views style.
 *
 * @see FormatterBase::defaultSettings()
 * @see StylePluginBase::defineOptions()
 *
 * @todo move style stuffs into plugins.
 */
class GridStackDefault extends BlazyDefault {

  /**
   * Defines root level.
   */
  const LEVEL_ROOT = 0;

  /**
   * Defines root item level.
   */
  const LEVEL_ROOT_ITEM = 1;

  /**
   * Defines nested level.
   */
  const LEVEL_NESTED = 2;

  /**
   * Defines nested item level.
   */
  const LEVEL_NESTED_ITEM = 3;

  /**
   * Defines dummy root selector.
   */
  const ROOT = ':root';

  /**
   * Defines dummy nested selector.
   */
  const NESTED = ':nested';

  /**
   * Defines a container.
   */
  const CONTAINER = 'Container';

  /**
   * Defines a region.
   */
  const REGION = 'Region';

  /**
   * Returns common settings across plugins.
   */
  public static function commonSettings() {
    return [
      'gridnative' => FALSE,
      'skin' => '',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function baseSettings() {
    return [
      'optionset' => 'default',
      'vanilla' => FALSE,
    ] + self::commonSettings() + parent::baseSettings();
  }

  /**
   * {@inheritdoc}
   */
  public static function imageSettings() {
    return [
      'background' => TRUE,
      'category' => '',
      'stamp' => '',
      'stamp_index' => 0,
    ] + parent::imageSettings() + self::baseSettings();
  }

  /**
   * {@inheritdoc}
   */
  public static function extendedSettings() {
    return self::imageSettings() + parent::extendedSettings();
  }

  /**
   * Returns view fields options for Views UI.
   */
  public static function viewFieldOptions() {
    return [
      'captions',
      'layouts',
      'images',
      'links',
      'titles',
      'classes',
      'overlays',
    ];
  }

  /**
   * Returns fixed settings not configurable via UI.
   */
  public static function fixedSettings() {
    return [
      'item_id' => 'box',
      'nameshort' => 'gs',
      'namespace' => 'gridstack',
      'ratio' => '',
      'blazy' => TRUE,
      'lazy' => 'blazy',
    ];
  }

  /**
   * Returns shared global form settings which should be consumed at formatters.
   */
  public static function cleanUiSettings() {
    return [
      'debug' => FALSE,
      'dev' => FALSE,
      'framework' => '',
      'no_classes' => FALSE,
      'library' => '',
      'optimized' => FALSE,
      'html5_ac' => FALSE,
      'gridstatic' => FALSE,
    ];
  }

  /**
   * Returns shared global form settings which should be consumed at formatters.
   */
  public static function uiSettings() {
    return [
      'animationless' => FALSE,
      'editor_pos' => '',
      'excludes' => '',
      'fw_classes' => '',
      'helpless' => FALSE,
      'palettes' => '',
      'palettes_pos' => '',
      'skinless' => FALSE,
    ] + self::cleanUiSettings();
  }

  /**
   * Returns style settings.
   */
  public static function styleSettings() {
    return [
      'responsive_image_style' => '',
      'alpha' => '',
      'opacity' => '',
      'animations' => [],
      'colors' => [],
      'extras' => [],
    ];
  }

  /**
   * Returns background color settings.
   */
  public static function rangeElements() {

    // @todo height sm-height md-height lg-height
    return [
      'opacity',
      'alpha',
    ];
  }

  /**
   * Returns background color settings.
   */
  public static function bgElements() {
    return array_merge(self::rangeElements(), [
      'rgba',
      'bg',
    ]);
  }

  /**
   * Returns color settings.
   */
  public static function textElements() {
    return [
      'text',
      'a',
      'a:hover',
      'h2',
      'h3',
    ];
  }

  /**
   * Returns color settings.
   */
  public static function colorElements() {
    return array_merge([
      'rgba',
      'bg',
    ], self::textElements());
  }

  /**
   * Returns style settings.
   */
  public static function styleElements() {
    return array_merge(self::bgElements(), self::textElements());
  }

  /**
   * Returns the region layout settings.
   */
  public static function regionSettings() {
    return [
      'attributes' => '',
      'styles' => [],
      'target_id' => '',
      'wrapper' => '',
      'wrapper_classes' => '',
      'row_classes' => '',
      '_fullwidth' => FALSE,
    ];
  }

  /**
   * Returns the main layout settings.
   */
  public static function layoutSettings() {
    return [
      'current_selection' => '',
      'regions' => [],
      'field_name' => '',
      'gid' => '',
      'metadata' => '',
      'vid' => '',
      'vm' => '',
    ] + self::commonSettings() + self::regionSettings();
  }

  /**
   * Returns the main wrapper Layout Builder select options.
   */
  public static function mainWrapperOptions() {
    return [
      'article' => 'Article',
      'aside' => 'Aside',
      'main' => 'Main',
      'footer' => 'Footer',
      'section' => 'Section',
    ];
  }

  /**
   * Returns wrapper Layout Builder select options.
   */
  public static function regionWrapperOptions() {
    return self::mainWrapperOptions() + [
      'figure' => 'Figure',
      'header' => 'Header',
    ];
  }

  /**
   * Returns HTML or layout related settings, none of JS to shutup notices.
   */
  public static function htmlSettings() {
    return [
      '_lb' => FALSE,
      '_lbux' => FALSE,
      '_panels' => FALSE,
      '_ipe' => FALSE,
      'column' => 12,
      'contentless' => FALSE,
      'debug' => FALSE,
      'ungridstack' => FALSE,
      'id' => '',
      'lightbox' => '',
      'nested' => FALSE,
      'rid' => NULL,
      'root' => TRUE,
      '_root' => 'grids',
      'use_framework' => FALSE,
      'use_js' => TRUE,
      'use_inner' => TRUE,
      'view_name' => '',
    ] + self::commonSettings() + self::imageSettings() + self::fixedSettings();
  }

  /**
   * Returns breakpoints.
   */
  public static function breakpoints() {
    return [
      'xs' => 'xsmall',
      'sm' => 'small',
      'md' => 'medium',
      'lg' => 'large',
      'xl' => 'xlarge',
    ];
  }

  /**
   * Returns region ID.
   */
  public static function regionId($id) {
    return 'gridstack_' . $id;
  }

  /**
   * Returns variant wrapper AJAX ID.
   */
  public static function variantWrapperId($id) {
    return 'gridstack-variant-wrapper-' . str_replace([
      '_',
      ':',
    ], '-', $id);
  }

  /**
   * Returns gridstack random id related to the each layout.
   */
  public static function gid($id) {
    return str_replace([
      '-',
      ':',
    ], '_', $id);
  }

  /**
   * Returns gridstack layout id.
   */
  public static function layoutId($id) {
    return 'gridstack_' . $id;
  }

  /**
   * Returns theme properties.
   */
  public static function themeProperties() {
    return [
      'items',
      'optionset',
      'aside',
      'bottom',
      'preface',
      'postscript',
      'settings',
      'content_attributes',
      'wrapper_attributes',
    ];
  }

}

Classes

Namesort descending Description
GridStackDefault Defines shared plugin default settings for field formatter and Views style.