Carbon_Fields\Container\Container::add_fields PHP Method

add_fields() public method

If a field does not have DataStore already, the container data store is assigned to them instead.
public add_fields ( array $fields ) : object
$fields array
return object $this
    public function add_fields($fields)
    {
        foreach ($fields as $field) {
            if (!is_a($field, 'Carbon_Fields\\Field\\Field')) {
                Incorrect_Syntax_Exception::raise('Object must be of type Carbon_Fields\\Field\\Field');
            }
            $this->verify_unique_field_name($field->get_name());
            $field->set_context($this->type);
            if (!$field->get_datastore()) {
                $field->set_datastore($this->store);
            }
        }
        $this->fields = array_merge($this->fields, $fields);
        return $this;
    }

Usage Example

 /**
  * Append array of fields to the current fields set. All items of the array
  * must be instances of Field and their names should be unique for all
  * Carbon containers.
  * If a field does not have DataStore already, the container data store is
  * assigned to them instead.
  *
  * @param array $fields
  **/
 public function add_fields($fields)
 {
     parent::add_fields($fields);
     foreach ($this->fields as $field) {
         $field->set_prefix('');
     }
     return $this;
 }