Skip to content

Commit b4c13c6

Browse files
authored
Merge pull request #14 from mooore-digital/develop
v0.4.0
2 parents eb87351 + 48f9faf commit b4c13c6

File tree

7 files changed

+274
-1
lines changed

7 files changed

+274
-1
lines changed

Api/Data/SiteInterface.php

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

1923
/**
2024
* Get site_id
@@ -106,4 +110,56 @@ public function getApiPassword(): ?string;
106110
* @return SiteInterface
107111
*/
108112
public function setApiPassword(?string $apiPassword);
113+
114+
/**
115+
* Get replace_media_urls
116+
* @return bool
117+
*/
118+
public function getReplaceMediaUrls(): ?bool;
119+
120+
/**
121+
* Set replace_media_urls
122+
* @param bool $replaceMediaUrls
123+
* @return SiteInterface
124+
*/
125+
public function setReplaceMediaUrls(?bool $replaceMediaUrls);
126+
127+
/**
128+
* Get enable_blog
129+
* @return bool
130+
*/
131+
public function getEnableBlog(): ?bool;
132+
133+
/**
134+
* Set enable_blog
135+
* @param bool $enableBlog
136+
* @return SiteInterface
137+
*/
138+
public function setEnableBlog(?bool $enableBlog);
139+
140+
/**
141+
* Get blog_prefix
142+
* @return string
143+
*/
144+
public function getBlogPrefix(): ?string;
145+
146+
/**
147+
* Set blog_prefix
148+
* @param string $blogPrefix
149+
* @return SiteInterface
150+
*/
151+
public function setBlogPrefix(?string $blogPrefix);
152+
153+
/**
154+
* Get blog_stores
155+
* @return string
156+
*/
157+
public function getBlogStores(): string;
158+
159+
/**
160+
* Set blog_stores
161+
* @param string $blogStores
162+
* @return SiteInterface
163+
*/
164+
public function setBlogStores(string $blogStores);
109165
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.4.0] - 2022-06-24
10+
### Added
11+
- Added site settings to enable the media URL replace option
12+
- Add basic blog functionality
13+
914
## [0.3.0] - 2021-02-10
1015
### Added
1116
- Added optional API credential functionality for Wordpress' Application Passwords plugin

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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,80 @@ public function setApiPassword(?string $apiPassword)
142142
{
143143
return $this->setData(self::API_PASSWORD, $apiPassword);
144144
}
145+
146+
/**
147+
* Get replace_media_urls
148+
* @return bool|null
149+
*/
150+
public function getReplaceMediaUrls(): bool
151+
{
152+
return (bool) $this->_get(self::REPLACE_MEDIA_URLS);
153+
}
154+
155+
/**
156+
* Set replace_media_urls
157+
* @param bool $replaceMediaUrls
158+
* @return SiteInterface
159+
*/
160+
public function setReplaceMediaUrls($replaceMediaUrls)
161+
{
162+
return $this->setData(self::REPLACE_MEDIA_URLS, $replaceMediaUrls);
163+
}
164+
165+
/**
166+
* Get enable_blog
167+
* @return bool|null
168+
*/
169+
public function getEnableBlog(): bool
170+
{
171+
return (bool) $this->_get(self::ENABLE_BLOG);
172+
}
173+
174+
/**
175+
* Set enable_blog
176+
* @param bool $enableBlog
177+
* @return SiteInterface
178+
*/
179+
public function setEnableBlog($enableBlog)
180+
{
181+
return $this->setData(self::ENABLE_BLOG, $enableBlog);
182+
}
183+
184+
/**
185+
* Get blog_prefix
186+
* @return string
187+
*/
188+
public function getBlogPrefix(): ?string
189+
{
190+
return $this->_get(self::BLOG_PREFIX);
191+
}
192+
193+
/**
194+
* Set blog_prefix
195+
* @param string $apiPassword
196+
* @return SiteInterface
197+
*/
198+
public function setBlogPrefix(?string $blogPrefix)
199+
{
200+
return $this->setData(self::BLOG_PREFIX, $blogPrefix);
201+
}
202+
203+
/**
204+
* Get blog_stores
205+
* @return string
206+
*/
207+
public function getBlogStores(): string
208+
{
209+
return $this->_get(self::BLOG_STORES);
210+
}
211+
212+
/**
213+
* Set blog_stores
214+
* @param string $blogStores
215+
* @return SiteInterface
216+
*/
217+
public function setBlogStores(string $blogStores)
218+
{
219+
return $this->setData(self::BLOG_STORES, $blogStores);
220+
}
145221
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ Base module for Magento 2 Wordpress Integration, currently only used for module
1414
composer require mooore/magento2-module-wordpress-integration
1515
bin/magento setup:upgrade
1616
```
17+
18+
### Use magento store as image URLs
19+
20+
Create a symlink from your CMS environment's `wp-content` folder to `pub/media/wp-content` , and enable the "Replace Media URLs" option in a Site Config

etc/db_schema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
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="replace_media_urls" nullable="false" xsi:type="boolean"/>
17+
<column default="0" name="enable_blog" nullable="false" xsi:type="boolean"/>
18+
<column length="255" name="blog_prefix" nullable="true" xsi:type="varchar"/>
19+
<column length="255" name="blog_stores" nullable="false" xsi:type="varchar"/>
1620
</table>
1721
</schema>

view/adminhtml/ui_component/mooore_wordpressintegration_site_form.xml

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,35 @@
102102
</validation>
103103
</settings>
104104
</field>
105-
<field formElement="checkbox" name="enabled" sortOrder="50">
105+
<field formElement="checkbox" name="replace_media_urls" sortOrder="50">
106+
<argument name="data" xsi:type="array">
107+
<item name="config" xsi:type="array">
108+
<item name="source" xsi:type="string">Site</item>
109+
<item name="default" xsi:type="number">0</item>
110+
</item>
111+
</argument>
112+
<settings>
113+
<dataType>boolean</dataType>
114+
<label translate="true">Replace Media URLs</label>
115+
<notice translate="true">Please only enable this when you are absolutely sure about what you are doing! This may cause images no longer to be rendered.</notice>
116+
<dataScope>replace_media_urls</dataScope>
117+
<validation>
118+
<rule name="required-entry" xsi:type="boolean">false</rule>
119+
</validation>
120+
</settings>
121+
<formElements>
122+
<checkbox>
123+
<settings>
124+
<valueMap>
125+
<map name="false" xsi:type="number">0</map>
126+
<map name="true" xsi:type="number">1</map>
127+
</valueMap>
128+
<prefer>toggle</prefer>
129+
</settings>
130+
</checkbox>
131+
</formElements>
132+
</field>
133+
<field formElement="checkbox" name="enabled" sortOrder="9">
106134
<argument name="data" xsi:type="array">
107135
<item name="config" xsi:type="array">
108136
<item name="source" xsi:type="string">Site</item>
@@ -130,4 +158,102 @@
130158
</formElements>
131159
</field>
132160
</fieldset>
161+
<fieldset name="blog">
162+
<settings>
163+
<label>Blog</label>
164+
</settings>
165+
<field formElement="checkbox" name="enable_blog" sortOrder="10">
166+
<argument name="data" xsi:type="array">
167+
<item name="config" xsi:type="array">
168+
<item name="source" xsi:type="string">Site</item>
169+
<item name="default" xsi:type="number">0</item>
170+
</item>
171+
</argument>
172+
<settings>
173+
<dataType>boolean</dataType>
174+
<label translate="true">Enable Blog</label>
175+
<dataScope>enable_blog</dataScope>
176+
<validation>
177+
<rule name="required-entry" xsi:type="boolean">false</rule>
178+
</validation>
179+
<switcherConfig>
180+
<enabled>true</enabled>
181+
<rules>
182+
<rule name="0">
183+
<value>0</value>
184+
<actions>
185+
<action name="0">
186+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_prefix</target>
187+
<callback>hide</callback>
188+
</action>
189+
<action name="1">
190+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_stores</target>
191+
<callback>hide</callback>
192+
</action>
193+
</actions>
194+
</rule>
195+
<rule name="1">
196+
<value>1</value>
197+
<actions>
198+
<action name="0">
199+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_prefix</target>
200+
<callback>show</callback>
201+
</action>
202+
<action name="1">
203+
<target>mooore_wordpressintegration_site_form.mooore_wordpressintegration_site_form.blog.blog_stores</target>
204+
<callback>show</callback>
205+
</action>
206+
</actions>
207+
</rule>
208+
</rules>
209+
</switcherConfig>
210+
</settings>
211+
<formElements>
212+
<checkbox>
213+
<settings>
214+
<valueMap>
215+
<map name="false" xsi:type="number">0</map>
216+
<map name="true" xsi:type="number">1</map>
217+
</valueMap>
218+
<prefer>toggle</prefer>
219+
</settings>
220+
</checkbox>
221+
</formElements>
222+
</field>
223+
<field formElement="input" name="blog_prefix" sortOrder="20">
224+
<argument name="data" xsi:type="array">
225+
<item name="config" xsi:type="array">
226+
<item name="source" xsi:type="string">Site</item>
227+
</item>
228+
</argument>
229+
<settings>
230+
<dataType>text</dataType>
231+
<label translate="true">Blog Route Prefix</label>
232+
<dataScope>blog_prefix</dataScope>
233+
<notice translate="true">Allows you to set a default blog prefix, for example "/blog", leave this field empty to disable this feature.</notice>
234+
<validation>
235+
<rule name="required-entry" xsi:type="boolean">false</rule>
236+
</validation>
237+
</settings>
238+
</field>
239+
<field name="blog_stores" sortOrder="30">
240+
<argument name="data" xsi:type="array">
241+
<item name="options" xsi:type="object">Magento\Cms\Ui\Component\Listing\Column\Cms\Options</item>
242+
<item name="config" xsi:type="array">
243+
<item name="dataType" xsi:type="string">int</item>
244+
<item name="label" xsi:type="string" translate="true">Store View</item>
245+
<item name="formElement" xsi:type="string">multiselect</item>
246+
<item name="source" xsi:type="string">page</item>
247+
<item name="dataScope" xsi:type="string">blog_stores</item>
248+
<item name="default" xsi:type="string">0</item>
249+
<item name="validation" xsi:type="array">
250+
<item name="required-entry" xsi:type="boolean">true</item>
251+
</item>
252+
</item>
253+
</argument>
254+
<settings>
255+
<notice translate="true">Select which stores you want this blog site to be enabled.</notice>
256+
</settings>
257+
</field>
258+
</fieldset>
133259
</form>

0 commit comments

Comments
 (0)