You are here

public function GridStackVariantFormController::edit in GridStack 8.2

Returns the variant editor.

2 calls to GridStackVariantFormController::edit()
GridStackVariantFormController::add in modules/gridstack_ui/src/Controller/GridStackVariantFormController.php
Adds a gridstack variant.
GridStackVariantFormController::duplicate in modules/gridstack_ui/src/Controller/GridStackVariantFormController.php
Duplicates a gridstack variant.
1 string reference to 'GridStackVariantFormController::edit'
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 109

Class

GridStackVariantFormController
Provides controller to load GridStackVariantForm.

Namespace

Drupal\gridstack_ui\Controller

Code

public function edit($gridstack, $gid, $gridstack_variant) {
  $name = $this->request->query
    ->get('dup', NULL);
  $label = $this->request->query
    ->get('label', NULL);
  if ($name) {
    $values = $gridstack_variant
      ->toArray();
    $options = $values['options'];
    $options['icon'] = 'public://gridstack/' . $name . '.png';
    $entity = GridStackVariant::load($name);
    if (empty($entity)) {
      $entity = GridStackVariant::create([
        'name' => $name,
        'label' => $label ?: str_replace([
          '-',
          '_',
        ], ' ', $name),
        'options' => $options,
        'source' => $gridstack
          ->id(),
      ]);
      $entity
        ->set('id', $name);
      $entity
        ->save();
    }
    $gridstack_variant = $entity;
  }
  $form = $this
    ->entityFormBuilder()
    ->getForm($gridstack_variant, 'edit') ?: [];
  $response = new AjaxResponse();
  $response
    ->addCommand(new HtmlCommand('#' . GridStackDefault::variantWrapperId($gid), $form));
  return $response;
}