diff --git a/administrator/language/en-GB/en-GB.plg_sampledata_multilang.ini b/administrator/language/en-GB/en-GB.plg_sampledata_multilang.ini index b471c7da3ff55..11094c95162d7 100644 --- a/administrator/language/en-GB/en-GB.plg_sampledata_multilang.ini +++ b/administrator/language/en-GB/en-GB.plg_sampledata_multilang.ini @@ -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 - Multilingual" 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." @@ -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" 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.
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" @@ -24,7 +27,7 @@ PLG_SAMPLEDATA_MULTILANG_STEP2_SUCCESS="Step 2: The Language Switcher module has PLG_SAMPLEDATA_MULTILANG_STEP3_SUCCESS="Step 3: All Content Languages have been published!" PLG_SAMPLEDATA_MULTILANG_STEP4_SUCCESS="Step 4: Specific Main Menus have been created as well as associated 'List All Categories' menu items!" PLG_SAMPLEDATA_MULTILANG_STEP5_SUCCESS="Step 5: Specific Main Menus modules have been created!" -PLG_SAMPLEDATA_MULTILANG_STEP6_SUCCESS="Step 6: Categories, articles and 'Category Blog' menu items have been created and associated!" +PLG_SAMPLEDATA_MULTILANG_STEP6_SUCCESS="Step 6: Workflow, categories, articles and 'Category Blog' menu items have been created and associated!" PLG_SAMPLEDATA_MULTILANG_STEP7_SUCCESS="Step 7: The Main Menu Module containing the Home menu item set to ALL languages has been unpublished!" PLG_SAMPLEDATA_MULTILANG_STEP8_SUCCESS="Multilingual Sample Data has been installed!" PLG_SAMPLEDATA_MULTILANG_STEP_FAILED="Step %1$u Failed: %2$s" diff --git a/plugins/sampledata/multilang/multilang.php b/plugins/sampledata/multilang/multilang.php index 40087c4270818..4ff1e2a362b14 100644 --- a/plugins/sampledata/multilang/multilang.php +++ b/plugins/sampledata/multilang/multilang.php @@ -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 @@ -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. * @@ -366,11 +367,30 @@ 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(); + if (!$tableWorkflow = $this->addWorkflow()) + { + $response = array(); + $response['success'] = false; + $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_WORKFLOW', 6); + + return $response; + } + foreach ($siteLanguages as $siteLang) { - if (!$tableCategory = $this->addCategory($siteLang)) + + if (!$tableCategory = $this->addCategory($siteLang, $tableWorkflow->id)) { $response = array(); $response['success'] = false; @@ -381,7 +401,7 @@ public function onAjaxSampledataApplyStep6() $groupedAssociations['com_categories.item'][$siteLang->language] = $tableCategory->id; - if (!$tableArticle = $this->addArticle($siteLang, $tableCategory->id)) + if (!$tableArticle = $this->addArticle($siteLang, $tableCategory->id, $tableWorkflow->stageId)) { $response = array(); $response['success'] = false; @@ -961,16 +981,50 @@ private function addModuleInModuleMenu($moduleId) return true; } + /** + * Method to create a workflow for a specific language. + * + * @return JTable|boolean Workflow Object. False otherwise. + * + * @since __DEPLOY_VERSION__ + */ + public function addWorkflow() + { + $workflowModel = new WorkflowModel; + + $workflow = [ + 'title' => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_TITLE'), + 'description' => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_DESCRIPTION'), + 'published' => 1, + 'extension' => 'com_content' + ]; + + $workflowModel->save($workflow); + + $workflow = $workflowModel->getItem(); + + $query = $this->db->getQuery(true) + ->select($this->db->quoteName('id')) + ->from($this->db->quoteName('#__workflow_stages')) + ->where($this->db->quoteName('workflow_id') . ' = ' . (int) $workflow->id) + ->where($this->db->quoteName('default') . ' = 1'); + + $workflow->stageId = (int) $this->db->setQuery($query)->loadResult(); + + return $workflow; + } + /** * Method to create a category for a specific language. * * @param stdClass $itemLanguage Language Object. + * @param stdClass $workflowId Workflow ID for this category. * * @return JTable|boolean Category Object. False otherwise. * * @since 4.0.0 */ - public function addCategory($itemLanguage) + public function addCategory($itemLanguage, $workflowId = 0) { $newlanguage = new Language($itemLanguage->language, false); $newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true); @@ -985,7 +1039,7 @@ public function addCategory($itemLanguage) 'description' => '', 'published' => 1, 'access' => 1, - 'params' => '{"target":"","image":""}', + 'params' => '{"target":"","image":"", "workflow_id":"' . (int) $workflowId . '"}', 'metadesc' => '', 'metakey' => '', 'metadata' => '{"page_title":"","author":"","robots":""}', @@ -1028,12 +1082,13 @@ public function addCategory($itemLanguage) * * @param stdClass $itemLanguage Language Object. * @param integer $categoryId The id of the category where we want to add the article. + * @param integer $stageId The id of the initial stage. * * @return JTable|boolean Article Object. False otherwise. * * @since 4.0.0 */ - private function addArticle($itemLanguage, $categoryId) + private function addArticle($itemLanguage, $categoryId, $stageId) { $db = Factory::getDbo(); @@ -1057,7 +1112,6 @@ private function addArticle($itemLanguage, $categoryId) . 'debet libris consulatu.

', 'images' => json_encode(array()), 'urls' => json_encode(array()), - 'state' => 1, 'created' => $currentDate, 'created_by' => (int) $this->getAdminId(), 'created_by_alias' => 'Joomla', @@ -1110,6 +1164,21 @@ private function addArticle($itemLanguage, $categoryId) return false; } + $assoc = new stdClass; + + $assoc->item_id = $newId; + $assoc->stage_id = $stageId; + $assoc->extension = 'com_content'; + + try + { + $db->insertObject('#__workflow_associations', $assoc); + } + catch (JDatabaseExceptionExecuting $e) + { + return false; + } + return $article; }