Skip to content

Commit 22381c2

Browse files
committed
CON-226 - Add settings for blog
1 parent eb87351 commit 22381c2

File tree

5 files changed

+210
-1
lines changed

5 files changed

+210
-1
lines changed

Api/Data/SiteInterface.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ interface SiteInterface extends ExtensibleDataInterface
1515
const SITE_ID = 'site_id';
1616
const API_USERNAME = 'api_username';
1717
const API_PASSWORD = 'api_password';
18+
const ENABLE_BLOG = 'enable_blog';
19+
const BLOG_PREFIX = 'blog_prefix';
20+
const BLOG_STORES = 'blog_stores';
1821

1922
/**
2023
* Get site_id
@@ -106,4 +109,43 @@ public function getApiPassword(): ?string;
106109
* @return SiteInterface
107110
*/
108111
public function setApiPassword(?string $apiPassword);
112+
113+
/**
114+
* Get enable_blog
115+
* @return bool
116+
*/
117+
public function getEnableBlog(): ?bool;
118+
119+
/**
120+
* Set enable_blog
121+
* @param bool $enableBlog
122+
* @return SiteInterface
123+
*/
124+
public function setEnableBlog(?bool $enableBlog);
125+
126+
/**
127+
* Get blog_prefix
128+
* @return string
129+
*/
130+
public function getBlogPrefix(): ?string;
131+
132+
/**
133+
* Set blog_prefix
134+
* @param string $blogPrefix
135+
* @return SiteInterface
136+
*/
137+
public function setBlogPrefix(?string $blogPrefix);
138+
139+
/**
140+
* Get blog_stores
141+
* @return string
142+
*/
143+
public function getBlogStores(): string;
144+
145+
/**
146+
* Set blog_stores
147+
* @param string $blogStores
148+
* @return SiteInterface
149+
*/
150+
public function setBlogStores(string $blogStores);
109151
}

Controller/Adminhtml/Site/Save.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function execute()
5353
return $resultRedirect->setPath('*/*/');
5454
}
5555

56+
$data['blog_stores'] = is_array($data['blog_stores']) ? join(',', $data['blog_stores']) : $data['blog_stores'];
57+
5658
$model->setData($data);
5759

5860
try {

Model/Data/Site.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,68 @@ public function setApiPassword(?string $apiPassword)
142142
{
143143
return $this->setData(self::API_PASSWORD, $apiPassword);
144144
}
145+
146+
/**
147+
* Get enable_blog
148+
* @return bool|null
149+
*/
150+
public function getEnableBlog(): bool
151+
{
152+
return (bool) $this->_get(self::ENABLE_BLOG);
153+
}
154+
155+
/**
156+
* Set enable_blog
157+
* @param bool $enableBlog
158+
* @return SiteInterface
159+
*/
160+
public function setEnableBlog($enableBlog)
161+
{
162+
return $this->setData(self::ENABLE_BLOG, $enableBlog);
163+
}
164+
165+
/**
166+
* - Add data rentation for route prefix + store views
167+
* - Add check at cronjob per site to check which blog is enabled
168+
* - Add check at cronjob for all stores to see which is applicable
169+
* - Create rewrite URLs
170+
*/
171+
172+
/**
173+
* Get blog_prefix
174+
* @return string
175+
*/
176+
public function getBlogPrefix(): ?string
177+
{
178+
return $this->_get(self::BLOG_PREFIX);
179+
}
180+
181+
/**
182+
* Set blog_prefix
183+
* @param string $apiPassword
184+
* @return SiteInterface
185+
*/
186+
public function setBlogPrefix(?string $blogPrefix)
187+
{
188+
return $this->setData(self::BLOG_PREFIX, $blogPrefix);
189+
}
190+
191+
/**
192+
* Get blog_stores
193+
* @return string
194+
*/
195+
public function getBlogStores(): string
196+
{
197+
return $this->_get(self::BLOG_STORES);
198+
}
199+
200+
/**
201+
* Set blog_stores
202+
* @param string $blogStores
203+
* @return SiteInterface
204+
*/
205+
public function setBlogStores(string $blogStores)
206+
{
207+
return $this->setData(self::BLOG_STORES, $blogStores);
208+
}
145209
}

