GridStackVariant.php in GridStack 8.2
File
src/Entity/GridStackVariant.php
View source
<?php
namespace Drupal\gridstack\Entity;
use Drupal\Core\Url;
class GridStackVariant extends GridStack implements GridStackVariantInterface {
protected $source;
public static function load($id = '') {
return $id == 'default' ? GridStack::load('default') : parent::load($id);
}
public function source() {
return $this->source;
}
public function setSource($source) {
$this->source = $source;
return $this;
}
public function getOptionset($default = 'default', $custom = FALSE) {
$source = $this->source ? $this->source : $default;
return GridStack::loadWithFallback($custom ? $default : $source);
}
public function getOption($group, $default = NULL) {
if ($gridstack = $this
->getOptionset()) {
if ($group == 'use_framework') {
return $gridstack
->getOption($group, $default);
}
}
return parent::getOption($group, $default);
}
public static function defaultSettings() {
$default = $this
->getOptionset('default', TRUE);
return $default ? $default
->getOptions('settings') : [];
}
public function createDuplicateVariant($id, $label, array $options = []) {
$duplicate = $this
->createDuplicate();
$duplicate
->set('id', $id);
$duplicate
->set('name', $id);
$duplicate
->set('label', $label);
$duplicate
->set('options', $options);
return $duplicate;
}
public function toUrl($rel = 'edit-form', array $options = []) {
$uri = NULL;
$parameters = [];
if ($rel === 'add-form' || $rel === 'duplicate-form') {
$parameters['gridstack'] = $this
->getOptionset()
->id();
if ($rel === 'add-form') {
$uri = new Url("entity.gridstack_variant.add_form", $parameters);
}
else {
$uri = new Url("entity.gridstack_variant.duplicate_form", $parameters);
}
}
if ($rel === 'edit-form' || $rel === 'delete-form') {
$parameters['gridstack'] = $this
->getOptionset()
->id();
$parameters['gridstack_variant'] = $this
->id();
if ($rel === 'edit-form') {
$uri = new Url("entity.gridstack_variant.edit_form", $parameters);
}
else {
$uri = new Url("entity.gridstack_variant.delete_form", $parameters);
}
}
if ($uri) {
$options += [
'language' => NULL,
'entity_type' => 'gridstack_variant',
'entity' => $this,
];
$uri
->setOptions($options);
return $uri;
}
return parent::toUrl($rel, $options);
}
}