Drush: commands/core/outputformat/list.inc Source File

  1. 7.x doxygen/html/list_8inc_source.html
  2. master doxygen/html/list_8inc_source.html
1 <?php
2 
3 /**
4  * Output formatter 'list'
5  *
6  * @param $data
7  * The $data parameter is expected to be an array of key / value pairs.
8  * Each key / value pair is passed to some other output formatter for
9  * rendering; the key becomes the label, $metadata['label'], and the
10  * value becomes the $data for the sub-formatter.
11  * @param $metadata
12  * 'matches' - Specifies the exact kind of list to be rendered in an
13  * array of two elements. $matches[0] is the full name of the
14  * list format (e.g. 'string-list'), and $matches[1] is the type
15  * of the sub-formatter (e.g. 'string'). If not specified, 'string'
16  * is assumed.
17  *
18  * Code:
19  *
20  * return array('a', 'b', 'c');
21  *
22  * Output with --format=list: (list of string):
23  *
24  * a
25  * b
26  * c
27  */
29  function is_list() {
30  return TRUE;
31  }
32  function validate() {
33  // Separate the 'list' and 'filter' metadata from everything
34  // else in $engine_config['engine-info']
35  $list_metadata = array();
36  foreach ($this->engine_config as $key => $value) {
37  if ((substr($key, 0, 4) == 'list') || (substr($key, -6) == 'filter') || (substr($key, 0, 5) == 'field') || ($key == 'options')) {
38  unset($this->engine_config[$key]);
39  $list_metadata[$key] = $value;
40  }
41  }
42  foreach ($this->engine_config['engine-info'] as $key => $value) {
43  if ((substr($key, 0, 4) == 'list') || (substr($key, -6) == 'filter')) {
44  unset($this->engine_config['engine-info'][$key]);
45  $list_metadata[$key] = $value;
46  }
47  }
48  $sub_formatter = isset($list_metadata['list-item-type']) ? $list_metadata['list-item-type'] : 'string';
49  $this->sub_engine = drush_load_engine('outputformat', $sub_formatter, $this->engine_config);
50  if (!is_object($this->sub_engine)) {
51  return drush_set_error('DRUSH_INVALID_SUBFORMATTER', dt("The list output formatter could not load its subformatter: !sub", array('!sub' => $sub_formatter)));
52  }
53  $engine_info = $this->engine_config['engine-info'];
54  $this->engine_config = array(
55  'engine-info' => array(
56  'machine-parsable' => $this->sub_engine->engine_config['engine-info']['machine-parsable'],
57  ),
58  'metameta' => $this->sub_engine->engine_config,
59  ) + $list_metadata;
60  return TRUE;
61  }
62 
63  function format($input, $metadata) {
64  $output = '';
65  if (is_array($input)) {
66  // If this list is processing output from a command that produces table
67  // @todo - need different example below?
68  // output, but our subformatter only supports 'single' items (e.g. csv),
69  // then we will convert our data such that the output will be the keys
70  // of the table rows.
71  if (($this->data_type($metadata) == 'format-table') && ($this->supports_single_only($metadata)) && !isset($metadata['list-item'])) {
72  // If the user specified exactly one field with --fields, then
73  // use it to select the data column to use instead of the array key.
74  if (isset($metadata['field-labels']) && (count($metadata['field-labels']) == 1)) {
75  $first_label = key($metadata['field-labels']);
76  $input = drush_output_get_selected_field($input, $first_label);
77  }
78  else {
79  $input = array_keys($input);
80  }
81  }
82  $first = TRUE;
83  $field_selection_control = isset($metadata['list-field-selection-control']) ? $metadata['list-field-selection-control'] : 0;
84  $selected_output_fields = false;
85  if (empty($metadata['metameta'])) {
86  $metameta = $metadata;
87  unset($metameta['list-item']);
88  unset($metameta['list-item-default-value']);
89  }
90  else {
91  $metameta = $metadata['metameta'];
92  }
93  $list_separator_key = 'list-separator';
94  if ($this->sub_engine->is_list()) {
95  $list_separator_key = 'line-separator';
96  if (isset($metadata['list-separator'])) {
97  $metameta['list-separator'] = $metadata['list-separator'];
98  }
99  }
100  $separator = isset($metadata[$list_separator_key]) && !empty($metadata[$list_separator_key]) ? $metadata[$list_separator_key] : "\n";
101  // @todo - bug? we iterate over a hard coded, single item array?
102  foreach (array('field-labels') as $key) {
103  if (isset($metadata[$key])) {
104  $metameta[$key] = $metadata[$key];
105  }
106  }
107 
108  // Include field labels, if specified
109  if (!isset($metadata['list-item']) && isset($metadata['labeled-list']) && is_array($input) && isset($metadata['field-labels'])) {
110  if (isset($metadata['include-field-labels']) && $metadata['include-field-labels']) {
111  array_unshift($input, $metadata['field-labels']);
112  }
113  }
114  foreach ($input as $label => $data) {
115  // If this output formatter is set to print a single item from each
116  // element, select that item here.
117  if (isset($metadata['list-item'])) {
118  $data = isset($data[$metadata['list-item']]) ? $data[$metadata['list-item']] : $metadata['list-item-default-value'];
119  }
120  // If this formatter supports the --fields option, then filter and
121  // order the fields the user wants here. Note that we need to be
122  // careful about when we call drush_select_output_fields(); sometimes,
123  // there will be nested formatters of type 'list', and it would not
124  // do to select the output fields more than once.
125  // 'list-field-selection-control can be set to a positive number to
126  // cause output fields to be selected at a later point in the call chain.
127  elseif (is_array($data) && isset($metadata['field-labels'])) {
128  if (!$field_selection_control) {
129  $data = drush_select_output_fields($data, $metadata['field-labels'], $metadata['field-mappings']);
130  $selected_output_fields = true;
131  }
132  }
133  $metameta['label'] = $label;
134  if ($selected_output_fields) {
135  $metameta['list-field-selection-control'] = -1;
136  }
137  elseif ($field_selection_control) {
138  $metameta['list-field-selection-control'] = $field_selection_control - 1;
139  }
140  $formatted_item = $this->sub_engine->format($data, $metameta);
141  if ($formatted_item === FALSE) {
142  return FALSE;
143  }
144  if (!$first) {
145  $output .= $separator;
146  }
147  if (($separator != "\n") && !empty($separator) && (strpos($formatted_item, $separator) !== FALSE)) {
148  $formatted_item = drush_wrap_with_quotes($formatted_item);
149  }
150  $output .= $formatted_item;
151  $first = FALSE;
152  }
153  }
154  return $output;
155  }
156 }

