skeeks\cms\models\CmsComponentSettings::createByComponentSiteCode PHP Method

createByComponentSiteCode() public static method

public static createByComponentSiteCode ( Component $component, string $site_code ) : static
$component skeeks\cms\base\Component
$site_code string
return static
    public static function createByComponentSiteCode($component, $site_code)
    {
        $settings = static::fetchByComponentSiteCode($component, $site_code);
        if (!$settings) {
            $settings = new static(['component' => $component->className(), 'site_code' => $site_code]);
            if ($component->namespace) {
                $settings->namespace = $component->namespace;
            }
            $settings->save();
        }
        return $settings;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @return bool
  */
 public function saveDefaultSettingsBySiteCode($site_code)
 {
     $settings = CmsComponentSettings::createByComponentSiteCode($this, $site_code);
     $settings->value = $this->attributes;
     $this->invalidateCache();
     return $settings->save();
 }