You are here

public function GridStackVariantSelectionForm::editVariant in GridStack 8.2

Handles switching the available variants based on the selected one.

File

modules/gridstack_ui/src/Form/GridStackVariantSelectionForm.php, line 248

Class

GridStackVariantSelectionForm
Provides variant selection form.

Namespace

Drupal\gridstack_ui\Form

Code

public function editVariant(array &$form, FormStateInterface $form_state) {
  $element = $form['container'];
  $settings = $form['vid']['#settings'];
  $vid = $settings['vid'] = $form_state
    ->getValue('vid');
  if ($vid && GridStackVariant::load($vid)) {
    $links = $this->manager
      ->stylizer()
      ->builder()
      ->getVariantLinks($settings, $this->optionset, TRUE);
    if (!empty($links['edit'])) {
      $element['edit'] = $links['edit'];

      // Cannot use #access for this.
      $classes = $element['delete']['#attributes']['class'];
      $classes = array_diff($classes, [
        'visually-hidden',
      ]);
      $element['delete']['#attributes']['class'] = $classes;
    }
  }
  else {
    $element['back'] = [];
  }
  return $element;
}