WebflowPublish::dispatch($this->id, $mode);
}
+ public function onSaving(): bool
+ {
+ $this->saveDataInWebflow();
+ return parent::onSaving();
+ }
+
public function onSaved(): bool
{
+
$this->onPublish('auto');
- $this->saveDataInWebflow();
return parent::onSaved();
}
Webflow::setToken($this->webflow_api_token);
$mainLocale = $this->getMainLocale();
- $api = json_decode($this->api, true);
+ if (is_string($this->api)) {
+ $api = json_decode($this->api, true);
+ }
+ $seo = $this->getTranslations('seo');
- $clearCache = false;
- if (!$this->_compareObjects($this->api['seo'], $this->seo[$mainLocale])) {
- dd('seo has changed');
- $clearCache = true;
+ $hasChanged = false;
+
+ foreach ($seo[$mainLocale] as $page) {
+
+ if ($page['og_title_copied']) {
+ $page['og_title'] = $page['seo_title'];
+ }
+ if ($page['og_description_copied']) {
+ $page['og_description'] = $page['seo_description'];
+ }
+
+ if (!$this->_compareArrays($api['seo'][$page['id']], $page)) {
+ $api['seo'][$page['id']] = $page;
+ $hasChanged = true;
+ Webflow::savePageMeta($page);
+ }
}
- if ($clearCache) {
- Webflow::clearCache();
- $this->refreshFormDataFromAPI();
+ if ($hasChanged) {
+ $this->api = json_encode($api);
+ $this->saveQuietly();
}
+
}
- protected function _compareObjects($a, $b)
+ protected function _compareArrays($a, $b, $params = null)
{
- return $a === $b;
+ if (null === $params) {
+ $params = array_keys($a);
+ }
+ foreach ($params as $p) {
+ $va = $a[$p] ?? null;
+ $vb = $b[$p] ?? null;
+
+ if ($va != $vb) {
+ return false;
+ }
+ }
+
+ return true;
}
protected function refreshFormDataFromAPI()
{
+ Webflow::clearCache();
$this->api = Webflow::getEditableData($this->webflow);
$mainLocale = $this->getMainLocale();
if (!isset($seo[$locale])) {
$seo[$locale] = [];
}
- foreach ($seo[$mainLocale] as $id => $s) {
- $seo[$locale][$id] = $s;
+ foreach ($seo[$mainLocale] as $s) {
+ $seo[$locale][] = $s;
}
}
$this->setTranslations('seo', $seo);
-
$this->saveQuietly();
}
public function mirror($slow = true, $force = false)
{
Webflow::setToken($this->webflow_api_token);
- Webflow::clearCache();
$this->refreshFormDataFromAPI();
$path = $this->getMirrorPath();
$locales = json_decode($locales, true);
}
Cache::put('webflow_' . $this->id . '_locales', $locales);
- Webflow::setToken($this->webflow_api_token);
- $this->refreshFormDataFromAPI();
-
return parent::onRetrieved();
}
$this->addField('id', HiddenVisible::class, __('#'));
$this->addField('url', HiddenVisible::class, __('URL'));
- $this->addField('type', Hidden::class, __('Type'));
+ $this->addField('type', HiddenVisible::class, __('Type'));
+ $this->addField('draft', Checkbox::class, __('Brouillon'));
$this->addField('slug', Text::class, __('Slug') . ' (' . __('slug') . ')', ['when' => ['url' => ['operator' => '!', 'value' => '/index.html']]]);
$this->addField('seo_title', Text::class, __('Titre'), ['when' => ['type' => 'page']]);
$this->addField('og_title_copied', Checkbox::class, __('Utiliser le titre ci-dessus pour les réseaux sociaux'), ['when' => ['type' => 'page']]);