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);
    }
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);
    }
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 ) ; }
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
Sorts the list of fields by view mode ordering .