Skip to content

Commit

Permalink
Implement the workflow into the multilang sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
bembelimen committed Sep 2, 2018
1 parent f4a4f2a commit ed4d66c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
Expand Up @@ -4,6 +4,8 @@
; Note : All ini files need to be saved as UTF-8

PLG_SAMPLEDATA_MULTILANG="Sample Data - Multilingual"
PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_DESCRIPTION="A sample workflow for \"Sample Data - Multilingual\""
PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_TITLE="Sample Workflow"
PLG_SAMPLEDATA_MULTILANG_ERROR_ALLCATEGORIES="Step %1$u: Failed creating the 'List All Categories (%2$s)' menu item."
PLG_SAMPLEDATA_MULTILANG_ERROR_ARTICLE="Step %1$u: Failed creating the Article (%2$s)."
PLG_SAMPLEDATA_MULTILANG_ERROR_ASSOC_ALLCATEGORIES="Step %1$u: Failed associating the 'List All Categories' menu items."
Expand All @@ -16,6 +18,7 @@ PLG_SAMPLEDATA_MULTILANG_ERROR_MAINMENU_MODULE="Step %1$u: Failed unpublishing t
PLG_SAMPLEDATA_MULTILANG_ERROR_MENUMODULES="Step %1$u: Failed creating the %2$s menu module."
PLG_SAMPLEDATA_MULTILANG_ERROR_MENUS="Step %1$u: Failed creating the Main menu (%2$s)."
PLG_SAMPLEDATA_MULTILANG_ERROR_SWITCHER="Step %1$u: Failed creating and enabling the %2$s."
PLG_SAMPLEDATA_MULTILANG_ERROR_WORKFLOW="Step %1$u: Failed creating the Workflow (%2$s)"
PLG_SAMPLEDATA_MULTILANG_MISSING_LANGUAGE="The site should have at least 2 languages installed and their content languages created."
PLG_SAMPLEDATA_MULTILANG_OVERVIEW_DESC="Sample data which will set up a multilingual site.<br>Before launching, make sure you have at least 2 languages installed with their Content Languages and that no sample data has been installed."
PLG_SAMPLEDATA_MULTILANG_OVERVIEW_TITLE="Multilingual Sample Data"
Expand Down
58 changes: 54 additions & 4 deletions plugins/sampledata/multilang/multilang.php
Expand Up @@ -20,6 +20,7 @@
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Table\Table;
use Joomla\Component\Workflow\Administrator\Model\WorkflowModel;

/**
* Sampledata - Multilang Plugin
Expand Down Expand Up @@ -335,7 +336,7 @@ public function onAjaxSampledataApplyStep5()
}

/**
* Sixth step to add categories, articles and blog menu items
* Sixth step to add workflow, categories, articles and blog menu items
*
* @return array or void Will be converted into the JSON response to the module.
*
Expand Down Expand Up @@ -366,11 +367,29 @@ public function onAjaxSampledataApplyStep6()
return $response;
}

if (!ComponentHelper::isEnabled('com_workflow'))
{
$response = array();
$response['success'] = true;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 6, 'com_workflow');

return $response;
}

$siteLanguages = $this->getInstalledlangsFrontend();

foreach ($siteLanguages as $siteLang)
{
if (!$tableCategory = $this->addCategory($siteLang))
if (!$tableWorkflow = $this->addWorkflow($siteLang))
{
$response = array();
$response['success'] = false;
$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_WORKFLOW', 6, $siteLang->language);

return $response;
}

if (!$tableCategory = $this->addCategory($siteLang, $tableWorkflow->id))
{
$response = array();
$response['success'] = false;
Expand Down Expand Up @@ -961,16 +980,47 @@ private function addModuleInModuleMenu($moduleId)
return true;
}

/**
* Method to create a workflow for a specific language.
*
* @param stdClass $itemLanguage Language Object.
*
* @return JTable|boolean Workflow Object. False otherwise.
*
* @since __DEPLOY_VERSION__
*/
public function addWorkflow($itemLanguage)
{
$newlanguage = new Language($itemLanguage->language, false);
$newlanguage->load('plg_sampledata_multilang', JPATH_ADMINISTRATOR, $itemLanguage->language, true);

$workflowModel = new WorkflowModel;

$workflow = [
'title' => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_TITLE') . ' (' . strtolower($itemLanguage->language) . ')',
'description' => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_DESCRIPTION'),
'published' => 1,
'extension' => 'com_content'
];

$workflowModel->save($workflow);

$workflow = $workflowModel->getItem();

return $workflow;
}

/**
* Method to create a category for a specific language.
*
* @param stdClass $itemLanguage Language Object.
* @param stdClass $workflow_id Workflow ID for this category.
*
* @return JTable|boolean Category Object. False otherwise.
*
* @since 4.0.0
*/
public function addCategory($itemLanguage)
public function addCategory($itemLanguage, $workflow_id = 0)
{
$newlanguage = new Language($itemLanguage->language, false);
$newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
Expand All @@ -985,7 +1035,7 @@ public function addCategory($itemLanguage)
'description' => '',
'published' => 1,
'access' => 1,
'params' => '{"target":"","image":""}',
'params' => '{"target":"","image":"", "workflow_id":"' . (int) $workflow_id . '"}',
'metadesc' => '',
'metakey' => '',
'metadata' => '{"page_title":"","author":"","robots":""}',
Expand Down

0 comments on commit ed4d66c

Please sign in to comment.