Carbon_Fields\Field\Group_Field::set_name PHP Method

set_name() public method

Set the group name.
public set_name ( string $name )
$name string Group name, either sanitized or not
    public function set_name($name)
    {
        $name = preg_replace('~\\s+~', '_', strtolower($name));
        if (substr($name, 0, 1) != '_') {
            // add underscore to custom field name -- this will remove it from
            // custom fields list in administration
            $name = '_' . $name;
        }
        $this->name = $name;
    }

Usage Example

Example #1
0
 /**
  * Add a set/group of fields.
  */
 public function add_fields()
 {
     $argv = func_get_args();
     $argc = count($argv);
     if ($argc == 1) {
         $fields = $argv[0];
         $name = '';
         $label = null;
     } else {
         if ($argc == 2) {
             if (is_array($argv[0])) {
                 list($fields, $name) = $argv;
             } else {
                 list($name, $fields) = $argv;
             }
             $label = null;
         } else {
             if ($argc == 3) {
                 if (is_array($argv[0])) {
                     list($fields, $name, $label) = $argv;
                 } else {
                     list($name, $label, $fields) = $argv;
                 }
             }
         }
     }
     if (array_key_exists('_' . $name, $this->groups)) {
         Incorrect_Syntax_Exception::raise('Group with name "' . $name . '" in Complex Field "' . $this->get_label() . '" already exists.');
     } else {
         $group = new Group_Field();
         $group->set_name($name);
         $group->add_fields($fields);
         $group->set_label($label);
         $this->groups[$group->get_name()] = $group;
         return $this;
     }
 }