function drush_outputformat_list::validate

8.0.x list.inc drush_outputformat_list::validate()
6.x list.inc drush_outputformat_list::validate()
7.x list.inc drush_outputformat_list::validate()
master list.inc drush_outputformat_list::validate()

File

commands/core/outputformat/list.inc, line 32

Class

drush_outputformat_list
Output formatter 'list'

Code

function validate() {
  // Separate the 'list' and 'filter' metadata from everything
  // else in $engine_config['engine-info']
  $list_metadata = array();
  foreach ($this->engine_config as $key => $value) {
    if ((substr($key, 0, 4) == 'list') || (substr($key, -6) == 'filter') || (substr($key, 0, 5) == 'field') || ($key == 'options')) {
      unset($this->engine_config[$key]);
      $list_metadata[$key] = $value;
    }
  }
  foreach ($this->engine_config['engine-info'] as $key => $value) {
    if ((substr($key, 0, 4) == 'list') || (substr($key, -6) == 'filter')) {
      unset($this->engine_config['engine-info'][$key]);
      $list_metadata[$key] = $value;
    }
  }
  $sub_formatter = isset($list_metadata['list-item-type']) ? $list_metadata['list-item-type'] : 'string';
  $this->sub_engine = drush_load_engine('outputformat', $sub_formatter, $this->engine_config);
  if (!is_object($this->sub_engine)) {
    return drush_set_error('DRUSH_INVALID_SUBFORMATTER', dt("The list output formatter could not load its subformatter: !sub", array('!sub' => $sub_formatter)));
  }
  $engine_info = $this->engine_config['engine-info'];
  $this->engine_config = array(
    'engine-info' => array(
      'machine-parsable' => $this->sub_engine->engine_config['engine-info']['machine-parsable'],
    ),
    'metameta' => $this->sub_engine->engine_config,
  ) + $list_metadata;
  return TRUE;
}