/** * Returns the table configuration and data in a format ready to be * processed by the _shared/table view. * * This method override for Grid also namepaces any form inputs inside * the table to nest all the inputs inside a single array for when the * form is submitted. * * @param URL $base_url URL object of the base URL used for setting * the search and sort criteria for sorting and * pagination URLs * @return array Array of view variables, structure is below */ public function viewData($base_url = NULL) { $view_data = parent::viewData($base_url); // We'll use this in our lambda functions below $grid = $this; // Namespace existing rows in Grid foreach ($view_data['data'] as &$row) { $row['columns'] = array_map(function ($field) use($grid, $row) { if (isset($row['attrs']['row_id']) && is_numeric($row['attrs']['row_id'])) { $row_id = 'row_id_' . $row['attrs']['row_id']; } elseif (!isset($row['attrs']['row_id'])) { $row_id = 'new_row_0'; } else { $row_id = $row['attrs']['row_id']; } $field_content_key = isset($field['html']) ? 'html' : 'content'; $field[$field_content_key] = $grid->namespaceForGrid($field[$field_content_key], $row_id); return $field; }, $row['columns']); // This no longer needs to be here unset($row['attrs']['row_id']); } // Make the field name available so we can set as table's ID $view_data['grid_field_name'] = $this->config['field_name']; $view_data['validation_errors'] = isset($this->config['validation_errors']) ? $this->config['validation_errors'] : array(); return $view_data; }