It's possible for arguments can make use of additional fields as well as field handlers, and probably filters and sorts too.

Hence the add_additional_fields() could really do to be moved up to the views_handler class.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

    $group_params = array();
    if ($this->options['group_type'] != 'group') {
      $group_params = array(
        'function' => $this->options['group_type'],
      );
    }

The gorupby support should probably be just part of the field so some kind of refactoring might be required.

pcambra’s picture

Status: Active » Needs review
FileSize
4.51 KB

Just needed this for areas which behave the same as fields for this part, moved the add additional fields method one level up and works fine.

I've kept the group thing just in the field, not really sure how that works.

Status: Needs review » Needs work

The last submitted patch, 1321018-move_add_additional_fields_up-2.patch, failed testing.

pcambra’s picture

Status: Needs work » Needs review
FileSize
4.51 KB

Dumb mistake, this one should be better

dawehner’s picture

The change really looks great, though to be able to sleep better some manual testing by an independent person would be cool :) (I won't trust the test coverage at all in D7)

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 6 year old patch in #4 to views_handler_field.inc and handlers.inc does not apply to the latest views 7.x-3.x-dev and if still applicable needs to be rerolled.

Checking patch handlers/views_handler_field.inc...
error: while searching for:
  }

  /**
   * Add 'additional' fields to the query.
   *
   * @param $fields
   * An array of fields. The key is an identifier used to later find the
   * field alias used. The value is either a string in which case it's
   * assumed to be a field on this handler's table; or it's an array in the
   * form of
   * @code array('table' => $tablename, 'field' => $fieldname) @endcode
   */
  function add_additional_fields($fields = NULL) {
    if (!isset($fields)) {
      // notice check
      if (empty($this->additional_fields)) {
        return;
      }
      $fields = $this->additional_fields;
    }

    $group_params = array();
    if ($this->options['group_type'] != 'group') {
      $group_params = array(
        'function' => $this->options['group_type'],
      );
    }

    if (!empty($fields) && is_array($fields)) {
      foreach ($fields as $identifier => $info) {
        if (is_array($info)) {
          if (isset($info['table'])) {
            $table_alias = $this->query->ensure_table($info['table'], $this->relationship);
          }
          else {
            $table_alias = $this->table_alias;
          }

          if (empty($table_alias)) {
            debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table'])));
            $this->aliases[$identifier] = 'broken';
            continue;
          }

          $params = array();
          if (!empty($info['params'])) {
            $params = $info['params'];
          }

          $params += $group_params;
          $this->aliases[$identifier] = $this->query->add_field($table_alias, $info['field'], NULL, $params);
        }
        else {
          $this->aliases[$info] = $this->query->add_field($this->table_alias, $info, NULL, $group_params);
        }
      }
    }
  }

  /**

error: patch failed: handlers/views_handler_field.inc:103
error: handlers/views_handler_field.inc: patch does not apply
Checking patch includes/handlers.inc...
error: while searching for:
  }

  /**
   * Provide text for the administrative summary
   */
  function admin_summary() { }

error: patch failed: includes/handlers.inc:650
error: includes/handlers.inc: patch does not apply
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.63 KB

Patch rerolled.

Andrew Answer’s picture

Patch rerolled/fixed after last commits.