original_string: public function sortByViewMode($viewMode, $dir = SORT_ASC)
      {
          $items = [];
          $sorted = $this->sortBy(function ($field) use ($viewMode) {
              if (isset($field->metadata->view_modes[$viewMode])) {
                  return $field->metadata->view_modes[$viewMode]['ordering'];
              }
  
              return 0;
          }, $dir);
  
          foreach ($sorted as $item) {
              $items[] = $item;
          }
  
          return new FieldCollection($items);
      }
code: public function sortByViewMode($viewMode, $dir = SORT_ASC)
      {
          $items = [];
          $sorted = $this->sortBy(function ($field) use ($viewMode) {
              if (isset($field->metadata->view_modes[$viewMode])) {
                  return $field->metadata->view_modes[$viewMode]['ordering'];
              }
  
              return 0;
          }, $dir);
  
          foreach ($sorted as $item) {
              $items[] = $item;
          }
  
          return new FieldCollection($items);
      }
code_tokens: public function sortByViewMode ( $ viewMode , $ dir = SORT_ASC ) { $ items = [ ] ; $ sorted = $ this -> sortBy ( function ( $ field ) use ( $ viewMode ) { if ( isset ( $ field -> metadata -> view_modes [ $ viewMode ] ) ) { return $ field -> metadata -> view_modes [ $ viewMode ] [ 'ordering' ] ; } return 0 ; } , $ dir ) ; foreach ( $ sorted as $ item ) { $ items [ ] = $ item ; } return new FieldCollection ( $ items ) ; }
docstring: Sorts the list of fields by view mode ordering.
  
  Fields might have different orderings for each view mode.
  
  @param string $viewMode View mode slug to use for sorting
  @param int $dir either SORT_DESC or SORT_ASC
  @return \Field\Collection\FieldCollection
docstring_tokens: Sorts the list of fields by view mode ordering .