You are here

WebformTable.php in Webform 6.x

Same filename in this branch
  1. 6.x src/Element/WebformTable.php
  2. 6.x src/Plugin/WebformElement/WebformTable.php
Same filename and directory in other branches
  1. 8.5 src/Element/WebformTable.php

File

src/Element/WebformTable.php
View source
<?php

namespace Drupal\webform\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Table;

/**
 * Provides a render element for webform table.
 *
 * @FormElement("webform_table")
 */
class WebformTable extends Table {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return parent::getInfo() + [
      '#theme_wrappers' => [
        'form_element',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function processTable(&$element, FormStateInterface $form_state, &$complete_form) {

    // @see \Drupal\Core\Render\Element\Table::getInfo
    $element['#input'] = TRUE;
    $element['#tableselect'] = FALSE;
    $element['#tabledrag'] = FALSE;
    $element['#tree'] = FALSE;

    // Add .webform-table class to the table element.
    $element['#attributes']['class'][] = 'webform-table';

    // Remove 'for' attribute from form wrapper's label.
    $element['#label_attributes']['webform-remove-for-attribute'] = TRUE;

    // Add webform table CSS.
    $element['#attached']['library'][] = 'webform/webform.element.table';
    return $element;
  }

}

Classes

Namesort descending Description
WebformTable Provides a render element for webform table.