You are here

class Tablefield in TableField 8.2

Same name in this branch
  1. 8.2 src/Utility/Tablefield.php \Drupal\tablefield\Utility\Tablefield
  2. 8.2 src/Element/Tablefield.php \Drupal\tablefield\Element\Tablefield

Provides helpers to use timers throughout a request.

Hierarchy

Expanded class hierarchy of Tablefield

1 string reference to 'Tablefield'
tablefield.routing.yml in ./tablefield.routing.yml
tablefield.routing.yml

File

src/Utility/Tablefield.php, line 10

Namespace

Drupal\tablefield\Utility
View source
class Tablefield {

  /**
   * Helper function to turn form elements into a structured array.
   *
   * @param array $tablefield
   *   The table as it appears in FAPI.
   */
  public static function rationalizeTable(array $tablefield) {
    $tabledata = [];

    // Rationalize the table data.
    if (!empty($tablefield)) {

      // Remove exterraneous form data.
      $count_cols = $tablefield['rebuild']['count_cols'];
      $count_rows = $tablefield['rebuild']['count_rows'];
      unset($tablefield['rebuild']);
      unset($tablefield['import']);
      foreach ($tablefield as $key => $value) {
        preg_match('/cell_(.*)_(.*)/', $key, $cell);

        // $cell[1] is row count $cell[2] is col count.
        if ((int) $cell[1] < $count_rows && (int) $cell[2] < $count_cols) {
          $tabledata[$cell[1]][$cell[2]] = $value;
        }
      }
    }
    return $tabledata;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Tablefield::rationalizeTable public static function Helper function to turn form elements into a structured array.