You are here

public function GridStackVariantFormController::add in GridStack 8.2

Adds a gridstack variant.

1 string reference to 'GridStackVariantFormController::add'
gridstack_ui.routing.yml in modules/gridstack_ui/gridstack_ui.routing.yml
modules/gridstack_ui/gridstack_ui.routing.yml

File

modules/gridstack_ui/src/Controller/GridStackVariantFormController.php, line 46

Class

GridStackVariantFormController
Provides controller to load GridStackVariantForm.

Namespace

Drupal\gridstack_ui\Controller

Code

public function add($gridstack, $gid, $gridstack_variant) {
  $name = str_replace([
    '-',
  ], '_', $gridstack_variant);
  $entity = GridStackVariant::load($name);
  if (empty($entity)) {
    $values = $gridstack
      ->toArray();
    $options = $values['options'];
    $options['icon'] = 'public://gridstack/' . $name . '.png';
    $entity = GridStackVariant::create([
      'name' => $name,
      'label' => str_replace([
        '-',
        '_',
      ], ' ', $gridstack_variant),
      'options' => $options,
      'source' => $gridstack
        ->id(),
    ]);
    $entity
      ->set('id', $name);
    $entity
      ->save();
  }
  return $this
    ->edit($gridstack, $gid, $entity);
}