You are here

ElevateZoomPlus.php in ElevateZoom Plus 7

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

File

src/Entity/ElevateZoomPlus.php
View source
<?php

namespace Drupal\elevatezoomplus\Entity;

use Drupal\slick\Entity\SlickBase;

/**
 * Defines the ElevateZoomPlus configuration entity.
 */
class ElevateZoomPlus extends SlickBase implements ElevateZoomPlusInterface {

  /**
   * Defines elevatezoomplus table name.
   */
  const TABLE = 'elevatezoomplus_optionset';

  /**
   * {@inheritdoc}
   */
  public static function create(array $values = []) {
    ctools_include('export');
    $optionset = ctools_export_crud_new(static::TABLE);
    $optionset->options = $optionset->options['settings'] = [];
    foreach (self::defaultProperties() as $key => $ignore) {
      if (isset($values[$key])) {
        $optionset->{$key} = $values[$key];
      }
    }
    if (empty($values['label']) && isset($values['name'])) {
      $optionset->label = $values['name'];
    }
    $defaults['settings'] = self::defaultSettings();
    $optionset->options = $optionset->options + $defaults;
    return $optionset;
  }

  /**
   * Returns the typecast values.
   *
   * @param array $settings
   *   An array of Optionset settings.
   */
  public static function typecast(array &$settings = []) {
    if (empty($settings)) {
      return;
    }
    $defaults = self::defaultSettings();
    foreach ($defaults as $name => $value) {
      if (isset($settings[$name])) {

        // Seems double is ignored, and causes a missing schema, unlike float.
        $type = gettype($defaults[$name]);
        $type = $type == 'double' ? 'float' : $type;

        // Change float to integer if value is no longer float.
        if ($name == 'lensOpacity' || $name == 'tintOpacity') {
          $type = $settings[$name] == '0' || $settings[$name] == '1' ? 'integer' : 'float';
        }
        settype($settings[$name], $type);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    if (!isset(static::$defaultSettings)) {
      static::$defaultSettings = [
        'responsive' => FALSE,
        'zoomType' => 'window',
        'zoomWindowWidth' => 400,
        'zoomWindowHeight' => 400,
        'zoomWindowOffsetX' => 0,
        'zoomWindowOffsetY' => 0,
        'zoomWindowPosition' => '1',
        'zoomWindowFadeIn' => FALSE,
        'zoomWindowFadeOut' => FALSE,
        'zoomTintFadeIn' => FALSE,
        'zoomTintFadeOut' => FALSE,
        'scrollZoom' => FALSE,
        'easing' => FALSE,
        'easingType' => 'zoomdefault',
        'easingDuration' => 2000,
        'borderSize' => 4,
        'borderColour' => '#888',
        'showLens' => TRUE,
        'containLensZoom' => FALSE,
        'lensBorder' => 1,
        'lensShape' => 'square',
        'lensSize' => 200,
        'lensFadeIn' => FALSE,
        'lensFadeOut' => FALSE,
        'lensColour' => 'white',
        'lensOpacity' => 0.4,
        'lenszoom' => FALSE,
        'tint' => FALSE,
        'tintColour' => '#333',
        'tintOpacity' => 0.4,
        'constrainType' => '',
        'constrainSize' => '',
        'imageCrossfade' => FALSE,
        'cursor' => 'default',
        'loadingIcon' => '',
      ];
    }
    return static::$defaultSettings;
  }

}

Classes

Namesort descending Description
ElevateZoomPlus Defines the ElevateZoomPlus configuration entity.