CommonTreeDropdown::prepareInputForUpdate PHP Method

prepareInputForUpdate() public method

public prepareInputForUpdate ( $input )
    function prepareInputForUpdate($input)
    {
        if (isset($input[$this->getForeignKeyField()])) {
            // Can't move a parent under a child
            if (in_array($input[$this->getForeignKeyField()], getSonsOf($this->getTable(), $input['id']))) {
                return false;
            }
            // Parent changes => clear ancestors and update its level and completename
            if ($input[$this->getForeignKeyField()] != $this->fields[$this->getForeignKeyField()]) {
                $input["ancestors_cache"] = '';
                return $this->adaptTreeFieldsFromUpdateOrAdd($input);
            }
        }
        // Name changes => update its completename (and its level : side effect ...)
        if (isset($input['name']) && $input['name'] != $this->fields['name']) {
            return $this->adaptTreeFieldsFromUpdateOrAdd($input);
        }
        return $input;
    }

Usage Example

 /**
  * Used to update the ForeignKeyField
  *
  * @param $input datas used to add the item
  *
  * @return the modified $input array
  **/
 function prepareInputForUpdate($input)
 {
     $input[$this->getForeignKeyField()] = $this->getNewAncestor();
     // We call the parent to manage tree
     return parent::prepareInputForUpdate($input);
 }
All Usage Examples Of CommonTreeDropdown::prepareInputForUpdate