public function viewModeMove($viewMode, $id, $direction)
    {
        $this->_validateViewMode($viewMode);
        $instance = $this->_getOrThrow($id);
        $unordered = [];
        $position = false;
        $k = 0;
        $list = $this->_getInstances()
            ->sortBy(function ($fieldInstance) use ($viewMode) {
                if (isset($fieldInstance->view_modes[$viewMode]['ordering'])) {
                    return $fieldInstance->view_modes[$viewMode]['ordering'];
                }

                return 0;
            }, SORT_ASC);

        foreach ($list as $field) {
            if ($field->id === $instance->id) {
                $position = $k;
            }

            $unordered[] = $field;
            $k++;
        }

        if ($position !== false) {
            $ordered = array_move($unordered, $position, $direction);
            $before = md5(serialize($unordered));
            $after = md5(serialize($ordered));

            if ($before != $after) {
                foreach ($ordered as $k => $field) {
                    $viewModes = $field->view_modes;
                    $viewModes[$viewMode]['ordering'] = $k;
                    $field->set('view_modes', $viewModes);
                    $this->FieldInstances->save($field);
                }
            }
        }

        $this->title(__d('field', 'Change Field Order'));
        $this->redirect($this->referer());
    }