/** * Gather the data needed to process all Grid field * * The returned object will be passed to replace() as a third parameter. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Object EE_Grid_field_parser object */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $grid_field_names = array(); // Run the preprocessor for each site foreach ($pre->site_ids() as $site_id) { $gfields = $pre->channel()->gfields; // Skip a site if it has no Grid fields if (!isset($gfields[$site_id]) or empty($gfields[$site_id])) { continue; } $grid_field_names = array_merge($grid_field_names, array_values(array_flip($gfields[$site_id]))); ee()->load->library('grid_parser'); ee()->grid_parser->pre_process($tagdata, $pre, $gfields[$site_id]); } $grid_field_names = $pre->prefix() . implode('|' . $pre->prefix(), $grid_field_names); // Match all conditionals with these Grid field names so we can // make {if grid_field} work preg_match_all("/" . preg_quote(LD) . "((if:(else))*if)\\s+({$grid_field_names})(?!:)(\\s+|" . preg_quote(RD) . ")/s", $tagdata, $matches); // For each field found in a conditional, add it to the modified // conditionals array to make the conditional evaluate with the // :total_rows modifier, otherwise it will evaluate based on what's // in channel_data, and only data from searchable fields is there if (isset($matches[4]) && !empty($matches[4])) { foreach ($matches[4] as $value) { $pre->modified_conditionals[$value][] = 'total_rows'; } } return NULL; }
/** * Set up the relationship parser's tree and data pre-caching. * * The returned object will be passed to replace() as a third parameter. * * @param String The tagdata to be parsed * @param Object The preparser object. * @return Array The relationship parser object */ public function pre_process($tagdata, EE_Channel_preparser $pre) { $rfields = $pre->channel()->rfields; $process_fields = array(); foreach ($pre->site_ids() as $site_id) { if (!isset($rfields[$site_id]) or empty($rfields[$site_id])) { continue; } $process_fields[$site_id] = $rfields[$site_id]; } if (empty($process_fields)) { return NULL; } ee()->load->library('relationships_parser'); try { return ee()->relationships_parser->create($process_fields, $pre->entry_ids()); } catch (EE_Relationship_exception $e) { ee()->TMPL->log_item($e->getMessage()); } return NULL; }