Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Implement the workflow into the blog sample data #21953

Merged
merged 3 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.plg_sampledata_blog.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_5_INTROTEXT="<p>Templates control
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_5_TITLE="Your Template"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_0_TITLE="Blog"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE="Help"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_0_DESCRIPTION="A sample workflow for the blog sample datas"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> data

PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_0_TITLE="Sample Workflow"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE="Blog"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_1_TITLE="About"
PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_2_TITLE="Author Login"
Expand Down
42 changes: 35 additions & 7 deletions plugins/sampledata/blog/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

defined('_JEXEC') or die;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Workflow\Administrator\Model\WorkflowModel;

/**
* Sampledata - Blog Plugin
Expand Down Expand Up @@ -110,6 +111,34 @@ public function onAjaxSampledataApplyStep1()
$language = Multilanguage::isEnabled() ? Factory::getLanguage()->getTag() : '*';
$langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';

// Create a sample workflow
$workflowModel = new WorkflowModel;

$workflow = [
'title' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_0_TITLE'),
'description' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_0_DESCRIPTION'),
'published' => 1,
'extension' => 'com_content'
];

try
{
if (!$workflowModel->save($workflow))
{
throw new Exception($workflowModel->getError());
}
}
catch (Exception $e)
{
$response = array();
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());

return $response;
}

$workflow_id = (int) $workflowModel->getItem()->id;

// Create "blog" category.
$categoryModel = new \Joomla\Component\Categories\Administrator\Model\CategoryModel;
$catIds = array();
Expand Down Expand Up @@ -137,7 +166,7 @@ public function onAjaxSampledataApplyStep1()
'associations' => array(),
'description' => '',
'language' => $language,
'params' => '',
'params' => '{"workflow_id": "' . $workflow_id . '"}',
);

try
Expand Down Expand Up @@ -184,7 +213,7 @@ public function onAjaxSampledataApplyStep1()
'associations' => array(),
'description' => '',
'language' => $language,
'params' => '',
'params' => '{"workflow_id": "' . $workflow_id . '"}',
);

try
Expand Down Expand Up @@ -260,7 +289,6 @@ public function onAjaxSampledataApplyStep1()

$article['language'] = $language;
$article['associations'] = array();
$article['state'] = 1;
$article['featured'] = 0;
$article['images'] = '';
$article['metakey'] = '';
Expand Down