You are here

private function QuickTabsInstanceEditForm::getRow in Quick Tabs 8.3

Builds and returns instance row.

1 call to QuickTabsInstanceEditForm::getRow()
QuickTabsInstanceEditForm::getConfigurationDataForm in src/Form/QuickTabsInstanceEditForm.php
Returns configuration data form.

File

src/Form/QuickTabsInstanceEditForm.php, line 341

Class

QuickTabsInstanceEditForm
Class QuickTabsInstanceEditForm.

Namespace

Drupal\quicktabs\Form

Code

private function getRow($row_number, $tab = NULL) {
  if ($tab === NULL) {
    $tab = [];
  }
  $type = $this->tabTypeManager;
  $plugin_definitions = $type
    ->getDefinitions();
  $types = [];
  foreach ($plugin_definitions as $index => $def) {
    $name = $def['name'];
    $types[$index] = $name
      ->render();
  }
  ksort($types);
  $row = [];

  // TableDrag: Mark the table row as draggable.
  $row['#attributes']['class'][] = 'draggable';

  // TableDrag: Sort the table row according to its configured weight.
  $row['#weight'] = isset($tab['weight']) ? $tab['weight'] : 0;
  $row['title'] = [
    '#type' => 'textfield',
    '#size' => '10',
    '#default_value' => isset($tab['title']) ? $tab['title'] : '',
  ];

  // TableDrag: Weight column element.
  $row['weight'] = [
    '#type' => 'weight',
    '#title' => $this
      ->t('Weight'),
    '#title_display' => 'invisible',
    '#default_value' => isset($tab['weight']) ? $tab['weight'] : 0,
    // Classify the weight element for #tabledrag.
    '#attributes' => [
      'class' => [
        'mytable-order-weight',
      ],
    ],
  ];
  $row['type'] = [
    '#type' => 'select',
    '#options' => $types,
    '#default_value' => isset($tab['type']) ? $tab['type'] : key($types),
  ];
  foreach ($plugin_definitions as $index => $def) {
    $name = $def['name'];
    $row['content'][$index] = [
      '#prefix' => '<div class="' . $index . '-plugin-content plugin-content qt-tab-options-form qt-tab-' . $index . '-options-form" >',
      '#suffix' => '</div>',
    ];
    $object = $type
      ->createInstance($index);
    $row['content'][$index]['options'] = $object
      ->optionsForm($tab);
  }

  // There are two functions attached to the remove button.
  // The submit function will be called first and used to remove selected row.
  // The callback function will then return the rendered rows.
  $row['operations'] = [
    '#row_number' => $row_number,
    // We need this - the call to getTriggeringElement when clicking the
    // remove button won't work without it.
    '#name' => 'row-' . $row_number,
    '#type' => 'submit',
    '#value' => $this
      ->t('Remove'),
    '#attributes' => [
      'class' => [
        'delete-tab',
      ],
      'title' => $this
        ->t('Click here to delete this tab.'),
    ],
    '#submit' => [
      [
        $this,
        'ajaxFormSubmit',
      ],
    ],
    '#ajax' => [
      'callback' => [
        $this,
        'ajaxFormCallback',
      ],
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'effect' => 'fade',
    ],
  ];
  return $row;
}