*/
protected $options = [];
+ /**
+ * The slick HTML ID.
+ *
+ * @var int
+ */
+ private static $slickId;
+
/**
* {@inheritdoc}
*/
/**
* {@inheritdoc}
*/
- public function getSetting($setting_name) {
- return isset($this->getSettings()[$setting_name]) ? $this->getSettings()[$setting_name] : NULL;
+ public function getSetting($name) {
+ return isset($this->getSettings()[$name]) ? $this->getSettings()[$name] : NULL;
}
/**
* {@inheritdoc}
*/
- public static function defaultSettings($group = 'settings') {
- return self::load('default')->options[$group];
+ public function setSetting($name, $value) {
+ $this->options['settings'][$name] = $value;
+ return $this;
}
/**
- * Overrides \Drupal\Core\Entity\Entity::create().
+ * {@inheritdoc}
*/
- public static function create(array $values = []) {
- $optionset = parent::create($values);
-
- $optionset->setSettings($optionset->getSettings());
- return $optionset;
+ public static function defaultSettings($group = 'settings') {
+ return self::load('default')->options[$group];
}
/**
* Returns the Slick responsive settings.
+ *
+ * @return array
+ * The responsive options.
*/
public function getResponsiveOptions() {
if (empty($this->breakpoints)) {
/**
* Sets the Slick responsive settings.
+ *
+ * @return $this
+ * The class instance that this method is called on.
*/
- public function setResponsiveSettings($settings, $delta = 0) {
- $this->options['responsives']['responsive'][$delta]['settings'] = $settings;
+ 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 = [];
$cleaned[$key]['breakpoint'] = $responsives[$key]['breakpoint'];
// Destroy responsive slick if so configured.
- if ($responsives[$key]['unslick']) {
+ if (!empty($responsives[$key]['unslick'])) {
$cleaned[$key]['settings'] = 'unslick';
unset($responsives[$key]['unslick']);
}
/**
* Defines the dependent options.
+ *
+ * @return array
+ * The dependent options.
*/
public static function getDependentOptions() {
$down_arrow = ['downArrowTarget', 'downArrowOffset'];
/**
* Returns the trusted HTML ID of a single slick instance.
*
+ * @return string
+ * The html ID.
+ *
* @todo: Consider Blazy::getHtmlId() instead.
*/
public static function getHtmlId($string = 'slick', $id = '') {
- $slick_id = &drupal_static('slick_id', 0);
+ if (!isset(static::$slickId)) {
+ static::$slickId = 0;
+ }
// Do not use dynamic Html::getUniqueId, otherwise broken asnavfors.
- return empty($id) ? Html::getId($string . '-' . ++$slick_id) : $id;
+ return empty($id) ? Html::getId($string . '-' . ++static::$slickId) : strip_tags($id);
}
/**
* Returns HTML or layout related settings to shut up notices.
+ *
+ * @return array
+ * The default settings.
*/
public static function htmlSettings() {
return [