Carbon_Fields\Field\Group_Field::set_label PHP Method

set_label() public method

Set the group label.
public set_label ( string $label )
$label string If null, the label will be generated from the group name
    public function set_label($label)
    {
        // Try to guess field label from it's name
        if (is_null($label)) {
            // remove the leading underscore(if it's there)
            $label = preg_replace('~^_~', '', $this->name);
            // remove the leading "crb_"(if it's there)
            $label = preg_replace('~^crb_~', '', $label);
            // split the name into words and make them capitalized
            $label = ucwords(str_replace('_', ' ', $label));
        }
        $this->label = $label;
    }

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;
     }
 }