Backend\Core\Engine\Meta::save PHP Method

save() public method

Saves the meta object
Deprecation: just use the entity for doctrine
public save ( boolean $update = false ) : integer
$update boolean Should we update the record or insert a new one.
return integer
    public function save($update = false)
    {
        $this->validate();
        $update = (bool) $update;
        //serialize data for save
        if (!empty($this->data['data'])) {
            $this->data['data'] = serialize($this->data['data']);
        }
        // build meta
        $db = BackendModel::getContainer()->get('database');
        if ($this->id !== null && $update === true) {
            $db->update('meta', $this->data, 'id = ?', array($this->id));
            return $this->id;
        } else {
            unset($this->data['id']);
            return (int) $db->insert('meta', $this->data);
        }
    }

Usage Example

 /**
  * Handles the form
  *
  * @return bool
  */
 public function handle()
 {
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $fields = $this->form->getFields();
     // we already have a teammember? Let's update
     if ($this->teamMember instanceof TeamMember) {
         $this->teamMember->change($this->meta->save(), $fields['name']->getValue(), $fields['description']->getValue());
         return true;
     }
     // time to create a new entity
     $this->teamMember = TeamMember::create($this->meta->save(), Language::getWorkingLanguage(), $fields['name']->getValue(), $fields['description']->getValue());
     return true;
 }