definition['relationship table'])) { $this->table = $this->definition['relationship table']; } if (isset($this->definition['relationship field'])) { $this->field = $this->definition['relationship field']; } } /** * Get this field's label. */ function label() { if (!isset($this->options['label'])) { return $this->ui_name(); } return $this->options['label']; } function option_definition() { $options = parent::option_definition(); $label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field']; $options['label'] = array('default' => $label, 'translatable' => TRUE); $options['required'] = array('default' => FALSE); return $options; } /** * Default options form that provides the label widget that all fields * should have. */ function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['label'] = array( '#type' => 'textfield', '#title' => t('Identifier'), '#default_value' => isset($this->options['label']) ? $this->options['label'] : '', '#description' => t('Edit the administrative label displayed when referencing this relationship form filters, etc.'), ); $form['required'] = array( '#type' => 'checkbox', '#title' => t('Require this relationship'), '#description' => t('Enable to hide items that do not contain this relationship'), '#default_value' => !empty($this->options['required']), ); } /** * Called to implement a relationship in a query. */ function query() { // Figure out what base table this relationship brings to the party. $table_data = views_fetch_data($this->definition['base']); $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field']; $this->ensure_my_table(); $def = $this->definition; $def['table'] = $this->definition['base']; $def['field'] = $base_field; $def['left_table'] = $this->table_alias; $def['left_field'] = $this->field; if (!empty($this->options['required'])) { $def['type'] = 'INNER'; } if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { $join = new $def['join_handler']; } else { $join = new views_join(); } $join->definition = $def; $join->options = $this->options; $join->construct(); $join->adjusted = TRUE; // use a short alias for this: $alias = $def['table'] . '_' . $this->table; $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); // Add access tags if the base table provide it. if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) { $access_tag = $table_data['table']['base']['access query tag']; $this->query->addTag($access_tag); } } /** * You can't groupby a relationship. */ function use_group_by() { return FALSE; } } /** * A special handler to take the place of missing or broken handlers. */ class views_handler_relationship_broken extends views_handler_relationship { function ui_name($short = FALSE) { return t('Broken/missing handler'); } function ensure_my_table() { /* No table to ensure! */ } function query() { /* No query to run */ } function options_form(&$form, &$form_state) { $form['markup'] = array( '#markup' => '
' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '
', ); } /** * Determine if the handler is considered 'broken' */ function broken() { return TRUE; } } /** * @} */