You are here

function wingsuit_lb_form_alter in Gin Layout Builder 8.2

Implements hook_form_alter().

File

modules/wingsuit_lb/wingsuit_lb.module, line 33

Code

function wingsuit_lb_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $node = \Drupal::routeMatch()
    ->getParameter('node');
  if ($node instanceof NodeInterface && $form_id === 'node_' . $node
    ->bundle() . '_layout_builder_form') {
    $add_template_to_library_url = Url::fromRoute('section_library.add_template_to_library', [
      'section_storage_type' => 'overrides',
      'section_storage' => $node
        ->getEntityTypeId() . '.' . $node
        ->id(),
      'delta' => 1,
    ], [
      'attributes' => [
        'class' => [
          'glb-button ws-lb-button',
          'use-ajax',
        ],
        'data-dialog-type' => 'dialog',
        'data-dialog-renderer' => 'off_canvas',
      ],
    ]);
    $form['actions']['add_to_library'] = [
      '#type' => 'link',
      '#weight' => 10,
      '#url' => $add_template_to_library_url,
      '#title' => [
        '#markup' => '<div class="ws-lb-button__icon"></div>' . t('Add to library'),
      ],
      '#access' => $add_template_to_library_url
        ->access(),
    ];
    $form['actions']['submit']['#value'] = t('Save and Preview');
    $form['actions']['layout_builder_save_and_edit_layout']['#value'] = t('Save');
  }
  if (in_array($form_id, [
    'section_library_add_template_to_library',
    'section_library_add_section_to_library',
  ])) {
    $form['#after_build'][] = 'gin_lb_after_build';
    $form['#gin_lb_form'] = TRUE;
    $form['#attributes']['class'][] = 'glb-form';
  }
}