ExpressionEngine® User Guide

Legacy Documentation

You are using the documentation for version 4.3.8. Go here for the latest version.

Grid Fieldtype Extension Hooks

grid_query

grid_query($entry_ids, $field_id, $content_type, $data_table, $sql)

Allows developers to modify and run the query that gathers Grid row data for both the publish form and the front-end tag rendering.

How it’s called:

if (ee()->extensions->active_hook('grid_query') === TRUE)
{
  $rows = ee()->extensions->call(
    'grid_query',
    $entry_ids,
    $field_id,
    $content_type,
    $this->_data_table($content_type, $field_id),
    ee()->db->_compile_select(FALSE, FALSE)
  );
}
else
{
  $rows = ee()->db->get(
    $this->_data_table($content_type, $field_id)
  )->result_array();
}
Parameters:
  • $entry_ids (int) – Entry IDs to gather data for.
  • $field_id (int) – Field ID of field currently being queried.
  • $content_type (string) – The name of the content type this Grid field lives in, such as ‘channel’.
  • $data_table (string) – Name of the table to query the data from.
  • $sql (string) – Compiled SQL about to be run to gather Grid row data.
Returns:

Result Array of query result.

Return type:

Array

New in version 2.7.0.

grid_save

grid_save($entry_id, $field_id, $content_type, $data_table, $data)

Allows developers to modify or add to the Grid data array before saving.

How it’s called:

$data = ee()->extensions->call(
  'grid_save',
  $entry_id,
  $field_id,
  $content_type,
  $table_name,
  $data
);
Parameters:
  • $entry_id (int) – Entry ID of entry being saved.
  • $field_id (int) – Field ID of field being saved.
  • $content_type (string) – The name of the content type this Grid field lives in, such as ‘channel’.
  • $data_table (string) – Name of the Grid data table to modify.
  • $data (array) – Array of data with keys for new_rows, updated_rows and deleted_rows.
Returns:

Array of data with aforementioned keys intact.

Return type:

Array

New in version 2.7.0.