Skip to content

Commit c690800

Browse files
authored
Merge pull request #90 from ihor-klymchuk/master
Added short description field to blog post
2 parents 9df4309 + c60dcde commit c690800

File tree

4 files changed

+57
-25
lines changed

4 files changed

+57
-25
lines changed

Model/Post.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @method string getIdentifier()
2727
* @method $this setIdentifier(string $value)
2828
* @method string getContent()
29+
* @method string getShortContent()
2930
* @method $this setContent(string $value)
3031
* @method string getContentHeading()
3132
* @method $this setContentHeading(string $value)
@@ -383,35 +384,41 @@ public function getShortFilteredContent()
383384
{
384385
$key = 'short_filtered_content';
385386
if (!$this->hasData($key)) {
386-
$content = $this->getFilteredContent();
387-
$pageBraker = '<!-- pagebreak -->';
388-
389-
$p = mb_strpos($content, $pageBraker);
390-
if (!$p) {
391-
$p = (int) $this->scopeConfig->getValue(
392-
'mfblog/post_list/shortcotent_length',
393-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
387+
if ($this->getShortContent()) {
388+
$content = $this->filterProvider->getPageFilter()->filter(
389+
$this->getShortContent()
394390
);
395-
}
391+
} else {
392+
$content = $this->getFilteredContent();
393+
$pageBraker = '<!-- pagebreak -->';
394+
395+
$p = mb_strpos($content, $pageBraker);
396+
if (!$p) {
397+
$p = (int)$this->scopeConfig->getValue(
398+
'mfblog/post_list/shortcotent_length',
399+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
400+
);
401+
}
396402

397-
if ($p) {
398-
$content = mb_substr($content, 0, $p);
399-
try {
400-
libxml_use_internal_errors(true);
401-
$dom = new \DOMDocument();
402-
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
403-
$body = $dom->getElementsByTagName('body');
404-
if ( $body && $body->length > 0 ) {
405-
$body = $body->item(0);
406-
$_content = new \DOMDocument;
407-
foreach ($body->childNodes as $child){
408-
$_content->appendChild($_content->importNode($child, true));
403+
if ($p) {
404+
$content = mb_substr($content, 0, $p);
405+
try {
406+
libxml_use_internal_errors(true);
407+
$dom = new \DOMDocument();
408+
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
409+
$body = $dom->getElementsByTagName('body');
410+
if ($body && $body->length > 0) {
411+
$body = $body->item(0);
412+
$_content = new \DOMDocument;
413+
foreach ($body->childNodes as $child) {
414+
$_content->appendChild($_content->importNode($child, true));
415+
}
416+
$content = $_content->saveHTML();
409417
}
410-
$content = $_content->saveHTML();
418+
} catch (\Exception $e) {
411419
}
412-
} catch (\Exception $e) {}
420+
}
413421
}
414-
415422
$this->setData($key, $content);
416423
}
417424

Setup/UpgradeSchema.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
341341

342342
}
343343

344+
if (version_compare($version, '2.5.3') < 0) {
345+
$connection->addColumn(
346+
$setup->getTable('magefan_blog_post'),
347+
'short_content',
348+
[
349+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
350+
'length' => '2M',
351+
'nullable' => true,
352+
'comment' => 'Post short content',
353+
]
354+
);
355+
}
356+
344357
$setup->endSetup();
345358
}
346359
}

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
-->
1010
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
11-
<module name="Magefan_Blog" setup_version="2.5.2">
11+
<module name="Magefan_Blog" setup_version="2.5.3">
1212
<sequence>
1313
<module name="Magento_Cms"/>
1414
<module name="Magento_Catalog"/>

view/adminhtml/ui_component/blog_post_form.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@
176176
</item>
177177
</argument>
178178
</field>
179+
<field name="short_content">
180+
<argument name="data" xsi:type="array">
181+
<item name="config" xsi:type="array">
182+
<item name="label" xsi:type="string" translate="true">Short Content</item>
183+
<item name="formElement" xsi:type="string">wysiwyg</item>
184+
<item name="source" xsi:type="string">post</item>
185+
<item name="wysiwyg" xsi:type="boolean">true</item>
186+
<item name="dataScope" xsi:type="string">short_content</item>
187+
<item name="sortOrder" xsi:type="number">60</item>
188+
</item>
189+
</argument>
190+
</field>
179191
</fieldset>
180192
<fieldset name="additional_options">
181193
<argument name="data" xsi:type="array">

0 commit comments

Comments
 (0)