class Slick in Slick Carousel 7.3
Same name and namespace in other branches
- 8.2 src/Entity/Slick.php \Drupal\slick\Entity\Slick
- 8 src/Entity/Slick.php \Drupal\slick\Entity\Slick
Defines the Slick configuration entity.
Hierarchy
- class \Drupal\slick\Entity\SlickBase implements SlickBaseInterface
- class \Drupal\slick\Entity\Slick implements SlickInterface
Expanded class hierarchy of Slick
10 files declare their use of Slick
- slick.api.php in ./
slick.api.php - Hooks and API provided by the Slick module.
- slick.deprecated.inc in ./
slick.deprecated.inc - To be removed once Slick views, etc. have 3.x, or before Slick full release.
- slick.install in ./
slick.install - Installation actions for Slick.
- slick.module in ./
slick.module - Slick carousel integration, the last carousel you'll ever need.
- slick.slick_optionset.inc in ./
slick.slick_optionset.inc - Slick default optionset API include file.
2 string references to 'Slick'
- SlickCrudTest::getInfo in tests/
SlickCrudTest.test - Provides info for the UI.
- SlickLibrary::library in src/
SlickLibrary.php - Implements hook_library_info_build().
File
- src/
Entity/ Slick.php, line 8
Namespace
Drupal\slick\EntityView source
class Slick extends SlickBase implements SlickInterface {
/**
* The optionset group for easy selections.
*
* @var string
*/
public $collection = '';
/**
* The skin name for the optionset.
*
* @var string
*/
public $skin = '';
/**
* The number of breakpoints for the optionset.
*
* @var int
*/
public $breakpoints = 0;
/**
* The flag indicating to optimize the stored options by removing defaults.
*
* @var bool
*/
public $optimized = 0;
/**
* {@inheritdoc}
*/
public function getSkin() {
return $this->skin;
}
/**
* {@inheritdoc}
*/
public function getBreakpoints() {
return $this->breakpoints;
}
/**
* {@inheritdoc}
*/
public function getCollection() {
return $this->collection;
}
/**
* {@inheritdoc}
*/
public function optimized() {
return $this->optimized;
}
/**
* 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 == 'edgeFriction') {
$type = $settings[$name] == '1' ? 'integer' : 'float';
}
settype($settings[$name], $type);
}
}
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
if (!isset(static::$defaultSettings)) {
static::$defaultSettings = [
'mobileFirst' => FALSE,
'asNavFor' => '',
'accessibility' => TRUE,
'adaptiveHeight' => FALSE,
'autoplay' => FALSE,
'autoplaySpeed' => 3000,
'pauseOnHover' => TRUE,
'pauseOnDotsHover' => FALSE,
'arrows' => TRUE,
'prevArrow' => 'Previous',
'nextArrow' => 'Next',
'downArrow' => FALSE,
'downArrowTarget' => '',
'downArrowOffset' => 0,
'centerMode' => FALSE,
'centerPadding' => '50px',
'dots' => FALSE,
'dotsClass' => 'slick-dots',
'appendDots' => '$(element)',
'draggable' => TRUE,
'fade' => FALSE,
'focusOnSelect' => FALSE,
'infinite' => TRUE,
'initialSlide' => 0,
'lazyLoad' => 'ondemand',
'mouseWheel' => FALSE,
'randomize' => FALSE,
'respondTo' => 'window',
'rows' => 1,
'slidesPerRow' => 1,
'slide' => '',
'slidesToShow' => 1,
'slidesToScroll' => 1,
'speed' => 500,
'swipe' => TRUE,
'swipeToSlide' => FALSE,
'edgeFriction' => 0.35,
'touchMove' => TRUE,
'touchThreshold' => 5,
'useCSS' => TRUE,
'cssEase' => 'ease',
'cssEaseBezier' => '',
'cssEaseOverride' => '',
'useTransform' => TRUE,
'easing' => 'linear',
'variableWidth' => FALSE,
'vertical' => FALSE,
'verticalSwiping' => FALSE,
'waitForAnimate' => TRUE,
];
}
return static::$defaultSettings;
}
/**
* Returns default database field property values.
*
* @return mixed[]
* An array of property values, keyed by property name.
*/
public static function defaultProperties() {
return parent::defaultProperties() + [
'breakpoints' => 0,
'collection' => '',
'optimized' => 0,
'skin' => '',
];
}
/**
* Returns the Slick responsive settings.
*
* @return array
* The responsive options.
*/
public function getResponsiveOptions() {
if (empty($this->breakpoints)) {
return FALSE;
}
$options = [];
if (isset($this->options['responsives']['responsive'])) {
$responsives = $this->options['responsives'];
if ($responsives['responsive']) {
foreach ($responsives['responsive'] as $delta => $responsive) {
if (empty($responsives['responsive'][$delta]['breakpoint'])) {
unset($responsives['responsive'][$delta]);
}
if (isset($responsives['responsive'][$delta])) {
$options[$delta] = $responsive;
}
}
}
}
return $options;
}
/**
* Sets the Slick responsive settings.
*
* @return $this
* The class instance that this method is called on.
*/
public function setResponsiveSettings($values, $delta = 0, $key = 'settings') {
$this->options['responsives']['responsive'][$delta][$key] = $values;
return $this;
}
/**
* Strip out options containing default values so to have real clean JSON.
*
* @return array
* The cleaned out settings.
*/
public function removeDefaultValues(array $js) {
$config = [];
$defaults = self::defaultSettings();
// Remove wasted dependent options if disabled, empty or not.
if (!$this->optimized) {
$this
->removeWastedDependentOptions($js);
}
$config = array_diff_assoc($js, $defaults);
// Remove empty lazyLoad, or left to default ondemand, to avoid JS error.
if (empty($config['lazyLoad'])) {
unset($config['lazyLoad']);
}
// Do not pass arrows HTML to JSON object as some are enforced.
$excludes = [
'downArrow',
'downArrowTarget',
'downArrowOffset',
'prevArrow',
'nextArrow',
];
foreach ($excludes as $key) {
unset($config[$key]);
}
// Clean up responsive options if similar to defaults.
if ($responsives = $this
->getResponsiveOptions()) {
$cleaned = [];
foreach ($responsives as $key => $responsive) {
$cleaned[$key]['breakpoint'] = $responsives[$key]['breakpoint'];
// Destroy responsive slick if so configured.
if (!empty($responsives[$key]['unslick'])) {
$cleaned[$key]['settings'] = 'unslick';
unset($responsives[$key]['unslick']);
}
else {
// Remove wasted dependent options if disabled, empty or not.
if (!$this->optimized) {
$this
->removeWastedDependentOptions($responsives[$key]['settings']);
}
$cleaned[$key]['settings'] = array_diff_assoc($responsives[$key]['settings'], $defaults);
}
}
$config['responsive'] = $cleaned;
}
return $config;
}
/**
* Removes wasted dependent options, even if not empty.
*/
public function removeWastedDependentOptions(array &$js) {
foreach (self::getDependentOptions() as $key => $option) {
if (isset($js[$key]) && empty($js[$key])) {
foreach ($option as $dependent) {
unset($js[$dependent]);
}
}
}
if (!empty($js['useCSS']) && !empty($js['cssEaseBezier'])) {
$js['cssEase'] = $js['cssEaseBezier'];
}
unset($js['cssEaseOverride'], $js['cssEaseBezier']);
}
/**
* Defines the dependent options.
*
* @return array
* The dependent options.
*/
public static function getDependentOptions() {
$down_arrow = [
'downArrowTarget',
'downArrowOffset',
];
return [
'arrows' => [
'prevArrow',
'nextArrow',
'downArrow',
] + $down_arrow,
'downArrow' => $down_arrow,
'autoplay' => [
'pauseOnHover',
'pauseOnDotsHover',
'autoplaySpeed',
],
'centerMode' => [
'centerPadding',
],
'dots' => [
'dotsClass',
'appendDots',
],
'swipe' => [
'swipeToSlide',
],
'useCSS' => [
'cssEase',
'cssEaseBezier',
'cssEaseOverride',
],
'vertical' => [
'verticalSwiping',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Slick:: |
public | property | The number of breakpoints for the optionset. | |
Slick:: |
public | property | The optionset group for easy selections. | |
Slick:: |
public | property | The flag indicating to optimize the stored options by removing defaults. | |
Slick:: |
public | property | The skin name for the optionset. | |
Slick:: |
public static | function |
Returns default database field property values. Overrides SlickBase:: |
|
Slick:: |
public static | function |
Returns available slick default options under group 'settings'. Overrides SlickBase:: |
|
Slick:: |
public | function |
Returns the number of breakpoints. Overrides SlickInterface:: |
|
Slick:: |
public | function |
Returns the group this optioset instance belongs to for easy selections. Overrides SlickInterface:: |
|
Slick:: |
public static | function | Defines the dependent options. | |
Slick:: |
public | function | Returns the Slick responsive settings. | |
Slick:: |
public | function |
Returns the Slick skin. Overrides SlickInterface:: |
|
Slick:: |
public | function |
Returns whether to optimize the stored options, or not. Overrides SlickInterface:: |
|
Slick:: |
public | function | Strip out options containing default values so to have real clean JSON. | |
Slick:: |
public | function | Removes wasted dependent options, even if not empty. | |
Slick:: |
public | function | Sets the Slick responsive settings. | |
Slick:: |
public static | function |
Returns the typecast values. Overrides SlickBase:: |
|
SlickBase:: |
protected static | property | The plugin default settings. | 1 |
SlickBase:: |
public | property | The human-readable name for the optionset. | |
SlickBase:: |
public | property | The legacy CTools ID for the configurable optionset. | |
SlickBase:: |
public | property | The plugin instance options. | |
SlickBase:: |
public static | function |
Returns a new optionset object without saving it to the database. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function | Deletes the optionset from database. | |
SlickBase:: |
public static | function |
Checks whether an optionset with the given name already exists. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function |
Returns the Slick options by group, or property. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function |
Returns the value of a slick setting. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function |
Returns the array of slick settings. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function | Overrides Drupal\Core\Entity\Entity::id(). | |
SlickBase:: |
public | function | The slick label. | |
SlickBase:: |
public static | function |
Returns the given optionset object identified by $id. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public static | function |
Fetches all optionsets from the storage. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public static | function | Load the optionset with a fallback. | |
SlickBase:: |
public | function | Saves the optionset to database. | |
SlickBase:: |
public | function |
Sets the value of a slick setting. Overrides SlickBaseInterface:: |
|
SlickBase:: |
public | function |
Sets the array of slick settings. Overrides SlickBaseInterface:: |
|
SlickBase:: |
constant | Defines slick table name. | ||
SlickBase:: |
public | function | Returns an array of all property values. |