original_string: public function move($id, $direction)
      {
          $instance = $this->_getOrThrow($id);
          $unordered = [];
          $direction = !in_array($direction, ['up', 'down']) ? 'up' : $direction;
          $position = false;
          $list = $this->_getInstances();
  
          foreach ($list as $k => $field) {
              if ($field->id === $instance->id) {
                  $position = $k;
              }
  
              $unordered[] = $field;
          }
  
          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) {
                      $field->set('ordering', $k);
                      $this->FieldInstances->save($field);
                  }
              }
          }
  
          $this->title(__d('field', 'Reorder Field'));
          $this->redirect($this->referer());
      }
code: public function move($id, $direction)
      {
          $instance = $this->_getOrThrow($id);
          $unordered = [];
          $direction = !in_array($direction, ['up', 'down']) ? 'up' : $direction;
          $position = false;
          $list = $this->_getInstances();
  
          foreach ($list as $k => $field) {
              if ($field->id === $instance->id) {
                  $position = $k;
              }
  
              $unordered[] = $field;
          }
  
          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) {
                      $field->set('ordering', $k);
                      $this->FieldInstances->save($field);
                  }
              }
          }
  
          $this->title(__d('field', 'Reorder Field'));
          $this->redirect($this->referer());
      }
code_tokens: public function move ( $ id , $ direction ) { $ instance = $ this -> _getOrThrow ( $ id ) ; $ unordered = [ ] ; $ direction = ! in_array ( $ direction , [ 'up' , 'down' ] ) ? 'up' : $ direction ; $ position = false ; $ list = $ this -> _getInstances ( ) ; foreach ( $ list as $ k => $ field ) { if ( $ field -> id === $ instance -> id ) { $ position = $ k ; } $ unordered [ ] = $ field ; } 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 ) { $ field -> set ( 'ordering' , $ k ) ; $ this -> FieldInstances -> save ( $ field ) ; } } } $ this -> title ( __d ( 'field' , 'Reorder Field' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
docstring: Moves a field up or down.
  
  The ordering indicates the position they are displayed on entity's
  editing form.
  
  @param int $id Field instance id
  @param string $direction Direction, 'up' or 'down'
  @return void Redirects to previous page
docstring_tokens: Moves a field up or down .