File

doxygen/html/list_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: commands/core/outputformat/list.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_afac61274991793aa7e9133a8f4f291e.html">commands</a></li><li class="navelem"><a class="el" href="dir_5762b63965e3a68a35f77c23b4dd4668.html">core</a></li><li class="navelem"><a class="el" href="dir_08bd30a1fd1a2638a60914f8265d8164.html">outputformat</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">list.inc</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Output formatter &#39;list&#39;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * @param $data</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *   The $data parameter is expected to be an array of key / value pairs.</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *   Each key / value pair is passed to some other output formatter for</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *   rendering; the key becomes the label, $metadata[&#39;label&#39;], and the</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> *   value becomes the $data for the sub-formatter.</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * @param $metadata</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> *   &#39;matches&#39; - Specifies the exact kind of list to be rendered in an</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *     array of two elements.  $matches[0] is the full name of the</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> *     list format (e.g. &#39;string-list&#39;), and $matches[1] is the type</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> *     of the sub-formatter (e.g. &#39;string&#39;).  If not specified, &#39;string&#39;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *     is assumed.</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * Code:</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> *   return array(&#39;a&#39;, &#39;b&#39;, &#39;c&#39;);</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> * Output with --format=list: (list of string):</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"> *   a</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="comment"> *   b</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment"> *   c</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00028"></a><span class="lineno"><a class="code" href="classdrush__outputformat__list.html">   28</a></span>&#160;<span class="keyword">class </span><a class="code" href="classdrush__outputformat__list.html">drush_outputformat_list</a> <span class="keyword">extends</span> <a class="code" href="classdrush__outputformat.html">drush_outputformat</a> {</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;  <span class="keyword">function</span> is_list() {</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;  }</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;  <span class="keyword">function</span> validate() {</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;    <span class="comment">// Separate the &#39;list&#39; and &#39;filter&#39; metadata from everything</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    <span class="comment">// else in $engine_config[&#39;engine-info&#39;]</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    $list_metadata = array();</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    <span class="keywordflow">foreach</span> ($this-&gt;engine_config as $key =&gt; $value) {</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;      <span class="keywordflow">if</span> ((substr($key, 0, 4) == <span class="stringliteral">&#39;list&#39;</span>) || (substr($key, -6) == <span class="stringliteral">&#39;filter&#39;</span>) || (substr($key, 0, 5) == <span class="stringliteral">&#39;field&#39;</span>) || ($key == <span class="stringliteral">&#39;options&#39;</span>)) {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;        unset($this-&gt;engine_config[$key]);</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;        $list_metadata[$key] = $value;</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;      }</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    }</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="keywordflow">foreach</span> ($this-&gt;engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>] as $key =&gt; $value) {</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;      <span class="keywordflow">if</span> ((substr($key, 0, 4) == <span class="stringliteral">&#39;list&#39;</span>) || (substr($key, -6) == <span class="stringliteral">&#39;filter&#39;</span>)) {</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        unset($this-&gt;engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>][$key]);</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        $list_metadata[$key] = $value;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      }</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    $sub_formatter = isset($list_metadata[<span class="stringliteral">&#39;list-item-type&#39;</span>]) ? $list_metadata[<span class="stringliteral">&#39;list-item-type&#39;</span>] : <span class="stringliteral">&#39;string&#39;</span>;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    $this-&gt;sub_engine = <a class="code" href="engines_8inc.html#a8d6f32991f4806b9311373a0c9afcbd5">drush_load_engine</a>(<span class="stringliteral">&#39;outputformat&#39;</span>, $sub_formatter, $this-&gt;engine_config);</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    <span class="keywordflow">if</span> (!is_object($this-&gt;sub_engine)) {</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_INVALID_SUBFORMATTER&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;The list output formatter could not load its subformatter: !sub&quot;</span>, array(<span class="stringliteral">&#39;!sub&#39;</span> =&gt; $sub_formatter)));</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    }</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    $engine_info = $this-&gt;engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>];</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    $this-&gt;engine_config = array(</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;      <span class="stringliteral">&#39;engine-info&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <span class="stringliteral">&#39;machine-parsable&#39;</span> =&gt; $this-&gt;sub_engine-&gt;engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>][<span class="stringliteral">&#39;machine-parsable&#39;</span>],</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;      ),</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      <span class="stringliteral">&#39;metameta&#39;</span> =&gt; $this-&gt;sub_engine-&gt;engine_config,</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    ) + $list_metadata;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  }</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  <span class="keyword">function</span> format($input, $metadata) {</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    $output = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="keywordflow">if</span> (is_array($input)) {</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;      <span class="comment">// If this list is processing output from a command that produces table</span></div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;      <span class="comment">// @todo - need different example below?</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;      <span class="comment">// output, but our subformatter only supports &#39;single&#39; items (e.g. csv),</span></div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;      <span class="comment">// then we will convert our data such that the output will be the keys</span></div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;      <span class="comment">// of the table rows.</span></div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;      <span class="keywordflow">if</span> (($this-&gt;data_type($metadata) == <span class="stringliteral">&#39;format-table&#39;</span>) &amp;&amp; ($this-&gt;supports_single_only($metadata)) &amp;&amp; !isset($metadata[<span class="stringliteral">&#39;list-item&#39;</span>])) {</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        <span class="comment">// If the user specified exactly one field with --fields, then</span></div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;        <span class="comment">// use it to select the data column to use instead of the array key.</span></div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="keywordflow">if</span> (isset($metadata[<span class="stringliteral">&#39;field-labels&#39;</span>]) &amp;&amp; (count($metadata[<span class="stringliteral">&#39;field-labels&#39;</span>]) == 1)) {</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;          $first_label = key($metadata[<span class="stringliteral">&#39;field-labels&#39;</span>]);</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;          $input = <a class="code" href="group__outputfunctions.html#gaede2988d7b8cf9d1e8c6285690e29f6d">drush_output_get_selected_field</a>($input, $first_label);</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;        }</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;          $input = array_keys($input);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        }</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;      }</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;      $first = TRUE;</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;      $field_selection_control = isset($metadata[<span class="stringliteral">&#39;list-field-selection-control&#39;</span>]) ? $metadata[<span class="stringliteral">&#39;list-field-selection-control&#39;</span>] : 0;</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;      $selected_output_fields = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;      <span class="keywordflow">if</span> (empty($metadata[<span class="stringliteral">&#39;metameta&#39;</span>])) {</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;        $metameta = $metadata;</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;        unset($metameta[<span class="stringliteral">&#39;list-item&#39;</span>]);</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        unset($metameta[<span class="stringliteral">&#39;list-item-default-value&#39;</span>]);</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;      }</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;        $metameta = $metadata[<span class="stringliteral">&#39;metameta&#39;</span>];</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;      }</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;      $list_separator_key = <span class="stringliteral">&#39;list-separator&#39;</span>;</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;      <span class="keywordflow">if</span> ($this-&gt;sub_engine-&gt;is_list()) {</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        $list_separator_key = <span class="stringliteral">&#39;line-separator&#39;</span>;</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="keywordflow">if</span> (isset($metadata[<span class="stringliteral">&#39;list-separator&#39;</span>])) {</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;          $metameta[<span class="stringliteral">&#39;list-separator&#39;</span>] = $metadata[<span class="stringliteral">&#39;list-separator&#39;</span>];</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        }</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;      }</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;      $separator = isset($metadata[$list_separator_key]) &amp;&amp; !empty($metadata[$list_separator_key]) ? $metadata[$list_separator_key] : <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;      <span class="comment">// @todo - bug? we iterate over a hard coded, single item array?</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;      <span class="keywordflow">foreach</span> (array(<span class="stringliteral">&#39;field-labels&#39;</span>) as $key) {</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        <span class="keywordflow">if</span> (isset($metadata[$key])) {</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;          $metameta[$key] = $metadata[$key];</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        }</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;      }</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;      <span class="comment">// Include field labels, if specified</span></div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;      <span class="keywordflow">if</span> (!isset($metadata[<span class="stringliteral">&#39;list-item&#39;</span>]) &amp;&amp; isset($metadata[<span class="stringliteral">&#39;labeled-list&#39;</span>]) &amp;&amp; is_array($input) &amp;&amp; isset($metadata[<span class="stringliteral">&#39;field-labels&#39;</span>])) {</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;        <span class="keywordflow">if</span> (isset($metadata[<span class="stringliteral">&#39;include-field-labels&#39;</span>]) &amp;&amp; $metadata[<span class="stringliteral">&#39;include-field-labels&#39;</span>]) {</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;          array_unshift($input, $metadata[<span class="stringliteral">&#39;field-labels&#39;</span>]);</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;        }</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;      }</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;      <span class="keywordflow">foreach</span> ($input as $label =&gt; $data) {</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;        <span class="comment">// If this output formatter is set to print a single item from each</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;        <span class="comment">// element, select that item here.</span></div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;        <span class="keywordflow">if</span> (isset($metadata[<span class="stringliteral">&#39;list-item&#39;</span>])) {</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;          $data = isset($data[$metadata[<span class="stringliteral">&#39;list-item&#39;</span>]]) ? $data[$metadata[<span class="stringliteral">&#39;list-item&#39;</span>]] : $metadata[<span class="stringliteral">&#39;list-item-default-value&#39;</span>];</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        }</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;        <span class="comment">// If this formatter supports the --fields option, then filter and</span></div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        <span class="comment">// order the fields the user wants here.  Note that we need to be</span></div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        <span class="comment">// careful about when we call drush_select_output_fields(); sometimes,</span></div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="comment">// there will be nested formatters of type &#39;list&#39;, and it would not</span></div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        <span class="comment">// do to select the output fields more than once.</span></div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;        <span class="comment">// &#39;list-field-selection-control can be set to a positive number to</span></div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;        <span class="comment">// cause output fields to be selected at a later point in the call chain.</span></div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        elseif (is_array($data) &amp;&amp; isset($metadata[<span class="stringliteral">&#39;field-labels&#39;</span>])) {</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;          <span class="keywordflow">if</span> (!$field_selection_control) {</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;            $data = <a class="code" href="group__outputfunctions.html#gad9b277fa4b12ca658eb5f00dc5cfb14a">drush_select_output_fields</a>($data, $metadata[<span class="stringliteral">&#39;field-labels&#39;</span>], $metadata[<span class="stringliteral">&#39;field-mappings&#39;</span>]);</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;            $selected_output_fields = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;          }</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        }</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;        $metameta[<span class="stringliteral">&#39;label&#39;</span>] = $label;</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;        <span class="keywordflow">if</span> ($selected_output_fields) {</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;          $metameta[<span class="stringliteral">&#39;list-field-selection-control&#39;</span>] = -1;</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;        }</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        elseif ($field_selection_control) {</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;          $metameta[<span class="stringliteral">&#39;list-field-selection-control&#39;</span>] = $field_selection_control - 1;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;        }</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;        $formatted_item = $this-&gt;sub_engine-&gt;format($data, $metameta);</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;        <span class="keywordflow">if</span> ($formatted_item === FALSE) {</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;          <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;        }</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;        <span class="keywordflow">if</span> (!$first) {</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;          $output .= $separator;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;        }</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;        <span class="keywordflow">if</span> (($separator != <span class="stringliteral">&quot;\n&quot;</span>) &amp;&amp; !empty($separator) &amp;&amp; (strpos($formatted_item, $separator) !== FALSE)) {</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;          $formatted_item = <a class="code" href="group__commandwrappers.html#ga05d2e2e3f00d7f104058db507f0837b0">drush_wrap_with_quotes</a>($formatted_item);</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        }</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        $output .= $formatted_item;</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;        $first = FALSE;</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;      }</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;    }</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    <span class="keywordflow">return</span> $output;</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  }</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Nov 2 2016 07:28:53 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>