Carbon_Fields\Field\Field::set_prefix PHP Method

set_prefix() public method

Set field name prefix. Calling this method will update the current field name and the conditional logic fields.
public set_prefix ( string $prefix ) : object
$prefix string
return object $this
    public function set_prefix($prefix)
    {
        $escaped_prefix = preg_quote($this->name_prefix, '~');
        $this->name = preg_replace('~^' . $escaped_prefix . '~', '', $this->name);
        $this->name_prefix = $prefix;
        $this->name = $this->name_prefix . $this->name;
        return $this;
    }

Usage Example

 /**
  * Generate and set the field prefix.
  * @param string $prefix
  */
 public function set_prefix($prefix)
 {
     parent::set_prefix($prefix);
     foreach ($this->groups as $group) {
         $group->set_prefix($prefix);
     }
 }