etc/db_schema.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
<column default="1" name="enabled" nullable="false" xsi:type="boolean"/>
1414
<column length="255" name="api_username" nullable="true" xsi:type="varchar"/>
1515
<column length="255" name="api_password" nullable="true" xsi:type="varchar"/>
16+
<column default="0" name="enable_blog" nullable="false" xsi:type="boolean"/>
17+
<column length="255" name="blog_prefix" nullable="true" xsi:type="varchar"/>
18+
<column length="255" name="blog_stores" nullable="false" xsi:type="varchar"/>
1619
</table>
1720
</schema>

view/adminhtml/ui_component/mooore_wordpressintegration_site_form.xml

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
</validation>
103103
</settings>
104104
</field>
105-
<field formElement="checkbox" name="enabled" sortOrder="50">
105+
<field formElement="checkbox" name="enabled" sortOrder="9">
106106
<argument name="data" xsi:type="array">
107107
<item name="config" xsi:type="array">
108108
<item name="source" xsi:type="string">Site</item>
@@ -130,4 +130,102 @@
130130
</formElements>
131131
</field>
132132
</fieldset>
133+
<fieldset name="blog">
134+
<settings>
135+
<label>Blog</label>
136+
</settings>
137+
<field formElement="checkbox" name="enable_blog" sortOrder="10">
138+
<argument name="data" xsi:type="array">
139+
<item name="config" xsi:type="array">
140+
<item name="source" xsi:type="string">Site</item>
141+
<item name="default" xsi:type="number">0</item>
142+
</item>
143+
</argument>
144+
<settings>
145+
<dataType>boolean</dataType>
146+
<label translate="true">Enable Blog</label>
147+
<dataScope>enable_blog</dataScope>
148+
<validation>
149+
<rule name="required-entry" xsi:type="boolean">false</rule>
150+
</validation>
151+
<switcherConfig>
152+
<enabled>true</enabled>
153+
<rules>
154+
<rule name="0">
155+
<value>0</value>
156+
<actions>
157+
<action name="0">
158+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_prefix</target>
159+
<callback>hide</callback>
160+
</action>
161+
<action name="1">
162+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_stores</target>
163+
<callback>hide</callback>
164+
</action>
165+
</actions>
166+
</rule>
167+
<rule name="1">
168+
<value>1</value>
169+
<actions>
170+
<action name="0">
171+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_prefix</target>
172+
<callback>show</callback>
173+
</action>
174+
<action name="1">
175+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_stores</target>
176+
<callback>show</callback>
177+
</action>
178+
</actions>
179+
</rule>
180+
</rules>
181+
</switcherConfig>
182+
</settings>
183+
<formElements>
184+
<checkbox>
185+
<settings>
186+
<valueMap>
187+
<map name="false" xsi:type="number">0</map>
188+
<map name="true" xsi:type="number">1</map>
189+
</valueMap>
190+
<prefer>toggle</prefer>
191+
</settings>
192+
</checkbox>
193+
</formElements>
194+
</field>
195+
<field formElement="input" name="blog_prefix" sortOrder="20">
196+
<argument name="data" xsi:type="array">
197+
<item name="config" xsi:type="array">
198+
<item name="source" xsi:type="string">Site</item>
199+
</item>
200+
</argument>
201+
<settings>
202+
<dataType>text</dataType>
203+
<label translate="true">Blog Route Prefix</label>
204+
<dataScope>blog_prefix</dataScope>
205+
<notice translate="true">Allows you to set a default blog prefix, for example "/blog", leave this field empty to disable this feature.</notice>
206+
<validation>
207+
<rule name="required-entry" xsi:type="boolean">false</rule>
208+
</validation>
209+
</settings>
210+
</field>
211+
<field name="blog_stores" sortOrder="30">
212+
<argument name="data" xsi:type="array">
213+
<item name="options" xsi:type="object">Magento\Cms\Ui\Component\Listing\Column\Cms\Options</item>
214+
<item name="config" xsi:type="array">
215+
<item name="dataType" xsi:type="string">int</item>
216+
<item name="label" xsi:type="string" translate="true">Store View</item>
217+
<item name="formElement" xsi:type="string">multiselect</item>
218+
<item name="source" xsi:type="string">page</item>
219+
<item name="dataScope" xsi:type="string">blog_stores</item>
220+
<item name="default" xsi:type="string">0</item>
221+
<item name="validation" xsi:type="array">
222+
<item name="required-entry" xsi:type="boolean">true</item>
223+
</item>
224+
</item>
225+
</argument>
226+
<settings>
227+
<notice translate="true">Select which stores you want this blog site to be enabled.</notice>
228+
</settings>
229+
</field>
230+
</fieldset>
133231
</form>

0 commit comments

Comments
 (0)